Merge "Update vLB to Ubuntu 1604 and VPP 1707"
[demo.git] / vnfs / vLB / scripts / v_packetgen_for_dns_demo_init.sh
1 #!/bin/bash
2
3 # Start VPP
4 systemctl start vpp
5 sleep 1
6
7 # Compute the network CIDR from the Netmask
8 mask2cidr() {
9     nbits=0
10     IFS=.
11     for dec in $1 ; do
12         case $dec in
13             255) let nbits+=8;;
14             254) let nbits+=7;;
15             252) let nbits+=6;;
16             248) let nbits+=5;;
17             240) let nbits+=4;;
18             224) let nbits+=3;;
19             192) let nbits+=2;;
20             128) let nbits+=1;;
21             0);;
22             *) echo "Error: $dec is not recognized"; exit 1
23         esac
24     done
25     echo "$nbits"
26 }
27
28 IPADDR1_MASK=$(ifconfig eth1 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
29 IPADDR1_CIDR=$(mask2cidr $IPADDR1_MASK)
30
31 # Configure VPP for vPacketGenerator
32 IPADDR1=$(ifconfig eth1 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
33 HWADDR1=$(ifconfig eth1 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
34 FAKE_HWADDR1=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
35 VLB_IPADDR=$(cat /opt/config/vlb_ipaddr.txt)
36 GW=$(route -n | grep "^0.0.0.0" | awk '{print $2}')
37
38 ifconfig eth1 down
39 ifconfig eth1 hw ether $FAKE_HWADDR1
40 ip addr flush dev eth1
41 ifconfig eth1 up
42 vppctl tap connect tap111 hwaddr $HWADDR1
43 vppctl set int ip address tap-0 $IPADDR1"/"$IPADDR1_CIDR
44 vppctl set int state tap-0 up
45 brctl addbr br0
46 brctl addif br0 tap111
47 brctl addif br0 eth1
48 ifconfig br0 up
49 vppctl ip route add 0.0.0.0/0 via $GW
50 sleep 1
51
52 # Set br0 with public IP and valid MAC so that Linux will have public network access
53 ifconfig br0 hw ether $HWADDR1
54 ifconfig br0 $IPADDR1 netmask $IPADDR1_MASK
55 route add default gw $GW
56
57 #Adding static arp entry for VPP so that it will be able to send packets to default GW
58 while [ $(ping -c 1 $VLB_IPADDR | grep received | cut -d" " -f4) != 1 ]; 
59 do
60         echo "Wait";
61         sleep 1;
62 done
63
64 sleep 3
65 VLB_MAC=$(arp -n | grep -w $VLB_IPADDR | tr -s ' ' | cut -d' ' -f3)
66 vppctl set ip arp tap-0 $VLB_IPADDR $VLB_MAC
67
68 # Install packet streams
69 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns1
70 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns2
71 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns3
72 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns4
73 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns5
74 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns6
75 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns7
76 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns8
77 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns9
78 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns10
79
80 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns1
81 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns2
82 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns3
83 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns4
84 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns5
85 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns6
86 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns7
87 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns8
88 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns9
89 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns10
90
91 vppctl exec /opt/dns_streams/stream_dns1
92 vppctl exec /opt/dns_streams/stream_dns2
93 vppctl exec /opt/dns_streams/stream_dns3
94 vppctl exec /opt/dns_streams/stream_dns4
95 vppctl exec /opt/dns_streams/stream_dns5
96 vppctl exec /opt/dns_streams/stream_dns6
97 vppctl exec /opt/dns_streams/stream_dns7
98 vppctl exec /opt/dns_streams/stream_dns8
99 vppctl exec /opt/dns_streams/stream_dns9
100 vppctl exec /opt/dns_streams/stream_dns10
101
102 vppctl set int ip address pg0 $(cat /opt/config/pg_int.txt)"/"$IPADDR1_CIDR
103 sleep 1
104
105 # Start HoneyComb
106 VERSION=$(cat /opt/config/demo_artifacts_version.txt)
107 echo "" > /var/lib/honeycomb/persist/context/data.json
108 echo "" > /var/lib/honeycomb/persist/config/data.json
109 /opt/honeycomb/sample-distribution-$VERSION/honeycomb &>/dev/null &disown
110 sleep 20
111
112 # Enable traffic flows
113 cd /opt
114 chmod +x run_streams_dns.sh
115 ./run_streams_dns.sh &>/dev/null &disown