Val:~$ whoami

I am Val Glinskiy, network engineer specializing in data center networks. TIME magazine selected me as Person of the Year in 2006.

Search This Blog

Wednesday, October 14, 2009

How to generate lots of BGP routes

I needed to test in the lab whether my Cisco router can handle more than 300K routes - size of current full BGP table. Now, Cisco router can only accept 200 network statements under router bgp configuration, so I would need 1500 routers. Even if I had that many routers to my disposal, it would have taken days to configure all of them. As always, open source software can help. Quagga lets you run OSPF, BGP, RIP, RIPng on Linux and Solaris. If you go with all default options, it is very easy to install. Download and unpack. Go to quagga directory, in my case it was quagga-0.98.6, type
sudo make install
That's it. By default, it went into /usr/local/. I have Debian 4 (Etch) with 2.6.8 kernel and a lot of development packages installed. The only thing I had to do was to add /usr/local/lib to /etc/ file and run /sbin/ldconfig.
Here is the setup

Now I need a valid configuration file for Quagga BGP. Adding 300000 network statements manually is not something system administrators do on Linux. Hence, here is the script

my $host="quagga-host";         #quagga router name
my $logpass="zebra";            #login password
my $enable="zebra";             #enable password
my $myasn="65099";              #local AS number
my $router_id="";     #bgp router-id
my $remote_as="65001";          #remote-as number
my $remote_ip="";     #BGP neighbor ip address
my $route_count=0;
my $max_routes=300000;              #max number of routers to generate

open (BGPCONF,'>bgpd.conf')|| die "Can not open bgpd.conf for writing";
print BGPCONF "hostname $host\npassword $logpass\nenable password $enable\nline vty \n";
print BGPCONF "router bgp $myasn\n  bgp router-id $router_id\n  neighbor $remote_ip remote-as $remote_as\n";
MAXR: while ($route_count <= $max_routes ) { 
$octet1=int(rand(223))+1; #generate 1st octet randomly in 1-223 range, 224 and up is multicust and class E  
if ($octet1 ==127) {next;} #need to make sure that 127.X.X.0/24 is excluded 
while ( $octet2 <= 255 ){
while ( $octet3 <= 255 ) {
print BGPCONF "  network $octet1\.$octet2\.$octet3\.0/24\n";
if ($route_count == $max_routes) {last MAXR;}
close BGPCONF;
this script will generate bgpd.conf for Quagga. Since it is lab environment not connected to any real network, I do not really care about zebra configuration or restricting access to Quagga BGP console. Copy bgpd.conf file into /usr/local/etc and run /usr/local/sbin/bgpd -d -f /usr/local/etc/bgpd.conf -u root -g root Again, this is not production environment. Do not run Quagga as root in production. Here is relevant configuration from Cisco router:
interface GigabitEthernet0/0
ip address
network mask
media-type rj45
negotiation auto
router bgp 65001
no synchronization
bgp log-neighbor-changes
neighbor remote-as 65099
no auto-summary
Let's see if it works. On Linux host:
sh-2.05b$ telnet localhost 2605
Connected to localhost.localdomain.
Escape character is '^]'.

Hello, this is Quagga (version 0.98.6).
Copyright 1996-2005 Kunihiro Ishiguro, et al.

User Access Verification

quagga-host> sho ip bgp summ
BGP router identifier, local AS number 65099
2 BGP AS-PATH entries
0 BGP community entries

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd      4 65001     283     606        0    0    0 03:41:55        1

Total number of neighbors 1
on Cisco:
R1#sho ip bgp sum
BGP router identifier, local AS number 65001
BGP table version is 330002, main routing table version 330002
310001 network entries using 40920132 bytes of memory
310001 path entries using 16120052 bytes of memory
3/2 BGP path/bestpath attribute entries using 444 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
Bitfield cache entries: current 1 (at peak 2) using 32 bytes of memory
BGP using 57040684 total bytes of memory
BGP activity 310001/0 prefixes, 320001/10000 paths, scan interval 60 secs

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd      4 65099     602     322   330002    0    0 03:38:59   310000
Yep. It works.


  1. hi dude, somewhere in this script you will need to increment $route_count otherwise it loops forever

  2. hi dude, somewhere in this script you will need to increment $route_count otherwise it loops forever

  3. Thanks. Somehow, when I copy-paste'd it, I missed $route_count++ line.

  4. ...Well you need to increment the counter (route_count++ for every iteration) else you will compare it with var max_routes ?. What i just changed is a assign to octet2 and initial value ($octet2=0, under the if statement for 127 equality). Without it there is no initial value for that variable and the first network (rand(223).x.y.z/24) in x [octet2] gets created as null (rand(223)..y.z/24). Nice, easy and practical stuff. An alternative could be found here:


  5. Thanks for pointing this out. I do assign $octet2=0, but because of blogger unfortunate formatting it ended up on the same string as "if ($octet1 ==127)" and looked like a comment

  6. Yes you are right, i have just noticed it in the comments section from the copy/paste tmp file that i used from the previous post.


  7. Hi,
    can anyone tell me where and by which name i need to save this configuration file.
    appreciate your help.
    good day.

    1. This is perl script and can be saved as whatever file name you want. You need to make it executable, or run "perl ". The script will create bgpd.conf file for your quagga installation. If you used default parameters, you need to copy bgpd.conf to /usr/local/etc

    2. Thanks to you ,
      it worked.
      have a good day ahead, mate.

  8. Thanks for the script! It's really nice to have this capability essentially anywhere, and script makes it so simple!


  9. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you Best bgp configuration service provider.