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 | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 12 | |
| 13 | for H in `seq 1 ${NUM}` ; do |
Paul Jakma | 0e7c124 | 2008-06-01 14:26:48 +0000 | [diff] [blame] | 14 | CONF="${CONFBASE}"/bgpd${H}.conf |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 15 | ADDR=${PREFIX}.${H} |
| 16 | |
| 17 | if [ ! -e "$CONF" ] ; then |
| 18 | # This sets up a ring of bgpd peerings |
| 19 | NEXT=$(( ($H % ${NUM}) + 1 )) |
| 20 | PREV=$(( (($H + 3) % ${NUM}) + 1 )) |
| 21 | NEXTADDR="${PREFIX}.${NEXT}" |
| 22 | NEXTAS=$((${ASBASE} + $NEXT)) |
| 23 | PREVADDR="${PREFIX}.${PREV}" |
| 24 | PREVAS=$((${ASBASE} + $PREV)) |
| 25 | |
| 26 | # Edit config to suit. |
| 27 | cat > "$CONF" <<- EOF |
| 28 | password whatever |
| 29 | service advanced-vty |
| 30 | ! |
| 31 | router bgp $((64560+${H})) |
| 32 | bgp router-id ${ADDR} |
| 33 | network 10.${H}.1.0/24 pathlimit 1 |
| 34 | network 10.${H}.2.0/24 pathlimit 2 |
| 35 | network 10.${H}.3.0/24 pathlimit 3 |
| 36 | neighbor default peer-group |
| 37 | neighbor default update-source ${ADDR} |
| 38 | neighbor default capability orf prefix-list both |
| 39 | neighbor default soft-reconfiguration inbound |
| 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 | EOF |
| 45 | chown quagga:quagga "$CONF" |
| 46 | fi |
| 47 | # You may want to automatically add configure a local address |
| 48 | # on a loop interface. |
| 49 | # |
| 50 | # Solaris: ifconfig vni${H} plumb ${ADDR}/32 up |
| 51 | # Linux: ip address add ${ADDR}/32 dev lo 2> /dev/null |
Paul Jakma | 0e7c124 | 2008-06-01 14:26:48 +0000 | [diff] [blame] | 52 | ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \ |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 53 | -l ${ADDR} \ |
Paul Jakma | 0e7c124 | 2008-06-01 14:26:48 +0000 | [diff] [blame] | 54 | -f "${CONF}" \ |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 55 | -P $((${VTYBASE}+${H})) \ |
| 56 | -d |
| 57 | done |