Release 1.11 version
[demo.git] / vnfs / vFW / scripts / v_firewall_init.sh
1 #!/bin/bash
2
3 # Convert Network CIDR to Netmask
4 mask2cidr() {
5     nbits=0
6     IFS=.
7     for dec in $1 ; do
8         case $dec in
9             255) let nbits+=8;;
10             254) let nbits+=7;;
11             252) let nbits+=6;;
12             248) let nbits+=5;;
13             240) let nbits+=4;;
14             224) let nbits+=3;;
15             192) let nbits+=2;;
16             128) let nbits+=1;;
17             0);;
18             *) echo "Error: $dec is not recognized"; exit 1
19         esac
20     done
21     echo "$nbits"
22 }
23
24 # Start VPP
25 start vpp
26 sleep 1
27
28 # Configure VPP for vFirewall
29 IPADDR1=$(ifconfig eth1 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
30 IPADDR2=$(ifconfig eth2 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
31 HWADDR1=$(ifconfig eth1 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
32 HWADDR2=$(ifconfig eth2 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
33 FAKE_HWADDR1=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
34 FAKE_HWADDR2=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
35
36 IPADDR1_MASK=$(ifconfig eth1 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
37 IPADDR1_CIDR=$(mask2cidr $IPADDR1_MASK)
38 IPADDR2_MASK=$(ifconfig eth2 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
39 IPADDR2_CIDR=$(mask2cidr $IPADDR2_MASK)
40
41 ifconfig eth1 down
42 ifconfig eth2 down
43 ifconfig eth1 hw ether $FAKE_HWADDR1
44 ifconfig eth2 hw ether $FAKE_HWADDR2
45 ip addr flush dev eth1
46 ip addr flush dev eth2
47 ifconfig eth1 up
48 ifconfig eth2 up
49 vppctl tap connect tap111 hwaddr $HWADDR1
50 vppctl tap connect tap222 hwaddr $HWADDR2
51 vppctl set int ip address tap-0 $IPADDR1"/"$IPADDR1_CIDR
52 vppctl set int ip address tap-1 $IPADDR2"/"$IPADDR2_CIDR
53 vppctl set int state tap-0 up
54 vppctl set int state tap-1 up
55 brctl addbr br0
56 brctl addif br0 tap111
57 brctl addif br0 eth1
58 brctl addbr br1
59 brctl addif br1 tap222
60 brctl addif br1 eth2
61 ifconfig br0 up
62 ifconfig br1 up
63 sleep 1
64
65 # Start HoneyComb
66 VERSION=$(cat /opt/config/demo_artifacts_version.txt)
67 mkdir -p /var/lib/honeycomb/persist/{config,context}/
68 echo "" > /var/lib/honeycomb/persist/context/data.json
69 echo "" > /var/lib/honeycomb/persist/config/data.json
70 /opt/honeycomb/sample-distribution-$VERSION/honeycomb &>/dev/null &disown
71 sleep 1
72
73 # Start VES client
74 cd /opt/VES/evel/evel-library/code/VESreporting/
75 ./go-client.sh &>/dev/null &disown