How to use the exabgp.util.concat_bytes 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 / open / capability / capabilities.py View on Github external
def pack (self):
		rs = []
		for k,capabilities in six.iteritems(self):
			for capability in capabilities.extract():
				rs.append(concat_bytes(character(k),character(len(capability)),capability))
		parameters = concat_bytes_i(concat_bytes(character(2),character(len(r)),r) for r in rs)
		return concat_bytes(character(len(parameters)),parameters)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / operational.py View on Github external
def message (self, negotiated):
		self.sent_routerid = self.routerid if self.routerid else negotiated.sent_open.router_id
		if self.sequence is None:
			self.sent_sequence = (self.__sequence_number.setdefault(self.routerid,0) + 1) % 0xFFFFFFFF
			self.__sequence_number[self.sent_routerid] = self.sent_sequence
		else:
			self.sent_sequence = self.sequence

		return self._message(concat_bytes(
			self.sent_routerid.pack(),pack('!L',self.sent_sequence),
			self.data
		))
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / mprnlri.py View on Github external
_,rd_size = Family.size.get(self.family(),(0,0))
				nh_rd = character(0)*rd_size if rd_size else b''
				nexthop = nh_rd + nlri.nexthop.ton(negotiated,nlri.afi)

			# mpunli[nexthop] = nlri
			mpnlri.setdefault(nexthop,[]).append(nlri.pack(negotiated))

		for nexthop,nlris in six.iteritems(mpnlri):
			payload = concat_bytes(self.afi.pack(), self.safi.pack(), character(len(nexthop)), nexthop, character(0))
			header_length = len(payload)
			for nlri in nlris:
				if self._len(payload + nlri) > maximum:
					if len(payload) == header_length or len(payload) > maximum:
						raise Notify(6, 0, 'attributes size is so large we can not even pack on MPRNLRI')
					yield self._attribute(payload)
					payload = concat_bytes(self.afi.pack(), self.safi.pack(), character(len(nexthop)), nexthop, character(0), nlri)
					continue
				payload  = concat_bytes(payload, nlri)
			if len(payload) == header_length or len(payload) > maximum:
				raise Notify(6, 0, 'attributes size is so large we can not even pack on MPRNLRI')
			yield self._attribute(payload)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / sr / ipv6sid.py View on Github external
def pack (self):
		return concat_bytes(
			pack('!B', self.TLV),
			pack('!H', self.LENGTH),
			pack('!B', 0),
			pack('!H', 0),
			IP.pton(self.v6sid)
		)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / open / capability / capabilities.py View on Github external
def pack (self):
		rs = []
		for k,capabilities in six.iteritems(self):
			for capability in capabilities.extract():
				rs.append(concat_bytes(character(k),character(len(capability)),capability))
		parameters = concat_bytes_i(concat_bytes(character(2),character(len(r)),r) for r in rs)
		return concat_bytes(character(len(parameters)),parameters)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / nlri / flow.py View on Github external
rules = self.rules[ID]
			# for each component get all the operation to do
			# the format use does not prevent two opposing rules meaning that no packet can ever match
			for rule in rules:
				rule.operations &= (CommonOperator.EOL ^ 0xFF)
			rules[-1].operations |= CommonOperator.EOL
			# and add it to the last rule
			if ID not in (FlowDestination.ID,FlowSource.ID):
				ordered_rules.append(character(ID))
			ordered_rules.append(concat_bytes_i(rule.pack() for rule in rules))

		components = self.rd.pack() + concat_bytes_i(ordered_rules)

		lc = len(components)
		if lc < 0xF0:
			return concat_bytes(character(lc),components)
		if lc < 0x0FFF:
			return concat_bytes(pack('!H',lc | 0xF000),components)
		raise Notify(3,0,"my administrator attempted to announce a Flow Spec rule larger than encoding allows, protecting the innocent the only way I can")
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / sr / labelindex.py View on Github external
def pack (self):
		return concat_bytes(
			pack('!B', self.TLV),
			pack('!H', self.LENGTH),
			pack('!B',0),  # reserved
			pack('!H',0),  # flags
			pack('!I',self.labelindex)
		)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / generic.py View on Github external
def pack (self, negotiated=None):
		flag = self.FLAG
		length = len(self.data)
		if length > 0xFF:
			flag |= Attribute.Flag.EXTENDED_LENGTH
		if flag & Attribute.Flag.EXTENDED_LENGTH:
			len_value = pack('!H',length)
		else:
			len_value = character(length)
		return concat_bytes(character(flag),character(self.ID),len_value,self.data)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / attribute / sr / srgb.py View on Github external
def pack (self):
		t = pack('!B', self.TLV)
		val = b''
		for srgb in self.srgbs:
			base = pack("!L", srgb[0])[1:]
			srange = pack("!L", srgb[1])[1:]
			val = concat_bytes(base,srange,val)
		flags = pack('!H',0)
		val = concat_bytes(flags,val)
		l = pack('!H', len(val))
		return concat_bytes(t,l,val)
github Exa-Networks / exabgp / lib / exabgp / bgp / message / update / nlri / evpn / segment.py View on Github external
def _pack (self, packed=None):
		if self._packed:
			return self._packed

		if packed:
			self._packed = packed
			return packed

		self._packed = concat_bytes(
			self.rd.pack(),
			self.esi.pack(),
			character(len(self.ip)*8 if self.ip else 0),
			self.ip.pack() if self.ip else b''
		)
		return self._packed