Ovnaction and vfw updates for deploy api change
[multicloud/k8s.git] / kud / tests / vFW / firewall
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 make gcc libcurl4-gnutls-dev unzip
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     local ves_path=VES
51     local ves_reporting_path="${ves_path}/evel/evel-library"
52
53     pushd /opt
54     wget -q "https://nexus.onap.org/content/repositories/staging/org/onap/demo/vnf/vfw/vfw-scripts/${version}/vfw-scripts-${version}.zip"
55     unzip "vfw-scripts-${version}.zip"
56     chmod +x *.sh
57
58     _untar_url "sample-distribution/${version}/sample-distribution-${version}-hc.tar.gz"
59     mkdir -p honeycomb
60     mv sample-distribution-$version honeycomb
61
62     _untar_url "ves5/ves/${version}/ves-${version}-demo.tar.gz"
63     mv ves-$version $ves_path
64
65     _untar_url "ves5/ves_vfw_reporting/${version}/ves_vfw_reporting-${version}-demo.tar.gz"
66     mkdir -p $ves_reporting_path/code
67     mv ves_vfw_reporting-$version $ves_reporting_path/code/VESreporting
68
69     chmod +x $ves_reporting_path/code/VESreporting/go-client.sh
70     pushd $ves_reporting_path/bldjobs/
71     make clean
72     make
73     sleep 1
74     popd
75
76     # TODO(electrocucaracha) Fix it in upstream
77     sed -i 's/start vpp/systemctl start vpp/g' v_firewall_init.sh
78     mv vfirewall.sh /etc/init.d
79     update-rc.d vfirewall.sh defaults
80     systemctl start firewall
81     popd
82 }
83
84 mkdir -p /opt/config/
85 echo "$protected_net_cidr"     > /opt/config/protected_net_cidr.txt
86 echo "$vfw_private_ip_0"       > /opt/config/fw_ipaddr.txt
87 echo "$vsn_private_ip_0"       > /opt/config/sink_ipaddr.txt
88 echo "$demo_artifacts_version" > /opt/config/demo_artifacts_version.txt
89 echo "$dcae_collector_ip"      > /opt/config/dcae_collector_ip.txt
90 echo "$dcae_collector_port"    > /opt/config/dcae_collector_port.txt
91
92 echo 'vm.nr_hugepages = 1024' >> /etc/sysctl.conf
93 sysctl -p
94
95 install_dependencies
96 install_vpp
97 install_vfw_scripts