fix regex expression to find IPV4 address
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / check_prox_system_setup.sh
1 #!/usr/bin/env bash
2 ##
3 ## Copyright (c) 2010-2021 Intel Corporation
4 ##
5 ## Licensed under the Apache License, Version 2.0 (the "License");
6 ## you may not use this file except in compliance with the License.
7 ## You may obtain a copy of the License at
8 ##
9 ##     http://www.apache.org/licenses/LICENSE-2.0
10 ##
11 ## Unless required by applicable law or agreed to in writing, software
12 ## distributed under the License is distributed on an "AS IS" BASIS,
13 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ## See the License for the specific language governing permissions and
15 ## limitations under the License.
16 ##
17 ## This script should run after booting: see check-prox-system-setup.service
18
19 NCPUS="$(lscpu | egrep '^CPU\(s\):' | awk '{ print $2 }')"
20 MAXCOREID="$((NCPUS-1))"
21
22 tuned_config="/etc/tuned/realtime-virtual-guest-variables.conf"
23 log_file="/opt/rapid/prox_system_setup.log"
24 system_ready="/opt/rapid/system_ready_for_rapid"
25 tuned_done="/opt/rapid/tuned_done"
26 after_boot_file="/opt/rapid/after_boot.sh"
27
28 tuned_and_reboot () {
29   echo "Applying tuned profile">>$log_file
30   tuned-adm profile realtime-virtual-guest
31   touch "$tuned_done"
32   echo "Rebooting...">>$log_file
33   reboot
34   exit 0
35 }
36
37 if [ -f "$tuned_config" ]
38 then
39     while read -r line
40     do
41         case $line in
42             isolated_cores=1-$MAXCOREID*)
43                 if test ! -f "$tuned_done"; then
44                   tuned_and_reboot
45                 fi
46                 if test -f "$after_boot_file"; then
47                   echo "Executing: $after_boot_file">>$log_file
48                   ("$after_boot_file")
49                 fi
50                 echo "Isolated CPU(s) OK, no reboot: $line">>$log_file
51                 ## rapid scripts will wait for the system_ready file to exist
52                 ## Only then, they will be able to connect to the PROX instance
53                 ## and start the testing
54                 touch "$system_ready"
55                 ## On some systems, we still need to use the igb_uio driver.
56                 ## Example: good performance on AWS with the ENA interface.
57                 ## Make sure that you change devbind.sh to use the preferred
58                 ## driver. vfio is the default.
59                 modprobe uio
60                 insmod /opt/rapid/dpdk/build/kmod/igb_uio.ko wc_activate=1
61                 exit 0
62             ;;
63             isolated_cores=*)
64                 echo "Isolated CPU(s) NOK: $line">>$log_file
65                 sed -i "/^isolated_cores=.*/c\isolated_cores=1-$MAXCOREID" $tuned_config
66                 tuned_and_reboot
67             ;;
68             *)
69                 echo "$line"
70             ;;
71         esac
72     done < "$tuned_config"
73     echo "isolated_cores=1-$MAXCOREID" >> $tuned_config
74     echo "No Isolated CPU(s) defined in config, line added: isolated_cores=1-$MAXCOREID">>$log_file
75     tuned_and_reboot
76 else
77     echo "$tuned_config not found.">>$log_file
78 fi