I finally decided to request full BGP tables from all of my ISPs, so I can easily change the preferred path to certain destinations.

However this meant that now I have to monitor both the state of the BGP sessions, but also the amount of routes that I receive from my neighbors.

Before my days with full BGP tables I relied on this simple alias:

alias bgp_states='birdc show protocols|awk "/^BIRD|bgp/{printf \"%20s\t%s\t%s\t%s\t%s\t%s\n\", \$1, \$2, \$3, \$4, \$5, \$6}"'
alias bgp_states='birdc show protocols|column -t|grep -E "^BIRD|bgp"'

The above alias(with its two implementations), worked like charm and produced:

root@sfgw:~# bgp_states
BIRD                  1.5.0   ready.
bgp_itd_backup        BGP     main    up     2016-02-16  Established
bgp_evolink_main      BGP     main    up     2016-02-16  Established
bgp_evolink_backup    BGP     main    up     2016-02-16  Established
bgp_itd_main          BGP     main    up     2016-02-16  Established
bgp_telehouse_main    BGP     main    up     18:08:55    Established
bgp_telehouse_backup  BGP     main    up     18:09:25    Established
root@sfgw:~#

However, with full BGP tables, I needed a little bit more information. So I replaced the above aliases with this function:


function bgp_states {
    for i in $(birdc show protocols|grep -E "^BIRD|bgp"|sed 's/\s\+/|/g'); do
        a=( ${i//|/ })
        echo ${a[*]}|awk '{printf "%-16s\t%s\t%s\t%s\t%s\t%s\n", $1, $2, $3, $4, $5, $6;}'
        birdc show protocol all ${a[0]}|grep Routes
    done
}

I was lazy and didn’t want to implement it properly with while read or IFS. Maybe I’ll have version two for this function, also.

So its results are a bit more informative:

root@sfgw:~# bgp_states
BIRD                    1.5.0   ready.
bgp_itd_backup          BGP     main    up      2016-02-16      Established
  Routes:         575148 imported, 1 exported, 20951 preferred
bgp_evolink_main        BGP     main    up      2016-02-16      Established
  Routes:         1 imported, 1 exported, 0 preferred
bgp_evolink_backup      BGP     main    up      2016-02-16      Established
  Routes:         1 imported, 1 exported, 0 preferred
bgp_itd_main            BGP     main    up      2016-02-16      Established
  Routes:         575148 imported, 1 exported, 0 preferred
bgp_telehouse_main      BGP     main    up      18:08:55        Established
  Routes:         575939 imported, 1 exported, 233100 preferred
bgp_telehouse_backup    BGP     main    up      18:09:25        Established
  Routes:         472013 imported, 1 exported, 324399 preferred
root@sfgw:~#

Comments are closed.

Posted by HackMan
Dated: 19th February 2016
Filled Under: Linux General, Networking, Technology, Uncategorized