4300c553be4d0efca7a85a8c16417220a515e80b
[demo.git] / vnfs / vLBMS / scripts / v_lb_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 eth3 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
29 IPADDR1_CIDR=$(mask2cidr $IPADDR1_MASK)
30 IPADDR2_MASK=$(ifconfig eth1 | grep "Mask" | awk '{print $4}' | awk -F ":" '{print $2}')
31 IPADDR2_CIDR=$(mask2cidr $IPADDR2_MASK)
32
33 # Configure VPP for vPacketGenerator
34 IPADDR1=$(ifconfig eth3 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
35 IPADDR2=$(ifconfig eth1 | grep "inet addr" | tr -s ' ' | cut -d' ' -f3 | cut -d':' -f2)
36 HWADDR1=$(ifconfig eth3 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
37 HWADDR2=$(ifconfig eth1 | grep HWaddr | tr -s ' ' | cut -d' ' -f5)
38 FAKE_HWADDR1=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
39 FAKE_HWADDR2=$(echo -n 00; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"')
40 GW=$(route -n | grep "^0.0.0.0" | awk '{print $2}')
41 PKTGEN_IPADDR=$(cat /opt/config/pktgen_ipaddr.txt)
42 PKTGEN_MAC=$(cat /opt/config/pktgen_mac.txt)
43 VIP=$(cat /opt/config/vip.txt)
44
45 ifconfig eth3 down
46 ifconfig eth3 hw ether $FAKE_HWADDR1
47 ip addr flush dev eth3
48 ifconfig eth3 up
49 vppctl tap connect tappub hwaddr $HWADDR1
50 vppctl set int ip address tap-0 $VIP"/"$IPADDR1_CIDR
51 vppctl set int state tap-0 up
52 brctl addbr br0
53 brctl addif br0 tappub
54 brctl addif br0 eth3
55 ifconfig br0 up
56
57 ifconfig eth1 down
58 ifconfig eth1 hw ether $FAKE_HWADDR2
59 ip addr flush dev eth1
60 ifconfig eth1 up
61 vppctl tap connect tap111 hwaddr $HWADDR2
62 vppctl set int ip address tap-1 $IPADDR2"/"$IPADDR2_CIDR
63 vppctl set int state tap-1 up
64 brctl addbr br1
65 brctl addif br1 tap111
66 brctl addif br1 eth1
67 ifconfig br1 up
68 sleep 1
69
70 vppctl lb conf ip4-src-address $IPADDR2
71 vppctl lb vip $IPADDR1"/32" encap gre4
72 sleep 1
73
74 vppctl set ip arp proxy $IPADDR1" - "$IPADDR1
75 vppctl set interface proxy-arp tap-0 enable
76 vppctl set ip arp tap-0 $PKTGEN_IPADDR $PKTGEN_MAC
77
78 # Start Honeycomb and initialize the vLB with information about vDNS
79 cd /opt
80 ./vlb-vnf-onap-distribution-$(cat /opt/config/demo_artifacts_version.txt)/honeycomb &>/var/log/honeycomb.log &disown
81 sleep 10
82
83 OAM_VDNS_IP=$(cat /opt/config/oam_vdns_ip.txt)
84 VDNS_IPADDR=$(cat /opt/config/vdns_ipaddr.txt)
85 curl -X PUT http://localhost:8183/restconf/config/vlb-business-vnf-onap-plugin:vlb-business-vnf-onap-plugin/vdns-instances/vdns-instance/$VDNS_IPADDR -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Content-Type: application/json' -H 'Postman-Token: 8bfe8815-3efb-4c9b-8974-7b8d7b6da4c6' -H "Authorization: Basic YWRtaW46YWRtaW4=" -d '{"vdns-instance": [{ "ip-addr": "'$VDNS_IPADDR'", "oam-ip-addr": "'$OAM_VDNS_IP'", "enabled": true }]}'
86
87 # Start VES agent
88 #cd /opt/VES/evel/evel-library/code/VESreporting/
89 #echo 0 > active_dns.txt
90 #./go-client.sh &>/dev/null &disown