Update INFO.yaml with new PTL
[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 create tap hw-addr $HWADDR1
44 vppctl set int ip address tap0 $IPADDR1"/"$IPADDR1_CIDR
45 vppctl set int state tap0 up
46 vppctl loop create
47 brctl addbr br0
48 brctl addif br0 tap0
49 brctl addif br0 eth1
50 ifconfig br0 up
51 vppctl ip route add $PROTECTED_NET_CIDR via $FW_IPADDR
52 sleep 1
53
54 # Install packet streams
55 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp1
56 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp2
57 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp3
58 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp4
59 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp5
60 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp6
61 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp7
62 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp8
63 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp9
64 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$SINK_IPADDR"/" /opt/pg_streams/stream_fw_udp10
65 vppctl exec /opt/pg_streams/stream_fw_udp1
66 vppctl exec /opt/pg_streams/stream_fw_udp2
67 vppctl exec /opt/pg_streams/stream_fw_udp3
68 vppctl exec /opt/pg_streams/stream_fw_udp4
69 vppctl exec /opt/pg_streams/stream_fw_udp5
70 vppctl exec /opt/pg_streams/stream_fw_udp6
71 vppctl exec /opt/pg_streams/stream_fw_udp7
72 vppctl exec /opt/pg_streams/stream_fw_udp8
73 vppctl exec /opt/pg_streams/stream_fw_udp9
74 vppctl exec /opt/pg_streams/stream_fw_udp10
75 sleep 1
76
77 vppctl packet-generator enable
78 vppctl set int unnumbered pg0 use tap0
79 vppctl set int state pg0 up
80
81 # Start HoneyComb
82 VERSION=$(cat /opt/config/demo_artifacts_version.txt)
83 mkdir -p /var/lib/honeycomb/persist/{config,context}/
84 echo "" > /var/lib/honeycomb/persist/context/data.json
85 echo "" > /var/lib/honeycomb/persist/config/data.json
86 /opt/honeycomb/honeycomb &>/dev/null &disown
87 sleep 20
88
89 # Enable traffic flows
90 cd /opt
91 chmod +x run_traffic_fw_demo.sh
92 ./run_traffic_fw_demo.sh &>/dev/null &disown