blob: 028ad696e52a1189e064150b2a798b09dd8622eb [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 ))
23 PREV=$(( (($H + 3) % ${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))
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 Jakmace9c3cc2008-06-12 18:53:09 +000047 !
48 address-family ipv6
Paul Jakmaf04b0e62008-07-21 18:43:04 +000049 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 Jakmace9c3cc2008-06-12 18:53:09 +000053 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 Jakma3a02d1f2007-11-01 14:29:11 +000063 EOF
Paul Jakmace9c3cc2008-06-12 18:53:09 +000064 chown ${CHOWNSTR} "$CONF"
Paul Jakma3a02d1f2007-11-01 14:29:11 +000065 fi
66 # You may want to automatically add configure a local address
67 # on a loop interface.
68 #
Paul Jakmaf04b0e62008-07-21 18:43:04 +000069 # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up
70 # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null
Paul Jakma0e7c1242008-06-01 14:26:48 +000071 ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000072 -l ${ADDR} \
Paul Jakma0e7c1242008-06-01 14:26:48 +000073 -f "${CONF}" \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000074 -P $((${VTYBASE}+${H})) \
75 -d
76done