multiple-bgpd.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # Public domain, not copyrighted..
  3. NUM=8
  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. NEXT2=$(( (($H+1) % ${NUM}) + 1 ))
  21. PREV2=$(( (($H + $NUM - 3) % ${NUM}) + 1 ))
  22. NEXTADDR="${PREFIX}${NEXT}"
  23. NEXTAS=$((${ASBASE} + $NEXT))
  24. PREVADDR="${PREFIX}${PREV}"
  25. PREVAS=$((${ASBASE} + $PREV))
  26. NEXT2ADDR="${PREFIX}${NEXT2}"
  27. NEXT2AS=$((${ASBASE} + $NEXT2))
  28. PREV2ADDR="${PREFIX}${PREV2}"
  29. PREV2AS=$((${ASBASE} + $PREV2))
  30. ASN=$((64560+${H}))
  31. # Edit config to suit.
  32. cat > "$CONF" <<- EOF
  33. password whatever
  34. service advanced-vty
  35. !
  36. router bgp ${ASN}
  37. bgp router-id ${ADDR}
  38. maximum-paths 32
  39. bgp bestpath as-path multipath-relax
  40. network 10.${H}.1.0/24 pathlimit 1
  41. network 10.${H}.2.0/24 pathlimit 2
  42. network 10.${H}.3.0/24 pathlimit 3
  43. network 10.${H}.0.0/24
  44. neighbor default peer-group
  45. neighbor default update-source ${ADDR}
  46. neighbor default capability orf prefix-list both
  47. neighbor default soft-reconfiguration inbound
  48. neighbor default route-map test out
  49. neighbor ${NEXTADDR} remote-as ${NEXTAS}
  50. neighbor ${NEXTADDR} peer-group default
  51. neighbor ${PREVADDR} remote-as ${PREVAS}
  52. neighbor ${PREVADDR} peer-group default
  53. neighbor ${NEXT2ADDR} remote-as ${NEXT2AS}
  54. neighbor ${NEXT2ADDR} peer-group default
  55. neighbor ${PREV2ADDR} remote-as ${PREV2AS}
  56. neighbor ${PREV2ADDR} peer-group default
  57. !
  58. address-family ipv6
  59. network 3ffe:${H}::/48
  60. network 3ffe:${H}:1::/48 pathlimit 1
  61. network 3ffe:${H}:2::/48 pathlimit 3
  62. network 3ffe:${H}:3::/48 pathlimit 3
  63. neighbor default activate
  64. neighbor default capability orf prefix-list both
  65. neighbor default default-originate
  66. neighbor default route-map test out
  67. neighbor ${NEXTADDR} peer-group default
  68. neighbor ${PREVADDR} peer-group default
  69. neighbor ${NEXT2ADDR} peer-group default
  70. neighbor ${PREV2ADDR} peer-group default
  71. exit-address-family
  72. !
  73. ! bgpd still has problems with extcommunity rt/soo
  74. route-map test permit 10
  75. set extcommunity rt ${ASN}:1
  76. set extcommunity soo ${ASN}:2
  77. set community ${ASN}:1
  78. !
  79. line vty
  80. exec-timeout 0 0
  81. !
  82. end
  83. EOF
  84. chown ${CHOWNSTR} "$CONF"
  85. fi
  86. # You may want to automatically add configure a local address
  87. # on a loop interface.
  88. #
  89. # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up
  90. # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null
  91. ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \
  92. -l ${ADDR} \
  93. -f "${CONF}" \
  94. -P $((${VTYBASE}+${H})) \
  95. -d
  96. done