Example #1
0
 def test_stream_parser(self):
     msgs = [
         bgp.BGPNotification(error_code=1, error_subcode=2, data="foo"),
         bgp.BGPNotification(error_code=3, error_subcode=4, data="bar"),
         bgp.BGPNotification(error_code=5, error_subcode=6, data="baz"),
     ]
     binmsgs = b''.join([bytes(msg.serialize()) for msg in msgs])
     sp = bgp.StreamParser()
     results = []
     for b in binmsgs:
         for m in sp.parse(b):
             results.append(m)
     eq_(str(results), str(msgs))
Example #2
0
 def test_notification(self):
     data = "hoge"
     msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
     binmsg = msg.serialize()
     msg2, rest = bgp.BGPMessage.parser(binmsg)
     eq_(str(msg), str(msg2))
     eq_(len(msg), 21 + len(data))
     eq_(rest, '')
Example #3
0
 def test_peer_down_notification(self):
     reason = bmp.BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION
     data = b'hoge'
     data = bgp.BGPNotification(error_code=1, error_subcode=2, data=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=self._time())
     binmsg = msg.serialize()
     msg2, rest = bmp.BMPMessage.parser(binmsg)
     eq_(msg.to_jsondict(), msg2.to_jsondict())
     eq_(rest, b'')