vfirewall usecase for arm64
[demo.git] / vnfs / vFW / scripts / v_packetgen_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 vPacketGenerator
35 IPADDR1=$(ifconfig enp2s0 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
36 HWADDR1=$(ifconfig enp2s0 | grep -Po "HWaddr \K(.*)")
37 FAKE_HWADDR1=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
38 PROTECTED_NET_CIDR=$(cat /opt/config/protected_net_cidr.txt)
39 FW_IPADDR=$(cat /opt/config/fw_ipaddr.txt)
40 SINK_IPADDR=$(cat /opt/config/sink_ipaddr.txt)
41
42 IPADDR1_MASK=$(ifconfig enp2s0 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
43 IPADDR1_CIDR=$(mask2cidr $IPADDR1_MASK)
44
45 ifconfig enp2s0 down
46 ifconfig enp2s0 hw ether $FAKE_HWADDR1
47 ip addr flush dev enp2s0
48 ifconfig enp2s0 up
49 vppctl tap connect tap111 hwaddr $HWADDR1
50 vppctl set int ip address tapcli-0 $IPADDR1"/"$IPADDR1_CIDR
51 vppctl set int state tapcli-0 up
52 brctl addbr br0
53 brctl addif br0 tap111
54 brctl addif br0 enp2s0
55 ifconfig br0 up
56 vppctl ip route add $PROTECTED_NET_CIDR via $FW_IPADDR
57 sleep 1
58
59 # Install packet streams
60 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp1
61 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp2
62 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp3
63 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp4
64 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp5
65 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp6
66 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp7
67 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp8
68 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp9
69 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp10
70 vppctl exec /opt/pg_streams/stream_fw_udp1
71 vppctl exec /opt/pg_streams/stream_fw_udp2
72 vppctl exec /opt/pg_streams/stream_fw_udp3
73 vppctl exec /opt/pg_streams/stream_fw_udp4
74 vppctl exec /opt/pg_streams/stream_fw_udp5
75 vppctl exec /opt/pg_streams/stream_fw_udp6
76 vppctl exec /opt/pg_streams/stream_fw_udp7
77 vppctl exec /opt/pg_streams/stream_fw_udp8
78 vppctl exec /opt/pg_streams/stream_fw_udp9
79 vppctl exec /opt/pg_streams/stream_fw_udp10
80 sleep 1
81
82 # Start HoneyComb
83 #VERSION=$(cat /opt/config/demo_artifacts_version.txt)
84 mkdir -p /var/lib/honeycomb/persist/{config,context}/
85 echo "" > /var/lib/honeycomb/persist/context/data.json
86 echo "" > /var/lib/honeycomb/persist/config/data.json
87 #/opt/honeycomb/sample-distribution-$VERSION/honeycomb &>/dev/null &disown
88 systemctl restart honeycomb
89 sleep 20
90
91 # Enable traffic flows
92 cd /opt
93 chmod +x run_traffic_fw_demo.sh
94 ./run_traffic_fw_demo.sh &>/dev/null &disown