blob: 20a92a91606c01c69a01a2ae3fdf44933720263f [file] [log] [blame]
Paul Jakma3a02d1f2007-11-01 14:29:11 +00001#!/bin/bash
2
3# Public domain, not copyrighted..
4
5NUM=5
6VTYBASE=2610
7ASBASE=64560
8BGPD=/path/to/bgpd
Paul Jakmaf04b0e62008-07-21 18:43:04 +00009PREFIX=192.168.145.
10#PREFIX=3ffe:123:456::
11ADDRPLEN=32
Paul Jakma0e7c1242008-06-01 14:26:48 +000012CONFBASE=/tmp
13PIDBASE=/var/run/quagga
Paul Jakmace9c3cc2008-06-12 18:53:09 +000014CHOWNSTR=quagga:quagga
Paul Jakma3a02d1f2007-11-01 14:29:11 +000015
16for H in `seq 1 ${NUM}` ; do
Paul Jakma0e7c1242008-06-01 14:26:48 +000017 CONF="${CONFBASE}"/bgpd${H}.conf
Paul Jakmaf04b0e62008-07-21 18:43:04 +000018 ADDR=${PREFIX}${H}
Paul Jakma3a02d1f2007-11-01 14:29:11 +000019
20 if [ ! -e "$CONF" ] ; then
21 # This sets up a ring of bgpd peerings
22 NEXT=$(( ($H % ${NUM}) + 1 ))
Paul Jakma50e7a382012-01-09 13:54:33 +000023 PREV=$(( (($H + $NUM - 2) % ${NUM}) + 1 ))
Paul Jakmaf04b0e62008-07-21 18:43:04 +000024 NEXTADDR="${PREFIX}${NEXT}"
Paul Jakma3a02d1f2007-11-01 14:29:11 +000025 NEXTAS=$((${ASBASE} + $NEXT))
Paul Jakmaf04b0e62008-07-21 18:43:04 +000026 PREVADDR="${PREFIX}${PREV}"
Paul Jakma3a02d1f2007-11-01 14:29:11 +000027 PREVAS=$((${ASBASE} + $PREV))
Paul Jakmac112af22010-11-27 11:49:09 +000028 ASN=$((64560+${H}))
Paul Jakma3a02d1f2007-11-01 14:29:11 +000029
30 # Edit config to suit.
31 cat > "$CONF" <<- EOF
32 password whatever
33 service advanced-vty
34 !
Paul Jakmac112af22010-11-27 11:49:09 +000035 router bgp ${ASN}
Paul Jakma3a02d1f2007-11-01 14:29:11 +000036 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 Jakmac112af22010-11-27 11:49:09 +000044 neighbor default route-map test out
Paul Jakma3a02d1f2007-11-01 14:29:11 +000045 neighbor ${NEXTADDR} remote-as ${NEXTAS}
46 neighbor ${NEXTADDR} peer-group default
47 neighbor ${PREVADDR} remote-as ${PREVAS}
48 neighbor ${PREVADDR} peer-group default
Paul Jakmace9c3cc2008-06-12 18:53:09 +000049 !
50 address-family ipv6
Paul Jakmaf04b0e62008-07-21 18:43:04 +000051 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 Jakmace9c3cc2008-06-12 18:53:09 +000055 neighbor default activate
56 neighbor default capability orf prefix-list both
57 neighbor default default-originate
Paul Jakmac112af22010-11-27 11:49:09 +000058 neighbor default route-map test out
Paul Jakmace9c3cc2008-06-12 18:53:09 +000059 neighbor ${NEXTADDR} peer-group default
60 neighbor ${PREVADDR} peer-group default
61 exit-address-family
62 !
Paul Jakma50e7a382012-01-09 13:54:33 +000063 ! bgpd still has problems with extcommunity rt/soo
Paul Jakmac112af22010-11-27 11:49:09 +000064 route-map test permit 10
65 set extcommunity rt ${ASN}:1
66 set extcommunity soo ${ASN}:2
67 set community ${ASN}:1
Paul Jakmace9c3cc2008-06-12 18:53:09 +000068 line vty
69 !
70 end
Paul Jakma3a02d1f2007-11-01 14:29:11 +000071 EOF
Paul Jakmace9c3cc2008-06-12 18:53:09 +000072 chown ${CHOWNSTR} "$CONF"
Paul Jakma3a02d1f2007-11-01 14:29:11 +000073 fi
74 # You may want to automatically add configure a local address
75 # on a loop interface.
76 #
Paul Jakmaf04b0e62008-07-21 18:43:04 +000077 # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up
78 # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null
Paul Jakma0e7c1242008-06-01 14:26:48 +000079 ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000080 -l ${ADDR} \
Paul Jakma0e7c1242008-06-01 14:26:48 +000081 -f "${CONF}" \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000082 -P $((${VTYBASE}+${H})) \
83 -d
84done