BGP協議的Python實現:yabgp

jopen 9年前發布 | 17K 次閱讀 yabgp Python開發

YABGP是BGP協議的另一個Python實現。它可以被用于建立與各種路由器的BGP連接(包括實思科/華為/ Juniper路由器和一些路由器模擬器像GNS3)和接收/解析BGP消息以供將來分析。

We write it in strict accordance with the specifications of RFCs.

This software can be used on Linux/Unix, Mac OS and Windows systems.

Features

  • It can establish BGP session based on IPv4 address (TCP Layer) in active mode(as TCP client);
  • Support TCP MD5 authentication(IPv4 and does not support Windows now);
  • BGP capabilities support: 4 Bytes ASN, IPv4 address family, Route Refresh(Cisco Route Refresh);
  • Decode all BGP messages to human readable strings and write files to disk(configurable);

Quick Start

We recommend runyabgpthrough python virtual-env from source code or pip install

Use yabgp from source code:

$ virtualenv yabgp-virl
$ source yabgp-virl/bin/activate
$ git clone https://github.com/smartbgp/yabgp
$ cd yabgp
$ pip install -r requirements.txt
$ cd bin
$ python yabgpd -h

Use pip install

$ virtualenv yabgp-virl
$ source yabgp-virl/bin/activate
$ pip install yabgp
$ which yabgpd
/home/bgpmon/yabgp-virl/bin/yabgpd
$ yabgpd -h

For example:

$ yabgpd --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/yabgp/yabgp.ini

BGP message example:

inyabgp.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

項目主頁:http://www.baiduhome.net/lib/view/home/1435109486857

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!