Exemple #1
0
    def _parse(self, addr_type, raw):
        """
        Parse a raw byte string.

        :param int addr_type: Host address type
        :param bytes raw: raw bytes.
        """
        haddr_type = haddr_get_type(addr_type)
        addr_len = ISD_AS.LEN + haddr_type.LEN
        data = Raw(raw, "SCIONAddr", addr_len, min_=True)
        self.isd_as = ISD_AS(data.pop(ISD_AS.LEN))
        self.host = haddr_type(data.pop(haddr_type.LEN))
def addr_c2py(caddr):
    """
    Helper function to convert C_SCIONAddr to SCIONAddr
    :param caddr: C_SCIONAddr to convert
    :type caddr: C_SCIONAddr
    :returns: Converted object
    :rtype: SCIONAddr
    """
    isd_as = ISD_AS(caddr.isd_as.to_bytes(4, 'big'))
    if caddr.host.addr_type == 0:
        return None
    htype = haddr_get_type(caddr.host.addr_type)
    haddr = haddr_parse(caddr.host.addr_type,
                        bytes(caddr.host.addr)[:htype.LEN])
    return SCIONAddr.from_values(isd_as, haddr)
Exemple #3
0
 def _get_path_via_api(self):
     """
     Test local API.
     """
     data = self._try_sciond_api()
     path_len = data.pop(1) * 8
     self.path = SCIONPath(data.pop(path_len))
     haddr_type = haddr_get_type(data.pop(1))
     data.pop(haddr_type.LEN)  # first hop, unused here
     data.pop(2)  # port number, unused here
     self.path.mtu = struct.unpack("!H", data.pop(2))[0]
     ifcount = data.pop(1)
     self.iflist = []
     for i in range(ifcount):
         isd_as = ISD_AS(data.pop(ISD_AS.LEN))
         ifid = struct.unpack("!H", data.pop(2))[0]
         self.iflist.append((isd_as, ifid))
Exemple #4
0
 def calc_len(cls, type_):  # pragma: no cover
     class_ = haddr_get_type(type_)
     return ISD_AS.LEN + class_.LEN