Пример #1
0
 def __init__(self, server_id, conf_dir):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     """
     super().__init__(server_id, conf_dir)
     # Sanity check that we should indeed be a local beacon server.
     assert not self.topology.is_core_as, "This shouldn't be a core BS!"
     self.beacons = PathStore(self.path_policy)
     self.up_segments = PathStore(self.path_policy)
     self.down_segments = PathStore(self.path_policy)
     self.cert_chain = self.trust_store.get_cert(self.addr.isd_as)
     assert self.cert_chain
Пример #2
0
 def test_none(self):
     pth_str = PathStore(self.path_policy)
     pth_str.candidates = [MagicMock(spec_set=['id']) for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].id = i
     pth_str.remove_segments([0, 1, 2, 3, 4])
     ntools.eq_(pth_str.candidates, [])
Пример #3
0
 def test(self):
     inst = PathStore(create_mock_full({'history_limit': 3}))
     numCandidates = 5
     pathLength = 5
     inst.candidates = []
     inst.disjointness = {}
     for i in range(numCandidates):
         id_ = i * (2 * pathLength + 1)
         asms = []
         for j in range(pathLength):
             isdas = 9, id_ + j + 1
             hof = create_mock_full({'egress_if': isdas[1] + pathLength})
             pcbm = create_mock_full({'hof()': hof})
             asms.append(
                 create_mock_full({
                     "isd_as()": isdas,
                     "pcbm()": pcbm
                 }))
             inst.disjointness[isdas[1]] = 1.0
             inst.disjointness[hof.egress_if] = 1.0
         pcb = create_mock_full({"iter_asms()": asms})
         record = create_mock_full({
             'pcb': pcb,
             'disjointness': 0,
             'id': id_
         })
         inst.disjointness[id_] = 1.0
         inst.candidates.append(record)
     inst._update_disjointness_db = create_mock()
     inst._update_all_disjointness()
     for i in range(numCandidates):
         ntools.assert_almost_equal(inst.candidates[i].disjointness, 1.0)
Пример #4
0
 def _setup(self, filter_=True):
     inst = PathStore("path_policy")
     inst.path_policy = create_mock(["check_filters"])
     inst.path_policy.check_filters.return_value = filter_
     pcb = create_mock(["get_hops_hash", "get_timestamp"],
                       class_=PathSegment)
     return inst, pcb
Пример #5
0
    def _ps_factory(self):
        """

        :returns:
        :rtype:
        """
        return PathStore(self.path_policy)
Пример #6
0
 def test_basic(self):
     pth_str = PathStore(self.path_policy)
     pth_str.candidates = [MagicMock(spec_set=['id', 'pcb'])
                           for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].id = i
         pth_str.candidates[i].pcb = i
     ntools.eq_(pth_str.get_segment(2), 2)
Пример #7
0
 def test_basic(self):
     pth_str = PathStore(self._setup())
     pth_str.best_paths_history = []
     pth_str.best_paths_history.append(
         [MagicMock(spec_set=['pcb']) for i in range(5)])
     for i in range(5):
         pth_str.best_paths_history[0][i].pcb = i
     ntools.eq_(pth_str.get_latest_history_snapshot(3), [0, 1, 2])
Пример #8
0
 def test_less_arg(self):
     pth_str = PathStore(self._setup({'best_set_size': 4}))
     pth_str.best_paths_history = []
     pth_str.best_paths_history.append(
         [MagicMock(spec_set=['pcb']) for i in range(5)])
     for i in range(5):
         pth_str.best_paths_history[0][i].pcb = i
     ntools.eq_(pth_str.get_latest_history_snapshot(), [0, 1, 2, 3])
Пример #9
0
 def _setup(self, filter_=True):
     inst = PathStore("path_policy")
     inst.path_policy = create_mock(["check_filters"])
     if not filter_:
         inst.path_policy.check_filters.side_effect = SCIONPathPolicyViolated()
     pcb = create_mock(["get_hops_hash", "get_timestamp"],
                       class_=PathSegment)
     return inst, pcb
Пример #10
0
 def test_basic(self, time_):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str.disjointness = {0: math.e, 1: math.e**2}
     pth_str.last_dj_update = 22
     time_.return_value = 23
     pth_str._update_disjointness_db()
     ntools.eq_(pth_str.last_dj_update, time_.return_value)
     ntools.assert_almost_equal(pth_str.disjointness[0], 1.0)
     ntools.assert_almost_equal(pth_str.disjointness[1], math.e)
Пример #11
0
 def _setup(self):
     inst = PathStore("path_policy")
     inst._remove_expired_segments = create_mock()
     inst._update_all_fidelity = create_mock()
     inst.candidates = []
     for i, fidelity in enumerate([0, 5, 2, 6, 3]):
         candidate = create_mock(["pcb", "fidelity", "sending"])
         candidate.pcb = "pcb%d" % i
         candidate.fidelity = fidelity
         inst.candidates.append(candidate)
     return inst
Пример #12
0
 def test_expire_paths(self, psi):
     """
     Test trimming the size of the candidate set by removing an expired
     segment.
     """
     pth_str = PathStore("path_policy")
     pth_str.path_policy = MagicMock(spec_set=['candidates_set_size'])
     pth_str.path_policy.candidates_set_size = 0
     pth_str.candidates = [0]
     pth_str._remove_expired_segments = (lambda: pth_str.candidates.pop())
     pth_str._trim_candidates()
     ntools.eq_(pth_str.candidates, [])
Пример #13
0
 def __init__(self,
              server_id,
              conf_dir,
              spki_cache_dir=GEN_CACHE_PATH,
              prom_export=None):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param str prom_export: prometheus export address.
     """
     super().__init__(server_id,
                      conf_dir,
                      spki_cache_dir=spki_cache_dir,
                      prom_export=prom_export)
     # Sanity check that we should indeed be a local beacon server.
     assert not self.topology.is_core_as, "This shouldn't be a core BS!"
     self.beacons = PathStore(self.path_policy)
     self.up_segments = PathStore(self.path_policy)
     self.down_segments = PathStore(self.path_policy)
     self.cert_chain = self.trust_store.get_cert(self.addr.isd_as)
     assert self.cert_chain
Пример #14
0
 def test_basic(self, time_):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str.candidates = [MagicMock(spec_set=['expiration_time', 'id'])
                           for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].expiration_time = i
         pth_str.candidates[i].id = i
     time_.return_value = 2
     pth_str.remove_segments = MagicMock(spec_set=[])
     pth_str._remove_expired_segments()
     pth_str.remove_segments.assert_called_once_with([0, 1, 2])
Пример #15
0
 def test_basic(self):
     pth_str = PathStore(self.path_policy)
     pth_str.candidates = [MagicMock(spec_set=['id', 'fidelity'])
                           for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].id = i
         pth_str.candidates[i].fidelity = i
     pth_str._update_all_fidelity = MagicMock(spec_set=[])
     pth_str.remove_segments([1, 2, 3])
     ntools.eq_(len(pth_str.candidates), 2)
     ntools.eq_(pth_str.candidates[0].id, 4)
     ntools.eq_(pth_str.candidates[1].id, 0)
     pth_str._update_all_fidelity.assert_called_once_with()
Пример #16
0
 def test_basic(self):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str._update_all_disjointness = MagicMock(spec_set=[])
     pth_str._update_all_delay_time = MagicMock(spec_set=[])
     pth_str.candidates = [MagicMock(spec_set=['update_fidelity'])
                           for i in range(5)]
     pth_str._update_all_fidelity()
     pth_str._update_all_disjointness.assert_called_once_with()
     pth_str._update_all_delay_time.assert_called_once_with()
     for i in range(5):
         pth_str.candidates[i].update_fidelity.assert_called_once_with(
             path_policy)
Пример #17
0
 def test_pcbs_from_future(self):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str.candidates = [MagicMock(spec_set=['pcb', 'delay_time',
                                               'last_seen_time'])
                           for i in range(5)]
     for i in range(5):
         pcb = MagicMock(spec_set=['get_timestamp'])
         pcb.get_timestamp.return_value = 2
         pth_str.candidates[i].pcb = pcb
         pth_str.candidates[i].last_seen_time = i
     pth_str._update_all_delay_time()
     for i in range(5):
         pth_str.candidates[i].pcb.get_timestamp.assert_called_once_with()
         ntools.assert_true(pth_str.candidates[i].delay_time > 0)
Пример #18
0
 def test_basic(self):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str.candidates = [MagicMock(spec_set=['pcb', 'delay_time',
                                               'last_seen_time'])
                           for i in range(5)]
     for i in range(5):
         pcb = MagicMock(spec_set=['get_timestamp'])
         pcb.get_timestamp.return_value = 0
         pth_str.candidates[i].pcb = pcb
         pth_str.candidates[i].last_seen_time = 2 * i + 2
     pth_str._update_all_delay_time()
     for i in range(5):
         pth_str.candidates[i].pcb.get_timestamp.assert_called_once_with()
         ntools.assert_almost_equal(pth_str.candidates[i].delay_time,
                                    ((2 * i + 2) / 10))
Пример #19
0
 def test_remove_low_fidelity_path(self, psi):
     """
     Add a path, find that the candidate set size is too large, and remove
     the lowest-fidelity path.
     """
     pth_str = PathStore("path_policy")
     pth_str.path_policy = MagicMock(spec_set=['candidates_set_size'])
     pth_str.path_policy.candidates_set_size = 2
     pth_str.candidates = [create_mock(['fidelity']) for i in range(3)]
     pth_str.candidates[0].fidelity = 2
     pth_str.candidates[1].fidelity = 0
     pth_str.candidates[2].fidelity = 1
     remainder = [pth_str.candidates[0], pth_str.candidates[2]]
     pth_str._remove_expired_segments = create_mock()
     pth_str._update_all_fidelity = create_mock()
     pth_str._trim_candidates()
     pth_str._remove_expired_segments.assert_called_once_with()
     pth_str._update_all_fidelity.assert_called_once_with()
     ntools.eq_(pth_str.candidates, remainder)
Пример #20
0
    def test(self):
        """
        Test the main functionalities of the path store.
        """
        path_policy_file = "topology/ISD1/path_policies/ISD1-AD10.json"
        path_policy = PathPolicy.from_file(path_policy_file)
        test_segments = PathStore(path_policy)
        print("Best paths: " + str(len(test_segments.get_best_segments())))
        print("Paths in path store: " + str(len(test_segments.candidates)))
        print("Paths in latest history snapshot: " +
              str(len(test_segments.get_latest_history_snapshot())) + "\n")

        path = 1
        for _ in range(1, 6):
            for _ in range(1, 6):
                pcb = PathSegment()
                pcb.iof = InfoOpaqueField.from_values(OFT.TDC_XOVR, False,
                                                      int(time.time()), path)
                ad_marking = self._create_ad_marking()
                pcb.add_ad(ad_marking)
                print("insert path " + str(path) + ", exp time: " +
                      str(pcb.get_expiration_time()))
                test_segments.add_segment(pcb)
                path += 1
            print("Best paths: " + str(len(test_segments.get_best_segments())))
            print("Paths in path store: " + str(len(test_segments.candidates)))
            print("Paths in latest history snapshot: " +
                  str(len(test_segments.get_latest_history_snapshot())))
            print("Time: " + str(int(time.time())) + "\n")
            time.sleep(5)

        print("Waiting for some paths to expire...")
        time.sleep(25)
        print("Best paths: " + str(len(test_segments.get_best_segments())))
        print("Paths in path store: " + str(len(test_segments.candidates)))
        print("Paths in latest history snapshot: " +
              str(len(test_segments.get_latest_history_snapshot())))
Пример #21
0
 def test_not_present(self):
     pth_str = PathStore(self.path_policy)
     pth_str.candidates = [MagicMock(spec_set=['id']) for i in range(5)]
     ntools.assert_is_none(pth_str.get_segment(2))
Пример #22
0
 def test_false(self):
     pth_str = PathStore(self._setup())
     ntools.eq_(pth_str.get_latest_history_snapshot(3), [])