def test_peer_up_notification(self): opt_param = [ bgp.BGPOptParamCapabilityUnknown(cap_code=200, cap_value=b'hoge'), bgp.BGPOptParamCapabilityRouteRefresh(), bgp.BGPOptParamCapabilityMultiprotocol(afi=afi.IP, safi=safi.MPLS_VPN) ] open_message = bgp.BGPOpen(my_as=40000, bgp_identifier='192.0.2.2', opt_param=opt_param) msg = bmp.BMPPeerUpNotification(local_address='192.0.2.2', local_port=179, remote_port=11089, sent_open_message=open_message, received_open_message=open_message, 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=self._time()) binmsg = msg.serialize() msg2, rest = bmp.BMPMessage.parser(binmsg) eq_(msg.to_jsondict(), msg2.to_jsondict()) eq_(rest, b'')
def _construct_peer_up_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_distinguisher = 0 peer_as = peer._neigh_conf.remote_as peer_bgp_id = peer.protocol.recv_open_msg.bgp_identifier timestamp = peer.state._established_time local_address = peer.host_bind_ip local_port = int(peer.host_bind_port) peer_address, remote_port = peer.protocol._remotename remote_port = int(remote_port) sent_open_msg = peer.protocol.sent_open_msg recv_open_msg = peer.protocol.recv_open_msg msg = bmp.BMPPeerUpNotification(local_address=local_address, local_port=local_port, remote_port=remote_port, sent_open_message=sent_open_msg, received_open_message=recv_open_msg, peer_type=peer_type, is_post_policy=False, peer_distinguisher=peer_distinguisher, peer_address=peer_address, peer_as=peer_as, peer_bgp_id=peer_bgp_id, timestamp=timestamp) return msg