bgp-origin-as.sh 816 B

12345678910111213141516171819202122232425
  1. #!/bin/sh
  2. #
  3. # List all known BGP prefixes along with their origin AS. For Anycast
  4. # prefixes, there may be multiple AS announcing the same prefixes, we
  5. # display the one related to the best route we have.
  6. #
  7. # TODO: this script currently doesn't grab our own announced prefix.
  8. MY_AS=76184
  9. ssh -N -M -S '~/.ssh/master_%r-%h-%p' -o ControlPersist=10 mejis.polynome.dn42 >/dev/null &
  10. sleep 1
  11. prefixes="$(ssh mejis.polynome.dn42 -S '~/.ssh/master_%r-%h-%p' "vtysh -c 'show ip route'" | grep '^B>*' | cut -d ' ' -f 2)"
  12. for prefix in $prefixes
  13. do
  14. echo -n "$prefix "
  15. ssh mejis.polynome.dn42 -S '~/.ssh/master_%r-%h-%p' "vtysh -c 'show ip bgp $prefix'" \
  16. | grep -B 2 'best$' | head -1 \
  17. | sed -e 's/^ *//' -e 's/,.*//' \
  18. | awk '{ print $(NF); }' \
  19. | sed -e "s/Local/$MY_AS/"
  20. done