Parametrize CIDR and Netmask in the demos
[demo.git] / vnfs / vLB / scripts / v_lb_init.sh
1 #!/bin/bash
2
3 # Start VPP
4 start vpp
5 sleep 1
6
7 # Compute the network CIDR from the Netmask
8 mask2cidr() {
9     nbits=0
10     IFS=.
11     for dec in $1 ; do
12         case $dec in
13             255) let nbits+=8;;
14             254) let nbits+=7;;
15             252) let nbits+=6;;
16             248) let nbits+=5;;
17             240) let nbits+=4;;
18             224) let nbits+=3;;
19             192) let nbits+=2;;
20             128) let nbits+=1;;
21             0);;
22             *) echo "Error: $dec is not recognized"; exit 1
23         esac
24     done
25     echo "$nbits"
26 }
27
28 IPADDR1_MASK=$(ifconfig eth0 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
29 IPADDR1_CIDR=$(mask2cidr $IPADDR1_MASK)
30 IPADDR2_MASK=$(ifconfig eth1 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
31 IPADDR2_CIDR=$(mask2cidr $IPADDR2_MASK)
32
33 # Configure VPP for vPacketGenerator
34 IPADDR1=$(ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
35 IPADDR2=$(ifconfig eth1 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
36 HWADDR1=$(ifconfig eth0 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
37 HWADDR2=$(ifconfig eth1 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
38 FAKE_HWADDR1=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null |hexdump -v -e '/1 ":%02X"')
39 FAKE_HWADDR2=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null |hexdump -v -e '/1 ":%02X"')
40 GW=$(route -n | grep "^0.0.0.0" | awk '{print $2}')
41
42 ifconfig eth0 down
43 ifconfig eth0 hw ether $FAKE_HWADDR1
44 ip addr flush dev eth0
45 ifconfig eth0 up
46 vppctl tap connect tappub hwaddr $HWADDR1
47 vppctl set int ip address tap-0 $IPADDR1"/"$IPADDR1_CIDR
48 vppctl set int state tap-0 up
49 brctl addbr br0
50 brctl addif br0 tappub
51 brctl addif br0 eth0
52 ifconfig br0 up
53
54 ifconfig eth1 down
55 ifconfig eth1 hw ether $FAKE_HWADDR2
56 ip addr flush dev eth1
57 ifconfig eth1 up
58 vppctl tap connect tap111 hwaddr $HWADDR2
59 vppctl set int ip address tap-1 $IPADDR2"/"$IPADDR2_CIDR
60 vppctl set int state tap-1 up
61 brctl addbr br1
62 brctl addif br1 tap111
63 brctl addif br1 eth1
64 ifconfig br1 up
65 sleep 1
66
67 vppctl lb conf ip4-src-address $IPADDR2
68 vppctl lb vip $IPADDR1"/32" encap gre4
69 vppctl ip route add 0.0.0.0/0 via $GW
70 sleep 1
71
72 cd /opt/FDserver
73 ./dnsmembership.sh &>/dev/null &disown
74
75 # Start VES client
76 cd /opt/VES/code/evel_training/VESreporting/
77 echo 0 > active_dns.txt
78 ./go-client.sh &>/dev/null &disown