コード例 #1
0
ファイル: prefix.py プロジェクト: benagricola/exabgp
	def unpack (cls, exdata):
		data = exdata

		# Get the data length to understand if addresses are IPv4 or IPv6
		datalen = len(data)

		rd = RouteDistinguisher.unpack(data[:8])
		data = data[8:]

		esi = ESI.unpack(data[:10])
		data = data[10:]

		etag = EthernetTag.unpack(data[:4])
		data = data[4:]

		iplen = ord(data[0])
		data = data[1:]

		if datalen == (26 + 8):  # Using IPv4 addresses
			ip = IP.unpack(data[:4])
			data = data[4:]
			gwip = IP.unpack(data[:4])
			data = data[4:]
		elif datalen == (26 + 32):  # Using IPv6 addresses
			ip = IP.unpack(data[:16])
			data = data[16:]
			gwip = IP.unpack(data[:16])
			data = data[16:]
		else:
			raise Notify(3,5,"Data field length is given as %d, but EVPN route currently support only IPv4 or IPv6(34 or 58)" % iplen)

		label = Labels.unpack(data[:3])

		return cls(rd,esi,etag,label,ip,iplen,gwip,exdata)
コード例 #2
0
ファイル: prefix.py プロジェクト: Exa-Networks/exabgp
	def unpack (cls, data):
		if len(data) == 4:
			# IPv4 address
			addr = IP.unpack(data[:4])
		elif len(data) == 16:
			# IPv6
			addr = IP.unpack(data[:16])
		return cls(iface_addr=addr)
コード例 #3
0
ファイル: lterid.py プロジェクト: Exa-Networks/exabgp
	def unpack (cls,data,length):
		if len(data) == 4:
			# IPv4 address
			terid = IP.unpack(data[:4])
		elif len(data) == 16:
			# IPv6
			terid = IP.unpack(data[:16])
		return cls(terid=terid)
コード例 #4
0
ファイル: bgpls.py プロジェクト: rendoaw/exabgp34-bgpls
        def unpack (cls, afi, safi, data, addpath, nexthop, action):
                local_node_id = ""
                local_asn = ""
                local_ipv4 = ""
                remote_node_id = ""
                remote_asn = ""
                remote_ipv4 = ""
                
                nlri_type = data[0:2]
                nlri_length, = unpack('!H',data[2:4])
                protocol_id = data[4:5]
                topology_type = data[5:13]
                nlri_offset = 13
                nlri_cur_pos = 0
                while nlri_offset < nlri_length:
                        tlv_type, tlv_length, tlv_value = decode_tlv(data, nlri_offset, 2, 2)
                        
                        if tlv_type == LSTLV.LOCAL_NODE_DESCRIPTORS:
                                node_length = tlv_length
                                node_offset = nlri_offset + 4
                                node_cur_pos = 0
                                while node_cur_pos < node_length:
                                        node_tlv_type, node_tlv_length, node_tlv_value = decode_tlv(data, node_offset, 2, 2)
                                        if node_tlv_type == LSTLV.IGP_ROUTER_ID:
                                                local_node_id = str(IP.unpack(node_tlv_value))
                                        if node_tlv_type == LSTLV.ASN:
                                                local_asn = str(int(binascii.hexlify(node_tlv_value), 16))
                                        node_offset = node_offset+2+2+node_tlv_length
                                        node_cur_pos = node_cur_pos+2+2+node_tlv_length
                                        
                        if tlv_type == LSTLV.REMOTE_NODE_DESCRIPTORS:
                                node_length = tlv_length
                                node_offset = nlri_offset + 4
                                node_cur_pos = 0
                                while node_cur_pos < node_length:
                                        node_tlv_type, node_tlv_length, node_tlv_value = decode_tlv(data, node_offset, 2, 2)
                                        if node_tlv_type == LSTLV.IGP_ROUTER_ID:
                                                print str(int(binascii.hexlify(node_tlv_value), 16))
                                                remote_node_id = str(IP.unpack(node_tlv_value))
                                        if node_tlv_type == LSTLV.ASN:
                                                remote_asn = str(int(binascii.hexlify(node_tlv_value), 16))
                                        node_offset = node_offset+2+2+node_tlv_length
                                        node_cur_pos = node_cur_pos+2+2+node_tlv_length
                                        
                        if tlv_type == LSTLV.LOCAL_IPV4:
                                local_ipv4 = str(IP.unpack(tlv_value))

                        if tlv_type == LSTLV.REMOTE_IPV4:
                                remote_ipv4 = str(IP.unpack(tlv_value))

                        nlri_offset = nlri_offset+2+2+tlv_length
                        nlri_cur_pos = nlri_cur_pos +2+2+tlv_length
                
                nlri = cls(local_node_id, local_asn, remote_node_id, remote_asn, local_ipv4, remote_ipv4, action)
                nlri.action = action
                if action == 1:
                    nlri.nexthop = IP.unpack(nexthop)
                return len(data), nlri
コード例 #5
0
ファイル: ospfaddr.py プロジェクト: szhong-jnpr/exabgp
	def unpack (cls,data,length):
		if len(data) == 4:
    		# IPv4 address
			addr = IP.unpack(data[:4])
		elif len(data) == 16:
    		# IPv6
			addr = IP.unpack(data[:16])
		else:
			raise Notify(3,5, "Error parsing OSPF Forwarding Address. Wrong size")
		return cls(addr=addr)
コード例 #6
0
ファイル: flow.py プロジェクト: xiaopeng163/exabgp
	def __init__ (self, afi=AFI.ipv4,safi=SAFI.flow_ip,nexthop=None,rd=None):
		NLRI.__init__(self,afi,safi)
		self.rules = {}
		self.action = OUT.UNSET
		self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		self.rd = rd if rd else RouteDistinguisher.NORD
		self.unique = unique.next()
コード例 #7
0
ファイル: mpls.py プロジェクト: asnd/exabgp
	def __init__(self,afi,safi,packed,mask,nexthop,action):
		self.labels = Labels.NOLABEL
		self.rd = RouteDistinguisher.NORD
		self.nexthop = IP.unpack(nexthop) if nexthop else NoIP
		self.action = action
		NLRI.__init__(self,afi,safi)
		CIDR.__init__(self,packed,mask)
コード例 #8
0
ファイル: mac.py プロジェクト: Akheon23/exabgp
	def unpack (cls, data):
		datalen = len(data)
		rd = RouteDistinguisher.unpack(data[:8])
		esi = ESI.unpack(data[8:18])
		etag = EthernetTag.unpack(data[18:22])
		maclength = ord(data[22])

		if (maclength > 48 or maclength < 0):
			raise Notify(3,5,'invalid MAC Address length in %s' % cls.NAME)
		end = 23 + 6 # MAC length MUST be 6

		mac = MACQUAL.unpack(data[23:end])

		length = ord(data[end])
		iplen = length / 8

		if datalen in [36,39]:  # No IP information (1 or 2 labels)
			iplenUnpack = 0
			if iplen != 0:
				raise Notify(3,5,"IP length is given as %d, but current MAC route has no IP information" % iplen)
		elif datalen in [40, 43]:  # Using IPv4 addresses (1 or 2 labels)
			iplenUnpack = 4
			if (iplen > 32 or iplen < 0):
				raise Notify(3,5,"IP field length is given as %d, but current MAC route is IPv4 and valus is out of range" % iplen)
		elif datalen in [52, 55]:  # Using IPv6 addresses (1 or 2 labels)
			iplenUnpack = 16
			if (iplen > 128 or iplen < 0):
				raise Notify(3,5,"IP field length is given as %d, but current MAC route is IPv6 and valus is out of range" % iplen)
		else:
			raise Notify(3,5,"Data field length is given as %d, but does not match one of the expected lengths" % datalen)

		ip = IP.unpack(data[end+1:end+1+iplenUnpack])
		label = Labels.unpack(data[end+1+iplenUnpack:end+1+iplenUnpack+3])

		return cls(rd,esi,etag,mac,maclength,label,ip,data)
コード例 #9
0
ファイル: flow.py プロジェクト: RagnarDanneskjold/exabgp
	def __init__ (self,afi=AFI.ipv4,safi=SAFI.flow_ip,nexthop=None,rd=None):
		NLRI.__init__(self,afi,safi)
		self.rules = {}
		self.action = OUT.announce
		self.nexthop = IP.unpack(nexthop) if nexthop else NoIP
		self.rd = rd
		self.unique = unique.next()
コード例 #10
0
ファイル: route.py プロジェクト: Shmuma/exabgp
	def next_hop (self, scope, name, command, tokens):
		if scope[-1]['announce'][-1].attributes.has(Attribute.CODE.NEXT_HOP):
			return self.error.set(self.syntax)

		try:
			# next-hop self is unsupported
			ip = tokens.pop(0)
			if ip.lower() == 'self':
				if 'local-address' in scope[-1]:
					la = scope[-1]['local-address']
				elif self._nexthopself:
					la = self._nexthopself
				else:
					return self.error.set('next-hop self can only be specified with a neighbor')
				nh = IP.unpack(la.pack())
			else:
				nh = IP.create(ip)

			change = scope[-1]['announce'][-1]
			nlri = change.nlri
			afi = nlri.afi
			safi = nlri.safi

			nlri.nexthop = nh

			if afi == AFI.ipv4 and safi in (SAFI.unicast,SAFI.multicast):
				change.attributes.add(Attribute.unpack(NextHop.ID,NextHop.FLAG,nh.packed,None))
				# NextHop(nh.ip,nh.packed) does not cache the result, using unpack does
				# change.attributes.add(NextHop(nh.ip,nh.packed))

			return True
		except Exception:
			return self.error.set(self.syntax)
コード例 #11
0
ファイル: mpls.py プロジェクト: Shmuma/exabgp
	def __init__ (self, afi, safi, packed, mask, nexthop, action,path=None):
		self.path_info = PathInfo.NOPATH if path is None else path
		self.labels = Labels.NOLABEL
		self.rd = RouteDistinguisher.NORD
		self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		self.action = action
		NLRI.__init__(self,afi,safi)
		CIDR.__init__(self,packed,mask)
コード例 #12
0
ファイル: multicast.py プロジェクト: Krychuu/exabgp
	def unpack(cls,data):
		rd = RouteDistinguisher.unpack(data[:8])
		etag = EthernetTag.unpack(data[8:12])
		iplen = ord(data[12])
		ip = IP.unpack(data[12:12+iplen])
		if iplen not in (4,16):
			raise Exception("IP len is %d, but EVPN route currently support only IPv4" % iplen)
		return cls(rd,etag,ip)
コード例 #13
0
ファイル: ipv6sid.py プロジェクト: Exa-Networks/exabgp
	def unpack (cls,data,length):
		v6sid = -1
		if cls.LENGTH != length:
			raise Notify(3,5, "Invalid TLV size. Should be {0} but {1} received".format(cls.LENGTH, length))
		# RESERVED: 24 bit field for future use.  MUST be clear on
		# transmission an MUST be ignored at reception.
		data = data[3:19]
		v6sid = IP.unpack(data)
		return cls(v6sid=v6sid,packed=data)
コード例 #14
0
ファイル: node.py プロジェクト: szhong-jnpr/exabgp
	def unpack (cls, data, igp):
		dtype, dlength = unpack('!HH',data[0:4])
		if dtype not in NODE_TLVS.keys():
			raise Exception("Unknown Node Descriptor Sub-TLV")
		# OSPF Area-ID
		if dtype == 514:
			return cls(node_id=IP.unpack(data[4: 4 + dlength]),
					dtype=dtype,packed=data[:4+dlength]), data[4 + dlength:]
		# IGP Router-ID: The TLV size in combination with the protocol
		# identifier enables the decoder to determine the type
		# of the node: sec 3.2.1.4.
		elif dtype == 515:
    		# OSPFv{2,3} non-pseudonode
			if (igp == 3 or igp == 6) and dlength == 4:
				r_id = IP.unpack(data[4: 4 + 4])
				return cls(node_id=r_id, dtype=dtype,
						packed=data[:4+dlength]), data[4 + 4:]
			# OSPFv{2,3} LAN pseudonode
			if (igp == 3 or igp == 6) and dlength == 8:
				r_id = IP.unpack(data[4: 4 + 4])
				dr_id = IP.unpack(data[8: 4 + 8])
				return cls(node_id=r_id,dtype=dtype,psn=None,
						dr_id=dr_id,packed=data[:4+dlength]), data[4 + 8:]
			# IS-IS non-pseudonode
			if (igp == 1 or igp == 2) and dlength == 6:
				return cls(node_id=ISO.unpack_sysid(data[4: 4 + 6]),
					dtype=dtype,packed=data[:4+dlength]), data[4 + 6:]
			# IS-IS LAN pseudonode = ISO Node-ID + PSN
			# Unpack ISO address
			if (igp == 1 or igp == 2) and dlength == 7:
				iso_node = ISO.unpack_sysid(data[4: 4 + 6])
				psn = unpack('!B', data[4 + 6: 4 + 7])[0]
				return cls(node_id=iso_node,dtype=dtype,
						psn=psn,packed=data[:4+dlength]), data[4 + 7:]
		elif dtype == 512 and dlength == 4:
    		# ASN
			return cls(node_id=unpack('!L', data[4: 4 + dlength])[0],
					dtype=dtype,packed=data[:4+dlength]), data[4 + 4:]
		elif dtype == 513 and dlength == 4:
    		# BGP-LS
			return cls(node_id=unpack('!L',data[4: 4 + dlength])[0],
					dtype=dtype,packed=data[:4+dlength]), data[4 + 4:]
		else:
			raise Notify(3,5,'could not decode Local Node descriptor')
コード例 #15
0
ファイル: segment.py プロジェクト: Exa-Networks/exabgp
	def unpack (cls, data):
		rd = RouteDistinguisher.unpack(data[:8])
		esi = ESI.unpack(data[8:18])
		iplen = ordinal(data[18])

		if iplen not in (32,128):
			raise Notify(3,5,"IP length field is given as %d in current Segment, expecting 32 (IPv4) or 128 (IPv6) bits" % iplen)

		ip = IP.unpack(data[19:19+(iplen//8)])

		return cls(rd,esi,ip,data)
コード例 #16
0
ファイル: vpls.py プロジェクト: dwcarder/sdn-ix-demo
	def unpack (cls,afi,safi,data,addpath,nexthop,action):
		# label is 20bits, stored using 3 bytes, 24 bits
		length, = unpack('!H',data[0:2])
		if len(data) != length+2:
			raise Notify(3,10,'l2vpn vpls message length is not consistent with encoded data')
		rd = RouteDistinguisher(data[2:10])
		ve,offset,size = unpack('!HHH',data[10:16])
		base = unpack('!L','\x00'+data[16:19])[0]>>4
		nlri = cls(rd,ve,base,offset,size)
		nlri.action = action
		nlri.nexthop = IP.unpack(nexthop)
		return len(data), nlri
コード例 #17
0
ファイル: vpls.py プロジェクト: asnd/exabgp
	def unpack (cls,afi,safi,data,addpath,nexthop,action):
		# label is 20bits, stored using 3 bytes, 24 bits
		length, = unpack('!H',data[0:2])
		if len(data) != length+2:
			raise Notify(3,10,'l2vpn vpls message length is not consistent with encoded data')
		rd = RouteDistinguisher(data[2:10])
		ve,offset,size = unpack('!HHH',data[10:16])
		base = unpack('!L','\x00'+data[16:19])[0]>>4
		nlri = cls(rd,ve,base,offset,size)
		nlri.action = action
		nlri.nexthop = IP.unpack(nexthop)
		return len(data), nlri
コード例 #18
0
ファイル: ipv6sid.py プロジェクト: bopopescu/exabgp-1
 def unpack(cls, data, length):
     v6sid = -1
     if cls.LENGTH != length:
         raise Notify(
             3, 5,
             "Invalid TLV size. Should be {0} but {1} received".format(
                 cls.LENGTH, length))
     # RESERVED: 24 bit field for future use.  MUST be clear on
     # transmission an MUST be ignored at reception.
     data = data[3:19]
     v6sid = IP.unpack(data)
     return cls(v6sid=str(v6sid), packed=data)
コード例 #19
0
    def unpack(cls, data):
        datalen = len(data)
        rd = RouteDistinguisher.unpack(data[:8])
        esi = ESI.unpack(data[8:18])
        etag = EthernetTag.unpack(data[18:22])
        maclength = ordinal(data[22])

        if (maclength > 48 or maclength < 0):
            raise Notify(3, 5, 'invalid MAC Address length in %s' % cls.NAME)
        end = 23 + 6  # MAC length MUST be 6

        mac = MACQUAL.unpack(data[23:end])

        length = ordinal(data[end])
        iplen = length / 8

        if datalen in [33, 36]:  # No IP information (1 or 2 labels)
            iplenUnpack = 0
            if iplen != 0:
                raise Notify(
                    3, 5,
                    "IP length is given as %d, but current MAC route has no IP information"
                    % iplen)
        elif datalen in [37, 40]:  # Using IPv4 addresses (1 or 2 labels)
            iplenUnpack = 4
            if (iplen > 32 or iplen < 0):
                raise Notify(
                    3, 5,
                    "IP field length is given as %d, but current MAC route is IPv4 and valus is out of range"
                    % iplen)
        elif datalen in [49, 52]:  # Using IPv6 addresses (1 or 2 labels)
            iplenUnpack = 16
            if (iplen > 128 or iplen < 0):
                raise Notify(
                    3, 5,
                    "IP field length is given as %d, but current MAC route is IPv6 and valus is out of range"
                    % iplen)
        else:
            raise Notify(
                3, 5,
                "Data field length is given as %d, but does not match one of the expected lengths"
                % datalen)

        payload = data[end + 1:end + 1 + iplenUnpack]
        if payload:
            ip = IP.unpack(data[end + 1:end + 1 + iplenUnpack])
        else:
            ip = None
        label = Labels.unpack(data[end + 1 + iplenUnpack:end + 1 +
                                   iplenUnpack + 3])

        return cls(rd, esi, etag, mac, maclength, label, ip, data)
コード例 #20
0
ファイル: prefix.py プロジェクト: bopopescu/exabgp-1
    def unpack(cls, exdata):
        data = exdata

        # Get the data length to understand if addresses are IPv4 or IPv6
        datalen = len(data)

        rd = RouteDistinguisher.unpack(data[:8])
        data = data[8:]

        esi = ESI.unpack(data[:10])
        data = data[10:]

        etag = EthernetTag.unpack(data[:4])
        data = data[4:]

        iplen = data[0]
        data = data[1:]

        if datalen == (26 + 8):  # Using IPv4 addresses
            ip = IP.unpack(data[:4])
            data = data[4:]
            gwip = IP.unpack(data[:4])
            data = data[4:]
        elif datalen == (26 + 32):  # Using IPv6 addresses
            ip = IP.unpack(data[:16])
            data = data[16:]
            gwip = IP.unpack(data[:16])
            data = data[16:]
        else:
            raise Notify(
                3,
                5,
                "Data field length is given as %d, but EVPN route currently support only IPv4 or IPv6(34 or 58)"
                % datalen,
            )

        label = Labels.unpack(data[:3])

        return cls(rd, esi, etag, label, ip, iplen, gwip, exdata)
コード例 #21
0
ファイル: nlri.py プロジェクト: earies/exabgp
	def unpack (cls, afi, safi, data, addpath, nexthop, action):
		code = ord(data[0])
		length = ord(data[1])

		if code in cls.registered_evpn:
			klass = cls.registered_evpn[code].unpack(data[2:length+2])
		else:
			klass = cls(data[2:length+2], nexthop, action, addpath)
		klass.CODE = code
		klass.action = action
		klass.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		klass.addpath = addpath

		return length+2,klass
コード例 #22
0
    def unpack(cls, afi, safi, data, addpath, nexthop, action):
        code = ord(data[0])
        length = ord(data[1])

        if code in cls.registered_evpn:
            klass = cls.registered_evpn[code].unpack(data[2:length + 2])
        else:
            klass = cls(data[2:length + 2], nexthop, action, addpath)
        klass.CODE = code
        klass.action = action
        klass.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
        klass.addpath = addpath

        return length + 2, klass
コード例 #23
0
    def unpack(cls, data):
        rd = RouteDistinguisher.unpack(data[:8])
        esi = ESI.unpack(data[8:18])
        iplen = ord_(data[18])

        if iplen not in (32, 128):
            raise Notify(
                3, 5,
                "IP field length is given as %d in current Segment, expecting 32 (IPv4) or 128 (IPv6) bits"
                % iplen)

        ip = IP.unpack(data[19:19 + (iplen / 8)])

        return cls(rd, esi, ip, data)
コード例 #24
0
 def unpack(cls, data, negotiated):
     ls_attributes = {}
     ls_attributes['hostname'] = ""
     ls_attributes['available_bw'] = {}
     ls_attributes['isis_area_id'] = ""
     ls_attributes['ipv4_router_id'] = ""
     ls_attributes['admin_group'] = ""
     ls_attributes['max_link_bw'] = -1
     ls_attributes['max_resv_bw'] = -1
     ls_attributes['te_metric'] = -1
     ls_attributes['metric'] = -1
     #print "data = "+ binascii.hexlify(bytearray(data))
     offset = 0
     while offset < len(data):
         t, l, v = decode_tlv(data, offset, 2, 2)
         if t == 1026:
             ls_attributes['hostname'] = str(v)
         if t == 1027:
             ls_attributes['isis_area_id'] = str(binascii.hexlify(v))
         if t == 1028:
             ls_attributes['ipv4_router_id'] = str(IP.unpack(v))
         if t == 1088:
             ls_attributes['admin_group'] = str(binascii.hexlify(v))
         if t == 1089:
             ls_attributes['max_link_bw'] = str(int(unpack('>f', v)[0]) * 8)
         if t == 1090:
             ls_attributes['max_resv_bw'] = str(int(unpack('>f', v)[0]) * 8)
         if t == 1091:
             ls_attributes['available_bw'][0] = str(
                 int(unpack('>f', v[0:4])[0]) * 8)
             ls_attributes['available_bw'][1] = str(
                 int(unpack('>f', v[4:8])[0]) * 8)
             ls_attributes['available_bw'][2] = str(
                 int(unpack('>f', v[8:12])[0]) * 8)
             ls_attributes['available_bw'][3] = str(
                 int(unpack('>f', v[12:16])[0]) * 8)
             ls_attributes['available_bw'][4] = str(
                 int(unpack('>f', v[16:20])[0]) * 8)
             ls_attributes['available_bw'][5] = str(
                 int(unpack('>f', v[20:24])[0]) * 8)
             ls_attributes['available_bw'][6] = str(
                 int(unpack('>f', v[24:28])[0]) * 8)
             ls_attributes['available_bw'][7] = str(
                 int(unpack('>f', v[28:32])[0]) * 8)
         if t == 1092:
             ls_attributes['te_metric'] = str(int(binascii.hexlify(v), 16))
         if t == 1095:
             ls_attributes['metric'] = str(int(binascii.hexlify(v), 16))
         offset = offset + l + 2 + 2
     return cls(ls_attributes)
コード例 #25
0
ファイル: mac.py プロジェクト: jbfavre/exabgp
	def unpack(cls,data):
		rd = RouteDistinguisher.unpack(data[:8])
		esi = ESI.unpack(data[8:18])
		etag = EthernetTag.unpack(data[18:22])
		length = ord(data[22])

		if length % 8 != 0:
			raise Exception('invalid MAC Address length in %s' % cls.NAME)
		end = 23 + length/8

		mac = MAC.unpack(data[23:end])

		length = ord(data[end])
		if length % 8 != 0:
			raise Exception('invalid IP Address length in %s' % cls.NAME)
		iplen = length / 8

		ip = IP.unpack(data[end+1:end+1+iplen])
		label = Labels.unpack(data[end+1+iplen:])

		return cls(rd,esi,etag,mac,label,ip,data)
コード例 #26
0
    def next_hop(self, scope, name, command, tokens):
        if scope[-1]['announce'][-1].attributes.has(Attribute.CODE.NEXT_HOP):
            return self.error.set(self.syntax)

        try:
            # next-hop self is unsupported
            ip = tokens.pop(0)
            if ip.lower() == 'self':
                if 'local-address' in scope[-1]:
                    la = scope[-1]['local-address']
                elif self._nexthopself:
                    la = self._nexthopself
                else:
                    return self.error.set(
                        'next-hop self can only be specified with a neighbor')
                nh = IP.unpack(la.pack())
            else:
                nh = IP.create(ip)

            change = scope[-1]['announce'][-1]
            nlri = change.nlri
            afi = nlri.afi
            safi = nlri.safi

            nlri.nexthop = nh

            if afi == AFI.ipv4 and safi in (SAFI.unicast, SAFI.multicast):
                change.attributes.add(
                    Attribute.unpack(NextHop.ID, NextHop.FLAG, nh.packed,
                                     None))
                # NextHop(nh.ip,nh.packed) does not cache the result, using unpack does
                # change.attributes.add(NextHop(nh.ip,nh.packed))

            return True
        except Exception:
            return self.error.set(self.syntax)
コード例 #27
0
ファイル: ospfaddr.py プロジェクト: gklinich/exabgp
 def unpack(cls, data):
     length = len(data)
     if length not in (4, 16):
         raise Notify(3, 5,
                      "Error parsing OSPF Forwarding Address. Wrong size")
     return cls(IP.unpack(data))
コード例 #28
0
 def __init__(self, packed, nexthop, action, path=None):
     NLRI.__init__(self, AFI.l2vpn, SAFI.evpn)
     self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
     self.action = action
     self.packed = packed
コード例 #29
0
ファイル: rtc.py プロジェクト: Akheon23/exabgp
	def __init__ (self, afi, safi, action, nexthop, origin, rt):
		Address.__init__(self,afi,safi)
		self.action = action
		self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		self.origin = origin
		self.rt = rt
コード例 #30
0
ファイル: ospfaddr.py プロジェクト: bopopescu/exabgp-1
 def unpack(cls, data, length):
     size = len(data)
     if size not in (4, 16):
         raise Notify(3, 5,
                      "Error parsing OSPF Forwarding Address. Wrong size")
     return cls(IP.unpack(data[:size]))
コード例 #31
0
ファイル: srrid.py プロジェクト: Exa-Networks/exabgp
	def unpack (cls,data,length):
		if len(data) == 4:
			srid = IP.unpack(data[:4])
		elif len(data) == 16:
			srid = IP.unpack(data[:16])
		return cls(srid=srid)
コード例 #32
0
ファイル: srv6l3vpnsid.py プロジェクト: bopopescu/exabgp-1
 def unpack(cls, data, length):
     l3vpnsid = -1
     if cls.LENGTH != length:
         raise Notify(3, 5, "Invalid TLV size. Should be {0} but {1} received".format(cls.LENGTH, length))
     l3vpnsid = IP.unpack(data[1:17])
     return cls(l3vpnsid=str(l3vpnsid), packed=data)
コード例 #33
0
ファイル: inet.py プロジェクト: xiaopeng163/exabgp
	def __init__ (self, afi, safi, packed, mask, nexthop, action):
		self.path_info = PathInfo.NOPATH
		self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		NLRI.__init__(self,afi,safi)
		CIDR.__init__(self,packed,mask)
		self.action = action
コード例 #34
0
ファイル: srrid.py プロジェクト: gklinich/exabgp
 def unpack(cls, data):
     length = len(data)
     if length not in (4, 16):
         raise Notify(3, 5, "Error parsing SR Source Router ID. Wrong size")
     return cls(IP.unpack(data))
コード例 #35
0
ファイル: rtc.py プロジェクト: vincentbernat/exabgp
 def __init__(self, afi, safi, action, nexthop, origin, rt):
     NLRI.__init__(self, afi, safi)
     self.action = action
     self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
     self.origin = origin
     self.rt = rt
コード例 #36
0
ファイル: nlri.py プロジェクト: earies/exabgp
	def __init__ (self, packed, nexthop, action, path=None):
		NLRI.__init__(self, AFI.l2vpn, SAFI.evpn)
		self.nexthop = IP.unpack(nexthop) if nexthop else NoNextHop
		self.action = action
		self._packed = packed
コード例 #37
0
ファイル: prefix.py プロジェクト: xw2060/exabgp
	def __init__ (self, afi, safi, packed, mask, nexthop, action,path=None):
		self.path_info = PathInfo.NOPATH if path is None else path
		self.nexthop = IP.unpack(nexthop) if nexthop else NoIP
		NLRI.__init__(self,afi,safi)
		CIDR.__init__(self,packed,mask)
		self.action = action
コード例 #38
0
ファイル: node.py プロジェクト: bopopescu/Exa-Networks-exabgp
	def unpack (cls, data, igp):
		dtype, dlength = unpack('!HH',data[0:4])
		if dtype not in NODE_TLVS.keys():
			raise Exception("Unknown Node Descriptor Sub-TLV")
		# OSPF Area-ID
		if dtype == 514:
			return cls(
				node_id=IP.unpack(data[4: 4 + dlength]),
				dtype=dtype,
				packed=data[:4+dlength]
			), data[4 + dlength:]
		# IGP Router-ID: The TLV size in combination with the protocol
		# identifier enables the decoder to determine the type
		# of the node: sec 3.2.1.4.
		elif dtype == 515:
			# OSPFv{2,3} non-pseudonode
			if (igp == 3 or igp == 6) and dlength == 4:
				r_id = IP.unpack(data[4: 4 + 4])
				return cls(
					node_id=r_id,
					dtype=dtype,
					packed=data[:4+dlength]
				), data[4 + 4:]
			# OSPFv{2,3} LAN pseudonode
			if (igp == 3 or igp == 6) and dlength == 8:
				r_id = IP.unpack(data[4: 4 + 4])
				dr_id = IP.unpack(data[8: 4 + 8])
				return cls(
					node_id=r_id,
					dtype=dtype,
					psn=None,
					dr_id=dr_id,
					packed=data[:4+dlength]
				), data[4 + 8:]
			# IS-IS non-pseudonode
			if (igp == 1 or igp == 2) and dlength == 6:
				return cls(
					node_id=ISO.unpack_sysid(data[4: 4 + 6]),
					dtype=dtype,
					packed=data[:4+dlength]
				), data[4 + 6:]
			# IS-IS LAN pseudonode = ISO Node-ID + PSN
			# Unpack ISO address
			if (igp == 1 or igp == 2) and dlength == 7:
				iso_node = ISO.unpack_sysid(data[4: 4 + 6])
				psn = unpack('!B', data[4 + 6: 4 + 7])[0]
				return cls(
					node_id=iso_node,
					dtype=dtype,
					psn=psn,
					packed=data[:4+dlength]
				), data[4 + 7:]
		elif dtype == 512 and dlength == 4:
			# ASN
			return cls(
				node_id=unpack('!L', data[4: 4 + dlength])[0],
				dtype=dtype,
				packed=data[:4+dlength]
			), data[4 + 4:]
		elif dtype == 513 and dlength == 4:
			# BGP-LS
			return cls(
				node_id=unpack('!L',data[4: 4 + dlength])[0],
				dtype=dtype,
				packed=data[:4+dlength]
			), data[4 + 4:]
		else:
			raise Notify(3,5,'could not decode Local Node descriptor')
コード例 #39
0
ファイル: rterid.py プロジェクト: bopopescu/exabgp-1
 def unpack(cls, data, length):
     size = len(data)
     if size not in (4, 16):
         raise Notify(3, 5, "Invalid remote-te size")
     return cls(IP.unpack(data[:size]))
コード例 #40
0
ファイル: nexthop.py プロジェクト: Shmuma/exabgp
	def unpack (cls, data, negotiated=None):
		if not data:
			return NoNextHop
		return IP.unpack(data,NextHop)
コード例 #41
0
ファイル: nexthop.py プロジェクト: reiaaoyama/exabgp
 def unpack(cls, data, negotiated=None):
     if not data:
         return NoNextHop
     return IP.unpack(data, NextHop)
コード例 #42
0
ファイル: srrid.py プロジェクト: bopopescu/exabgp-1
 def unpack(cls, data, length):
     size = len(data)
     if size not in (4, 16):
         raise Notify(3, 5, "Error parsing SR Source Router ID. Wrong size")
     return cls(IP.unpack(data[:size]))
コード例 #43
0
 def unpack(cls, data, length):
     if len(data) == 4:
         srid = IP.unpack(data[:4])
     elif len(data) == 16:
         srid = IP.unpack(data[:16])
     return cls(srid=srid)
コード例 #44
0
 def unpack(cls, data):
     length = len(data)
     if length not in (4, 16):
         raise Notify(3, 5, "Invalid remote-te size")
     return cls(IP.unpack(data))
コード例 #45
0
 def __init__(self, afi, safi, action, nexthop, origin, rt):
     Address.__init__(self, afi, safi)
     self.action = action
     self.nexthop = IP.unpack(nexthop) if nexthop else NoIP
     self.origin = origin
     self.rt = rt