mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-01-23 09:32:07 +01:00
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>
This commit is contained in:
parent
5fb5b6c57d
commit
2adfda55e6
@ -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()
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user