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