Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVPN: NO_LABEL + mac/prefix length fixes and notifications #258

Merged
merged 4 commits into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/sdist/
/cover/

*.sln

.DS_Store
.coveralls.yml*
.coverage
Expand Down
35 changes: 25 additions & 10 deletions lib/exabgp/bgp/message/update/nlri/evpn/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from exabgp.bgp.message.update.nlri.qualifier.etag import EthernetTag
from exabgp.bgp.message.update.nlri.qualifier.mac import MAC as MACQUAL


from exabgp.bgp.message.update.nlri.evpn.nlri import EVPN

from exabgp.bgp.message.notification import Notify


# ===================================================================== EVPNNLRI

Expand All @@ -41,8 +42,8 @@ class MAC (EVPN):
NAME = "MAC/IP advertisement"
SHORT_NAME = "MACAdv"

def __init__ (self, rd, esi, etag, mac, maclen, label,ip,packed=None):
EVPN.__init__(self,packed)
def __init__ (self, rd, esi, etag, mac, maclen, label, ip, packed=None):
EVPN.__init__(self, packed)
self.rd = rd
self.esi = esi
self.etag = etag
Expand Down Expand Up @@ -103,23 +104,37 @@ def pack (self):

@classmethod
def unpack (cls, data):
datalen = len(data)
rd = RouteDistinguisher.unpack(data[:8])
esi = ESI.unpack(data[8:18])
etag = EthernetTag.unpack(data[18:22])
maclength = ord(data[22])

if maclength % 8 != 0:
raise Exception('invalid MAC Address length in %s' % cls.NAME)
end = 23 + maclength/8
if (maclength > 48 or maclength < 0):
raise Notify(3,5,'invalid MAC Address length in %s' % cls.NAME)
end = 23 + 6 # MAC length MUST be 6

mac = MACQUAL.unpack(data[23:end])

length = ord(data[end])
if length % 8 != 0:
raise Exception('invalid IP Address length in %s' % cls.NAME)
iplen = length / 8

ip = IP.unpack(data[end+1:end+1+iplen])
label = Labels.unpack(data[end+1+iplen:])
if datalen in [36,39]: # No IP information (1 or 2 labels)
iplenUnpack = 0
if iplen != 0:
raise Notify(3,5,"IP length is given as %d, but current MAC route has no IP information" % iplen)
elif datalen in [40, 43]: # Using IPv4 addresses (1 or 2 labels)
iplenUnpack = 4
if (iplen > 32 or iplen < 0):
raise Notify(3,5,"IP field length is given as %d, but current MAC route is IPv4 and valus is out of range" % iplen)
elif datalen in [52, 55]: # Using IPv6 addresses (1 or 2 labels)
iplenUnpack = 16
if (iplen > 128 or iplen < 0):
raise Notify(3,5,"IP field length is given as %d, but current MAC route is IPv6 and valus is out of range" % iplen)
else:
raise Notify(3,5,"Data field length is given as %d, but does not match one of the expected lengths" % datalen)

ip = IP.unpack(data[end+1:end+1+iplenUnpack])
label = Labels.unpack(data[end+1+iplenUnpack:])

return cls(rd,esi,etag,mac,maclength,label,ip,data)
10 changes: 5 additions & 5 deletions lib/exabgp/bgp/message/update/nlri/evpn/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

from exabgp.bgp.message.update.nlri.evpn.nlri import EVPN

from exabgp.bgp.message.notification import Notify


# ------------ EVPN Prefix Advertisement NLRI ------------
# As described here:
# http://tools.ietf.org/html/draft-ietf-bess-evpn-prefix-advertisement-01
Expand Down Expand Up @@ -63,9 +66,7 @@ def __init__(self, rd, esi, etag, label, ip, iplen, gwip, packed=None):
self.iplen = iplen
self.gwip = gwip
self.label = label
if self.label is None:
raise RuntimeError('NO_LABEL is not defined - it MUST have a pack() function')
self.label = "NO_LABEL"
self.label = label if label else Labels.NOLABEL
self.pack()

def __str__ (self):
Expand Down Expand Up @@ -147,8 +148,7 @@ def unpack (cls, exdata):
gwip = IP.unpack(data[:16])
data = data[16:]
else:
# XXX: not nice, we should raise a Notification
raise Exception("Data field length is given as %d, but EVPN route currently support only IPv4 or IPv6(34 or 58)" % iplen)
raise Notify(3,5,"Data field length is given as %d, but EVPN route currently support only IPv4 or IPv6(34 or 58)" % iplen)

label = Labels.unpack(data[:3])

Expand Down