Route exchange test with testcase3
[sdnvpn.git] / sdnvpn / artifacts / quagga_setup.sh
1 #! /bin/bash
2
3 set -xe
4 # change the password because this script is run on a passwordless cloud-image
5 echo 'ubuntu:opnfv' | chpasswd
6
7 # Wait for a floating IP
8 # as a workaround to NAT breakage
9 sleep 100
10
11 # Variables to be filled in with python
12 NEIGHBOR_IP=$1
13 OWN_IP=$2
14 # directly access the instance from the external net without NAT
15 EXT_NET_MASK=$3
16 IP_PREFIX=$4
17 RD=$5
18 IRT=$6
19 ERT=$7
20
21 if [[ $(getent hosts | awk '{print $2}') != *"$(cat /etc/hostname | awk '{print $1}')"* ]]
22 then
23 echo "127.0.1.1 $(cat /etc/hostname | awk '{print $1}')" | tee -a /etc/hosts
24 fi
25
26 quagga_int=''
27 for net_int in $(netstat -ia | awk 'NR>2{print $1}');
28 do
29 if [ -z "$(ifconfig | grep $net_int)" ]
30 then
31 quagga_int=$net_int
32 break
33 fi
34 done
35 if [ -z "$quagga_int" ]
36 then
37 echo 'No available network interface'
38 fi
39
40 ip link set $quagga_int up
41 ip addr add $OWN_IP/$EXT_NET_MASK dev $quagga_int
42
43 # Download quagga/zrpc rpms
44 cd /root
45 wget http://artifacts.opnfv.org/sdnvpn/quagga4/quagga-ubuntu-updated.tar.gz
46 tar -xvf quagga-ubuntu-updated.tar.gz
47 cd /root/quagga
48 dpkg -i c-capnproto_1.0.2.75f7901.Ubuntu16.04_amd64.deb
49 dpkg -i zmq_4.1.3.56b71af.Ubuntu16.04_amd64.deb
50 dpkg -i quagga_1.1.0.cd8ab40.Ubuntu16.04_amd64.deb
51 dpkg -i thrift_1.0.0.b2a4d4a.Ubuntu16.04_amd64.deb
52 dpkg -i zrpc_0.2.0efd19f.thriftv4.Ubuntu16.04_amd64.deb
53
54 nohup /opt/quagga/sbin/bgpd &
55
56 cat > /tmp/quagga-config << EOF1
57 config terminal
58 router bgp 200
59  bgp router-id $OWN_IP
60  no bgp log-neighbor-changes
61  bgp graceful-restart stalepath-time 90
62  bgp graceful-restart restart-time 900
63  bgp graceful-restart
64  bgp graceful-restart preserve-fw-state
65  bgp bestpath as-path multipath-relax
66  neighbor $NEIGHBOR_IP remote-as 100
67  no neighbor $NEIGHBOR_IP activate
68  vrf $RD
69   rd $RD
70   rt import $IRT
71   rt export $ERT
72  exit
73 !
74 address-family vpnv4
75 neighbor $NEIGHBOR_IP activate
76 neighbor $NEIGHBOR_IP attribute-unchanged next-hop
77 exit
78 !
79 route-map map permit 1
80  set ip next-hop $OWN_IP
81 exit
82 !
83 router bgp 200
84 address-family vpnv4
85 network $IP_PREFIX rd $RD tag 100 route-map map
86 exit
87 !
88 EOF1
89
90 sleep 20
91
92 (sleep 1;echo "sdncbgpc";sleep 1;cat /tmp/quagga-config;sleep 1; echo "exit") |nc -q1 localhost 2605