How to use the exabgp.protocol.family.AFI.ipv4 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 / protocol / ip / netmask.py View on Github external
def create (cls,string,afi):
		if afi == AFI.ipv4:
			if string is cls.codes:
				klass = cls(cls.codes[string],32)
				klass.maximum = 32
				return klass
			maximum = 32
		elif afi == AFI.ipv6:
			if string in cls.codes:
				raise ValueError('IPv4 mask used with an IPv6 address')
			maximum = 128
		else:
			raise ValueError('invalid address family')

		if not string.isdigit():
			raise ValueError('invalid netmask %s' % string)

		value = long(string)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / factory.py View on Github external
if len(withdrawn) != lw:
		raise Notify(3,1,'invalid withdrawn routes length, not enough data available')

	la,attribute,announced = defix(data)

	if len(attribute) != la:
		raise Notify(3,1,'invalid total path attribute length, not enough data available')

	if 2 + lw + 2+ la + len(announced) != length:
		raise Notify(3,1,'error in BGP message length, not enough data for the size announced')

	attributes = AttributesFactory(NLRIFactory,negotiated,attribute)

	# Is the peer going to send us some Path Information with the route (AddPath)
	addpath = negotiated.addpath.receive(AFI(AFI.ipv4),SAFI(SAFI.unicast))
	nho = attributes.get(AID.NEXT_HOP,None)
	nh = nho.packed if nho else None

	if not withdrawn:
		logger.parser(LazyFormat("parsed no withdraw nlri",od,''))

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

	if not announced:
		logger.parser(LazyFormat("parsed no announced nlri",od,''))
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attributes / __init__.py View on Github external
# -- Reading AFI/SAFI
			afi,safi = unpack('!HB',data[:3])
			offset = 3

			# we do not want to accept unknown families
			if (afi,safi) not in self.negotiated.families:
				raise Notify(3,0,'presented a non-negotiated family %d/%d' % (afi,safi))

			# -- Reading length of next-hop
			len_nh = ord(data[offset])
			offset += 1

			rd = 0

			# check next-hope size
			if afi == AFI.ipv4:
				if safi in (SAFI.unicast,SAFI.multicast):
					if len_nh != 4:
						raise Notify(3,0,'invalid ipv4 unicast/multicast next-hop length %d expected 4' % len_nh)
				elif safi in (SAFI.mpls_vpn,):
					if len_nh != 12:
						raise Notify(3,0,'invalid ipv4 mpls_vpn next-hop length %d expected 12' % len_nh)
					rd = 8
				elif safi in (SAFI.flow_ip,):
					if len_nh not in (0,4):
						raise Notify(3,0,'invalid ipv4 flow_ip next-hop length %d expected 4' % len_nh)
				elif safi in (SAFI.flow_vpn,):
					if len_nh not in (0,4):
						raise Notify(3,0,'invalid ipv4 flow_vpn next-hop length %d expected 4' % len_nh)
			elif afi == AFI.ipv6:
				if safi in (SAFI.unicast,):
					if len_nh not in (16,32):
github Exa-Networks / exabgp / lib / exabgp / configuration / announce / ip.py View on Github external
def multicast_v4 (tokeniser):
	return ip_multicast(tokeniser,AFI.ipv4,SAFI.multicast)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / __init__.py View on Github external
def messages (self, negotiated, include_withdraw=True):
		# sort the nlris

		nlris = []
		mp_nlris = {}

		for nlri in sorted(self.nlris):
			if nlri.family() in negotiated.families:
				if nlri.afi == AFI.ipv4 and nlri.safi in [SAFI.unicast, SAFI.multicast]:
					nlris.append(nlri)
				else:
					mp_nlris.setdefault(nlri.family(), {}).setdefault(nlri.action, []).append(nlri)

		if not nlris and not mp_nlris:
			return

		attr = self.attributes.pack(negotiated, True)

		# Withdraws/NLRIS (IPv4 unicast and multicast)
		msg_size = negotiated.msg_size - 19 - 2 - 2 - len(attr)  # 2 bytes for each of the two prefix() header
		withdraws = b''
		announced = b''
		for nlri in nlris:
			packed = nlri.pack(negotiated)
			if len(announced + withdraws + packed) > msg_size:
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / factory.py View on Github external
if 2 + lw + 2+ la + len(announced) != length:
		raise Notify(3,1,'error in BGP message length, not enough data for the size announced')

	attributes = AttributesFactory(NLRIFactory,negotiated,attribute)

	# Is the peer going to send us some Path Information with the route (AddPath)
	addpath = negotiated.addpath.receive(AFI(AFI.ipv4),SAFI(SAFI.unicast))
	nho = attributes.get(AID.NEXT_HOP,None)
	nh = nho.packed if nho else None

	if not withdrawn:
		logger.parser(LazyFormat("parsed no withdraw nlri",od,''))

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

	if not announced:
		logger.parser(LazyFormat("parsed no announced nlri",od,''))

	while announced:
		length,nlri = NLRIFactory(AFI.ipv4,SAFI.unicast,announced,addpath,nh,IN.announced)
		logger.parser(LazyFormat("parsed announce nlri %s payload " % nlri,od,announced[:len(nlri)]))
		announced = announced[length:]
		nlris.append(nlri)

	for nlri in attributes.mp_withdraw:
		nlris.append(nlri)
github Exa-Networks / exabgp / lib / exabgp / configuration / neighbor / family.py View on Github external
def ipv4 (self,tokeniser):
		self._check_conflict()
		safi = tokeniser()

		if safi == 'unicast':
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.unicast)))
		elif safi == 'multicast':
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.multicast)))
		elif safi == 'nlri-mpls':
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.nlri_mpls)))
		elif safi == 'mpls-vpn':
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.mpls_vpn)))
		elif safi in ('flow'):
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.flow_ip)))
		elif safi == 'flow-vpn':
			self.content.append((AFI(AFI.ipv4),SAFI(SAFI.flow_vpn)))
		else:
			raise Raised('unknow family safi %s' % safi)

		self._drop_colon(tokeniser)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / open / capability / capabilities.py View on Github external
class Capabilities (dict):
	_ADD_PATH = [
		(AFI.ipv4,SAFI.unicast),
		(AFI.ipv6,SAFI.unicast),
		(AFI.ipv4,SAFI.nlri_mpls),
		(AFI.ipv4,SAFI.mpls_vpn),
		(AFI.ipv6,SAFI.mpls_vpn),
	]

	_NEXTHOP = [
		(AFI.ipv4, SAFI.unicast, AFI.ipv6),
		(AFI.ipv4, SAFI.multicast, AFI.ipv6),
		(AFI.ipv4, SAFI.nlri_mpls, AFI.ipv6),
		(AFI.ipv4, SAFI.mpls_vpn ,AFI.ipv6),
	]

	def announced (self, capability):
		return capability in self

	def __str__ (self):
		r = []
		for key in sorted(self.keys()):
			r.append(str(self[key]))
		return ', '.join(r)

	def _protocol (self, neighbor):
		families = neighbor.families()
		mp = MultiProtocol()
		mp.extend(families)
		self[Capability.CODE.MULTIPROTOCOL] = mp