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