Upgrade VES library from 4.2 to 5.x
[demo.git] / vnfs / vCPE / scripts / v_gmux_install.sh
1 #!/bin/bash
2
3 REPO_URL_BLOB=$(cat /opt/config/repo_url_blob.txt)
4 REPO_URL_ARTIFACTS=$(cat /opt/config/repo_url_artifacts.txt)
5 DEMO_ARTIFACTS_VERSION=$(cat /opt/config/demo_artifacts_version.txt)
6 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
7 VPP_SOURCE_REPO_URL=$(cat /opt/config/vpp_source_repo_url.txt)
8 VPP_SOURCE_REPO_BRANCH=$(cat /opt/config/vpp_source_repo_branch.txt)
9 VPP_PATCH_URL=$(cat /opt/config/vpp_patch_url.txt)
10 HC2VPP_SOURCE_REPO_URL=$(cat /opt/config/hc2vpp_source_repo_url.txt)
11 HC2VPP_SOURCE_REPO_BRANCH=$(cat /opt/config/hc2vpp_source_repo_branch.txt)
12 HC2VPP_PATCH_URL=$(cat /opt/config/hc2vpp_patch_url.txt)
13 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
14
15 # Convert Network CIDR to Netmask
16 cdr2mask () {
17         # Number of args to shift, 255..255, first non-255 byte, zeroes
18         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
19         [ $1 -gt 1 ] && shift $1 || shift
20         echo ${1-0}.${2-0}.${3-0}.${4-0}
21 }
22
23 # OpenStack network configuration
24 if [[ $CLOUD_ENV == "openstack" ]]
25 then
26         echo 127.0.0.1 $(hostname) >> /etc/hosts
27
28         # Allow remote login as root
29         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
30         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
31
32         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
33
34         IP=$(cat /opt/config/bng_mux_net_ipaddr.txt)
35         BITS=$(cat /opt/config/bng_mux_net_cidr.txt | cut -d"/" -f2)
36         NETMASK=$(cdr2mask $BITS)
37         echo "auto eth1" >> /etc/network/interfaces
38         echo "iface eth1 inet static" >> /etc/network/interfaces
39         echo "    address $IP" >> /etc/network/interfaces
40         echo "    netmask $NETMASK" >> /etc/network/interfaces
41         echo "    mtu $MTU" >> /etc/network/interfaces
42
43         IP=$(cat /opt/config/oam_ipaddr.txt)
44         BITS=$(cat /opt/config/oam_cidr.txt | cut -d"/" -f2)
45         NETMASK=$(cdr2mask $BITS)
46         echo "auto eth2" >> /etc/network/interfaces
47         echo "iface eth2 inet static" >> /etc/network/interfaces
48         echo "    address $IP" >> /etc/network/interfaces
49         echo "    netmask $NETMASK" >> /etc/network/interfaces
50         echo "    mtu $MTU" >> /etc/network/interfaces
51
52         IP=$(cat /opt/config/mux_gw_net_ipaddr.txt)
53         BITS=$(cat /opt/config/mux_gw_net_cidr.txt | cut -d"/" -f2)
54         NETMASK=$(cdr2mask $BITS)
55         echo "auto eth3" >> /etc/network/interfaces
56         echo "iface eth3 inet static" >> /etc/network/interfaces
57         echo "    address $IP" >> /etc/network/interfaces
58         echo "    netmask $NETMASK" >> /etc/network/interfaces
59         echo "    mtu $MTU" >> /etc/network/interfaces
60
61         ifup eth1
62         ifup eth2
63         ifup eth3
64 fi
65
66 # Download required dependencies
67 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
68 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
69 apt-get update
70 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
71 sleep 1
72
73 # Install the tools required for download codes
74 apt-get install -y expect git patch make
75
76 #Download and build the VPP codes
77 cd /opt
78 git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_BRANCH} vpp
79 wget -O Vpp-Add-VES-agent-for-vG-MUX.patch ${VPP_PATCH_URL} 
80
81 cd vpp
82 patch -p1 < ../Vpp-Add-VES-agent-for-vG-MUX.patch
83 expect -c "
84         spawn make install-dep;
85         expect {
86                 \"Do you want to continue?*\" {send \"Y\r\"; interact}
87         }
88 "
89
90 # Install the evel-library first since we need the lib
91 cd /opt
92 apt-get install -y libcurl4-openssl-dev
93 git clone http://gerrit.onap.org/r/demo
94 cd demo/vnfs/VES5.0/evel/evel-library/bldjobs 
95 make
96 cp ../libs/x86_64/libevel.so /usr/lib
97 ldconfig
98
99 cd /opt/vpp/build-root
100 ./bootstrap.sh
101 make V=0 PLATFORM=vpp TAG=vpp install-deb
102
103 # Install the VPP package
104 apt install -y python-ply-lex-3.5 python-ply-yacc-3.5 python-pycparser python-cffi
105 dpkg -i *.deb
106 systemctl stop vpp
107
108 # Auto-start configuration for the VPP
109 cat > /etc/vpp/startup.conf << EOF
110
111 unix {
112   nodaemon
113   log /tmp/vpp.log
114   full-coredump
115   cli-listen localhost:5002
116   startup-config /etc/vpp/setup.gate
117 }
118
119 api-trace {
120   on
121 }
122
123 api-segment {
124   gid vpp
125 }
126
127 cpu {
128         ## In the VPP there is one main thread and optionally the user can create worker(s)
129         ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
130
131         ## Manual pinning of thread(s) to CPU core(s)
132
133         ## Set logical CPU core where main thread runs
134         # main-core 1
135
136         ## Set logical CPU core(s) where worker threads are running
137         # corelist-workers 2-3,18-19
138
139         ## Automatic pinning of thread(s) to CPU core(s)
140
141         ## Sets number of CPU core(s) to be skipped (1 ... N-1)
142         ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
143         ## The main thread is automatically pinned to the first available CPU core and worker(s)
144         ## are pinned to next free CPU core(s) after core assigned to main thread
145         # skip-cores 4
146
147         ## Specify a number of workers to be created
148         ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
149         ## and main thread's CPU core
150         # workers 2
151
152         ## Set scheduling policy and priority of main and worker threads
153
154         ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
155         ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
156         # scheduler-policy fifo
157
158         ## Scheduling priority is used only for "real-time policies (fifo and rr),
159         ## and has to be in the range of priorities supported for a particular policy
160         # scheduler-priority 50
161 }
162
163 # dpdk {
164         ## Change default settings for all intefaces
165         # dev default {
166                 ## Number of receive queues, enables RSS
167                 ## Default is 1
168                 # num-rx-queues 3
169
170                 ## Number of transmit queues, Default is equal
171                 ## to number of worker threads or 1 if no workers treads
172                 # num-tx-queues 3
173
174                 ## Number of descriptors in transmit and receive rings
175                 ## increasing or reducing number can impact performance
176                 ## Default is 1024 for both rx and tx
177                 # num-rx-desc 512
178                 # num-tx-desc 512
179
180                 ## VLAN strip offload mode for interface
181                 ## Default is off
182                 # vlan-strip-offload on
183         # }
184
185         ## Whitelist specific interface by specifying PCI address
186         # dev 0000:02:00.0
187
188         ## Whitelist specific interface by specifying PCI address and in
189         ## addition specify custom parameters for this interface
190         # dev 0000:02:00.1 {
191         #       num-rx-queues 2
192         # }
193
194         ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
195         ## and uio_pci_generic (default)
196         # uio-driver vfio-pci
197
198         ## Disable mutli-segment buffers, improves performance but
199         ## disables Jumbo MTU support
200         # no-multi-seg
201
202         ## Increase number of buffers allocated, needed only in scenarios with
203         ## large number of interfaces and worker threads. Value is per CPU socket.
204         ## Default is 16384
205         # num-mbufs 128000
206
207         ## Change hugepages allocation per-socket, needed only if there is need for
208         ## larger number of mbufs. Default is 256M on each detected CPU socket
209         # socket-mem 2048,2048
210 # }
211
212 EOF
213
214 cat > /etc/vpp/setup.gate << EOF
215 set int state GigabitEthernet0/8/0 up
216 set int ip address GigabitEthernet0/8/0 10.1.0.20/24
217
218 set int state GigabitEthernet0/9/0 up
219 set int ip address GigabitEthernet0/9/0 10.5.0.20/24
220
221 create vxlan tunnel src 10.5.0.20 dst 10.5.0.21 vni 100
222 EOF
223
224 # Download and install HC2VPP from source
225 cd /opt
226 git clone ${HC2VPP_SOURCE_REPO_URL} -b ${HC2VPP_SOURCE_REPO_BRANCH} hc2vpp
227 wget -O Hc2vpp-Add-VES-agent-for-vG-MUX.patch ${HC2VPP_PATCH_URL}
228
229 apt-get install -y maven
230 cat > ~/.m2/settings.xml << EOF
231 <?xml version="1.0" encoding="UTF-8"?>
232 <!-- vi: set et smarttab sw=2 tabstop=2: -->
233 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
234   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
235   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
236
237   <profiles>
238     <profile>
239       <id>fd.io-release</id>
240       <repositories>
241         <repository>
242           <id>fd.io-mirror</id>
243           <name>fd.io-mirror</name>
244           <url>https://nexus.fd.io/content/groups/public/</url>
245           <releases>
246             <enabled>true</enabled>
247             <updatePolicy>never</updatePolicy>
248           </releases>
249           <snapshots>
250             <enabled>false</enabled>
251           </snapshots>
252         </repository>
253       </repositories>
254       <pluginRepositories>
255         <pluginRepository>
256           <id>fd.io-mirror</id>
257           <name>fd.io-mirror</name>
258           <url>https://nexus.fd.io/content/repositories/public/</url>
259           <releases>
260             <enabled>true</enabled>
261             <updatePolicy>never</updatePolicy>
262           </releases>
263           <snapshots>
264             <enabled>false</enabled>
265           </snapshots>
266         </pluginRepository>
267       </pluginRepositories>
268     </profile>
269
270     <profile>
271       <id>fd.io-snapshots</id>
272       <repositories>
273         <repository>
274           <id>fd.io-snapshot</id>
275           <name>fd.io-snapshot</name>
276           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
277           <releases>
278             <enabled>false</enabled>
279           </releases>
280           <snapshots>
281             <enabled>true</enabled>
282           </snapshots>
283         </repository>
284       </repositories>
285       <pluginRepositories>
286         <pluginRepository>
287           <id>fd.io-snapshot</id>
288           <name>fd.io-snapshot</name>
289           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
290           <releases>
291             <enabled>false</enabled>
292           </releases>
293           <snapshots>
294             <enabled>true</enabled>
295           </snapshots>
296         </pluginRepository>
297       </pluginRepositories>
298     </profile>
299     <profile>
300       <id>opendaylight-snapshots</id>
301       <repositories>
302         <repository>
303           <id>opendaylight-snapshot</id>
304           <name>opendaylight-snapshot</name>
305           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
306           <releases>
307             <enabled>false</enabled>
308           </releases>
309           <snapshots>
310             <enabled>true</enabled>
311           </snapshots>
312         </repository>
313       </repositories>
314       <pluginRepositories>
315         <pluginRepository>
316           <id>opendaylight-shapshot</id>
317           <name>opendaylight-snapshot</name>
318           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
319           <releases>
320             <enabled>false</enabled>
321           </releases>
322           <snapshots>
323             <enabled>true</enabled>
324           </snapshots>
325         </pluginRepository>
326       </pluginRepositories>
327     </profile>
328   </profiles>
329
330   <activeProfiles>
331     <activeProfile>fd.io-release</activeProfile>
332     <activeProfile>fd.io-snapshots</activeProfile>
333     <activeProfile>opendaylight-snapshots</activeProfile>
334   </activeProfiles>
335 </settings>
336 EOF
337
338 cd hc2vpp
339 patch -p1 < ../Hc2vpp-Add-VES-agent-for-vG-MUX.patch
340 mvn clean install
341 l_version=$(cat pom.xml | grep "<version>" | head -1)
342 l_version=$(echo "${l_version%<*}")
343 l_version=$(echo "${l_version#*>}")
344 mv vpp-integration/minimal-distribution/target/vpp-integration-distribution-${l_version}-hc/vpp-integration-distribution-${l_version} /opt/honeycomb
345 sed -i 's/127.0.0.1/0.0.0.0/g' /opt/honeycomb/config/honeycomb.json
346
347 # Create systemctl service for Honeycomb
348 cat > /etc/systemd/system/honeycomb.service << EOF
349 [Unit]
350 Description=Honeycomb Agent for the VPP control plane
351 Documentation=https://wiki.fd.io/view/Honeycomb
352 Requires=vpp.service
353 After=vpp.service
354
355 [Service]
356 ExecStart=/opt/honeycomb/honeycomb
357 Restart=always
358 RestartSec=10
359
360 [Install]
361 WantedBy=multi-user.target
362 EOF
363 systemctl enable /etc/systemd/system/honeycomb.service
364
365 #Create a systemd service for auto-save
366 cat > /usr/bin/save_config << EOF
367 #!/bin/bash
368
369 #########################################################################
370 #
371 #  Copyright (c) 2017 Intel and/or its affiliates.
372
373 #  Licensed under the Apache License, Version 2.0 (the "License");
374 #  you may not use this file except in compliance with the License.
375 #  You may obtain a copy of the License at:
376
377 #      http://www.apache.org/licenses/LICENSE-2.0
378
379 #  Unless required by applicable law or agreed to in writing, software
380 #  distributed under the License is distributed on an "AS IS" BASIS,
381 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382 #  See the License for the specific language governing permissions and
383 #  limitations under the License.
384 #
385 ##########################################################################
386
387 ############################### Variables ################################
388 VPP_SETUP_GATE=/etc/vpp/setup.gate
389
390 ############################### Functions ################################
391
392 # Write the commands to the startup scripts.
393 #
394 # We could set VPP configuration to the startup.conf.
395 # Write the configuration to the startup scripts so we could
396 # restore the system after rebooting.
397 #
398 write_startup_scripts()
399 {
400         local cmd=${2}
401         local is_add=${1}
402
403         if [[ ${is_add} == add ]] ;then
404                 while read -r line
405                 do
406                         if [[ ${line} == ${cmd} ]] ;then
407                                 return 0
408                         fi
409                 done < ${VPP_SETUP_GATE}
410
411                 echo "${cmd}" >> ${VPP_SETUP_GATE}
412         else
413                 while read -r line
414                 do
415                         if [[ ${line} == ${cmd} ]] ;then
416                                 sed -i "/${line}/d" ${VPP_SETUP_GATE}
417                                 return 0
418                         fi
419                 done < ${VPP_SETUP_GATE}
420         fi
421 }
422
423 # Saves the VES agent configuration to the startup script.
424 #
425 # Get the current VES agent configuration from the bash command:
426 # $vppctl show ves agent
427 #    Server Addr    Server Port Interval Enabled
428 #    127.0.0.1        8080         10    True
429 # Set the VES agent configuration with the bash command:
430 # $vppctl set ves agent server 127.0.0.1 port 8080 intval 10
431 #
432 save_ves_config()
433 {
434         local server=""
435         local port=""
436         local intval=""
437
438         local ves_config=`vppctl show ves agent | head -2 | tail -1`
439         if [ "${ves_config}" != "" ] ;then
440                 server=`echo ${ves_config} | awk '{ print $1 }'`
441                 port=`echo ${ves_config} | awk '{ print $2 }'`
442                 intval=`echo ${ves_config} | awk '{ print $3 }'`
443                 write_startup_scripts add "set ves agent server ${server} port ${port} intval ${intval}"
444         fi
445 }
446
447 # Save the VxLAN Tunnel Configuration to the startup script.
448 #
449 # Get the current VxLAN tunnel configuration with bash command:
450 # $vppctl show vxlan tunnel
451 #  [0] src 10.3.0.2 dst 10.1.0.20 vni 100 sw_if_index 1 encap_fib_index 0 fib_entry_index 7 decap_next l2
452 #  [1] src 10.5.0.20 dst 10.5.0.21 vni 100 sw_if_index 2 encap_fib_index 0 fib_entry_index 8 decap_next l2
453 # Set the VxLAN Tunnel with the bash command:
454 # $vppctl create vxlan tunnel src 10.3.0.2 dst 10.1.0.20 vni 100
455 # vxlan_tunnel0
456 save_vxlan_tunnel()
457 {
458         local src=""
459         local dst=""
460         local vni=""
461
462         vppctl show vxlan tunnel | while read line
463         do
464                 if [ "${line}" != "" ] ;then
465                         src=`echo ${line} | awk '{ print $3 }'`
466                         dst=`echo ${line} | awk '{ print $5 }'`
467                         vni=`echo ${line} | awk '{ print $7 }'`
468
469                         write_startup_scripts add "create vxlan tunnel src ${src} dst ${dst} vni ${vni}"
470                 fi
471         done
472 }
473
474 # Save the VxLAN tunnel L2 xconnect configuration to the startup script.
475 #
476 # Get the Current L2 Address configuration with bash command:
477 # $vppctl show int addr
478 # local0 (dn):
479 # vxlan_tunnel0 (up):
480 #   l2 xconnect vxlan_tunnel1
481 # vxlan_tunnel1 (up):
482 #   l2 xconnect vxlan_tunnel0
483 # Save the VxLAN tunnel L2 xconnect configuration with bash command:
484 # $vppctl set interface l2 xconnect vxlan_tunnel0 vxlan_tunnel1
485 #
486 save_vxlan_xconnect()
487 {
488         local ingress=""
489         local egress=""
490
491         vppctl show int addr | while read line
492         do
493                 if [[ ${line} == vxlan_tunnel* ]] ;then
494                         read next
495                         while [[ ${next} != l2* ]] || [[ ${next} == "" ]]
496                         do
497                                 line=`echo ${next}`
498                                 read next
499                         done
500                         if [[ ${next} == l2* ]] ;then
501                                 ingress=`echo ${line} | awk '{ print $1 }'`
502                                 egress=`echo ${next} | awk '{ print $3 }'`
503                                 write_startup_scripts add "set interface l2 xconnect ${ingress} ${egress}"
504                         fi
505                 fi
506         done
507 }
508
509 ################################# MAIN ###################################
510
511 save_ves_config
512
513 save_vxlan_tunnel
514
515 save_vxlan_xconnect
516
517 EOF
518 chmod a+x /usr/bin/save_config
519 cat > /etc/systemd/system/autosave.service << EOF
520 [Unit]
521 Description=Run Scripts at Start and Stop
522 Requires=vpp.service
523 After=vpp.service
524
525 [Service]
526 Type=oneshot
527 RemainAfterExit=true
528 ExecStop=/usr/bin/save_config
529
530 [Install]
531 WantedBy=multi-user.target
532 EOF
533 systemctl enable /etc/systemd/system/autosave.service
534
535 # Download DHCP config files
536 cd /opt
537 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gmux_init.sh
538 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gmux.sh
539 chmod +x v_gmux_init.sh
540 chmod +x v_gmux.sh
541 mv v_gmux.sh /etc/init.d
542 update-rc.d v_gmux.sh defaults
543
544 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
545 if [[ $CLOUD_ENV != "rackspace" ]]
546 then
547         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
548         grub-mkconfig -o /boot/grub/grub.cfg
549         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
550         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
551         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
552         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
553         reboot
554 fi
555
556 ./v_gmux_init.sh