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)) |
Paul Jakma | c112af2 | 2010-11-27 11:49:09 +0000 | [diff] [blame^] | 28 | ASN=$((64560+${H})) |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 29 | |
| 30 | # Edit config to suit. |
| 31 | cat > "$CONF" <<- EOF |
| 32 | password whatever |
| 33 | service advanced-vty |
| 34 | ! |
Paul Jakma | c112af2 | 2010-11-27 11:49:09 +0000 | [diff] [blame^] | 35 | router bgp ${ASN} |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 36 | bgp router-id ${ADDR} |
| 37 | network 10.${H}.1.0/24 pathlimit 1 |
| 38 | network 10.${H}.2.0/24 pathlimit 2 |
| 39 | network 10.${H}.3.0/24 pathlimit 3 |
| 40 | neighbor default peer-group |
| 41 | neighbor default update-source ${ADDR} |
| 42 | neighbor default capability orf prefix-list both |
| 43 | neighbor default soft-reconfiguration inbound |
Paul Jakma | c112af2 | 2010-11-27 11:49:09 +0000 | [diff] [blame^] | 44 | neighbor default route-map test out |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 45 | neighbor ${NEXTADDR} remote-as ${NEXTAS} |
| 46 | neighbor ${NEXTADDR} peer-group default |
| 47 | neighbor ${PREVADDR} remote-as ${PREVAS} |
| 48 | neighbor ${PREVADDR} peer-group default |
Paul Jakma | ce9c3cc | 2008-06-12 18:53:09 +0000 | [diff] [blame] | 49 | ! |
| 50 | address-family ipv6 |
Paul Jakma | f04b0e6 | 2008-07-21 18:43:04 +0000 | [diff] [blame] | 51 | network 3ffe:${H}::/48 |
| 52 | network 3ffe:${H}:1::/48 pathlimit 1 |
| 53 | network 3ffe:${H}:2::/48 pathlimit 3 |
| 54 | network 3ffe:${H}:3::/48 pathlimit 3 |
Paul Jakma | ce9c3cc | 2008-06-12 18:53:09 +0000 | [diff] [blame] | 55 | neighbor default activate |
| 56 | neighbor default capability orf prefix-list both |
| 57 | neighbor default default-originate |
Paul Jakma | c112af2 | 2010-11-27 11:49:09 +0000 | [diff] [blame^] | 58 | neighbor default route-map test out |
Paul Jakma | ce9c3cc | 2008-06-12 18:53:09 +0000 | [diff] [blame] | 59 | neighbor ${NEXTADDR} peer-group default |
| 60 | neighbor ${PREVADDR} peer-group default |
| 61 | exit-address-family |
| 62 | ! |
Paul Jakma | c112af2 | 2010-11-27 11:49:09 +0000 | [diff] [blame^] | 63 | route-map test permit 10 |
| 64 | set extcommunity rt ${ASN}:1 |
| 65 | set extcommunity soo ${ASN}:2 |
| 66 | set community ${ASN}:1 |
Paul Jakma | ce9c3cc | 2008-06-12 18:53:09 +0000 | [diff] [blame] | 67 | line vty |
| 68 | ! |
| 69 | end |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 70 | EOF |
Paul Jakma | ce9c3cc | 2008-06-12 18:53:09 +0000 | [diff] [blame] | 71 | chown ${CHOWNSTR} "$CONF" |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 72 | fi |
| 73 | # You may want to automatically add configure a local address |
| 74 | # on a loop interface. |
| 75 | # |
Paul Jakma | f04b0e6 | 2008-07-21 18:43:04 +0000 | [diff] [blame] | 76 | # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up |
| 77 | # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null |
Paul Jakma | 0e7c124 | 2008-06-01 14:26:48 +0000 | [diff] [blame] | 78 | ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \ |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 79 | -l ${ADDR} \ |
Paul Jakma | 0e7c124 | 2008-06-01 14:26:48 +0000 | [diff] [blame] | 80 | -f "${CONF}" \ |
Paul Jakma | 3a02d1f | 2007-11-01 14:29:11 +0000 | [diff] [blame] | 81 | -P $((${VTYBASE}+${H})) \ |
| 82 | -d |
| 83 | done |