Tuesday, September 26, 2017

ExaBGP and Cisco Nexus - BGP Simulation


Exabgp is one of the Simplest and opensource tool to insert BGP Routes ( IXIA Network being a Costly Affair )


Exabgp Requires two files to work

1.exabgp.conf  - Setting of BGP information of Peer

2. Script that prints routes to stdout , which is picked by exabgp daemon
 Script can in any language bash , python ..
 Route in stdout is in format of
 ( learn )
announce route 100.10.10.0/24 next-hop self
( unlearn)
withdraw route 101.10.10.0/24 next-hop self"

So if you connecting it to Cisco Nexus 7000 Switches , below is simplest congfiguration to get started.

Nexus 7000 Config


n7k# show running-config 

feature bgp

router bgp 100
  neighbor 20.1.1.20 remote-as 2
    address-family ipv4 unicast

interface Ethernet1/1
  ip address 20.1.1.10/24
  no shutdown


Exabgp Server

interface should be configure using ifconfig ethx 20.1.1.20 netmask 255.255.255.0
&
Exabgp.conf ( /etc/exabgp/exabgp.conf) - 

neighbor 20.1.1.10 {
        router-id 1.1.1.1;
        local-address 20.1.1.20;
        local-as 2;
        peer-as 100;
        family {
                ipv4 unicast;
        }
        process myapp {

                #run /usr/bin/python /etc/exabgp/iplist.py;
                #run /usr/bin/python /etc/exabgp/test.py;
                run /bin/bash /etc/exabgp/a.sh;
        }
}



where in process myapp section there is script to generates routes to stdout which is picked by Exabgp.

sample scripts eg.

1. Python

#!/usr/bin/env python
from sys import stdout
from time import sleep
import time
import sys

i  = 0
j = 0
k = 0

#learn Routes 100.10.1.0....10.10.255.0
while True:
        k += 1
        if k == 255:
                j += 1
                if j == 255:
                        break;
        sys.stdout.write('announce route 100.%d.%d.0/24 next-hop self \n' % (j,k))
        sys.stdout.flush()
        #introduce delay in annoucing route

sleep(10)

#unlearn Routes 10.10.101.0...10.10.255.0
count = 100
while True:
        count += 1
        if count == 255:
                break;
        sys.stdout.write('withdraw route 100.10.%d.0/24 next-hop self \n' % (count))
        sys.stdout.flush()
        #introduce delay in annoucing route

#Loop endlessly to allow ExaBGP to continue running
while True:
    sleep(1)


2. bash script example

#!/bin/bash

# A shell script to print each number five times.


                for (( k = 1 ; k <= 200; k++ )) ### Inner for loop ###
                        do
                        #echo "announce route 100.10.$k.0/24 next-hop self"
                        echo "withdraw route 100.10.$k.0/24 next-hop self"
                done
#  done


for (( ; ; ))
do
   sleep 1

done






Good Reads
https://www.m00nie.com/2014/01/bgp-rtbh-setup-using-exabgp/
http://www.trex.fi/2016/exabgp-trex.pdf
https://github.com/Exa-Networks/exabgp/wiki/Controlling-ExaBGP-:-_-README-first
http://blog.bajzelj.com/2015/12/using-exabgp-to-control-your-routers.html

No comments:

Post a Comment

Featured Post

XDP - Getting Started with XDP (Linux)