multiple-bgpd.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # Public domain, not copyrighted..
  3. NUM=5
  4. VTYBASE=2610
  5. ASBASE=64560
  6. BGPD=/path/to/bgpd
  7. PREFIX=192.168.145.
  8. #PREFIX=3ffe:123:456::
  9. ADDRPLEN=32
  10. CONFBASE=/tmp
  11. PIDBASE=/var/run/quagga
  12. CHOWNSTR=quagga:quagga
  13. for H in `seq 1 ${NUM}` ; do
  14. CONF="${CONFBASE}"/bgpd${H}.conf
  15. ADDR=${PREFIX}${H}
  16. if [ ! -e "$CONF" ] ; then
  17. # This sets up a ring of bgpd peerings
  18. NEXT=$(( ($H % ${NUM}) + 1 ))
  19. PREV=$(( (($H + $NUM - 2) % ${NUM}) + 1 ))
  20. NEXTADDR="${PREFIX}${NEXT}"
  21. NEXTAS=$((${ASBASE} + $NEXT))
  22. PREVADDR="${PREFIX}${PREV}"
  23. PREVAS=$((${ASBASE} + $PREV))
  24. ASN=$((64560+${H}))
  25. # Edit config to suit.
  26. cat > "$CONF" <<- EOF
  27. password whatever
  28. service advanced-vty
  29. !
  30. router bgp ${ASN}
  31. bgp router-id ${ADDR}
  32. network 10.${H}.1.0/24 pathlimit 1
  33. network 10.${H}.2.0/24 pathlimit 2
  34. network 10.${H}.3.0/24 pathlimit 3
  35. neighbor default peer-group
  36. neighbor default update-source ${ADDR}
  37. neighbor default capability orf prefix-list both
  38. neighbor default soft-reconfiguration inbound
  39. neighbor default route-map test out
  40. neighbor ${NEXTADDR} remote-as ${NEXTAS}
  41. neighbor ${NEXTADDR} peer-group default
  42. neighbor ${PREVADDR} remote-as ${PREVAS}
  43. neighbor ${PREVADDR} peer-group default
  44. !
  45. address-family ipv6
  46. network 3ffe:${H}::/48
  47. network 3ffe:${H}:1::/48 pathlimit 1
  48. network 3ffe:${H}:2::/48 pathlimit 3
  49. network 3ffe:${H}:3::/48 pathlimit 3
  50. neighbor default activate
  51. neighbor default capability orf prefix-list both
  52. neighbor default default-originate
  53. neighbor default route-map test out
  54. neighbor ${NEXTADDR} peer-group default
  55. neighbor ${PREVADDR} peer-group default
  56. exit-address-family
  57. !
  58. ! bgpd still has problems with extcommunity rt/soo
  59. route-map test permit 10
  60. set extcommunity rt ${ASN}:1
  61. set extcommunity soo ${ASN}:2
  62. set community ${ASN}:1
  63. line vty
  64. !
  65. end
  66. EOF
  67. chown ${CHOWNSTR} "$CONF"
  68. fi
  69. # You may want to automatically add configure a local address
  70. # on a loop interface.
  71. #
  72. # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up
  73. # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null
  74. ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \
  75. -l ${ADDR} \
  76. -f "${CONF}" \
  77. -P $((${VTYBASE}+${H})) \
  78. -d
  79. done