summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-10-22 14:27:27 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-10-23 12:04:26 +0900
commit2a4c36ef190e1b47da63dfcb534c7d434e42a3af (patch)
tree585ce1df42ad84ce2bce16a140dc635c02ab146f
parent6d11c925959a1f717cbd69e8a68e6a892c85ec55 (diff)
bgp: implement multiprotocol capability
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.py33
-rw-r--r--ryu/tests/unit/packet/test_bgp.py2
2 files changed, 33 insertions, 2 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 93ce4721..dab5150c 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -26,7 +26,6 @@ RFC 4271 BGP-4
# - RFC 4360 BGP Extended Communities Attribute
# - RFC 4364 BGP/MPLS IP Virtual Private Networks (VPNs)
# - RFC 4486 Subcodes for BGP Cease Notification Message
-# - RFC 4760 Multiprotocol Extensions for BGP-4
import abc
import struct
@@ -57,7 +56,7 @@ _MARKER = 16 * '\xff'
BGP_OPT_CAPABILITY = 2 # RFC 5492
-BGP_CAP_MULTI_PROTOCOL = 1 # RFC 4760
+BGP_CAP_MULTIPROTOCOL = 1 # RFC 4760
BGP_CAP_ROUTE_REFRESH = 2 # RFC 2918
BGP_CAP_FOUR_OCTET_AS_NUMBER = 65 # RFC 4893
@@ -327,6 +326,36 @@ class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
return buf
+@_OptParamCapability.register_type(BGP_CAP_MULTIPROTOCOL)
+class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
+ _CAP_PACK_STR = '!HBB' # afi, reserved, safi
+
+ def __init__(self, afi, safi, reserved=0, **kwargs):
+ super(BGPOptParamCapabilityMultiprotocol, self).__init__(**kwargs)
+ self.afi = afi
+ self.reserved = reserved
+ self.safi = safi
+
+ @classmethod
+ def parse_cap_value(cls, buf):
+ (afi, reserved, safi,) = struct.unpack_from(cls._CAP_PACK_STR,
+ buffer(buf))
+ return {
+ 'afi': afi,
+ 'reserved': reserved,
+ 'safi': safi,
+ }
+
+ def serialize_cap_value(self):
+ # fixup
+ self.reserved = 0
+
+ buf = bytearray()
+ msg_pack_into(self._CAP_PACK_STR, buf, 0,
+ self.afi, self.reserved, self.safi)
+ return buf
+
+
class BGPWithdrawnRoute(_IPAddrPrefix):
pass
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py
index 6e9f1a45..f614b212 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -45,6 +45,8 @@ class Test_bgp(unittest.TestCase):
opt_param = [bgp.BGPOptParamCapabilityUnknown(cap_code=200,
cap_value='hoge'),
bgp.BGPOptParamCapabilityRouteRefresh(),
+ bgp.BGPOptParamCapabilityMultiprotocol(
+ afi=afi.IP, safi=safi.MPLS_VPN),
bgp.BGPOptParamCapabilityFourOctetAsNumber(
as_number=1234567),
bgp.BGPOptParamUnknown(type_=99, value='fuga')]