#!/bin/sh

# ignore Control C
# if the user ^C exabgp we will get that signal too, ignore it and let exabgp send us a SIGTERM
TEMPFILE=/tmp/prefixes.bgp
PREFIXES=500000
BLOCK=128

trap '' SIGINT

# Dump our prefixs in a file for parsing a block at a time
/usr/local/bin/bs-prefixes.py $PREFIXES > $TEMPFILE

# Pause a bit to let BGP sessions come up
sleep 10

# Here we go, pause to throttle the advertisements a bit
LINE=0
while [ $LINE -lt $PREFIXES ]; do
   LINE=$(( $LINE + $BLOCK ))
   for pfx in `head -n $LINE $TEMPFILE | tail -n $BLOCK`; do
      echo "announce route $pfx next-hop 10.0.0.0"
   done
   sleep 2
done
