コード例 #1
0
ファイル: capabilities.py プロジェクト: yesbox/exabgp
	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)
コード例 #2
0
ファイル: mpurnlri.py プロジェクト: aabdnn/exabgp
	def packed_attributes (self, negotiated, maximum=Negotiated.FREE_SIZE):
		if not self.nlris:
			return

		# we changed the API to nrli.pack from addpath to negotiated but not pack itself

		mpurnlri = []
		for nlri in self.nlris:
			if nlri.family() != self.family():  # nlri is not part of specified family
				continue
			mpurnlri.append(nlri.pack(negotiated))

		payload = concat_bytes(self.afi.pack(), self.safi.pack())
		header_length = len(payload)
		for nlri in mpurnlri:
			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 MPURNLRI')
				yield self._attribute(payload)
				payload = concat_bytes(self.afi.pack(), self.safi.pack(), 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 MPURNLRI')
		yield self._attribute(payload)
コード例 #3
0
ファイル: capabilities.py プロジェクト: dhammika/exabgp
	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)
コード例 #4
0
	def packed_attributes (self, negotiated, maximum=Negotiated.FREE_SIZE):
		if not self.nlris:
			return

		# addpath = negotiated.addpath.send(self.afi,self.safi)
		# nexthopself = negotiated.nexthopself(self.afi)
		mpnlri = {}
		for nlri in self.nlris:
			if nlri.family() != self.family():  # nlri is not part of specified family
				continue
			if nlri.nexthop is NoNextHop:
				# EOR and Flow may not have any next_hop
				nexthop = b''
			else:
				_,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)
コード例 #5
0
    def pack_nlri(self, negotiated=None):
        ordered_rules = []
        # the order is a RFC requirement
        for ID in sorted(self.rules.keys()):
            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"
        )
コード例 #6
0
ファイル: mpurnlri.py プロジェクト: bopopescu/exabgpsec-1
    def packed_attributes(self, negotiated, maximum=Negotiated.FREE_SIZE):
        if not self.nlris:
            return

        # we changed the API to nrli.pack from addpath to negotiated but not pack itself

        mpurnlri = []
        for nlri in self.nlris:
            if nlri.family() != self.family(
            ):  # nlri is not part of specified family
                continue
            mpurnlri.append(nlri.pack(negotiated))

        payload = concat_bytes(self.afi.pack(), self.safi.pack())
        header_length = len(payload)
        for nlri in mpurnlri:
            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 MPURNLRI'
                    )
                yield self._attribute(payload)
                payload = concat_bytes(self.afi.pack(), self.safi.pack(), 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 MPURNLRI')
        yield self._attribute(payload)
コード例 #7
0
ファイル: srgb.py プロジェクト: bopopescu/Exa-Networks-exabgp
 def pack(self):
     payload = pack('!H', 0)  # flags
     for b, r in self.srgbs:
         payload = concat_bytes(payload,
                                pack("!L", b)[1:],
                                pack("!L", r)[1:])
     return concat_bytes(pack('!B', self.TLV), pack('!H', len(payload)),
                         payload)
コード例 #8
0
 def extract(self):
     restart = pack('!H', ((self.restart_flag << 12) |
                           (self.restart_time & Graceful.TIME_MASK)))
     families = [(afi.pack(), safi.pack(), character(self[(afi, safi)]))
                 for (afi, safi) in self.keys()]
     sfamilies = concat_bytes_i(
         concat_bytes(pafi, psafi, family)
         for (pafi, psafi, family) in families)
     return [concat_bytes(restart, sfamilies)]
コード例 #9
0
	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)
コード例 #10
0
ファイル: srgb.py プロジェクト: Exa-Networks/exabgp
	def pack (self):
		payload = pack('!H',0)  # flags
		for b,r in self.srgbs:
			payload = concat_bytes(
				payload,
				pack("!L",b)[1:],
				pack("!L",r)[1:]
			)
		return concat_bytes(
			pack('!B', self.TLV),
			pack('!H', len(payload)),
			payload
		)
コード例 #11
0
ファイル: aspath.py プロジェクト: Exa-Networks/exabgp
	def _segment (self, seg_type, values, asn4):
		length = len(values)
		if length:
			if length > 255:
				return self._segment(seg_type,values[:255],asn4) + self._segment(seg_type,values[255:],asn4)
			return concat_bytes(character(seg_type),character(len(values)),concat_bytes_i(v.pack(asn4) for v in values))
		return b""
コード例 #12
0
 def pack(self):
     t = pack('!B', self.TLV)
     l = pack('!H', self.LENGTH)
     r0 = pack('!B', 0)
     r1 = pack('!H', 0)
     val = IP.pton(self.v6sid)
     return concat_bytes(t, l, r0, r1, val)
コード例 #13
0
ファイル: labelindex.py プロジェクト: steiler/exabgp
 def pack(self):
     t = pack('!B', self.TLV)
     l = pack('!H', self.LENGTH)
     val = pack('!I', self.labelindex)
     reserved = pack('!B', 0)
     flags = pack('!H', 0)
     return concat_bytes(t, l, reserved, flags, val)
コード例 #14
0
 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))
コード例 #15
0
ファイル: bgpsec.py プロジェクト: usnistgov/exabgpsrx
 def _signature_blocks(self, negotiated, asns=None, skis=None):
     self.signature_block = self._signature_block(negotiated, asns, skis)
     if not self.signature_block:
         return None
     return concat_bytes(
         pack('!H', (self.signature_block_len + self.SIG_BLOCK_LEN)),
         b''.join(self.signature_block))
コード例 #16
0
ファイル: operational.py プロジェクト: Exa-Networks/exabgp
		def __init__ (self, afi, safi, sequence):
			OperationalFamily.__init__(
				self,
				Operational.CODE.NS,
				afi,safi,
				concat_bytes(sequence,self.ERROR_SUBCODE)
			)
コード例 #17
0
ファイル: hostname.py プロジェクト: Exa-Networks/exabgp
	def extract (self):
		return [concat_bytes(
			character(len(self.host_name)),
			self.host_name,
			character(len(self.domain_name)),
			self.domain_name,
		)]
コード例 #18
0
ファイル: ipv6sid.py プロジェクト: Exa-Networks/exabgp
	def pack (self):
		return concat_bytes(
			pack('!B', self.TLV),
			pack('!H', self.LENGTH),
			pack('!B', 0),
			pack('!H', 0),
			IP.pton(self.v6sid)
		)
コード例 #19
0
 def pack_nlri(self, negotiated=None):
     return concat_bytes(
         b'\x00\x11',  # pack('!H',17)
         self.rd.pack(),
         pack('!HHH', self.endpoint, self.offset, self.size),
         pack('!L', (self.base << 4)
              | 0x1)[1:]  # setting the bottom of stack, should we ?
     )
コード例 #20
0
	def message (self,negotiated=None):
		return self._message(concat_bytes(
			self.version.pack(),
			self.asn.trans().pack(),
			self.hold_time.pack(),
			self.router_id.pack(),
			self.capabilities.pack()
		))
コード例 #21
0
 def extract(self):
     return [
         concat_bytes(
             character(len(self.host_name)),
             self.host_name,
             character(len(self.domain_name)),
             self.domain_name,
         )
     ]
コード例 #22
0
ファイル: bgpsec.py プロジェクト: usnistgov/exabgpsrx
    def _signature(self, asn=None, ski=None):
        signature = []
        signature = self._signature_from_lib(asn, ski)
        if not signature:  # in case None
            #self.logger.BGPSEC("Signature is not made due to Key issues")
            return None

        self.signature_block_len += len(signature)
        return concat_bytes(pack('!H', len(signature)), b''.join(signature))
コード例 #23
0
	def pack (self):
		return concat_bytes(
			pack('!B', self.TLV),
			pack('!H', self.LENGTH),
			pack('!B', 0),
			IP.pton(self.l3vpnsid),
			pack('!B', 0),
			pack('!H', 0xffff),
			pack('!B', 0),
		)
コード例 #24
0
ファイル: aspath.py プロジェクト: leleobhz/exabgp
 def _segment(self, seg_type, values, asn4):
     length = len(values)
     if length:
         if length > 255:
             return self._segment(seg_type, values[:255],
                                  asn4) + self._segment(
                                      seg_type, values[255:], asn4)
         return concat_bytes(character(seg_type), character(len(values)),
                             concat_bytes_i(v.pack(asn4) for v in values))
     return b""
コード例 #25
0
	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)
コード例 #26
0
    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(),
                                    self.etag.pack(), self.label.pack())
        return self._packed
コード例 #27
0
ファイル: operational.py プロジェクト: leleobhz/exabgp
    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))
コード例 #28
0
ファイル: operational.py プロジェクト: Exa-Networks/exabgp
	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
		))
コード例 #29
0
    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.etag.pack(),
                                    character(len(self.ip) * 8),
                                    self.ip.pack())
        return self._packed
コード例 #30
0
 def _attribute(self, value):
     flag = self.FLAG
     if flag & Attribute.Flag.OPTIONAL and not value:
         return b''
     length = len(value)
     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,
                         value)
コード例 #31
0
    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
コード例 #32
0
ファイル: flow.py プロジェクト: richardstrnad/exabgp
	def pack_nlri (self, negotiated=None):
		ordered_rules = []
		# the order is a RFC requirement
		for ID in sorted(self.rules.keys()):
			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")
コード例 #33
0
ファイル: ethernetad.py プロジェクト: Exa-Networks/exabgp
	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(),
			self.etag.pack(),
			self.label.pack()
		)
		return self._packed
コード例 #34
0
ファイル: segment.py プロジェクト: Exa-Networks/exabgp
	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
コード例 #35
0
ファイル: multicast.py プロジェクト: Exa-Networks/exabgp
	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.etag.pack(),
			character(len(self.ip)*8),
			self.ip.pack()
		)
		return self._packed
コード例 #36
0
ファイル: prefix.py プロジェクト: Exa-Networks/exabgp
	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(),
			self.etag.pack(),
			character(self.iplen),
			self.ip.pack(),
			self.gwip.pack(),
			self.label.pack(),
		)
		return self._packed
コード例 #37
0
    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(),
            self.etag.pack(),
            character(self.iplen),
            self.ip.pack(),
            self.gwip.pack(),
            self.label.pack(),
        )
        return self._packed
コード例 #38
0
    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(),
            self.etag.pack(),
            character(self.maclen),  # only 48 supported by the draft
            self.mac.pack(),
            character(len(self.ip) * 8 if self.ip else 0),
            self.ip.pack() if self.ip else b'',
            self.label.pack())
        return self._packed
コード例 #39
0
ファイル: mac.py プロジェクト: Exa-Networks/exabgp
	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(),
			self.etag.pack(),
			character(self.maclen),  # only 48 supported by the draft
			self.mac.pack(),
			character(len(self.ip)*8 if self.ip else 0),
			self.ip.pack() if self.ip else b'',
			self.label.pack()
		)
		return self._packed
コード例 #40
0
ファイル: operational.py プロジェクト: Exa-Networks/exabgp
	def _message (self, data):
		return Message._message(self,concat_bytes(
			self.what.pack(),
			pack('!H',len(data)),
			data
		))
コード例 #41
0
ファイル: refresh.py プロジェクト: Exa-Networks/exabgp
	def message (self,negotiated=None):
		return self._message(concat_bytes(self.afi.pack(),character(self.reserved),self.safi.pack()))
コード例 #42
0
ファイル: message.py プロジェクト: Exa-Networks/exabgp
	def _message (self, message):
		message_len = pack('!H',19+len(message))
		return concat_bytes(self.MARKER,message_len,self.TYPE,message)
コード例 #43
0
ファイル: operational.py プロジェクト: Exa-Networks/exabgp
	def _message (self, data):
		return Operational._message(self,concat_bytes(
			self.afi.pack(),
			self.safi.pack(),
			data
		))
コード例 #44
0
ファイル: __init__.py プロジェクト: cloudscale-ch/exabgp
 def prefix(data):
     # This function needs renaming
     return concat_bytes(pack('!H', len(data)), data)
コード例 #45
0
ファイル: operational.py プロジェクト: leleobhz/exabgp
 def _message(self, data):
     return Message._message(
         self, concat_bytes(self.what.pack(), pack('!H', len(data)), data))
コード例 #46
0
ファイル: operational.py プロジェクト: leleobhz/exabgp
 def __init__(self, afi, safi, sequence):
     OperationalFamily.__init__(
         self, Operational.CODE.NS, afi, safi,
         concat_bytes(sequence, self.ERROR_SUBCODE))
コード例 #47
0
ファイル: rt_record.py プロジェクト: Exa-Networks/exabgp
	def from_rt(cls, route_target):
		packed = route_target.pack()
		return cls.unpack(concat_bytes(packed[0:1], character(cls.COMMUNITY_SUBTYPE), packed[2:]))
コード例 #48
0
ファイル: operational.py プロジェクト: leleobhz/exabgp
 def _message(self, data):
     return Operational._message(
         self, concat_bytes(self.afi.pack(), self.safi.pack(), data))
コード例 #49
0
ファイル: flow.py プロジェクト: richardstrnad/exabgp
	def pack (self):
		raw = self.cidr.pack_nlri()
		# ID is defined in subclasses
		return concat_bytes(character(self.ID),raw)  # pylint: disable=E1101
コード例 #50
0
ファイル: flow.py プロジェクト: richardstrnad/exabgp
	def pack (self):
		# ID is defined in subclasses
		return concat_bytes(character(self.ID),character(self.cidr.mask),character(self.offset),self.cidr.pack_ip())  # pylint: disable=E1101
コード例 #51
0
ファイル: bgpsec.py プロジェクト: usnistgov/exabgpsrx
 def _secure_path(self, negotiated, asns=None):
     self.secure_path = self._secure_path_segment(negotiated, asns)
     return concat_bytes(
         pack('!H', (self.secure_path_len + self.SEC_PATH_LEN)),
         b''.join(self.secure_path))
コード例 #52
0
ファイル: __init__.py プロジェクト: aabdnn/exabgp
	def prefix (data):
		# This function needs renaming
		return concat_bytes(pack('!H',len(data)),data)
コード例 #53
0
ファイル: graceful.py プロジェクト: Exa-Networks/exabgp
	def extract (self):
		restart  = pack('!H',((self.restart_flag << 12) | (self.restart_time & Graceful.TIME_MASK)))
		families = [(afi.pack(),safi.pack(),character(self[(afi,safi)])) for (afi,safi) in self.keys()]
		sfamilies = concat_bytes_i(concat_bytes(pafi,psafi,family) for (pafi,psafi,family) in families)
		return [concat_bytes(restart,sfamilies)]
コード例 #54
0
ファイル: flow.py プロジェクト: richardstrnad/exabgp
	def pack (self):
		l,v = self.encode(self.value)
		op = self.operations | _len_to_bit(l)
		return concat_bytes(character(op),v)
コード例 #55
0
ファイル: aigp.py プロジェクト: Exa-Networks/exabgp
	def pack (self):
		return concat_bytes_i(concat_bytes(character(tlv.type),pack('!H',len(tlv.value)+3),tlv.value) for tlv in self)