diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-10-22 14:27:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-10-23 12:04:26 +0900 |
commit | 6d11c925959a1f717cbd69e8a68e6a892c85ec55 (patch) | |
tree | 001bacaef5af501125ada92521403d02c28aca79 | |
parent | 61b89177112d4894aff16d69c20dc398e4e89eec (diff) |
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>
-rw-r--r-- | ryu/lib/packet/bgp.py | 38 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_bgp.py | 2 |
2 files changed, 40 insertions, 0 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index eb3e2d13..93ce4721 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -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 diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py index 0dc7fb61..6e9f1a45 100644 --- a/ryu/tests/unit/packet/test_bgp.py +++ b/ryu/tests/unit/packet/test_bgp.py @@ -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 = [ |