def test_ip_reach_ipv6(self, ):
     data = b'\x7f \x01\x07\x00\x00\x00\x80'
     tlv = IpReach.unpack(data, 4)
     self.assertEqual(
         tlv.json(),
         '"ip-reachability-tlv": "2001:700:0:8000::", "ip-reach-prefix": "2001:700:0:8000::/127"'
     )
    def test_ip_reach_ipv4(self, ):
        data = b'\n\n\x00'

        tlv = IpReach.unpack(data, 3)
        self.assertEqual(
            tlv.json(),
            '"ip-reachability-tlv": "10.0.0.0", "ip-reach-prefix": "10.0.0.0/10"'
        )
Exemple #3
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,
        )
Exemple #4
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 == 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
		)
Exemple #5
0
 def test_ip_reach(self,):
     data = b'\n\n\x00'
     tlv = IpReach.unpack(data)
     self.assertEqual(tlv.json(), '"ip-reachability-tlv": "10.0.0.0"')
 def test_ip_reach(self, ):
     data = b'\n\n\x00'
     tlv = IpReach.unpack(data)
     self.assertEqual(tlv.json(), '"ip-reachability-tlv": "10.0.0.0"')