If you haven’t read the intro post to this series, Getting Started with ExaBGP, check that article out first as this post will be expanding on the previous example to show how to use python for more automated interaction with ExaBGP.

The first example I’ll cover is using a basic health check test to determine if a route should be announced or withdrawn from BGP. Here is our python script healthcheck.py with comments inline:

Let’s update our ExaBGP’s conf.ini to run this python script:

Now when we run ExaBGP with $ exabgp conf.ini, the health check python script will also run and push either ‘announce’ or ‘withdraw’ commands depending on the service availability. It doesn’t matter that we’re sending BGP UPDATE messages with the same route over and over again, but we may want to increase the delay if it’s causing high CPU on the device. Here’s what we see in the ExaBGP output about every 10 seconds:

Very cool, right?  Ok, but now what if we block/kill the TCP check?

Boom, routes removed. That’s fantastic. What if we want to check multiple end hosts and automate different prefix advertisements?  Well, that could entail an entire application to manage and monitor the end host and prefix objects, but here’s a quick and dirty modification of our healthcheck.py script:

We can create a list of tracked objects to iterate through every 10 seconds or so (depending on timeouts and availability of the services we’re checking). Just envision the flexibility possible if we were to read from a database for each tracked object and do some real threading to get the timing of the checks more precise.

The next post in this series will expand on the automation of ExaBGP using python by providing an API to control routes from an external system, so please check back soon.

Series Navigation<< ExaBGP and python: Getting StartedGive ExaBGP an HTTP API with SimpleHTTPServer or Flask >>

Leave a Reply

Your email address will not be published. Required fields are marked *