def _api_handle_seg_type_request(self, pld, meta): request = pld.union assert isinstance(request, SCIONDSegTypeHopRequest), type(request) segmentType = request.p.type db = [] if segmentType == PST.CORE: db = self.core_segments elif segmentType == PST.UP: db = self.up_segments elif segmentType == PST.DOWN: db = self.down_segments else: logging.error("Requesting segment type %s unrecognized.", segmentType) seg_entries = [] for segment in db(full=True): if_list = [] for asm in segment.iter_asms(): isd_as = asm.isd_as() hof = asm.pcbm(0).hof() egress = hof.egress_if ingress = hof.ingress_if if ingress: if_list.append(PathInterface.from_values(isd_as, ingress)) if egress: if_list.append(PathInterface.from_values(isd_as, egress)) reply_entry = SCIONDSegTypeHopReplyEntry.from_values( if_list, segment.get_timestamp(), segment.get_expiration_time()) seg_entries.append(reply_entry) seg_reply = SCIONDMsg( SCIONDSegTypeHopReply.from_values(seg_entries), pld.id) self.send_meta(seg_reply.pack(), meta)
def _build_shortcut_interface_list(up_seg, up_idx, down_seg, down_idx, peers=None): """ Builds interface list for a shortcut path. :param up_seg: Up segment used in path :type up_seg: PathSegment :param up_idx: Index of peer/xovr point in up_seg :type up_idx: int :param down_seg: Down segment used in path :type down_seg: PathSegment :param down_idx: Index of peer/xovr point in down_seg :type down_idx: int :param tuple peers: Tuple of up segment peer HOF, down segment peer HOF """ asm_list = list(reversed(list(up_seg.iter_asms(up_idx)))) if_list = _build_interface_list(asm_list) if peers: up_peer_hof, down_peer_hof = peers assert up_peer_hof and down_peer_hof up_ia = up_seg.asm(up_idx).isd_as() down_ia = down_seg.asm(down_idx).isd_as() if_list.append(PathInterface.from_values(up_ia, up_peer_hof.ingress_if)) if_list.append( PathInterface.from_values(down_ia, down_peer_hof.ingress_if)) asm_list = list(down_seg.iter_asms(down_idx)) if_list += _build_interface_list(asm_list, up=False) return if_list
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) ])
def _check_xovr_peers(self, peers, build_if_list): 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 build_if_list.side_effect = [[], []] if_list = path_combinator._build_shortcut_interface_list( up_seg, up_idx, down_seg, down_idx, peers) assert_these_calls(build_if_list, [call(["B", "A"]), call(["C", "D"], cons_dir=True)]) if peers: up_hof, down_hof = peers ntools.eq_( if_list, [PathInterface.from_values(11, up_hof.ingress_if), PathInterface.from_values(12, down_hof.ingress_if)])
def _build_interface_list(asms, up=True): """ Builds list of interface IDs of segment ASMarkings. Order of IDs depends on up flag. """ if_list = [] for i, asm in enumerate(asms): isd_as = asm.isd_as() hof = asm.pcbm(0).hof() egress = hof.egress_if ingress = hof.ingress_if if up: if egress: if_list.append(PathInterface.from_values(isd_as, egress)) if ingress and i != len(asms) - 1: if_list.append(PathInterface.from_values(isd_as, ingress)) else: if ingress and i != 0: if_list.append(PathInterface.from_values(isd_as, ingress)) if egress: if_list.append(PathInterface.from_values(isd_as, egress)) return if_list
def iter_ifs(self): for if_ in self.p.interfaces: yield PathInterface(if_)