Fix path to honeycomb in vLB/vDNS scripts
[demo.git] / vnfs / vLBMS / scripts / v_packetgen_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 VLB_MAC=$(cat /opt/config/vlb_mac.txt)
37 GW=$(route -n | grep "^0.0.0.0" | awk '{print $2}')
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 0.0.0.0/0 via $GW
51 sleep 1
52
53 # Set br0 with public IP and valid MAC so that Linux will have public network access
54 ifconfig br0 hw ether $HWADDR1
55 ifconfig br0 $IPADDR1 netmask $IPADDR1_MASK
56 route add default gw $GW
57 sleep 1
58 vppctl set ip arp tap-0 $VLB_IPADDR $VLB_MAC
59
60 # Install packet streams
61 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns1
62 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns2
63 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns3
64 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns4
65 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns5
66 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns6
67 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns7
68 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns8
69 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns9
70 sed -i -e "0,/UDP/ s/UDP:.*/UDP: "$IPADDR1" -> "$VLB_IPADDR"/" /opt/dns_streams/stream_dns10
71
72 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns1
73 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns2
74 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns3
75 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns4
76 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns5
77 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns6
78 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns7
79 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns8
80 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns9
81 sed -i -e "s/.*-> 53.*/    UDP: $RANDOM -> 53/" /opt/dns_streams/stream_dns10
82
83 vppctl exec /opt/dns_streams/stream_dns1
84 vppctl exec /opt/dns_streams/stream_dns2
85 vppctl exec /opt/dns_streams/stream_dns3
86 vppctl exec /opt/dns_streams/stream_dns4
87 vppctl exec /opt/dns_streams/stream_dns5
88 vppctl exec /opt/dns_streams/stream_dns6
89 vppctl exec /opt/dns_streams/stream_dns7
90 vppctl exec /opt/dns_streams/stream_dns8
91 vppctl exec /opt/dns_streams/stream_dns9
92 vppctl exec /opt/dns_streams/stream_dns10
93
94 vppctl set int ip address pg0 $(cat /opt/config/pg_int.txt)"/"$IPADDR1_CIDR
95 sleep 1
96
97 # Start Honeycomb
98 cd /opt
99 ./honeycomb/honeycomb &>/var/log/honeycomb.log &disown
100 sleep 10
101
102 chmod +x run_streams_dns.sh
103 ./run_streams_dns.sh &>/dev/null &disown