Skip to content

Commit

Permalink
Merge pull request #13 from pierky/large_bgp_communities
Browse files Browse the repository at this point in the history
Add large BGP communities support
  • Loading branch information
t2mune committed Nov 27, 2016
2 parents eb8d555 + 94a2d01 commit cf05346
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/mrt2exabgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ def get_bgp_attr(args, params, m, attr):
elif attr.type == BGP_ATTR_T['AIGP']:
line += ' aigp %d' % attr.aigp[0]['val']

elif attr.type == BGP_ATTR_T['LARGE_COMMUNITY']:
large_comm = ' '.join(attr.large_comm)
line += ' large-community [%s]' % large_comm

return line

def main():
Expand Down
2 changes: 2 additions & 0 deletions examples/print_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def print_bgp_attr(attr, n):
prline('Origin AS: %s' % attr.attr_set['origin_as'])
for attr in attr.attr_set['attr']:
print_bgp_attr(attr, 3)
elif attr.type == BGP_ATTR_T['LARGE_COMMUNITY']:
prline(line + ': %s' % ' '.join(attr.large_comm))
else:
line += ': 0x'
for c in attr.val:
Expand Down
20 changes: 19 additions & 1 deletion mrtparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def reverse_defaultdict(d):
17:'AS4_PATH', # Defined in RFC6793
18:'AS4_AGGREGATOR', # Defined in RFC6793
26:'AIGP', # Defined in RFC7311
32:'LARGE_COMMUNITY', # Defined in draft-ietf-idr-large-community
128:'ATTR_SET', # Defined in RFC6368
})

Expand Down Expand Up @@ -1162,7 +1163,7 @@ class BgpAttr(Base):
'flag', 'type', 'len', 'origin', 'as_path', 'next_hop', 'med',
'local_pref', 'aggr', 'comm', 'org_id', 'cl_list', 'mp_reach',
'mp_unreach', 'ext_comm', 'as4_path', 'as4_aggr', 'aigp', 'attr_set',
'val'
'large_comm', 'val'
]

def __init__(self, buf):
Expand All @@ -1187,6 +1188,7 @@ def __init__(self, buf):
self.as4_aggr = None
self.aigp = None
self.attr_set = None
self.larg_comm = None
self.val = None

def unpack(self, af=0):
Expand Down Expand Up @@ -1233,6 +1235,8 @@ def unpack(self, af=0):
self.unpack_aigp()
elif self.type == BGP_ATTR_T['ATTR_SET']:
self.unpack_attr_set()
elif self.type == BGP_ATTR_T['LARGE_COMMUNITY']:
self.unpack_large_community()
else:
self.val = self.val_bytes(self.len)
return self.p
Expand Down Expand Up @@ -1444,6 +1448,20 @@ def unpack_attr_set(self):
self.p += attr.unpack()
self.attr_set['attr'].append(attr)

def unpack_large_community(self):
'''
Decoder for LARGE_COMMUNITY attribute
'''
attr_len = self.p + self.len
self.large_comm = []
while self.p < attr_len:
global_admin = self.val_num(4)
local_data_part_1 = self.val_num(4)
local_data_part_2 = self.val_num(4)
self.large_comm.append(
'%d:%d:%d' %
(global_admin, local_data_part_1, local_data_part_2))

class Nlri(Base):
'''
Class for NLRI.
Expand Down
Binary file added samples/quagga_bgp_large_communities
Binary file not shown.

0 comments on commit cf05346

Please sign in to comment.