4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 #Get configuration of a host for using it as a compute node
27 echo -e "usage: $0 user ip_name nb_cores GiB_memory nb_10GB_interfaces [hostname] [>> host.yaml]\n Get host parameters and generated a yaml file to be used for openvim host-add"
28 echo -e " - In case hostname is not specified it will be used the name of the machine where the script is run"
29 echo -e " - nb_cores must be an odd number and bigger or equal to 4."
30 echo -e " - GiB_memory must be an odd number and bigger or equal to 16. 4GiB of memory will be reserved for the host OS, the rest will be used by VM."
31 echo -e " - nb_10GB_interfaces must be an odd number and bigger or equal to 4."
32 echo -e " - The output will be a server descriptor with two numas and resources (memory, cores and interfaces) equally distributed between them."
33 echo -e " - Each interface (physical funtion) will have defined 8 SR-IOV (virtual functions)."
37 function get_hash_value
() { echo `eval echo $\{\`echo $1[$2]\
`\}`; }
41 b1
=$
((seed
%16)); seed
=$
((seed
/16))
42 b2
=$
((seed
%16)); seed
=$
((seed
/16))
43 b3
=$
((seed
%16)); seed
=$
((seed
/16))
44 b4
=$
((seed
%16)); seed
=$
((seed
/16))
45 b5
=$
((seed
%16)); seed
=$
((seed
/16))
46 mac
=`printf "%02X:%02X:%02X:%02X:%02X:%02X" 2 $b5 $b4 $b3 $b2 $b1`
51 #check root privileges and non a root user behind
53 [ "$#" -lt "5" ] && echo "Missing parameters" && usage
54 [ "$#" -gt "6" ] && echo "Too many parameters" && usage
55 HOST_NAME
=`cat /etc/hostname`
56 [ "$#" -eq "6" ] && HOST_NAME
=$6
57 FEATURES_LIST
="lps,dioc,hwsv,tlbps,ht,lps,64b,iommu"
63 #Ensure the user input is big enough
64 ([ $
((CORES
%2)) -ne 0 ] ||
[ $CORES -lt 4 ] ) && echo -e "ERROR: Wrong number of cores\n" && usage
65 ([ $
((MEMORY
%2)) -ne 0 ] ||
[ $MEMORY -lt 16 ] ) && echo -e "ERROR: Wrong number of memory\n" && usage
66 ([ $
((INTERFACES
%2)) -ne 0 ] ||
[ $INTERFACES -lt 4 ] ) && echo -e "ERROR: Wrong number of interfaces\n" && usage
68 #Generate a cpu topology for 4 numas with hyperthreading
69 CPUS
=`pairs_gap=$((CORES/NUMAS));numa=0;inc=0;sibling=0;for((thread=0;thread<=$((pairs_gap-1));thread++)); do printf " ${numa}-${sibling}-${thread} ${numa}-${sibling}-$((thread+pairs_gap))";numa=$(((numa+1)%$NUMAS)); sibling=$((sibling+inc)); inc=$(((inc+1)%2)); done`
71 #in this developing/fake server all cores can be used
73 echo "#This file was created by $0"
74 echo "#for adding this compute node to openvim"
75 echo "#copy this file to openvim controller and run"
76 echo "#openvim host-add <this>"
79 echo " name: $HOST_NAME"
83 echo " name: $HOST_NAME"
87 echo " description: $HOST_NAME"
88 echo " features: $FEATURES_LIST"
94 while [ $numa -lt $NUMAS ]
96 echo " - numa_socket: $numa"
98 echo " hugepages: $((MEMORY/2-2))"
99 echo " memory: $((MEMORY/2))"
105 PHYSICAL
=`echo $cpu | cut -f 1 -d"-"`
106 CORE
=`echo $cpu | cut -f 2 -d"-"`
107 THREAD
=`echo $cpu | cut -f 3 -d"-"`
108 [ $PHYSICAL != $numa ] && continue #skip non physical
109 echo " - core_id: $CORE"
110 echo " thread_id: $THREAD"
111 [ $CORE -eq 0 ] && echo " status: noteligible"
115 #GENERATE INTERFACES INFORMATION AND PRINT IT
118 for ((iface
=0;iface
<$INTERFACES;iface
+=2))
120 name
="iface$iface_counter"
121 bus
=$
((iface
+last_iface
))
122 pci
=`printf "0000:%02X:00.0" $bus`
126 echo " - source_name: $name"
128 echo " pci: \"$pci\""
129 echo " mac: \"$mac\""
130 echo " switch_dpid: \"01:02:03:04:05:06\""
131 echo " switch_port: fake0/$iface_counter"
134 for((nb_sriov
=0;nb_sriov
<8;nb_sriov
++))
136 pci
=`printf "0000:%02X:10.%i" $bus $nb_sriov`
139 echo " - mac: \"$mac\""
140 echo " pci: \"$pci\""
141 echo " source_name: $nb_sriov"
144 iface_counter
=$
((iface_counter
+1))
146 last_iface
=$
(((numa
+1)*127/NUMAS
+5)) #made-up formula for more realistic pci numbers