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