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