bgp: implement MP_UNREACH_NLRI

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2013-10-22 14:27:26 +09:00 committed by FUJITA Tomonori
parent 61b8917711
commit 6d11c92595
2 changed files with 40 additions and 0 deletions

View File

@ -607,6 +607,44 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute):
return buf
@_PathAttribute.register_type(BGP_ATTR_TYPE_MP_UNREACH_NLRI)
class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
_VALUE_PACK_STR = '!HB' # afi, safi
_ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
def __init__(self, afi, safi, withdrawn_routes,
flags=0, type_=None, length=None):
super(BGPPathAttributeMpUnreachNLRI, self).__init__(flags=flags,
type_=type_,
length=length)
self.afi = afi
self.safi = safi
self.withdrawn_routes = withdrawn_routes
@classmethod
def parse_value(cls, buf):
(afi, safi,) = struct.unpack_from(cls._VALUE_PACK_STR, buffer(buf))
binnlri = buf[struct.calcsize(cls._VALUE_PACK_STR):]
nlri = []
while binnlri:
n, binnlri = _BinAddrPrefix.parser(binnlri)
nlri.append(n)
return {
'afi': afi,
'safi': safi,
'withdrawn_routes': nlri,
}
def serialize_value(self):
buf = bytearray()
msg_pack_into(self._VALUE_PACK_STR, buf, 0, self.afi, self.safi)
binnlri = bytearray()
for n in self.withdrawn_routes:
binnlri += n.serialize()
buf += binnlri
return buf
class BGPNLRI(_IPAddrPrefix):
pass

View File

@ -96,6 +96,8 @@ class Test_bgp(unittest.TestCase):
bgp.BGPPathAttributeMpReachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
next_hop='abcd',
nlri=mp_nlri),
bgp.BGPPathAttributeMpUnreachNLRI(afi=afi.IP, safi=safi.MPLS_VPN,
withdrawn_routes=mp_nlri),
bgp.BGPPathAttributeUnknown(flags=0, type_=100, value=300*'bar')
]
nlri = [