示例#1
0
    def unpack_nlri(cls, data, rd):
        ospf_type = None
        proto_id = unpack('!B', data[0:1])[0]
        if proto_id not in PROTO_CODES.keys():
            raise Exception('Protocol-ID {} is not valid'.format(proto_id))
        domain = unpack('!Q', data[1:9])[0]
        tlvs = data[9:]

        while tlvs:
            tlv_type, tlv_length = unpack('!HH', tlvs[:4])
            if tlv_type == 256:
                values = tlvs[4:4 + tlv_length]
                local_node = []
                while values:
                    # Unpack Local Node Descriptor Sub-TLVs
                    # We pass proto_id as TLV interpretation
                    # follows IGP type
                    node, left = NodeDescriptor.unpack(values, proto_id)
                    local_node.append(node)
                    if left == values:
                        raise RuntimeError("sub-calls should consume data")
                    values = left
                tlvs = tlvs[4 + tlv_length:]
                continue
            if tlv_type == 264:
                values = tlvs[4:4 + tlv_length]
                ospf_type = OspfRoute.unpack(values)
                tlvs = tlvs[4 + tlv_length:]
            if tlv_type == 265:
                values = tlvs[4:4 + tlv_length]
                prefix = IpReach.unpack(values, 4)
                tlvs = tlvs[4 + tlv_length:]

        return cls(
            domain=domain,
            proto_id=proto_id,
            packed=data,
            local_node=local_node,
            ospf_type=ospf_type,
            prefix=prefix,
            route_d=rd,
        )
示例#2
0
文件: prefixv4.py 项目: aabdnn/exabgp
	def unpack_nlri (cls, data, rd):
		ospf_type = None
		proto_id = unpack('!B',data[0:1])[0]
		if proto_id not in PROTO_CODES.keys():
			raise Exception('Protocol-ID {} is not valid'.format(proto_id))
		domain = unpack('!Q',data[1:9])[0]
		tlvs = data[9:]

		while tlvs:
			tlv_type, tlv_length = unpack('!HH', tlvs[:4])
			if tlv_type == 256:
				values = tlvs[4: 4 + tlv_length]
				local_node = []
				while values:
					# Unpack Local Node Descriptor Sub-TLVs
					# We pass proto_id as TLV interpretation
					# follows IGP type
					node, left = NodeDescriptor.unpack(values, proto_id)
					local_node.append(node)
					if left == tlvs:
						raise RuntimeError("sub-calls should consume data")
					values = left
				tlvs = tlvs[4 + tlv_length:]
				continue
			if tlv_type == 264:
				values = tlvs[4: 4 + tlv_length]
				ospf_type = OspfRoute.unpack(values)
				tlvs = tlvs[4 + tlv_length:]
			if tlv_type == 265:
				values = tlvs[4: 4 + tlv_length]
				prefix = IpReach.unpack(values)
				tlvs = tlvs[4 + tlv_length:]

		return cls(
			domain=domain,proto_id=proto_id,packed=data,
			local_node=local_node,ospf_type=ospf_type,
			prefix=prefix,route_d=rd
		)
示例#3
0
 def test_ospf_route_type(self,):
     data = b'\x04'
     tlv = OspfRoute.unpack(data)
     self.assertEqual(tlv.json(), '"ospf-route-type": 4')
示例#4
0
 def test_ospf_route_type(self, ):
     data = b'\x04'
     tlv = OspfRoute.unpack(data)
     self.assertEqual(tlv.json(), '"ospf-route-type": 4')