15732a1a9a1cfe8be4d724c08b6b3add41169722
[demo.git] / vnfs / vFW / scripts / v_packetgen_install.sh
1 #!/bin/bash
2
3 NEXUS_ARTIFACT_REPO=$(cat /opt/config/nexus_artifact_repo.txt)
4 DEMO_ARTIFACTS_VERSION=$(cat /opt/config/demo_artifacts_version.txt)
5 if [[ "$DEMO_ARTIFACTS_VERSION" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
6 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8
9 # Convert Network CIDR to Netmask
10 cdr2mask () {
11         # Number of args to shift, 255..255, first non-255 byte, zeroes
12         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
13         [ $1 -gt 1 ] && shift $1 || shift
14         echo ${1-0}.${2-0}.${3-0}.${4-0}
15 }
16
17 # OpenStack network configuration
18 if [[ $CLOUD_ENV == "openstack" ]]
19 then
20         echo 127.0.0.1 $(hostname) >> /etc/hosts
21
22         # Allow remote login as root
23         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
24         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
25
26         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
27
28         IP=$(cat /opt/config/vpg_private_ip_0.txt)
29         BITS=$(cat /opt/config/unprotected_private_net_cidr.txt | cut -d"/" -f2)
30         NETMASK=$(cdr2mask $BITS)
31         echo "auto eth1" >> /etc/network/interfaces
32         echo "iface eth1 inet static" >> /etc/network/interfaces
33         echo "    address $IP" >> /etc/network/interfaces
34         echo "    netmask $NETMASK" >> /etc/network/interfaces
35         echo "    mtu $MTU" >> /etc/network/interfaces
36
37         IP=$(cat /opt/config/vpg_private_ip_1.txt)
38         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
39         NETMASK=$(cdr2mask $BITS)
40         echo "auto eth2" >> /etc/network/interfaces
41         echo "iface eth2 inet static" >> /etc/network/interfaces
42         echo "    address $IP" >> /etc/network/interfaces
43         echo "    netmask $NETMASK" >> /etc/network/interfaces
44         echo "    mtu $MTU" >> /etc/network/interfaces
45
46         ifup eth1
47         ifup eth2
48 fi
49
50 # Download required dependencies
51 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
52 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
53 apt-get update
54 apt-get install --allow-unauthenticated -y make wget openjdk-8-jdk gcc libcurl4-openssl-dev python-pip bridge-utils apt-transport-https ca-certificates
55 pip install jsonschema
56
57 # Download code for packet generator
58 mkdir /opt/honeycomb
59 cd /opt
60
61 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip v_packetgen_init.sh > /opt/v_packetgen_init.sh
62 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip vpacketgen.sh > /opt/vpacketgen.sh
63 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip run_traffic_fw_demo.sh > /opt/run_traffic_fw_demo.sh
64 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip enable_disable_streams.sh > /opt/enable_disable_streams.sh
65 wget -O sample-distribution-$DEMO_ARTIFACTS_VERSION-hc.tar.gz "${NEXUS_ARTIFACT_REPO}/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf&a=sample-distribution&c=hc&e=tar.gz&v=$DEMO_ARTIFACTS_VERSION"
66 wget -O vfw_pg_streams-$DEMO_ARTIFACTS_VERSION-demo.tar.gz "${NEXUS_ARTIFACT_REPO}/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw_pg_streams&c=demo&e=tar.gz&v=$DEMO_ARTIFACTS_VERSION"
67
68 tar -zmxvf sample-distribution-$DEMO_ARTIFACTS_VERSION-hc.tar.gz
69 tar -zmxvf vfw_pg_streams-$DEMO_ARTIFACTS_VERSION-demo.tar.gz
70 mv vfw_pg_streams-$DEMO_ARTIFACTS_VERSION pg_streams
71 mv sample-distribution-$DEMO_ARTIFACTS_VERSION honeycomb
72 sed -i 's/"restconf-binding-address": "127.0.0.1",/"restconf-binding-address": "0.0.0.0",/g' honeycomb/sample-distribution-$DEMO_ARTIFACTS_VERSION/config/restconf.json
73 rm *.tar.gz
74 chmod +x v_packetgen_init.sh
75 chmod +x vpacketgen.sh
76 chmod +x run_traffic_fw_demo.sh
77 chmod +x enable_disable_streams.sh
78
79 # Install VPP
80 export UBUNTU="trusty"
81 export RELEASE=".stable.1609"
82 rm /etc/apt/sources.list.d/99fd.io.list
83 echo "deb [trusted=yes] https://nexus.fd.io/content/repositories/fd.io$RELEASE.ubuntu.$UBUNTU.main/ ./" | sudo tee -a /etc/apt/sources.list.d/99fd.io.list
84 apt-get update
85 apt-get install -y vpp vpp-dpdk-dkms vpp-lib vpp-dbg vpp-plugins vpp-dev
86 sleep 1
87
88 # Install honeycomb restart script (workaround due to honeycomb shutdown: check every 5 minutes if it's still up)
89 cat > /opt/start_honeycomb.sh <<EOF
90 #!/bin/bash
91 PID=$(ps -u root | grep java | awk '{printf $1}')
92 if [[ -z $PID ]]; then
93   VERSION=$(cat /opt/config/demo_artifacts_version.txt)
94   bash /opt/honeycomb/sample-distribution-$VERSION/honeycomb &>/dev/null &disown
95 fi
96 EOF
97 chmod +x /opt/start_honeycomb.sh
98 (crontab -l 2>/dev/null; echo "*/5 * * * * bash /opt/start_honeycomb.sh") | crontab -
99
100 # Run instantiation script
101 cd /opt
102 mv vpacketgen.sh /etc/init.d
103 update-rc.d vpacketgen.sh defaults
104 ./v_packetgen_init.sh