9.28.2009

Confirming BGP Advertisement

Needing a quick and easy way of confirming routing for a given prefix, I decided to write an Expect script that would check all of the major route-servers with telnet capability for BGP best path information and dampening/penalties. This is really useful for documenting evidence of a new route's completion.

#!/usr/bin/expect -f
#
# FILENAME: ask_looking_glasses.exp
# DESCRIPTION: Obtains BGP routing information from several well-known Internet
# route-servers.
# LAST UPDATE: 2009-09-21 - jds (Added flaps/dampening reporting)
#


if { $argv == "" } {
puts "Usage: ask_looking_glasses.exp <prefix/length> \[<prefix/length>\]...\n"
exit
}

# These are the only route-servers I could find that support telnet access
set rsvrlist [ list "route-server.ip.att.net" \
"route-server.gblx.net" \
"route-server.host.net" \
"route-server.he.net" \
"route-views.oregon-ix.net" \
"route-server.twtelecom.net" ]
set match ""

foreach rsvr $rsvrlist {
set timeout 20
log_user 0
puts "--------------------------------------------------------------------"
puts "Spawning telnet $rsvr..."
spawn telnet $rsvr
expect {
"remote host" {puts "Spawn failed!\n"; continue}
"not known" {puts "Spawn failed!\n"; continue}
"sername: " {send "rviews\r"}
">" {send "\r"}
}

puts "Spawn successful.\n Output follows:"

foreach prefix $argv {
# Kludge for a problem where the use of continue
# on the last iteration causes foreach to
# run an iteration with a null list item. Bug in
# TCL/Expect?
if {$prefix == ""} {
break
}

send_user "\\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ "
send_user "\\/ \\/ \\/ \\/ \\/ \\/ \\/\n"

# Check if prefix is well-formed
regexp {[0-9]{1,3}(\.[0-9]{1,3}){3}/[0-9]{1,2}} $prefix match
if {$match == ""} {
puts "$prefix is not well-formed!\n"
continue
} else {set match ""}

# If you'd like to know anything else, add it here
set cmdlist [list "sho ip bgp $prefix longer | incl \\/|>|Network" \
"sho ip bgp damp flap $prefix | incl \\/|>|Network" ]

foreach cmd $cmdlist {
# Kludge for a problem where the use of continue
# on the last iteration causes foreach to
# run an iteration with a null list item. Bug in
# TCL/Expect?
if {$cmd == ""} {
break
}

expect ">"

# Remove output processing where '| include' is
# not supported
if {$rsvr == "route-server.he.net"} {
regexp {sho ip bgp [0-9].*} $cmd match
if {$match != ""} {
set match ""
set cmd "sho ip bgp $prefix longer"
} else {set match ""}
}

# Skip flap-checking for servers without dampening
if {$rsvr == "route-server.twtelecom.net" \
||  $rsvr == "route-server.he.net" \
||  $rsvr == "route-server.host.net"} {
regexp {sho ip bgp damp.*} $cmd match
if {$match != ""} {
send "\r"
continue
} else {set match ""}
}

log_user 1
send "$cmd\r"

# Scroll through any paginated output
while {1} {
expect {
--
" --More-- " {send " "}
"\[0-9a-zA-Z\]>" {break}
}
}
log_user 0
send "\r"
}
puts "\n"
}
send "exit\r"
puts ""
}
exit


And here is an example of the output.

jstorm[0]@absinthe:~$ Documents/scripts/convenience/ask_looking_glasses.exp 38.126.72.0/24 61.8.132.0/24
--------------------------------------------------------------------
Spawning telnet route-server.ip.att.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*d 38.126.72.0/24   12.123.29.249                          0 7018 174 4903 ?
*>                  12.123.5.240                           0 7018 174 4903 ?
route-server>sho ip bgp damp flap 38.126.72.0/24 | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          From            Flaps Duration Reuse    Path
*d 38.126.72.0/24   12.123.29.249   9     01:41:03 00:09:30 7018 174 4903
*>                  12.123.5.240    9     01:41:26          7018 174 4903
route-server>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*  61.8.132.0/24    12.123.17.244                          0 7018 3356 9498 17447 i
*>                  12.123.1.236                           0 7018 3491 9498 17447 i
route-server>sho ip bgp damp flap 61.8.132.0/24 | incl \/|>|Network
route-server>


--------------------------------------------------------------------
Spawning telnet route-server.gblx.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
* i38.126.72.0/24   67.17.64.89            100    200      0 174 4903 ?
*>i                 67.17.64.89            100    200      0 174 4903 ?
route-server.phx1>sho ip bgp damp flap 38.126.72.0/24 | incl \/|>|Network
route-server.phx1>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*>i61.8.132.0/24    67.17.64.89              0    300      0 3491 9498 17447 i
route-server.phx1>sho ip bgp damp flap 61.8.132.0/24 | incl \/|>|Network
route-server.phx1>


--------------------------------------------------------------------
Spawning telnet route-server.host.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*> 38.126.72.0/24   64.135.0.1                             0 13645 7018 174 4903 ?
route-server>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*> 61.8.132.0/24    64.135.0.1                             0 13645 19151 3491 9498 17447 i
route-server>


--------------------------------------------------------------------
Spawning telnet route-server.he.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer
BGP table version is 0, local router ID is 64.62.142.154
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i38.126.72.0/24   154.54.10.37            20     47      0 174 4903 i
* i                 154.54.10.37            55     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
*>i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          60     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 66.160.128.118          55     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          60     70      0 174 4903 i
* i                 154.54.10.37            20     70      0 174 4903 i
* i                 66.160.128.118          55     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i
* i                 66.160.128.118          20     70      0 174 4903 i

Total number of prefixes 1
route-server.he.net>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer
BGP table version is 0, local router ID is 64.62.142.154
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i61.8.132.0/24    195.66.225.109           1    100      0 9498 17447 i
* i                 195.66.225.109           1    100      0 9498 17447 i
*>i                 216.218.252.172          1    100      0 9498 17447 i
* i                 195.66.225.109           1    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 216.218.252.178          1    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 195.66.225.109           1    100      0 9498 17447 i
* i                 216.218.252.180          1    100      0 3491 9498 17447 i
* i                 206.223.143.149          1    100      0 9498 17447 i
* i                 206.223.143.149         60    100      0 9498 17447 i
* i                 206.223.143.149         55    100      0 9498 17447 i
* i                 195.66.225.109           1    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         60    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i
* i                 206.223.143.149         20    100      0 9498 17447 i

Total number of prefixes 1
route-server.he.net>


--------------------------------------------------------------------
Spawning telnet route-views.oregon-ix.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*  38.126.72.0/24   203.181.248.168                        0 7660 2516 174 4903 ?
*>                  207.45.223.244                         0 6453 174 4903 ?
route-views.oregon-ix.net>sho ip bgp damp flap 38.126.72.0/24 | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          From            Flaps Duration Reuse    Path
*  38.126.72.0/24   203.181.248.168 11    01:41:11          7660 2516 174 4903
*>                  207.45.223.244  1     00:16:18          6453 174 4903
route-views.oregon-ix.net>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
   Network          Next Hop            Metric LocPrf Weight Path
*  61.8.132.0/24    216.218.252.164                        0 6939 9498 17447 i
*>                  4.69.184.193             0             0 3356 9498 17447 i
route-views.oregon-ix.net>sho ip bgp damp flap 61.8.132.0/24 | incl \/|>|Network
route-views.oregon-ix.net>


--------------------------------------------------------------------
Spawning telnet route-server.twtelecom.net...
Spawn successful.
 Output follows:
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 38.126.72.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
   Network          Next Hop            Metric LocPrf Weight Path
* i38.126.72.0/24   168.215.52.223           0    105      0 174 4903 ?
*>i                 168.215.52.6             0    105      0 174 4903 ?
route-server>

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
sho ip bgp 61.8.132.0/24 longer | incl \/|>|Network
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
   Network          Next Hop            Metric LocPrf Weight Path
* i61.8.132.0/24    168.215.52.235           0    105      0 7473 9498 17447 i
*>i                 168.215.52.202           0    105      0 3491 9498 17447 i
route-server>


I hope you find it as useful as I have.

Cheers.

No comments:

Post a Comment