Signed-off-by: YAMAMOTO Takashi <[email protected]>
---
 ryu/lib/packet/bgp.py             | 33 +++++++++++++++++++++++++++++++--
 ryu/tests/unit/packet/test_bgp.py |  2 ++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 93ce472..dab5150 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 6e9f1a4..f614b21 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')]
-- 
1.8.3.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to