Пример #1
0
		def _key_values (name, data):
			if len(data) < 2:
				raise Notify(2,0,"Bad length for OPEN %s (<2) %s" % (name,Capability.hex(data)))
			l = ord(data[1])
			boundary = l+2
			if len(data) < boundary:
				raise Notify(2,0,"Bad length for OPEN %s (buffer underrun) %s" % (name,Capability.hex(data)))
			key = ord(data[0])
			value = data[2:boundary]
			rest = data[boundary:]
			return key,value,rest
Пример #2
0
		def _key_values (name, data):
			if len(data) < 2:
				raise Notify(2,0,"Bad length for OPEN %s (<2) %s" % (name,Capability.hex(data)))
			l = ord(data[1])
			boundary = l+2
			if len(data) < boundary:
				raise Notify(2,0,"Bad length for OPEN %s (buffer underrun) %s" % (name,Capability.hex(data)))
			key = ord(data[0])
			value = data[2:boundary]
			rest = data[boundary:]
			return key,value,rest
Пример #3
0
	def unpack (data):
		def _key_values (name, data):
			if len(data) < 2:
				raise Notify(2,0,"Bad length for OPEN %s (<2) %s" % (name,Capability.hex(data)))
			l = ord(data[1])
			boundary = l+2
			if len(data) < boundary:
				raise Notify(2,0,"Bad length for OPEN %s (buffer underrun) %s" % (name,Capability.hex(data)))
			key = ord(data[0])
			value = data[2:boundary]
			rest = data[boundary:]
			return key,value,rest

		capabilities = Capabilities()

		option_len = ord(data[0])
		# XXX: FIXME: check the length of data
		if option_len:
			data = data[1:]
			while data:
				key,value,data = _key_values('parameter',data)
				# Paramaters must only be sent once.
				if key == Parameter.AUTHENTIFICATION_INFORMATION:
					raise Notify(2,5)

				if key == Parameter.CAPABILITIES:
					while value:
						capability,capv,value = _key_values('capability',value)
						capabilities[capability] = Capability.unpack(capability,capabilities,capv)
				else:
					raise Notify(2,0,'Unknow OPEN parameter %s' % hex(key))
		return capabilities
Пример #4
0
	def unpack (data):
		def _key_values (name, data):
			if len(data) < 2:
				raise Notify(2,0,"Bad length for OPEN %s (<2) %s" % (name,Capability.hex(data)))
			l = ord(data[1])
			boundary = l+2
			if len(data) < boundary:
				raise Notify(2,0,"Bad length for OPEN %s (buffer underrun) %s" % (name,Capability.hex(data)))
			key = ord(data[0])
			value = data[2:boundary]
			rest = data[boundary:]
			return key,value,rest

		capabilities = Capabilities()

		option_len = ord(data[0])
		# XXX: FIXME: check the length of data
		if option_len:
			data = data[1:]
			while data:
				key,value,data = _key_values('parameter',data)
				# Paramaters must only be sent once.
				if key == Parameter.AUTHENTIFICATION_INFORMATION:
					raise Notify(2,5)

				if key == Parameter.CAPABILITIES:
					while value:
						capability,capv,value = _key_values('capability',value)
						capabilities[capability] = Capability.unpack(capability,capabilities,capv)
				else:
					raise Notify(2,0,'Unknow OPEN parameter %s' % hex(key))
		return capabilities
Пример #5
0
 def family(self, tokeniser):
     data = self.get_section(SectionFamily.name, tokeniser)
     if data:
         self.content[Capability.CODE(
             Capability.CODE.MULTIPROTOCOL)] = MultiProtocol(
                 (afi, safi) for afi in sorted(data)
                 for safi in sorted(data[afi]))
     else:
         return False
Пример #6
0
    def enter(self, tokeniser):
        Section.enter(self, tokeniser)

        self.content[Capability.CODE(Capability.CODE.FOUR_BYTES_ASN)] = True
        self.content[Capability.CODE(Capability.CODE.AIGP)] = False
        self.content[Capability.CODE(Capability.CODE.ADD_PATH)] = 0
        self.content[Capability.CODE(Capability.CODE.OPERATIONAL)] = False
        self.content[Capability.CODE(Capability.CODE.ROUTE_REFRESH)] = False
        self.content[Capability.CODE(Capability.CODE.MULTISESSION)] = False
        self.content[Capability.CODE(Capability.CODE.GRACEFUL_RESTART)] = 0
Пример #7
0
    def addpath(self, tokeniser):
        self._check_duplicate(tokeniser, RaisedCapability)
        valid_options = ('receive', 'send', 'send/receive', 'disable',
                         'disabled')
        ap = tokeniser()
        if ap not in valid_options:
            raise RaisedCapability(
                tokeniser,
                "%s is not a invalid add-path paramerter, options are %s" %
                (ap, ', '.join(valid_options)))

        self.content[Capability.CODE(Capability.CODE.ADD_PATH)] = 0
        if ap.endswith('receive'):
            self.content[Capability.CODE.ADD_PATH] += 1
        if ap.startswith('send'):
            self.content[Capability.CODE.ADD_PATH] += 2
Пример #8
0
    def graceful(self, tokeniser):
        self._check_duplicate(tokeniser, RaisedCapability)
        token = tokeniser()
        if not token.isdigit():
            raise RaisedCapability(
                tokeniser,
                "%s is not a valid option for graceful-restart, it must be a positive number smaller than 2^16"
                % token)

        duration = int(token)
        if duration < 0:
            raise RaisedCapability(
                tokeniser,
                "%s is not a valid option for graceful-restart, it must be a positive number smaller than 2^16"
                % token)
        if duration > pow(2, 16):
            raise RaisedCapability(
                tokeniser,
                "%s is not a valid option for graceful-restart, it must be a positive number smaller than 2^16"
                % token)

        self.content[Capability.CODE(
            Capability.CODE.GRACEFUL_RESTART)] = duration
Пример #9
0
from exabgp.bgp.message.open.capability.capability import Capability

from exabgp.bgp.message.open.capability.addpath import AddPath
from exabgp.bgp.message.open.capability.asn4 import ASN4
from exabgp.bgp.message.open.capability.graceful import Graceful
from exabgp.bgp.message.open.capability.mp import MultiProtocol
from exabgp.bgp.message.open.capability.ms import MultiSession
from exabgp.bgp.message.open.capability.operational import Operational
from exabgp.bgp.message.open.capability.refresh import RouteRefresh
from exabgp.bgp.message.open.capability.refresh import EnhancedRouteRefresh
from exabgp.bgp.message.open.capability.unknown import UnknownCapability
from exabgp.bgp.message.open.capability.bgpsec import BGPSEC

# Must be imported and registered for the register API to work
Capability.register_capability(AddPath)
Capability.register_capability(ASN4)
Capability.register_capability(Graceful)
Capability.register_capability(MultiProtocol)
Capability.register_capability(MultiSession,Capability.CODE.MULTISESSION_CISCO)
Capability.register_capability(MultiSession,Capability.CODE.MULTISESSION)
Capability.register_capability(Operational)
Capability.register_capability(RouteRefresh,Capability.CODE.ROUTE_REFRESH)
Capability.register_capability(RouteRefresh,Capability.CODE.ROUTE_REFRESH_CISCO)
Capability.register_capability(EnhancedRouteRefresh)
Capability.register_capability(BGPSEC)
Capability.fallback_capability(UnknownCapability)
# End registration


class REFRESH (object):
Пример #10
0
"""

from exabgp.bgp.message.open.capability.capability import Capability

from exabgp.bgp.message.open.capability.addpath import AddPath
from exabgp.bgp.message.open.capability.asn4 import ASN4
from exabgp.bgp.message.open.capability.graceful import Graceful
from exabgp.bgp.message.open.capability.mp import MultiProtocol
from exabgp.bgp.message.open.capability.ms import MultiSession
from exabgp.bgp.message.open.capability.operational import Operational
from exabgp.bgp.message.open.capability.refresh import RouteRefresh
from exabgp.bgp.message.open.capability.refresh import EnhancedRouteRefresh
from exabgp.bgp.message.open.capability.unknown import UnknownCapability

# Must be imported and registered for the register API to work
Capability.register_capability(AddPath)
Capability.register_capability(ASN4)
Capability.register_capability(Graceful)
Capability.register_capability(MultiProtocol)
Capability.register_capability(MultiSession,Capability.CODE.MULTISESSION_CISCO)
Capability.register_capability(MultiSession,Capability.CODE.MULTISESSION)
Capability.register_capability(Operational)
Capability.register_capability(RouteRefresh,Capability.CODE.ROUTE_REFRESH)
Capability.register_capability(RouteRefresh,Capability.CODE.ROUTE_REFRESH_CISCO)
Capability.register_capability(EnhancedRouteRefresh)
Capability.fallback_capability(UnknownCapability)
# End registration


class REFRESH (object):
	ABSENT   = 0x01
Пример #11
0
 def aigp(self, tokeniser):
     self._check_duplicate(tokeniser, RaisedCapability)
     self.content[Capability.CODE(Capability.CODE.AIGP)] = boolean(
         tokeniser, False)
Пример #12
0
 def asn4(self, tokeniser):
     self._check_duplicate(tokeniser, RaisedCapability)
     self.content[Capability.CODE(
         Capability.CODE.FOUR_BYTES_ASN)] = boolean(tokeniser, True)
Пример #13
0
 def exit(self, tokeniser):
     if Capability.CODE(Capability.CODE.MULTIPROTOCOL) not in self.content:
         self.content[Capability.CODE(
             Capability.CODE.MULTIPROTOCOL)] = MultiProtocol(
                 known_families())
Пример #14
0
 def multisession(self, tokeniser):
     self._check_duplicate(tokeniser, RaisedCapability)
     self.content[Capability.CODE(
         Capability.CODE.MULTISESSION_CISCO)] = boolean(tokeniser, False)
Пример #15
0
 def refresh(self, tokeniser):
     self._check_duplicate(tokeniser, RaisedCapability)
     self.content[Capability.CODE(Capability.CODE.ROUTE_REFRESH)] = boolean(
         tokeniser, False)
Пример #16
0
 def operational(self, tokeniser):
     self._check_duplicate(tokeniser, RaisedCapability)
     self.content[Capability.CODE(Capability.CODE.OPERATIONAL)] = boolean(
         tokeniser, False)