OpenBGP is a Python implementation for BGP Protocol. It was born in Cisco around 2011, we use it to establish BGP connections with all kinds of routers (include real Cisco/HuaWei/Juniper routers and some router simulators in Cisco like IOL/IOU) and receive/parse BGP messages for future analysis.
We write it in strict accordance with the specifications of RFCs.
This software can be used on Linux/Unix, Mac OS and Windows systems.
Quick Start
We recommend run openbgp through python virtual-env from source code or pip install
Use openbgp from source code:
$ virtualenv openbgp-virl
$ source openbgp-virl/bin/activate
$ git clone https://github.com/openbgp/openbgp
$ cd openbgp
$ pip install -r requirements.txt
$ cd bin
$ python openbgpd -h
usage: openbgpd [-h] [--bgp-local_addr BGP_LOCAL_ADDR]
[--bgp-local_as BGP_LOCAL_AS] [--bgp-md5 BGP_MD5]
[--bgp-remote_addr BGP_REMOTE_ADDR]
[--bgp-remote_as BGP_REMOTE_AS] [--config-dir DIR]
[--config-file PATH] [--log-config-file LOG_CONFIG_FILE]
[--log-dir LOG_DIR] [--log-file LOG_FILE]
[--log-file-mode LOG_FILE_MODE] [--nouse-stderr]
[--use-stderr] [--verbose] [--version] [--noverbose]
optional arguments:
-h, --help show this help message and exit
--config-dir DIR Path to a config directory to pull *.conf files from.
This file set is sorted, so as to provide a
predictable parse order if individual options are
over-ridden. The set is parsed after the file(s)
specified via previous --config-file, arguments hence
over-ridden options in the directory take precedence.
--config-file PATH Path to a config file to use. Multiple config files
can be specified, with values in later files taking
precedence. The default files used are: None.
--log-config-file LOG_CONFIG_FILE
Path to a logging config file to use
--log-dir LOG_DIR log file directory
--log-file LOG_FILE log file name
--log-file-mode LOG_FILE_MODE
default log file permission
--nouse-stderr The inverse of --use-stderr
--use-stderr log to standard error
--verbose show debug output
--version show program's version number and exit
--noverbose The inverse of --verbose
bgp options:
--bgp-local_addr BGP_LOCAL_ADDR
The local address of the BGP
--bgp-local_as BGP_LOCAL_AS
The Local BGP AS number
--bgp-md5 BGP_MD5 The MD5 string use to auth
--bgp-remote_addr BGP_REMOTE_ADDR
The remote address of the peer
--bgp-remote_as BGP_REMOTE_AS
The remote BGP peer AS number
Use pip install
$ virtualenv openbgp-virl
$ source openbgp-virl/bin/activate
$ pip install openbgp
$ which openbgpd
/home/bgpmon/openbgp-virl/bin/openbgpd
$ openbgpd -h
usage: openbgpd [-h] [--bgp-local_addr BGP_LOCAL_ADDR]
[--bgp-local_as BGP_LOCAL_AS] [--bgp-md5 BGP_MD5]
[--bgp-remote_addr BGP_REMOTE_ADDR]
[--bgp-remote_as BGP_REMOTE_AS] [--config-dir DIR]
[--config-file PATH] [--log-config-file LOG_CONFIG_FILE]
[--log-dir LOG_DIR] [--log-file LOG_FILE]
[--log-file-mode LOG_FILE_MODE] [--nouse-stderr]
[--use-stderr] [--verbose] [--version] [--noverbose]
optional arguments:
-h, --help show this help message and exit
--config-dir DIR Path to a config directory to pull *.conf files from.
This file set is sorted, so as to provide a
predictable parse order if individual options are
over-ridden. The set is parsed after the file(s)
specified via previous --config-file, arguments hence
over-ridden options in the directory take precedence.
--config-file PATH Path to a config file to use. Multiple config files
can be specified, with values in later files taking
precedence. The default files used are: None.
--log-config-file LOG_CONFIG_FILE
Path to a logging config file to use
--log-dir LOG_DIR log file directory
--log-file LOG_FILE log file name
--log-file-mode LOG_FILE_MODE
default log file permission
--nouse-stderr The inverse of --use-stderr
--use-stderr log to standard error
--verbose show debug output
--version show program's version number and exit
--noverbose The inverse of --verbose
bgp options:
--bgp-local_addr BGP_LOCAL_ADDR
The local address of the BGP
--bgp-local_as BGP_LOCAL_AS
The Local BGP AS number
--bgp-md5 BGP_MD5 The MD5 string use to auth
--bgp-remote_addr BGP_REMOTE_ADDR
The remote address of the peer
--bgp-remote_as BGP_REMOTE_AS
The remote BGP peer AS number
For example:
$ openbgpd --bgp-local_addr=1.1.1.1 --bgp-local_as=65001 --bgp-remote_addr=1.1.1.2 --bgp-remote_as=65001 --bgp-md5=test --config-file=../etc/openbgp/openbgp.ini
BGP message example:
in openbgp.ini, you can point out if you want to store the parsing BGP message to local disk and where you want to put them in.
[message]
# how to process parsed BGP message?
# Whether the BGP message is written to disk
# write_disk = True
# the BGP messages storage path
# write_dir = /home/bgpmon/data/bgp/
write_dir = ./
# The Max size of one BGP message file, the unit is MB
# write_msg_max_size = 500
$ more 1429257741.41.msg
[1429258235.343657, 1, 1, {'bgpID': '192.168.45.1', 'Version': 4, 'holdTime': 180, 'ASN': 23650, 'Capabilities': {'GracefulRestart': False, 'ciscoMultiSession': False, 'ciscoRouteRefresh': True, '4byteAS': True, 'AFI_SAFI': [(1, 1)],
'7
0': '', 'routeRefresh': True}}, (0, 0)]
[1429258235.346803, 2, 4, None, (0, 0)]
[1429258235.349598, 3, 4, None, (0, 0)]
[1429258235.349837, 4, 2, {'ATTR': {1: 0, 2: [(2, [64639, 64660])], 3: '192.168.24.1', 4: 0, 5: 100}, 'WITHDRAW': [], 'NLRI': ['192.168.1.0/24']}, (1, 1)]
The structure of each line is:
[timestamp, sequence number, message type, message content, address family]
For message type:
MSG_OPEN = 1
MSG_UPDATE = 2
MSG_NOTIFICATION = 3
MSG_KEEPALIVE = 4
MSG_ROUTEREFRESH = 5
MSG_CISCOROUTEREFRESH = 128