Skip to content

Controlling ExaBGP : _ README first

Thomas Mangin edited this page Jan 3, 2014 · 2 revisions

Overview

ExaBGP was designed to be controlled from third party applications. Your application will be launched by ExaBGP which will then interact with it.

Two API are currently available to do so, the text API (more exhaustive) and its JSON conterpart (more recent but the way to go).

The way for a program to use the API is by reading from STDIN ( like if the command were entered using the keyboard ) and writing to STDOUT, like printing on the screen.

From version 3.3.0, the version reported in the JSON message reflect the last version at which a change was performed. Change must not be expected to always be backward compatible and the CHANGELOG (and this wiki) be looked at to understand the changes performed.

Example availables

Many examples are available in the example folder of ExaBGP, or the dev folder where the feature is use extensively for performing tests.

I will demonstrate how to use the feature using one of the test defined by the files exabgp/dev/runtest/api-add-remove.conf and exabgp/dev/runtest/api-add-remove.run

Configuring ExaBGP to use your program.

neighbor 127.0.0.1 {
	router-id 1.2.3.4;
	local-address 127.0.0.1;
	local-as 1;
	peer-as 1;
	graceful-restart;

	process announce-routes {
		run ./api-add-remove.run;
	}
}

The name "announce-routes" is just an informational string (which must not contain any spaces or tabulations).

The section "process" defined the program which is going to be run by ExaBGP. The path can be absolute or relative to the configuration file location.

The controlling application

#!/usr/bin/env python

import sys
import time

messages = [
'announce route 1.1.0.0/24 next-hop 101.1.101.1',
'announce route 1.1.0.0/25 next-hop 101.1.101.1',
'withdraw route 1.1.0.0/24 next-hop 101.1.101.1',
]

time.sleep(2)

while messages:
	message = messages.pop(0)
	sys.stdout.write( message + '\n')
	sys.stdout.flush()
	time.sleep(1)

while True:
	time.sleep(1)

This program will print three command to be executed by ExaBGP, announce a route, another and then ask for the first route to be withdrawn and then will then wait for termination.

Important note

Implementators using this API should keep in mind that read on STDIN are normally blocking. When using the same process for SENDING and receiving, ASYNC IO programming techniques should be used.

However two processes, one for sending and one for receiving, can be used, which may make the programming task easier if shared states are stored in a common database / key store / NoSQL application.