How to use the exabgp.bgp.message.update.attribute.attribute.Attribute function in exabgp

To help you get started, we’ve selected a few exabgp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / __init__.py View on Github external
if length == 30 and data.startswith(EOR.NLRI.PREFIX):
			return EOR.unpack_message(data,negotiated)

		withdrawn, _attributes, announced = cls.split(data)
		attributes = Attributes.unpack(_attributes,negotiated)

		if not withdrawn:
			logger.parser("no withdrawn NLRI")
		if not announced:
			logger.parser("no announced NLRI")

		# Is the peer going to send us some Path Information with the route (AddPath)
		addpath = negotiated.addpath.receive(AFI(AFI.ipv4),SAFI(SAFI.unicast))

		# empty string for NoIP, the packed IP otherwise (without the 3/4 bytes of attributes headers)
		_nexthop = attributes.get(Attribute.CODE.NEXT_HOP,NoIP)
		nexthop = _nexthop.packed

		# XXX: NEXTHOP MUST NOT be the IP address of the receiving speaker.

		nlris = []
		while withdrawn:
			length,nlri = NLRI.unpack(AFI.ipv4,SAFI.unicast,withdrawn,addpath,nexthop,IN.WITHDRAWN)
			logger.parser(LazyFormat("parsed withdraw nlri %s payload " % nlri,withdrawn[:len(nlri)]))
			withdrawn = withdrawn[length:]
			nlris.append(nlri)

		while announced:
			length,nlri = NLRI.unpack(AFI.ipv4,SAFI.unicast,announced,addpath,nexthop,IN.ANNOUNCED)
			logger.parser(LazyFormat("parsed announce nlri %s payload " % nlri,announced[:len(nlri)]))
			announced = announced[length:]
			nlris.append(nlri)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / nexthop.py View on Github external
Created by Thomas Mangin on 2009-11-05.
Copyright (c) 2009-2015 Exa Networks. All rights reserved.
"""

from exabgp.protocol.ip import IP
from exabgp.protocol.ip import NoIP
from exabgp.bgp.message.update.attribute.attribute import Attribute


# ================================================================== NextHop (3)

# The inheritance order is important and attribute MUST be first for the righ register to be called
# At least until we rename them to be more explicit

class NextHop (Attribute,IP):
	ID = Attribute.CODE.NEXT_HOP
	FLAG = Attribute.Flag.TRANSITIVE
	MULTIPLE = False
	CACHING = True

	def __init__ (self,ip,packed=None):
		# Need to conform to from IP interface
		self.ip = ip
		self.packed = packed if packed else IP.create(ip).pack()

	def pack (self,negotiated=None):
		return self._attribute(self.packed)

	def __cmp__(self,other):
		if not isinstance(other,self.__class__):
			return -1
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / aggregator.py View on Github external
import sys

from exabgp.bgp.message.open.asn import ASN
from exabgp.protocol.ip import IPv4

from exabgp.bgp.message.update.attribute.attribute import Attribute


# =============================================================== AGGREGATOR (7)
#

@Attribute.register()
class Aggregator (Attribute):
	ID = Attribute.CODE.AGGREGATOR
	FLAG = Attribute.Flag.TRANSITIVE | Attribute.Flag.OPTIONAL
	CACHING = True

	__slots__ = ['asn','speaker','_str']

	def __init__ (self, asn, speaker):
		self.asn = asn
		self.speaker = speaker
		self._str = None

	def __eq__ (self, other):
		return \
			self.ID == other.ID and \
			self.FLAG == other.FLAG and \
			self.asn == other.asn and \
			self.speaker == other.speaker
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / mpurnlri.py View on Github external
from exabgp.protocol.family import AFI
from exabgp.protocol.family import SAFI
from exabgp.protocol.family import Family

from exabgp.bgp.message.direction import IN
from exabgp.bgp.message.update.attribute.attribute import Attribute
from exabgp.bgp.message.update.nlri import NLRI

from exabgp.bgp.message.notification import Notify
from exabgp.bgp.message.open.capability import Negotiated


# ================================================================= MP NLRI (14)

@Attribute.register()
class MPURNLRI (Attribute,Family):
	FLAG = Attribute.Flag.OPTIONAL
	ID = Attribute.CODE.MP_UNREACH_NLRI

	# __slots__ = ['nlris']

	def __init__ (self, afi, safi, nlris):
		Family.__init__(self,afi,safi)
		self.nlris = nlris

	def __eq__ (self, other):
		return \
			self.ID == other.ID and \
			self.FLAG == other.FLAG and \
			self.nlris == other.nlris
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / clusterlist.py View on Github external
from exabgp.util import concat_bytes_i

from exabgp.protocol.ip import IPv4

from exabgp.bgp.message.update.attribute.attribute import Attribute


# ===================================================================
#

class ClusterID (IPv4):
	def __init__ (self, ip):
		IPv4.__init__(self,ip)


@Attribute.register()
class ClusterList (Attribute):
	ID = Attribute.CODE.CLUSTER_LIST
	FLAG = Attribute.Flag.OPTIONAL
	CACHING = True

	__slots__ = ['clusters','packed','_len']

	def __init__ (self, clusters, packed=None):
		self.clusters = clusters
		self._packed = self._attribute(packed if packed else concat_bytes_i(_.pack() for _ in clusters))
		self._len = len(clusters)*4

	def __eq__ (self, other):
		return \
			self.ID == other.ID and \
			self.FLAG == other.FLAG and \
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / attributes.py View on Github external
return ''

NOTHING = _NOTHING()


# =================================================================== Attributes
#

# 0                   1
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# |  Attr. Flags  |Attr. Type Code|
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

class Attributes (dict):
	MULTIPLE = (Attribute.CODE.MP_REACH_NLRI,Attribute.CODE.MP_UNREACH_NLRI)
	NO_GENERATION = (Attribute.CODE.NEXT_HOP, Attribute.CODE.INTERNAL_SPLIT, Attribute.CODE.INTERNAL_WATCHDOG, Attribute.CODE.INTERNAL_WITHDRAW)

	# A cache of parsed attributes
	cache = {}

	# The previously parsed Attributes
	cached = None
	# previously parsed attribute, from which cached was made of
	previous = ''

	representation = {
		# key:  (how, default, name, text_presentation, json_presentation),
		Attribute.CODE.ORIGIN:             ('string',  '', 'origin',             '%s',     '%s'),
		Attribute.CODE.AS_PATH:            ('multiple','', ('as-path','as-set','confederation-path','confederation-set'), '%s',     '%s'),
		Attribute.CODE.NEXT_HOP:           ('string',  '', 'next-hop',           '%s',     '%s'),
		Attribute.CODE.MED:                ('integer', '', 'med',                '%s',     '%s'),
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / aspath.py View on Github external
from exabgp.util import character
from exabgp.util import ordinal
from exabgp.util import concat_bytes
from exabgp.util import concat_bytes_i
from exabgp.bgp.message.open.asn import ASN
from exabgp.bgp.message.open.asn import AS_TRANS
from exabgp.bgp.message.update.attribute.attribute import Attribute
from exabgp.bgp.message.notification import Notify


# =================================================================== ASPath (2)
# only 2-4% of duplicated data therefore it is not worth to cache

@Attribute.register()
class ASPath (Attribute):
	AS_SET             = 0x01
	AS_SEQUENCE        = 0x02
	AS_CONFED_SEQUENCE = 0x03
	AS_CONFED_SET      = 0x04
	ASN4               = False

	ID = Attribute.CODE.AS_PATH
	FLAG = Attribute.Flag.TRANSITIVE

	__slots__ = ['as_seq','as_set','as_cseq','as_cset','segments','_packed','index','_str','_json']

	def __init__ (self, as_sequence, as_set, as_conf_sequence=None,as_conf_set=None,index=None):
		self.as_seq = as_sequence
		self.as_set = as_set
		self.as_cseq = as_conf_sequence if as_conf_sequence is not None else []
		self.as_cset = as_conf_set if as_conf_set is not None else []
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / med.py View on Github external
Created by Thomas Mangin on 2009-11-05.
Copyright (c) 2009-2017 Exa Networks. All rights reserved.
License: 3-clause BSD. (See the COPYRIGHT file)
"""

from struct import pack
from struct import unpack

from exabgp.bgp.message.update.attribute.attribute import Attribute


# ====================================================================== MED (4)
#

@Attribute.register()
class MED (Attribute):
	ID = Attribute.CODE.MED
	FLAG = Attribute.Flag.OPTIONAL
	CACHING = True

	__slots__ = ['med','_packed']

	def __init__ (self, med, packed=None):
		self.med = med
		self._packed = self._attribute(packed if packed is not None else pack('!L',med))

	def __eq__ (self, other):
		return \
			self.ID == other.ID and \
			self.FLAG == other.FLAG and \
			self.med == other.med
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / localpref.py View on Github external
Created by Thomas Mangin on 2009-11-05.
Copyright (c) 2009-2017 Exa Networks. All rights reserved.
License: 3-clause BSD. (See the COPYRIGHT file)
"""

from struct import pack
from struct import unpack

from exabgp.bgp.message.update.attribute.attribute import Attribute


# ========================================================= Local Preference (5)
#

@Attribute.register()
class LocalPreference (Attribute):
	ID = Attribute.CODE.LOCAL_PREF
	FLAG = Attribute.Flag.TRANSITIVE
	CACHING = True

	__slots__ = ['localpref','_packed']

	def __init__ (self, localpref, packed=None):
		self.localpref = localpref
		self._packed = self._attribute(packed if packed is not None else pack('!L',localpref))

	def __eq__ (self, other):
		return \
			self.ID == other.ID and \
			self.FLAG == other.FLAG and \
			self.localpref == other.localpref
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / aspath.py View on Github external
return cls(as_seq,as_set,as_cseq,as_cset,backup)

	@classmethod
	def unpack (cls, data, negotiated):
		if not data:
			return None  # ASPath.Empty
		return cls._new_aspaths(data,negotiated.asn4,ASPath)


ASPath.Empty = ASPath([],[])


# ================================================================= AS4Path (17)
#

@Attribute.register()
class AS4Path (ASPath):
	ID = Attribute.CODE.AS4_PATH
	FLAG = Attribute.Flag.TRANSITIVE | Attribute.Flag.OPTIONAL
	ASN4 = True

	def pack (self, negotiated=None):
		ASPath.pack(self,True)

	@classmethod
	def unpack (cls, data, negotiated):
		if not data:
			return None  # AS4Path.Empty
		return cls._new_aspaths(data,True,AS4Path)


AS4Path.Empty = AS4Path([],[])