BMP Peer Down Notification packet must have a per-peer header.

Signed-off-by: ISHIDA Wataru <[email protected]>
---
 ryu/lib/packet/bmp.py             |   27 +++++++++++++++++++++------
 ryu/services/protocols/bgp/bmp.py |   19 ++++++++++++++++++-
 ryu/tests/unit/packet/test_bmp.py |    9 ++++++++-
 3 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/ryu/lib/packet/bmp.py b/ryu/lib/packet/bmp.py
index 207ded8..2ed6e07 100644
--- a/ryu/lib/packet/bmp.py
+++ b/ryu/lib/packet/bmp.py
@@ -454,7 +454,7 @@ class BMPStatisticsReport(BMPPeerMessage):
 
 
 @BMPMessage.register_type(BMP_MSG_PEER_DOWN_NOTIFICATION)
-class BMPPeerDownNotification(BMPMessage):
+class BMPPeerDownNotification(BMPPeerMessage):
     """BMP Peer Down Notification Message
 
     ========================== ===============================================
@@ -468,14 +468,29 @@ class BMPPeerDownNotification(BMPMessage):
     ========================== ===============================================
     """
 
-    def __init__(self, reason, data, type_=BMP_MSG_PEER_DOWN_NOTIFICATION,
-                 len_=None, version=VERSION):
-        super(BMPPeerDownNotification, self).__init__(type_, len_, version)
+    def __init__(self, reason, data, peer_type, is_post_policy,
+                 peer_distinguisher, peer_address, peer_as, peer_bgp_id,
+                 timestamp, version=VERSION,
+                 type_=BMP_MSG_PEER_DOWN_NOTIFICATION, len_=None):
+
+        super(BMPPeerDownNotification,
+              self).__init__(peer_type=peer_type,
+                             is_post_policy=is_post_policy,
+                             peer_distinguisher=peer_distinguisher,
+                             peer_address=peer_address,
+                             peer_as=peer_as,
+                             peer_bgp_id=peer_bgp_id,
+                             timestamp=timestamp,
+                             len_=len_,
+                             type_=type_,
+                             version=version)
+
         self.reason = reason
         self.data = data
 
     @classmethod
     def parser(cls, buf):
+        kwargs, buf = super(BMPPeerDownNotification, cls).parser(buf)
         reason, = struct.unpack_from('!B', buffer(buf))
         buf = buf[struct.calcsize('!B'):]
 
@@ -491,14 +506,14 @@ class BMPPeerDownNotification(BMPMessage):
             reason = BMP_PEER_DOWN_REASON_UNKNOWN
             data = buf
 
-        kwargs = {}
         kwargs['reason'] = reason
         kwargs['data'] = data
 
         return kwargs
 
     def serialize_tail(self):
-        msg = struct.pack('!B', self.reason)
+        msg = super(BMPPeerDownNotification, self).serialize_tail()
+        msg += struct.pack('!B', self.reason)
 
         if self.reason == BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION:
             msg += self.data.serialize()
diff --git a/ryu/services/protocols/bgp/bmp.py 
b/ryu/services/protocols/bgp/bmp.py
index 92849ee..c899b5b 100644
--- a/ryu/services/protocols/bgp/bmp.py
+++ b/ryu/services/protocols/bgp/bmp.py
@@ -139,8 +139,25 @@ class BMPClient(Activity):
         return msg
 
     def _construct_peer_down_notification(self, peer):
+        if peer.is_mpbgp_cap_valid(bgp.RF_IPv4_VPN) or \
+                peer.is_mpbgp_cap_valid(bgp.RF_IPv6_VPN):
+            peer_type = bmp.BMP_PEER_TYPE_L3VPN
+        else:
+            peer_type = bmp.BMP_PEER_TYPE_GLOBAL
+
+        peer_as = peer._neigh_conf.remote_as
+        peer_bgp_id = self._core_service.router_id
+        peer_address, _ = peer.protocol._remotename
+
         return bmp.BMPPeerDownNotification(bmp.BMP_PEER_DOWN_REASON_UNKNOWN,
-                                           data=None)
+                                           data=None,
+                                           peer_type=peer_type,
+                                           is_post_policy=False,
+                                           peer_distinguisher=0,
+                                           peer_address=peer_address,
+                                           peer_as=peer_as,
+                                           peer_bgp_id=peer_bgp_id,
+                                           timestamp=0)
 
     def _construct_route_monitoring(self, peer, path):
         if peer.is_mpbgp_cap_valid(bgp.RF_IPv4_VPN) or \
diff --git a/ryu/tests/unit/packet/test_bmp.py 
b/ryu/tests/unit/packet/test_bmp.py
index dffb5c2..67c2c75 100644
--- a/ryu/tests/unit/packet/test_bmp.py
+++ b/ryu/tests/unit/packet/test_bmp.py
@@ -72,7 +72,14 @@ class Test_bmp(unittest.TestCase):
         reason = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
         data = "hoge"
         data = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
-        msg = bmp.BMPPeerDownNotification(reason, data)
+        msg = bmp.BMPPeerDownNotification(reason=reason, data=data,
+                                          peer_type=bmp.BMP_PEER_TYPE_GLOBAL,
+                                          is_post_policy=True,
+                                          peer_distinguisher=0,
+                                          peer_address='192.0.2.1',
+                                          peer_as=30000,
+                                          peer_bgp_id='192.0.2.1',
+                                          timestamp=time())
         binmsg = msg.serialize()
         msg2, rest = bmp.BMPMessage.parser(binmsg)
         eq_(msg.to_jsondict(), msg2.to_jsondict())
-- 
1.7.10.4


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to