-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_zebra_bgpd_conf.sh
executable file
·70 lines (57 loc) · 2.23 KB
/
gen_zebra_bgpd_conf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
#
# SQUAB(Scalable QUagga-based Automated configuration on BGP)
# gen_zebra_bgpd_conf.sh
# input: ROUTER_INDEX ASN BNET PEER_NUM PEER_ADDRESS INTRA_ROUTER_ADDRESS[es] LOCAL_PREF
# INTRA_ROUTER_ADDRESS[es] is ONE string!! (Ex.: "192.168.10.2 192.168.10.3")
#
ZEBRA_CONF_FILE="/etc/quagga/zebra.conf"
BGPD_CONF_FILE="/etc/quagga/bgpd.conf"
INTERFACE=($(echo $(ip addr | grep inet | grep eth | cut -f 11 -d' ' | tr '\n' ' ')))
IP_ADDR=($(echo $(ip addr | grep inet | grep eth | cut -f 6 -d' ' | tr '\n' ' ')))
echo "!" > $ZEBRA_CONF_FILE
echo "! zebra.conf" >> $ZEBRA_CONF_FILE
echo "! generated by gen_zebra_bgpd_conf.sh (SQUAB) `date`" >> $ZEBRA_CONF_FILE
echo "!" >> $ZEBRA_CONF_FILE
echo "hostname Router" >> $ZEBRA_CONF_FILE
echo "password zebra" >> $ZEBRA_CONF_FILE
echo "!" >> $ZEBRA_CONF_FILE
echo "! Interface's description." >> $ZEBRA_CONF_FILE
echo "!" >> $ZEBRA_CONF_FILE
for i in $(seq 0 $(expr ${#INTERFACE[@]} - 1))
do
echo "interface ${INTERFACE[i]}" >> $ZEBRA_CONF_FILE
echo " ip address ${IP_ADDR[i]}" >> $ZEBRA_CONF_FILE
echo " ipv6 nd suppress-ra" >> $ZEBRA_CONF_FILE
echo "!" >> $ZEBRA_CONF_FILE
done
cat $ZEBRA_CONF_FILE
ROUTER_INDEX=$1
ASN=$2
BNET=$3
PEER_NUM=$4
PEER_ADDRESS=$5
LOCAL_PREF=$7
echo "!" > $BGPD_CONF_FILE
echo "! bgpd.conf" >> $BGPD_CONF_FILE
echo "! generated by gen_zebra_bgpd_conf.sh (SQUAB) `date`" >> $BGPD_CONF_FILE
echo "!" >> $BGPD_CONF_FILE
echo "hostname bgpd" >> $BGPD_CONF_FILE
echo "password zebra" >> $BGPD_CONF_FILE
echo "log stdout" >> $BGPD_CONF_FILE
echo "!" >> $BGPD_CONF_FILE
echo "router bgp $ASN" >> $BGPD_CONF_FILE
echo " bgp router-id 10.10.10.$ROUTER_INDEX" >> $BGPD_CONF_FILE
echo " network $BNET" >> $BGPD_CONF_FILE
echo " neighbor $PEER_ADDRESS remote-as $PEER_NUM" >> $BGPD_CONF_FILE
echo " neighbor $PEER_ADDRESS next-hop-self" >> $BGPD_CONF_FILE
echo " neighbor $PEER_ADDRESS route-map setlocalpre in" >> $BGPD_CONF_FILE
echo "! intra AS router info"
for intra_router_address in $6 # $6 is ONE String!! (Ex.: "192.168.10.2 192.168.10.3")
do
echo " neighbor $intra_router_address remote-as $ASN" >> $BGPD_CONF_FILE
done
echo "route-map setlocalpre permit 10" >> $BGPD_CONF_FILE
echo " set local-preference $LOCAL_PREF" >> $BGPD_CONF_FILE
echo "!" >> $BGPD_CONF_FILE
cat $BGPD_CONF_FILE