summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-08-06 21:56:45 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-08-07 09:28:38 +0800
commit2adfda55e6dfe07c29949f2a4949318fd32d9529 (patch)
treef90d0867e300fb27ac2ee6ead87ae08cfafe8178
parent5fb5b6c57d8783c974fff469249a8013aa49c653 (diff)
packet/bmp: fix bug of BMP Peer Down Notification class
BMP Peer Down Notification packet must have a per-peer header. Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bmp.py27
-rw-r--r--ryu/services/protocols/bgp/bmp.py19
-rw-r--r--ryu/tests/unit/packet/test_bmp.py9
3 files changed, 47 insertions, 8 deletions
diff --git a/ryu/lib/packet/bmp.py b/ryu/lib/packet/bmp.py
index 207ded84..2ed6e07a 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 92849ee2..c899b5b6 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 dffb5c2f..67c2c755 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())