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

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 1d3d2e6..48d3f83 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -277,6 +277,25 @@ class 
BGPOptParamCapabilityRouteRefresh(_OptParamCapability):
         return bytearray()
 
 
+@_OptParamCapability.register_type(BGP_CAP_FOUR_OCTET_AS_NUMBER)
+class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
+    _CAP_PACK_STR = '!I'
+
+    def __init__(self, as_number, **kwargs):
+        super(BGPOptParamCapabilityFourOctetAsNumber, self).__init__(**kwargs)
+        self.as_number = as_number
+
+    @classmethod
+    def parse_cap_value(cls, buf):
+        (as_number, ) = struct.unpack_from(cls._CAP_PACK_STR, buffer(buf))
+        return {'as_number': as_number}
+
+    def serialize_cap_value(self):
+        buf = bytearray()
+        msg_pack_into(self._CAP_PACK_STR, buf, 0, self.as_number)
+        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 fa3b9f3..2e1da86 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.BGPOptParamCapabilityFourOctetAsNumber(
+                         as_number=1234567),
                      bgp.BGPOptParamUnknown(type_=99, value='fuga')]
         msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.2',
                           opt_param=opt_param)
-- 
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=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to