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

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index b1bc2f2..1d9b8e6 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -811,6 +811,57 @@ class BGPNotification(BGPMessage):
         return msg
 
 
[email protected]_type(BGP_MSG_ROUTE_REFRESH)
+class BGPRouteRefresh(BGPMessage):
+    """BGP-4 ROUTE REFRESH Message (RFC 2918) encoder/decoder class.
+
+    An instance has the following attributes at least.
+    Most of them are same to the on-wire counterparts but in host byte
+    order.
+    __init__ takes the correspondig args in this order.
+
+    ========================== ===============================================
+    Attribute                  Description
+    ========================== ===============================================
+    marker                     Marker field.  Ignored when encoding.
+    len                        Length field.  Ignored when encoding.
+    type                       Type field.  The default is
+                               BGP_MSG_ROUTE_REFRESH.
+    afi                        Address Family Identifier
+    safi                       Subsequent Address Family Identifier
+    ========================== ===============================================
+    """
+
+    _PACK_STR = '!HBB'
+    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
+
+    def __init__(self,
+                 afi, safi, reserved=0,
+                 type_=BGP_MSG_ROUTE_REFRESH, len_=None, marker=None):
+        super(BGPRouteRefresh, self).__init__(marker=marker, len_=len_,
+                                              type_=type_)
+        self.afi = afi
+        self.safi = safi
+        self.reserved = reserved
+
+    @classmethod
+    def parser(cls, buf):
+        (afi, reserved, safi,) = struct.unpack_from(cls._PACK_STR,
+                                                    buffer(buf))
+        return {
+            "afi": afi,
+            "reserved": reserved,
+            "safi": safi,
+        }
+
+    def serialize_tail(self):
+        # fixup
+        self.reserved = 0
+
+        return bytearray(struct.pack(self._PACK_STR, self.afi,
+                                     self.reserved, self.safi))
+
+
 class StreamParser(stream_parser.StreamParser):
     """Streaming parser for BGP-4 messages.
 
diff --git a/ryu/tests/unit/packet/test_bgp.py 
b/ryu/tests/unit/packet/test_bgp.py
index 99db218..889763d 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -19,6 +19,8 @@ from nose.tools import eq_
 from nose.tools import ok_
 
 from ryu.lib.packet import bgp
+from ryu.lib.packet import afi
+from ryu.lib.packet import safi
 
 
 class Test_bgp(unittest.TestCase):
@@ -115,6 +117,14 @@ class Test_bgp(unittest.TestCase):
         eq_(len(msg), 21 + len(data))
         eq_(rest, '')
 
+    def test_route_refresh(self):
+        msg = bgp.BGPRouteRefresh(afi=afi.IP, safi=safi.MPLS_VPN)
+        binmsg = msg.serialize()
+        msg2, rest = bgp.BGPMessage.parser(binmsg)
+        eq_(str(msg), str(msg2))
+        eq_(len(msg), 23)
+        eq_(rest, '')
+
     def test_stream_parser(self):
         msgs = [
             bgp.BGPNotification(error_code=1, error_subcode=2, data="foo"),
-- 
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