Exemple #1
0
    def _api_handle_path_request(self, pld, meta):
        request = pld.union
        assert isinstance(request, SCIONDPathRequest), type(request)
        req_id = pld.id

        dst_ia = request.dst_ia()
        src_ia = request.src_ia()
        if not src_ia:
            src_ia = self.addr.isd_as
        thread = threading.current_thread()
        thread.name = "SCIONDaemon API id:%s %s -> %s" % (
            thread.ident, src_ia, dst_ia)
        paths, error = self.get_paths(dst_ia, flush=request.p.flags.refresh)
        if request.p.maxPaths:
            paths = paths[:request.p.maxPaths]

        reply_entries = []
        for path_meta in paths:
            fwd_if = path_meta.fwd_path().get_fwd_if()
            # Set dummy host addr if path is empty.
            haddr, port = None, None
            if fwd_if:
                br = self.ifid2br[fwd_if]
                haddr, port = br.int_addrs.public[0]
            addrs = [haddr] if haddr else []
            first_hop = HostInfo.from_values(addrs, port)
            reply_entry = SCIONDPathReplyEntry.from_values(
                path_meta, first_hop)
            reply_entries.append(reply_entry)
        logging.debug("Replying to api request for %s with %d paths:\n%s",
                      dst_ia, len(paths), "\n".join([p.short_desc() for p in paths]))
        self._send_path_reply(req_id, reply_entries, error, meta)
Exemple #2
0
    def _api_handle_path_request(self, request, meta):
        req_id = request.id
        if request.p.flags.sibra:
            logging.warning(
                "Requesting SIBRA paths over SCIOND API not supported yet.")
            self._send_path_reply(req_id, [], SCIONDPathReplyError.INTERNAL,
                                  meta)
            return

        dst_ia = request.dst_ia()
        src_ia = request.src_ia()
        if not src_ia:
            src_ia = self.addr.isd_as
        thread = threading.current_thread()
        thread.name = "SCIONDaemon API id:%s %s -> %s" % (thread.ident, src_ia,
                                                          dst_ia)
        paths, error = self.get_paths(dst_ia, flush=request.p.flags.flush)
        if request.p.maxPaths:
            paths = paths[:request.p.maxPaths]
        logging.debug("Replying to api request for %s with %d paths", dst_ia,
                      len(paths))
        reply_entries = []
        for path_meta in paths:
            fwd_if = path_meta.fwd_path().get_fwd_if()
            # Set dummy host addr if path is empty.
            haddr, port = None, None
            if fwd_if:
                br = self.ifid2br[fwd_if]
                haddr, port = br.addr, br.port
            addrs = [haddr] if haddr else []
            first_hop = HostInfo.from_values(addrs, port)
            reply_entry = SCIONDPathReplyEntry.from_values(
                path_meta, first_hop)
            reply_entries.append(reply_entry)
        self._send_path_reply(req_id, reply_entries, error, meta)
Exemple #3
0
 def _resolve_dst_addr(self, src, dst):
     if dst.isd_as != src.isd_as:
         logging.error("Packet to remote AS w/o path, dst: %s", dst)
         return None
     host = dst.host
     if host.TYPE == AddrType.SVC:
         svc_type = SVC_TO_SERVICE[host.addr]
         svc_infos = self.get_service_info([svc_type])
         if svc_type in svc_infos:
             return svc_infos[svc_type].host_info(0)
         return None
     return HostInfo.from_values([host], SCION_UDP_EH_DATA_PORT)
Exemple #4
0
 def _api_handle_if_request(self, request, meta):
     all_brs = request.all_brs()
     if_list = []
     if not all_brs:
         if_list = list(request.iter_ids())
     if_entries = []
     for if_id, br in self.ifid2br.items():
         if all_brs or if_id in if_list:
             info = HostInfo.from_values([br.addr], br.port)
             reply_entry = SCIONDIFInfoReplyEntry.from_values(if_id, info)
             if_entries.append(reply_entry)
     if_reply = SCIONDIFInfoReply.from_values(request.id, if_entries)
     self.send_meta(if_reply.pack_full(), meta)
Exemple #5
0
 def _api_handle_if_request(self, pld, meta):
     request = pld.union
     assert isinstance(request, SCIONDIFInfoRequest), type(request)
     all_brs = request.all_brs()
     if_list = []
     if not all_brs:
         if_list = list(request.iter_ids())
     if_entries = []
     for if_id, br in self.ifid2br.items():
         if all_brs or if_id in if_list:
             br_addr, br_port = br.int_addrs.public[0]
             info = HostInfo.from_values([br_addr], br_port)
             reply_entry = SCIONDIFInfoReplyEntry.from_values(if_id, info)
             if_entries.append(reply_entry)
     if_reply = SCIONDMsg(SCIONDIFInfoReply.from_values(if_entries), pld.id)
     self.send_meta(if_reply.pack(), meta)
Exemple #6
0
 def _api_handle_service_request(self, request, meta):
     all_svcs = request.all_services()
     svc_list = []
     if not all_svcs:
         svc_list = list(request.iter_service_types())
     svc_entries = []
     for svc_type in ServiceType.all():
         if all_svcs or svc_type in svc_list:
             lookup_res = self.dns_query_topo(svc_type)
             host_infos = []
             for addr, port in lookup_res:
                 host_infos.append(HostInfo.from_values([addr], port))
             reply_entry = SCIONDServiceInfoReplyEntry.from_values(
                 svc_type, host_infos)
             svc_entries.append(reply_entry)
     svc_reply = SCIONDServiceInfoReply.from_values(request.id, svc_entries)
     self.send_meta(svc_reply.pack_full(), meta)