Skip to main content

Python BGP/BMP Message parser lib

Project description

Python Version Version License Build Status Test Coverage

This is a BGP/BMP Message unpack/pack lib written by Python which is inspired by exabgp especially its code structure design. We can use this lib to unpack or pack BGP/BMP messages both offline and online(like a live BGP speaker).

Quick Start

Install from source code:

$ git clone https://github.com/smartbgp/libbgp
$ cd libbgp
$ python setup.py install

or pip:

$ pip install libbgp

Usage

$ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from pprint import pprint
>>> from libbgp.bgp.message import Message
>>> update_msg_dict = {
...     'type': 2,
...     'msg': {
...         'attr': {
...             1: 2,
...             2: [(2, [701, 71])],
...             3: '219.158.1.204',
...             5: 100,
...             6: 0,
...             7: [71, '16.96.243.103'],
...             8: ['NO_EXPORT', '1234:5678'],
...             9: '219.158.1.204',
...             10: ['219.158.1.209', '0.0.0.30']
...         },
...         'nlri': ['192.168.1.1/32', '172.16.1.1/32'],
...         'withdraw': []
...     }
... }
>>> update_msg = Message.pack(update_msg_dict)
>>> update_msg.hex_value
'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00f\x02\x00\x00\x00E@\x01\x01\x02@\x02\x06\x02\x02\x02\xbd\x00G@\x03\x04\xdb\x9e\x01\xcc@\x05\x04\x00\x00\x00d@\x06\x01\x00\xc0\x07\x06\x00G\x10`\xf3g\xc0\x08\x08\xff\xff\xff\x01\x04\xd2\x16.\x80\t\x04\xdb\x9e\x01\xcc\x80\n\x08\xdb\x9e\x01\xd1\x00\x00\x00\x1e \xc0\xa8\x01\x01 \xac\x10\x01\x01'
>>> pprint(Message.unpack(update_msg.hex_value).dict())
{'msg': {'attr': {1: 2,
                  2: [(2, [701, 71])],
                  3: '219.158.1.204',
                  5: 100,
                  6: 0,
                  7: [71, '16.96.243.103'],
                  8: ['NO_EXPORT', '1234:5678'],
                  9: '219.158.1.204',
                  10: ['219.158.1.209', '0.0.0.30']},
         'nlri': ['192.168.1.1/32', '172.16.1.1/32'],
         'withdraw': []},
 'type': 2}
>>> Message.unpack(update_msg.hex_value).dict() == update_msg_dict
True
>>>

For more examples, Please reference libbgp/examples

Support

Please join our Slack http://smartbgp.slack.com/ for questions, discussion, suggestions, etc. And welcome to create issues and pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libbgp-0.2.0.tar.gz (22.9 kB view details)

Uploaded Source

File details

Details for the file libbgp-0.2.0.tar.gz.

File metadata

  • Download URL: libbgp-0.2.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for libbgp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b873dbc83190d8e5a2acb59b461bd75b8a92afbe168ff1597a7f967cb84431fe
MD5 7309eee3517dcdd59819ecc1096e2afa
BLAKE2b-256 0c4c2995449bfb23e689cf35decaf672a97e3262ce5b785fea006977558aef36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page