51d5c6760e8987c67ce5473f4b3c70a43c5ac460
[multicloud/k8s.git] / vagrant / tests / vFW / packetgen
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o nounset
12 set -o pipefail
13 set -o xtrace
14 set -o errexit
15
16 # install_dependencies() - Install required dependencies
17 function install_dependencies {
18     apt-get update
19     apt-get install -y -qq wget openjdk-8-jre bridge-utils net-tools bsdmainutils
20 }
21
22 # install_vpp() - Install VPP
23 function install_vpp {
24     local RELEASE=".stable.1609"
25
26     apt-get update
27     apt-get install -y -qq apt-transport-https
28     echo "deb [trusted=yes] https://nexus.fd.io/content/repositories/fd.io$RELEASE.ubuntu.$(lsb_release -c -s).main/ ./" | tee -a /etc/apt/sources.list.d/99fd.io.list
29     apt-get update
30     apt-get install -y -qq vpp vpp-lib vpp-plugins vpp-dpdk-dkms
31 }
32
33 function _untar_url {
34     local repo_url="https://nexus.onap.org/content/repositories/staging/org/onap/demo/vnf/"
35     local file_subpath=$1
36
37     wget -q -O tmp_file.tar.gz "${repo_url}/${file_subpath}"
38     sha1=$(wget ${repo_url}/${file_subpath}.sha1 -q -O -)
39     if [[ $(sha1sum tmp_file.tar.gz  | awk '{print $1}') != "$sha1" ]]; then
40         echo "The downloaded file is corrupted"
41         exit 1
42     fi
43     tar -zmxf tmp_file.tar.gz
44     rm tmp_file.tar.gz
45 }
46
47 # install_vfw_scripts() -
48 function install_vfw_scripts {
49     local version=$(cat /opt/config/demo_artifacts_version.txt)
50
51     pushd /opt
52     wget -q https://git.onap.org/demo/plain/vnfs/vFW/scripts/{v_packetgen_init,vpacketgen,run_traffic_fw_demo}.sh
53     chmod +x *.sh
54
55     _untar_url "sample-distribution/${version}/sample-distribution-${version}-hc.tar.gz"
56     mv sample-distribution-$version honeycomb
57
58     _untar_url "vfw/vfw_pg_streams/$version/vfw_pg_streams-$version-demo.tar.gz"
59     mv vfw_pg_streams-$version pg_streams
60
61     sed -i 's/"restconf-binding-address": "127.0.0.1",/"restconf-binding-address": "0.0.0.0",/g' /opt/honeycomb/config/honeycomb.json
62
63     # TODO(electrocucaracha) Fix it in upstream
64     sed -i 's/start vpp/systemctl start vpp/g' v_packetgen_init.sh
65     sed -i 's|/opt/honeycomb/sample-distribution-\$VERSION/honeycomb|/opt/honeycomb/honeycomb|g' v_packetgen_init.sh
66     mv vpacketgen.sh /etc/init.d/
67     update-rc.d vpacketgen.sh defaults
68     systemctl start packetgen
69     popd
70 }
71
72 mkdir -p /opt/config/
73 echo "$protected_net_cidr"     > /opt/config/protected_net_cidr.txt
74 echo "$vfw_private_ip_0"       > /opt/config/fw_ipaddr.txt
75 echo "$vsn_private_ip_0"       > /opt/config/sink_ipaddr.txt
76 echo "$demo_artifacts_version" > /opt/config/demo_artifacts_version.txt
77
78 echo 'vm.nr_hugepages = 1024' >> /etc/sysctl.conf
79 sysctl -p
80
81 install_dependencies
82 install_vpp
83 install_vfw_scripts