fe035cef7e3aa2bf68a719336c0277d4ecf4f846
[demo.git] / vnfs / vLBMS / 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 NB_API_VERSION=$(cat /opt/config/nb_api_version.txt)
7 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
8 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
9
10 # Convert Network CIDR to Netmask
11 cdr2mask () {
12         # Number of args to shift, 255..255, first non-255 byte, zeroes
13         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
14         [ $1 -gt 1 ] && shift $1 || shift
15         echo ${1-0}.${2-0}.${3-0}.${4-0}
16 }
17
18 # OpenStack network configuration
19 if [[ $CLOUD_ENV == "openstack" ]]
20 then
21         echo 127.0.0.1 $(hostname) >> /etc/hosts
22
23         # Allow remote login as root
24         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
25         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
26
27         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
28
29         IP=$(cat /opt/config/local_private_ipaddr.txt)
30         BITS=$(cat /opt/config/pktgen_private_net_cidr.txt | cut -d"/" -f2)
31         NETMASK=$(cdr2mask $BITS)
32         echo "auto eth1" >> /etc/network/interfaces
33         echo "iface eth1 inet static" >> /etc/network/interfaces
34         echo "    address $IP" >> /etc/network/interfaces
35         echo "    netmask $NETMASK" >> /etc/network/interfaces
36         echo "    mtu $MTU" >> /etc/network/interfaces
37
38         IP=$(cat /opt/config/oam_private_ipaddr.txt)
39         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
40         NETMASK=$(cdr2mask $BITS)
41         echo "auto eth2" >> /etc/network/interfaces
42         echo "iface eth2 inet static" >> /etc/network/interfaces
43         echo "    address $IP" >> /etc/network/interfaces
44         echo "    netmask $NETMASK" >> /etc/network/interfaces
45         echo "    mtu $MTU" >> /etc/network/interfaces
46 fi
47
48 # Download required dependencies
49 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
50 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
51 apt-get update
52 apt-get install --allow-unauthenticated -y make wget openjdk-8-jdk gcc libcurl4-openssl-dev python-pip bridge-utils apt-transport-https ca-certificates git maven
53 pip install jsonschema
54
55 # Download vFirewall demo code for packet generator
56 cd /opt
57 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip v_packetgen_init.sh > /opt/v_packetgen_init.sh
58 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip vpacketgen.sh > /opt/vpacketgen.sh
59 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip run_streams_dns.sh > /opt/run_streams_dns.sh
60 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip properties.conf > /opt/config/properties.conf
61 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip run_health.sh > /opt/run_health.sh
62 wget -O vlb_dns_streams-$DEMO_ARTIFACTS_VERSION-demo.tar.gz "${NEXUS_ARTIFACT_REPO}/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vlb&a=vlb_dns_streams&c=demo&e=tar.gz&v=$DEMO_ARTIFACTS_VERSION"
63
64 sed -i 's/primary=.*/primary=false/g' /opt/config/properties.conf
65 sed -i 's/vnfc=.*/vnfc=vPacketGen/g' /opt/config/properties.conf
66
67 tar -zmxvf vlb_dns_streams-$DEMO_ARTIFACTS_VERSION-demo.tar.gz
68 mv vlb_dns_streams-$DEMO_ARTIFACTS_VERSION dns_streams
69
70 # Clone Honeycomb interface for the VNF component
71 mkdir honeycomb-api
72 git init honeycomb-api
73 cd honeycomb-api
74 git remote add origin https://gerrit.onap.org/r/demo.git
75 git config core.sparsecheckout true
76 echo "vnfs/vLBMS/apis" >> .git/info/sparse-checkout
77 git pull --depth=1 origin master
78
79 mkdir ~/.m2
80 cat > ~/.m2/settings.xml << EOF
81 <?xml version="1.0" encoding="UTF-8"?>
82 <!-- vi: set et smarttab sw=2 tabstop=2: -->
83 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
84   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
85   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
86  
87   <profiles>
88     <profile>
89       <id>fd.io-release</id>
90       <repositories>
91         <repository>
92           <id>fd.io-mirror</id>
93           <name>fd.io-mirror</name>
94           <url>https://nexus.fd.io/content/groups/public/</url>
95           <releases>
96             <enabled>true</enabled>
97             <updatePolicy>never</updatePolicy>
98           </releases>
99           <snapshots>
100             <enabled>false</enabled>
101           </snapshots>
102         </repository>
103       </repositories>
104       <pluginRepositories>
105         <pluginRepository>
106           <id>fd.io-mirror</id>
107           <name>fd.io-mirror</name>
108           <url>https://nexus.fd.io/content/repositories/public/</url>
109           <releases>
110             <enabled>true</enabled>
111             <updatePolicy>never</updatePolicy>
112           </releases>
113           <snapshots>
114             <enabled>false</enabled>
115           </snapshots>
116         </pluginRepository>
117       </pluginRepositories>
118     </profile>
119  
120     <profile>
121       <id>fd.io-snapshots</id>
122       <repositories>
123         <repository>
124           <id>fd.io-snapshot</id>
125           <name>fd.io-snapshot</name>
126           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
127           <releases>
128             <enabled>false</enabled>
129           </releases>
130           <snapshots>
131             <enabled>true</enabled>
132           </snapshots>
133         </repository>
134       </repositories>
135       <pluginRepositories>
136         <pluginRepository>
137           <id>fd.io-snapshot</id>
138           <name>fd.io-snapshot</name>
139           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
140           <releases>
141             <enabled>false</enabled>
142           </releases>
143           <snapshots>
144             <enabled>true</enabled>
145           </snapshots>
146         </pluginRepository>
147       </pluginRepositories>
148     </profile>
149     <profile>
150       <id>opendaylight-snapshots</id>
151       <repositories>
152         <repository>
153           <id>opendaylight-snapshot</id>
154           <name>opendaylight-snapshot</name>
155           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
156           <releases>
157             <enabled>false</enabled>
158           </releases>
159           <snapshots>
160             <enabled>true</enabled>
161           </snapshots>
162         </repository>
163       </repositories>
164       <pluginRepositories>
165         <pluginRepository>
166           <id>opendaylight-shapshot</id>
167           <name>opendaylight-snapshot</name>
168           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
169           <releases>
170             <enabled>false</enabled>
171           </releases>
172           <snapshots>
173             <enabled>true</enabled>
174           </snapshots>
175         </pluginRepository>
176       </pluginRepositories>
177     </profile>
178   </profiles>
179  
180   <activeProfiles>
181     <activeProfile>fd.io-release</activeProfile>
182     <activeProfile>fd.io-snapshots</activeProfile>
183     <activeProfile>opendaylight-snapshots</activeProfile>
184   </activeProfiles>
185 </settings>
186 EOF
187
188 cd /opt/honeycomb-api/vnfs/vLBMS/apis
189 mvn clean install
190
191 sed -i 's/"restconf-binding-address": "127.0.0.1",/"restconf-binding-address": "0.0.0.0",/g' /opt/honeycomb-api/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/target/vlb-vnf-onap-distribution-$NB_API_VERSION-hc/vlb-vnf-onap-distribution-$NB_API_VERSION/config/honeycomb.json
192 sed -i 's/"netconf-tcp-binding-address": "127.0.0.1",/"netconf-tcp-binding-address": "0.0.0.0",/g' /opt/honeycomb-api/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/target/vlb-vnf-onap-distribution-$NB_API_VERSION-hc/vlb-vnf-onap-distribution-$NB_API_VERSION/config/honeycomb.json
193
194 cd /opt
195 rm *.tar.gz
196 chmod +x v_packetgen_init.sh
197 chmod +x vpacketgen.sh
198 chmod +x run_streams_dns.sh
199 chmod +x run_health.sh
200
201 echo "vpp" > config/service.txt
202
203 # Install VPP
204 export UBUNTU="xenial"
205 export RELEASE=".stable.1707"
206 rm /etc/apt/sources.list.d/99fd.io.list
207 echo "deb [trusted=yes] https://nexus.fd.io/content/repositories/fd.io$RELEASE.ubuntu.$UBUNTU.main/ ./" | tee -a /etc/apt/sources.list.d/99fd.io.list
208 apt-get update
209 apt-get install -y vpp vpp-dpdk-dkms vpp-lib vpp-dbg vpp-plugins vpp-dev
210 sleep 1
211
212 # Run instantiation script
213 cd /opt
214 mv vpacketgen.sh /etc/init.d
215 update-rc.d vpacketgen.sh defaults
216
217 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
218 if [[ $CLOUD_ENV != "rackspace" ]]
219 then
220         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
221         grub-mkconfig -o /boot/grub/grub.cfg
222         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
223         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
224         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
225         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
226         reboot
227 fi
228
229 ./v_packetgen_init.sh