143d5bcd0e
This is done to make pre-commit script happy. TrivialFix Change-Id: I4a080f8559b0392c6305c6d7c222be6ca006323c
2.0 KiB
2.0 KiB
BGP speaker library
Introduction
OS-Ken BGP speaker library helps you to enable your code to speak BGP protocol. The library supports IPv4, IPv4 MPLS-labeled VPN, IPv6 MPLS-labeled VPN and L2VPN EVPN address families.
Example
The following simple code creates a BGP instance with AS number 64512 and Router ID 10.0.0.1. It tries to establish a bgp session with a peer (its IP is 192.168.177.32 and the AS number is 64513). The instance advertizes some prefixes.
import eventlet
# BGPSpeaker needs sockets patched
eventlet.monkey_patch()
# initialize a log handler
# this is not strictly necessary but useful if you get messages like:
# No handlers could be found for logger "os_ken.lib.hub"
import logging
import sys
= logging.getLogger()
log
log.addHandler(logging.StreamHandler(sys.stderr))
from os_ken.services.protocols.bgp.bgpspeaker import BGPSpeaker
def dump_remote_best_path_change(event):
print 'the best path changed:', event.remote_as, event.prefix,\
event.nexthop, event.is_withdraw
def detect_peer_down(remote_ip, remote_as):
print 'Peer down:', remote_ip, remote_as
if __name__ == "__main__":
= BGPSpeaker(as_number=64512, router_id='10.0.0.1',
speaker =dump_remote_best_path_change,
best_path_change_handler=detect_peer_down)
peer_down_handler
'192.168.177.32', 64513)
speaker.neighbor_add(# uncomment the below line if the speaker needs to talk with a bmp server.
# speaker.bmp_server_add('192.168.177.2', 11019)
= 1
count while True:
30)
eventlet.sleep(= '10.20.' + str(count) + '.0/24'
prefix print "add a new prefix", prefix
speaker.prefix_add(prefix)+= 1
count if count == 4:
speaker.shutdown()break