blob: d6a38ed4511f69b26f17773a9575db9549a1f0c5 [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))
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 Jakmac112af22010-11-27 11:49:09 +000063 route-map test permit 10
64 set extcommunity rt ${ASN}:1
65 set extcommunity soo ${ASN}:2
66 set community ${ASN}:1
Paul Jakmace9c3cc2008-06-12 18:53:09 +000067 line vty
68 !
69 end
Paul Jakma3a02d1f2007-11-01 14:29:11 +000070 EOF
Paul Jakmace9c3cc2008-06-12 18:53:09 +000071 chown ${CHOWNSTR} "$CONF"
Paul Jakma3a02d1f2007-11-01 14:29:11 +000072 fi
73 # You may want to automatically add configure a local address
74 # on a loop interface.
75 #
Paul Jakmaf04b0e62008-07-21 18:43:04 +000076 # Solaris: ifconfig vni${H} plumb ${ADDR}/${ADDRPLEN} up
77 # Linux: ip address add ${ADDR}/${ADDRPLEN} dev lo 2> /dev/null
Paul Jakma0e7c1242008-06-01 14:26:48 +000078 ${BGPD} -i "${PIDBASE}"/bgpd${H}.pid \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000079 -l ${ADDR} \
Paul Jakma0e7c1242008-06-01 14:26:48 +000080 -f "${CONF}" \
Paul Jakma3a02d1f2007-11-01 14:29:11 +000081 -P $((${VTYBASE}+${H})) \
82 -d
83done