Esempio n. 1
0
 def test_9(self):
     pcbms = []
     for i in range(3):
         pcbms.append(
             create_mock_full({"sig_pack()": bytes("pcbm %i" % i,
                                                   "ascii")}))
     inst = ASMarking(
         create_mock_full({
             "isdas": _ISD_AS1,
             "trcVer": 2,
             "certVer": 3,
             "ifIDSize": 4,
             "hashTreeRoot": b"root",
             "mtu": 1482,
             "chain": b"chain"
         }))
     inst.iter_pcbms = create_mock_full(return_value=pcbms)
     expected = b"".join([
         _ISD_AS1_BYTES,
         bytes.fromhex("00000002 00000003 04"), b"pcbm 0", b"pcbm 1",
         b"pcbm 2", b"root",
         bytes.fromhex("05ca"), b"chain"
     ])
     # Call
     ntools.eq_(inst.sig_pack(8), expected)
Esempio n. 2
0
    def test_with_revocation(self, skip_peer):
        up_pcbms, down_pcbms = self._mk_pcbms()
        p = create_mock_full({"hashTreeRoot": b"1234"})
        up_asm = create_mock_full({"isd_as()": "1-1",
                                   "iter_pcbms()": up_pcbms,
                                   "p": p})
        down_asm = create_mock_full({"isd_as()": "2-1",
                                     "iter_pcbms()": down_pcbms,
                                     "p": p})
        up_peer_rev = create_mock()
        down_peer_rev = create_mock()
        peer_revs = create_mock(["get"])

        def get_side_effect(key):
            data = {("1-1", 3): up_peer_rev, ("2-1", 3): down_peer_rev}
            return data.get(key)

        peer_revs.get.side_effect = get_side_effect

        def skip_peer_side_effect(rev, ht_root):
            if rev in [up_peer_rev, down_peer_rev] and ht_root == b"1234":
                return True
            return False
        skip_peer.side_effect = skip_peer_side_effect

        # Call
        peers = path_combinator._find_peer_hfs(up_asm, down_asm, peer_revs)
        # Tests
        ntools.eq_(peers, [(up_pcbms[0].hof(), down_pcbms[0].hof(), 500)])
        skip_peer.assert_has_calls(
            [call(None, b"1234"), call(up_peer_rev, b"1234")], any_order=True)
Esempio n. 3
0
 def test_full(self, p_cls):
     msg = p_cls.new_message.return_value
     pcbms = []
     for i in range(3):
         pcbms.append(create_mock_full({"p": "pcbm %d" % i}))
     cchain = create_mock_full({"pack()": "cchain"})
     # Call
     ASMarking.from_values(_ISD_AS1,
                           2,
                           3,
                           pcbms,
                           "root",
                           "mtu",
                           cchain,
                           ifid_size=14)
     # Tests
     p_cls.new_message.assert_called_once_with(isdas=_ISD_AS1,
                                               trcVer=2,
                                               certVer=3,
                                               ifIDSize=14,
                                               hashTreeRoot="root",
                                               mtu="mtu",
                                               chain="cchain")
     msg.init.assert_called_once_with("pcbms", 3)
     for i, pcbm in enumerate(msg.pcbms):
         ntools.eq_("pcbm %d" % i, pcbm)
Esempio n. 4
0
    def test_with_revocation(self):
        up_pcbms, down_pcbms = self._mk_pcbms()
        up_asm = create_mock_full({
            "isd_as()": "1-ff00:0:300",
            "iter_pcbms()": up_pcbms
        })
        down_asm = create_mock_full({
            "isd_as()": "2-ff00:0:321",
            "iter_pcbms()": down_pcbms
        })
        up_peer_rev = create_mock()
        down_peer_rev = create_mock()
        peer_revs = create_mock(["get"])

        def get_side_effect(key):
            data = {
                ("1-ff00:0:300", 3): up_peer_rev,
                ("2-ff00:0:321", 3): down_peer_rev
            }
            return data.get(key)

        peer_revs.get.side_effect = get_side_effect

        # Call
        peers = path_combinator._find_peer_hfs(up_asm, down_asm, peer_revs)
        # Tests
        ntools.eq_(peers, [(up_pcbms[0].hof(), down_pcbms[0].hof(), 500)])
Esempio n. 5
0
 def _check_up_down(self, up):
     asms = []
     ifid = 0
     for i in range(1, 4):
         if up:
             hof = create_mock_full({
                 "egress_if": ifid,
                 "ingress_if": ifid + 1
             })
             if i == 3:
                 hof.ingress_if = 0
         else:
             hof = create_mock_full({
                 "egress_if": ifid + 1,
                 "ingress_if": ifid
             })
             if i == 3:
                 hof.egress_if = 0
         ifid += 2
         pcbm = create_mock_full({"hof()": hof})
         asms.append(create_mock_full({"isd_as()": i, "pcbm()": pcbm}))
     if_list = path_combinator._build_interface_list(asms, up)
     ntools.eq_(if_list, [
         PathInterface.from_values(1, 1),
         PathInterface.from_values(2, 2),
         PathInterface.from_values(2, 3),
         PathInterface.from_values(3, 4)
     ])
Esempio n. 6
0
 def _check_up_down(self, up):
     asms = []
     ifid = 0
     for i in range(1, 4):
         if up:
             hof = create_mock_full({
                 "egress_if": ifid,
                 "ingress_if": ifid + 1
             })
             if i == 3:
                 hof.ingress_if = 0
         else:
             hof = create_mock_full({
                 "egress_if": ifid + 1,
                 "ingress_if": ifid
             })
             if i == 3:
                 hof.egress_if = 0
         ifid += 2
         pcbm = create_mock_full({"hof()": hof})
         asms.append(create_mock_full({"isd_as()": i, "pcbm()": pcbm}))
     path = create_mock(["interfaces"])
     path.interfaces = []
     PathCombinator._add_interfaces(path, asms, up)
     ntools.eq_(path.interfaces, [(1, 1), (2, 2), (2, 3), (3, 4)])
Esempio n. 7
0
 def test_full(self, p_cls):
     msg = p_cls.new_message.return_value
     pcbms = []
     for i in range(3):
         pcbms.append(create_mock_full({"p": "pcbm %d" % i}))
     exts = []
     exts.append(
         create_mock_full({
             "EXT_TYPE": ASMExtType.ROUTING_POLICY,
             "p": {
                 "polType": RoutingPolType.ALLOW_AS,
                 "itf": 0,
                 "isdases": [_ISD_AS1]
             }
         }))
     # Call
     ASMarking.from_values(_ISD_AS1,
                           2,
                           3,
                           pcbms,
                           "root",
                           "mtu",
                           exts,
                           ifid_size=14)
     # Tests
     p_cls.new_message.assert_called_once_with(isdas=_ISD_AS1,
                                               trcVer=2,
                                               certVer=3,
                                               ifIDSize=14,
                                               hashTreeRoot="root",
                                               mtu="mtu")
     msg.init.assert_called_once_with("hops", 3)
     for i, pcbm in enumerate(msg.pcbms):
         ntools.eq_("pcbm %d" % i, pcbm)
Esempio n. 8
0
 def test(self, hash_func_for_type):
     # Setup
     siblings = []
     siblings.append(create_mock_full({"isLeft": True, "hash": "10s10"}))
     siblings.append(create_mock_full({"isLeft": False, "hash": "30s300"}))
     p = create_mock_full({
         "ifID": 2,
         "epoch": 0,
         "nonce": b"s20",
         "siblings": siblings,
         "prevRoot": "p",
         "nextRoot": "n",
         "hashType": 0
     })
     rev_info = create_mock_full({"p": p})
     hashes = [
         "20s20", "10s1020s20", "10s1020s2030s300", "p10s1020s2030s300",
         "10s1020s2030s300n"
     ]
     hash_func = create_mock_full(side_effect=hashes)
     hash_func_for_type.return_value = hash_func
     # Call
     hash01, hash12 = ConnectedHashTree.get_possible_hashes(rev_info)
     # Tests
     ntools.eq_(hash01, "p10s1020s2030s300")
     ntools.eq_(hash12, "10s1020s2030s300n")
Esempio n. 9
0
 def test_full(self, p_cls):
     msg = p_cls.new_message.return_value
     pcbms = []
     for i in range(3):
         pcbms.append(create_mock_full({"p": "pcbm %d" % i}))
     cchain = create_mock_full({"pack()": "cchain"})
     revs = []
     for i in range(2):
         revs.append(create_mock_full({"pack()": "rev %d" % i}))
     # Call
     ASMarking.from_values("isdas",
                           2,
                           3,
                           pcbms,
                           "eg rev token",
                           "mtu",
                           cchain,
                           ifid_size=14,
                           rev_infos=revs)
     # Tests
     p_cls.new_message.assert_called_once_with(isdas="isdas",
                                               trcVer=2,
                                               certVer=3,
                                               ifIDSize=14,
                                               egRevToken="eg rev token",
                                               mtu="mtu",
                                               chain="cchain")
     msg.init.assert_called_once_with("pcbms", 3)
     msg.exts.init.assert_called_once_with("revInfos", 2)
     for i, pcbm in enumerate(msg.pcbms):
         ntools.eq_("pcbm %d" % i, pcbm)
     for i, rev in enumerate(msg.exts.revInfos):
         ntools.eq_("rev %d" % i, rev)
Esempio n. 10
0
 def test_9(self):
     pcbms = []
     for i in range(3):
         pcbms.append(
             create_mock_full({"sig_pack()": bytes("pcbm %i" % i,
                                                   "ascii")}))
     exts = create_mock_full({"revInfos": [b"rev0", b"rev1"]})
     inst = ASMarking(
         create_mock_full({
             "isdas": "isdas",
             "trcVer": 2,
             "certVer": 3,
             "ifIDSize": 4,
             "egRevToken": b"eg rev",
             "exts": exts,
             "mtu": 1482,
             "chain": b"chain",
         }))
     inst.iter_pcbms = create_mock_full(return_value=pcbms)
     expected = b"".join([
         b"isdas",
         bytes.fromhex("00000002 00000003 04"), b"pcbm 0", b"pcbm 1",
         b"pcbm 2", b"eg rev", b"rev0", b"rev1",
         bytes.fromhex("05ca"), b"chain"
     ])
     # Call
     ntools.eq_(inst.sig_pack(9), expected)
Esempio n. 11
0
 def _setup(self):
     asms = []
     for i in range(3):
         pcbm = create_mock_full({"hof()": "hof %d" % i})
         asms.append(create_mock_full({"pcbm()": pcbm}))
     inst = PathSegment(None)
     inst.iter_asms = create_mock_full(return_value=asms)
     return inst
Esempio n. 12
0
 def _setup(self):
     inst = PathSegment({})
     inst.get_all_iftokens = create_mock_full(return_value=("t0", "t1"))
     h = create_mock_full({
         'update()': None,
         'digest()': "digest",
         'hexdigest()': "hexdigest"
     })
     return inst, h
Esempio n. 13
0
 def _setup_connector(self, response, cache=None, remaining_keys=None):
     cache = cache or {}
     remaining_keys = remaining_keys or set()
     counter = create_mock_full({"inc()": self.REQ_ID})
     connector = SCIONDConnector("addr", counter)
     connector._create_socket = create_mock()
     connector._get_response = create_mock_full(return_value=response)
     connector._try_cache = create_mock_full(return_value=(remaining_keys,
                                                           cache))
     return connector
Esempio n. 14
0
 def _create_entries(self, descs):
     response_entries = []
     for desc in descs:
         p = create_mock_full({"ifID": desc[0], "hostInfo": desc[1]})
         response_entries.append(
             create_mock_full({
                 "p": p,
                 "host_info()": desc[1]
             }))
     return response_entries
Esempio n. 15
0
 def _setup_connector(self, svc_info_desc=None):
     counter = create_mock_full({"inc()": 1})
     connector = SCIONDConnector("addr", counter)
     if svc_info_desc:
         svc_info = create_mock_full({"host_info()": svc_info_desc[1]})
         connector.get_service_info = create_mock_full(
             return_value={svc_info_desc[0]: svc_info})
     else:
         connector.get_service_info = create_mock()
     return connector
Esempio n. 16
0
 def test(self):
     up_pcbms, down_pcbms = self._mk_pcbms()
     up_asm = create_mock_full({"isd_as()": "1-ff00:0:300", "iter_pcbms()": up_pcbms})
     down_asm = create_mock_full({"isd_as()": "2-ff00:0:321",
                                  "iter_pcbms()": down_pcbms})
     peer_revs = create_mock_full({"get()": None})
     # Call
     ntools.eq_(path_combinator._find_peer_hfs(up_asm, down_asm, peer_revs),
                [(up_pcbms[0].hof(), down_pcbms[0].hof(), 500),
                 (up_pcbms[2].hof(), down_pcbms[1].hof(), 700)])
Esempio n. 17
0
 def test_outdated(self, db_rec):
     inst = PathSegmentDB()
     pcb = self._mk_pcb(-1)
     cur_rec = create_mock_full({"pcb": self._mk_pcb(0)})
     inst._db = create_mock_full(return_value={0: {'record': cur_rec}})
     record = create_mock_full({'id': "idstr"})
     db_rec.return_value = record
     # Call
     ntools.eq_(inst.update(pcb), DBResult.NONE)
     # Tests
     pcb.get_expiration_time.assert_called_once_with()
     cur_rec.pcb.get_expiration_time.assert_called_once_with()
Esempio n. 18
0
 def test(self):
     inst = SCIONAddrHdr()
     inst.calc_lens = create_mock_full(return_value=(1, 3))
     inst.src = create_mock_full({"host": create_mock(["TYPE"])})
     inst.dst = create_mock_full({"host": create_mock(["TYPE"])})
     # Call
     inst.update()
     # Tests
     inst.calc_lens.assert_called_once_with(inst.dst.host.TYPE,
                                            inst.src.host.TYPE)
     ntools.eq_(inst._total_len, 1)
     ntools.eq_(inst._pad_len, 3)
Esempio n. 19
0
 def test_expired_entry(self):
     key = ("1-ff00:0:300", 1)
     default = "default"
     rev_info = "rev_info"
     srev_info = create_mock_full({"rev_info()": rev_info})
     rev_cache = RevCache()
     rev_cache._cache[key] = srev_info
     rev_cache._check_active = create_mock_full(return_value=False)
     # Call
     ntools.eq_(rev_cache.get(key, default=default), default)
     # Tests
     assert_these_calls(rev_cache._check_active, [call(srev_info)])
Esempio n. 20
0
 def test_add(self, db_rec):
     inst = PathSegmentDB()
     inst._db = create_mock_full({'insert()': None}, return_value=[])
     pcb = self._mk_pcb()
     record = create_mock_full({'id': "id str"})
     db_rec.return_value = record
     # Call
     ntools.eq_(inst.update(pcb), DBResult.ENTRY_ADDED)
     # Tests
     db_rec.assert_called_once_with(pcb)
     inst._db.assert_called_once_with(id="id str", sibra=True)
     inst._db.insert.assert_called_once_with(record, "id str", 1, 2, 3, 4,
                                             True)
Esempio n. 21
0
 def test_3(self, _):
     asms = []
     for i in range(3):
         asms.append(
             create_mock_full({"sig_pack()": bytes("asm %i" % i, "ascii")}))
     inst = PathSegment(create_mock_full({"info": b"info"}))
     inst.is_sibra = create_mock_full()
     inst.iter_asms = create_mock_full(return_value=asms)
     inst.sibra_ext = create_mock_full({"sig_pack()": b"sibraext"})
     expected = b"".join(
         [b"info", b"asm 0", b"asm 1", b"asm 2", b"sibraext"])
     # Call
     ntools.eq_(inst.sig_pack(3), expected)
Esempio n. 22
0
 def test(self):
     up_pcbms, down_pcbms = self._mk_pcbms()
     p = create_mock_full({"hashTreeRoot": b"1234"})
     up_asm = create_mock_full({"isd_as()": "1-1", "iter_pcbms()": up_pcbms,
                                "p": p})
     down_asm = create_mock_full({"isd_as()": "2-1",
                                  "iter_pcbms()": down_pcbms,
                                  "p": p})
     peer_revs = create_mock_full({"get()": None})
     # Call
     ntools.eq_(path_combinator._find_peer_hfs(up_asm, down_asm, peer_revs),
                [(up_pcbms[0].hof(), down_pcbms[0].hof(), 500),
                 (up_pcbms[2].hof(), down_pcbms[1].hof(), 700)])
Esempio n. 23
0
    def test_peer(self, find):
        up_asms = [
            create_mock_full({"isd_as()": "1-1"}),  # peers with 1-10
            create_mock_full({"isd_as()": "1-2"}),  # peers with 1-12
            create_mock_full({"isd_as()": "1-3"}),
        ]
        up_seg = create_mock_full({
            "iter_asms()": up_asms,
            "get_rev_map()": {}
        })
        down_asms = [
            create_mock_full({"isd_as()": "1-10"}),  # peers with 1-1
            create_mock_full({"isd_as()": "1-11"}),
            create_mock_full({"isd_as()": "1-12"}),  # peers with 1-2
        ]
        down_seg = create_mock_full({
            "iter_asms()": down_asms,
            "get_rev_map()": {}
        })

        def matching_peers(a, b, c, d):
            return (a == up_asms[0]
                    and b == down_asms[0]) or (a == up_asms[1]
                                               and b == down_asms[2])

        find.side_effect = matching_peers
        # Call
        ntools.eq_(PathCombinator._get_xovr_peer(up_seg, down_seg),
                   (None, (2, 3)))
Esempio n. 24
0
 def _setup(self, l4_type):
     inst = SCIONL4Packet()
     inst._parse_pld_ctrl = create_mock()
     inst._parse_pld_ctrl.return_value = "pld ctrl"
     inst._parse_pld_scmp = create_mock()
     inst._parse_pld_scmp.return_value = "pld scmp"
     inst.set_payload = create_mock()
     inst._payload = create_mock(["pack"])
     if l4_type == L4Proto.UDP:
         inst.l4_hdr = create_mock_full({"TYPE": l4_type})
     elif l4_type == L4Proto.SCMP:
         inst.l4_hdr = create_mock_full({"TYPE": l4_type,
                                         "class_": "scmp_class", "type": "scmp_type"})
     return inst
Esempio n. 25
0
    def test_peer(self, find):
        up_asms = [
            create_mock_full({"isd_as()":
                              "1-ff00:0:300"}),  # peers with 1-ff00:0:310
            create_mock_full({"isd_as()":
                              "1-ff00:0:301"}),  # peers with 1-ff00:0:312
            create_mock_full({"isd_as()": "1-ff00:0:302"}),
        ]
        up_seg = create_mock_full({"iter_asms()": up_asms})
        down_asms = [
            create_mock_full({"isd_as()":
                              "1-ff00:0:310"}),  # peers with 1-ff00:0:300
            create_mock_full({"isd_as()": "1-ff00:0:311"}),
            create_mock_full({"isd_as()":
                              "1-ff00:0:312"}),  # peers with 1-ff00:0:301
        ]
        down_seg = create_mock_full({"iter_asms()": down_asms})
        peer_revs = create_mock()

        def matching_peers(a, b, c):
            return (a == up_asms[0]
                    and b == down_asms[0]) or (a == up_asms[1]
                                               and b == down_asms[2])

        find.side_effect = matching_peers
        # Call
        ntools.eq_(path_combinator._get_xovr_peer(up_seg, down_seg, peer_revs),
                   (None, (2, 3)))
Esempio n. 26
0
 def _mk_pcb(self, exp=0):
     ia = [
         {"isdas": ISD_AS("1-ff00:0:300"), "ingress_if": 1, "egress_if": 2},
         {"isdas": ISD_AS("1-ff00:0:301"), "ingress_if": 3, "egress_if": 4}
     ]
     asms = []
     for j in range(len(ia)):
         hof = create_mock_full(
             {'egress_if': ia[j]['egress_if'], 'ingress_if': ia[j]['ingress_if']})
         pcbm = create_mock_full({'hof()': hof})
         asms.append(create_mock_full({
             "isd_as()": ia[j]['isdas'], "pcbm()": pcbm}))
     pcb = create_mock_full(
         {"iter_asms()": asms, "short_desc()": "short desc"})
     return pcb
Esempio n. 27
0
 def _setup(self, src_type, haddr, saddr):
     inst = SCIONAddrHdr()
     inst.calc_lens = create_mock()
     inst.update = create_mock()
     data = create_mock_full({
         "pop()...": ("1-1", "2-2", "dst host", "src host"),
     })
     src_host = create_mock_full({"TYPE": src_type})
     src = create_mock_full({"host": src_host})
     haddr.side_effect = (
         create_mock_full({"LEN": 12}, return_value="dst haddr"),
         create_mock_full({"LEN": 34}, return_value="src haddr"),
     )
     saddr.side_effect = "dst", src
     return inst, data, src, "dst"
Esempio n. 28
0
 def _setup(self, time_, check_ret):
     check = create_mock_full(return_value=check_ret)
     fetch = create_mock()
     inst = RequestHandler("queue", check, fetch, "reply")
     inst._expire_reqs = create_mock()
     time_.return_value = 2
     return inst
Esempio n. 29
0
 def test_update(self, db_rec):
     inst = PathSegmentDB()
     pcb = self._mk_pcb(1)
     cur_rec = create_mock_full({
         "pcb": self._mk_pcb(0),
         "id": "cur rec",
         "exp_time": 44
     })
     inst._db = create_mock_full(return_value={0: {'record': cur_rec}})
     db_rec.return_value = create_mock_full({
         'id': "record",
         'exp_time': 32
     })
     # Call
     ntools.eq_(inst.update(pcb), DBResult.ENTRY_UPDATED)
     # Tests
     ntools.eq_(cur_rec.pcb, pcb)
Esempio n. 30
0
 def test(self, in_cksum):
     inst = SCIONUDPHeader()
     inst._dst = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"dsIA"}),
             "host": create_mock_full({"pack()": b"dstH"}),
         },
         class_=SCIONAddr)
     inst._src = create_mock_full(
         {
             "isd_as": create_mock_full({"pack()": b"srIA"}),
             "host": create_mock_full({"pack()": b"srcH"}),
         },
         class_=SCIONAddr)
     inst.pack = create_mock_full(return_value=b"packed with null checksum")
     payload = b"payload"
     expected_call = b"".join([
         b"dsIA",
         b"srIA",
         b"dstH",
         b"srcH",
         b"\x00",
         bytes([L4Proto.UDP]),
         b"packed with null checksum",
         payload,
     ])
     in_cksum.return_value = 0x3412
     # Call
     ntools.eq_(inst._calc_checksum(payload), bytes.fromhex("3412"))
     # Tests
     in_cksum.assert_called_once_with(expected_call)