示例#1
0
 def unpack(cls, msg):
     """
     Factory function.
     Return a NOTIFICATION object corresponding to the given packed msg.
     """
     length, type = Message.header_unpack(msg[:19])
     error_code, error_subcode = struct.unpack('!BB', msg[19:21])
     if length > 21:
         data = struct.unpack('!%ds' % (length - 21), msg[21:length])
     return cls(error_code, error_subcode, data)
示例#2
0
文件: open.py 项目: Kent1/pyBGP
    def unpack(cls, msg):
        """
        Factory function.
        Return a OPEN object corresponding to the given packed msg.
        """
        length, type = Message.header_unpack(msg)
        if type != Type.OPEN:
            raise Exception

        version, asn, hold_time, router_id = struct.unpack('!BHHI', msg[19:28])
        length_capabilities = struct.unpack('!B', msg[28:29])
        if length_capabilities:
            pass
        return cls(asn, hold_time, router_id)
示例#3
0
文件: update.py 项目: Kent1/pyBGP
    def unpack(cls, msg):
        """
        Factory function. Return a UPDATE object corresponding
        to the msg unpacked.
        """

        length, type = Message.header_unpack(msg)
        msg = msg[19:]

        # Unpack Withdrawn routes
        wd_routes_length, = struct.unpack('!H', msg[:2])
        wd_routes = []
        wr_packed = msg[2:2+wd_routes_length]
        while(wr_packed):
            ipfield = IPField.unpack(wr_packed)
            wd_routes.append(ipfield)
            wr_packed = wr_packed[len(ipfield):]
        msg = msg[2+wd_routes_length:]

        # Unpack Path Attributes
        path_attrs_length, = struct.unpack('!H', msg[:2])
        path_attrs = []
        pa_packed = msg[2:2+path_attrs_length]
        while(pa_packed):
            path_attr = PathAttribute.create(pa_packed)
            path_attrs.append(path_attr)
            pa_packed = pa_packed[len(path_attr):]
        msg = msg[2+path_attrs_length:]

        # Unpack NLRI
        nlris = []
        nlris_packed = msg[:length]
        while(nlris_packed):
            ipfield = IPField.unpack(nlris_packed)
            nlris.append(ipfield)
            nlris_packed = nlris_packed[len(ipfield):]

        return cls(wd_routes, path_attrs, nlris)