Esempio n. 1
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. 2
0
 def _resolve_not_core_not_core_scion(self, dst_ia):
     """Resolve SCION path from non-core to non-core."""
     up_segs = self.up_segments()
     down_segs = self.down_segments(last_ia=dst_ia)
     core_segs = self._calc_core_segs(dst_ia[0], up_segs, down_segs)
     full_paths = PathCombinator.build_shortcut_paths(up_segs, down_segs)
     tuples = []
     for up_seg in up_segs:
         for down_seg in down_segs:
             tuples.append((up_seg, None, down_seg))
             for core_seg in core_segs:
                 tuples.append((up_seg, core_seg, down_seg))
     full_paths.extend(PathCombinator.tuples_to_full_paths(tuples))
     return full_paths
Esempio n. 3
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. 4
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()
        up_rev_map = {("1-1", 3): up_peer_rev}
        down_rev_map = {("2-1", 3): down_peer_rev}

        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 = PathCombinator._find_peer_hfs(up_asm, down_asm, up_rev_map,
                                              down_rev_map)
        # 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. 5
0
 def test_no_xovr_peer(self, get_xovr_peer):
     up = self._mk_seg(True)
     down = self._mk_seg(True)
     get_xovr_peer.return_value = None, None
     # Call
     ntools.assert_is_none(PathCombinator._build_shortcut_path(up, down))
     # Tests
     get_xovr_peer.assert_called_once_with(up, down)
Esempio n. 6
0
 def _check_xovrs_peers(self, xovr, peer, is_peer, get_xovr_peer, join_peer,
                        join_xovr):
     up = self._mk_seg(True)
     down = self._mk_seg(True)
     get_xovr_peer.return_value = xovr, peer
     # Call
     if is_peer:
         ntools.eq_(PathCombinator._build_shortcuts(up, down),
                    join_peer.return_value)
     else:
         ntools.eq_(PathCombinator._build_shortcuts(up, down),
                    join_xovr.return_value)
     # Tests
     if is_peer:
         join_peer.assert_called_once_with(up, down, peer)
     else:
         join_xovr.assert_called_once_with(up, down, xovr)
Esempio n. 7
0
 def test(self):
     up_iof = create_mock(["hops"])
     up_hofs = ["up hof 1", "up hof 2", "up hof 3"]
     down_iof = create_mock(["hops"])
     down_hofs = ["down hof"]
     ret = PathCombinator._shortcut_path_args(up_iof, up_hofs, down_iof,
                                              down_hofs)
     ntools.eq_(ret, [up_iof, up_hofs])
     ntools.eq_(up_iof.hops, 3)
Esempio n. 8
0
 def test(self, build_path):
     up_segments = ['up0', 'up1']
     down_segments = ['down0', 'down1']
     build_path.side_effect = ['path0', 'path1', None, 'path1']
     ntools.eq_(
         PathCombinator.build_shortcut_paths(up_segments, down_segments),
         ["path0", "path1"])
     calls = [call(*x) for x in product(up_segments, down_segments)]
     assert_these_calls(build_path, calls)
Esempio n. 9
0
 def _resolve_core_core(self, dst_ia, sibra=False):
     """Resolve path from core to core."""
     res = set()
     for cseg in self.core_segments(last_ia=self.addr.isd_as,
                                    sibra=sibra,
                                    **dst_ia.params()):
         res.add((None, cseg, None))
     if sibra:
         return res
     return PathCombinator.tuples_to_full_paths(res)
Esempio n. 10
0
 def test_xovr(self, build_list, path_args, copy_segment):
     up_segment, down_segment, point = self._setup(path_args, copy_segment)
     path = SCIONPath.from_values()
     path.mtu = 1400
     ntools.eq_(
         PathCombinator._join_xovr(up_segment, down_segment, point)[0],
         path)
     copy_segment.assert_any_call(up_segment, 1)
     copy_segment.assert_any_call(down_segment, 2, up=False)
     ntools.eq_(build_list.call_count, 1)
Esempio n. 11
0
 def test_copy_down(self, deepcopy, copy_hofs):
     seg = create_mock(["iter_asms", "info"])
     info = create_mock(["up_flag"])
     deepcopy.return_value = info
     copy_hofs.return_value = "hofs", None
     # Call
     ntools.eq_(PathCombinator._copy_segment(seg, False, False, up=False),
                (info, "hofs", None))
     # Tests
     copy_hofs.assert_called_once_with(seg.iter_asms.return_value,
                                       reverse=False)
Esempio n. 12
0
 def test_down(self, deepcopy, copy_hofs):
     seg, info, hofs, upstream_hof = self._setup(deepcopy, copy_hofs)
     # Call
     ntools.eq_(PathCombinator._copy_segment_shortcut(seg, 7, up=False),
                (info, hofs, upstream_hof, "mtu"))
     # Tests
     ntools.assert_false(info.up_flag)
     copy_hofs.assert_called_once_with(seg.iter_asms.return_value,
                                       reverse=False)
     ntools.eq_(hofs[0].xover, True)
     ntools.eq_(upstream_hof.verify_only, True)
Esempio n. 13
0
 def test_peer(self, find_peers, build_list, path_args, copy_segment):
     up_segment, down_segment, point = self._setup(path_args, copy_segment)
     find_peers.return_value = [("uph1", "dph1", 1500),
                                ("uph2", "dph2", 1500)]
     path = SCIONPath.from_values()
     path.mtu = 1400
     ntools.eq_(
         PathCombinator._join_peer(up_segment, down_segment, point)[0],
         path)
     copy_segment.assert_any_call(up_segment, 1)
     copy_segment.assert_any_call(down_segment, 2, up=False)
     ntools.eq_(build_list.call_count, 2)
Esempio n. 14
0
 def _check_xovrs_peers(self, xovr, peer, is_peer, get_xovr_peer,
                        join_shortcuts):
     up = self._mk_seg(True)
     down = self._mk_seg(True)
     get_xovr_peer.return_value = xovr, peer
     # Call
     ntools.eq_(PathCombinator._build_shortcut_path(up, down),
                join_shortcuts.return_value)
     # Tests
     expected = xovr
     if is_peer:
         expected = peer
     join_shortcuts.assert_called_once_with(up, down, expected, is_peer)
Esempio n. 15
0
    def _check_xovr_peers(self, peers, add_ifs):
        path = create_mock(["interfaces"])
        path.interfaces = []
        up_asm = create_mock_full({"isd_as()": 11})
        up_seg = create_mock_full({"iter_asms()": ["A", "B"], "asm()": up_asm})
        up_idx = 1
        down_asm = create_mock_full({"isd_as()": 12})
        down_seg = create_mock_full({
            "iter_asms()": ["C", "D"],
            "asm()": down_asm
        })
        down_idx = 2

        PathCombinator._build_interface_list(path, up_seg, up_idx, down_seg,
                                             down_idx, peers)
        assert_these_calls(
            add_ifs,
            [call(path, ["B", "A"]),
             call(path, ["C", "D"], up=False)])
        if peers:
            up_hof, down_hof = peers
            ntools.eq_(path.interfaces, [(11, up_hof.ingress_if),
                                         (12, down_hof.ingress_if)])
Esempio n. 16
0
 def test_up(self, deepcopy, copy_hofs):
     seg, info, hofs, upstream_hof = self._setup(deepcopy, copy_hofs)
     # Call
     ntools.eq_(PathCombinator._copy_segment_shortcut(seg, 4),
                (info, hofs, upstream_hof, "mtu"))
     # Tests
     deepcopy.assert_called_once_with(seg.info)
     ntools.eq_(info.hops, 6)
     ntools.ok_(info.up_flag)
     copy_hofs.assert_called_once_with(seg.iter_asms.return_value,
                                       reverse=True)
     ntools.eq_(hofs[-1].xover, True)
     ntools.eq_(upstream_hof.xover, False)
     ntools.eq_(upstream_hof.verify_only, True)
Esempio n. 17
0
 def test_full(self):
     asms = []
     for i in range(4):
         pcbm = create_mock(["hof", "p"])
         pcbm.hof.return_value = i
         pcbm.p = create_mock(["inMTU"])
         pcbm.p.inMTU = (i + 1) * 2
         asm = create_mock(["pcbm", "p"])
         asm.pcbm.return_value = pcbm
         asm.p = create_mock(["mtu"])
         asm.p.mtu = (i + 1) * 0.5
         asms.append(asm)
     # Call
     ntools.eq_(PathCombinator._copy_hofs(asms), ([3, 2, 1, 0], 0.5))
Esempio n. 18
0
 def _resolve_not_core_core(self, dst_ia, sibra=False):
     """Resolve path from non-core to core."""
     res = set()
     params = dst_ia.params()
     params["sibra"] = sibra
     if dst_ia[0] == self.addr.isd_as[0]:
         # Dst in local ISD. First check whether DST is a (super)-parent.
         for useg in self.up_segments(**params):
             res.add((useg, None, None))
     # Check whether dst is known core AS.
     for cseg in self.core_segments(**params):
         # Check do we have an up-seg that is connected to core_seg.
         for useg in self.up_segments(first_ia=cseg.last_ia(), sibra=sibra):
             res.add((useg, cseg, None))
     if sibra:
         return res
     return PathCombinator.tuples_to_full_paths(res)
Esempio n. 19
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
     })
     # Call
     ntools.eq_(PathCombinator._find_peer_hfs(up_asm, down_asm, {}, {}), [
         (up_pcbms[0].hof(), down_pcbms[0].hof(), 500),
         (up_pcbms[2].hof(), down_pcbms[1].hof(), 700),
     ])
Esempio n. 20
0
 def _resolve_core_not_core(self, dst_ia, sibra=False):
     """Resolve path from core to non-core."""
     res = set()
     # First check whether there is a direct path.
     for dseg in self.down_segments(first_ia=self.addr.isd_as,
                                    last_ia=dst_ia,
                                    sibra=sibra):
         res.add((None, None, dseg))
     # Check core-down combination.
     for dseg in self.down_segments(last_ia=dst_ia, sibra=sibra):
         dseg_ia = dseg.first_ia()
         if self.addr.isd_as == dseg_ia:
             pass
         for cseg in self.core_segments(first_ia=dseg_ia,
                                        last_ia=self.addr.isd_as,
                                        sibra=sibra):
             res.add((None, cseg, dseg))
     if sibra:
         return res
     return PathCombinator.tuples_to_full_paths(res)
Esempio n. 21
0
 def test_copy_up(self, deepcopy, copy_hofs):
     seg = create_mock(["iter_asms", "info"])
     info = create_mock(["up_flag"])
     deepcopy.return_value = info
     hofs = []
     for _ in range(3):
         hof = create_mock(["xover"])
         hof.xover = False
         hofs.append(hof)
     copy_hofs.return_value = hofs, None
     # Call
     ntools.eq_(PathCombinator._copy_segment(seg, True, True),
                (info, hofs, None))
     # Tests
     deepcopy.assert_called_once_with(seg.info)
     ntools.eq_(info.up_flag, True)
     copy_hofs.assert_called_once_with(seg.iter_asms.return_value,
                                       reverse=True)
     ntools.eq_(hofs[0].xover, True)
     ntools.eq_(hofs[1].xover, False)
     ntools.eq_(hofs[2].xover, True)
Esempio n. 22
0
 def test_xovr(self, find):
     up_asms = [
         create_mock_full({"isd_as()": "1-1"}),
         create_mock_full({"isd_as()": "1-2"}),
         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-1"}),
         create_mock_full({"isd_as()": "1-2"}),
         create_mock_full({"isd_as()": "1-4"}),
     ]
     down_seg = create_mock_full({
         "iter_asms()": down_asms,
         "get_rev_map()": {}
     })
     find.return_value = False
     # Call
     ntools.eq_(PathCombinator._get_xovr_peer(up_seg, down_seg),
                ((2, 2), None))
Esempio n. 23
0
 def _check_none(self, up_seg, down_seg):
     ntools.eq_(PathCombinator._build_shortcuts(up_seg, down_seg), [])
Esempio n. 24
0
 def test_none(self):
     seg = create_mock_full({"iter_asms()": [], "get_rev_map()": {}})
     # Call
     ntools.eq_(PathCombinator._get_xovr_peer(seg, seg), (None, None))
Esempio n. 25
0
 def test_without_core_conn(self):
     up, core, down = self._setup(1, 0, 0, 1)
     ntools.assert_true(PathCombinator._check_connected(up, None, down))
Esempio n. 26
0
 def test_with_core_conn(self):
     up, core, down = self._setup(1, 1, 2, 2)
     ntools.assert_true(PathCombinator._check_connected(up, core, down))
Esempio n. 27
0
 def test_with_core_down_discon(self):
     up, core, down = self._setup(1, 1, 2, 3)
     ntools.assert_false(PathCombinator._check_connected(up, core, down))
Esempio n. 28
0
 def test_no_segment(self):
     ntools.eq_(PathCombinator._copy_segment(None, False, False, "xovrs"),
                (None, None, float("inf")))
Esempio n. 29
0
 def _check_none(self, up_seg, down_seg):
     ntools.assert_is_none(
         PathCombinator._build_shortcut_path(up_seg, down_seg))