| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| 4 | # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. |
| 5 | # This file is part of openmano |
| 6 | # All Rights Reserved. |
| 7 | # |
| 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 |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 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 |
| 18 | # under the License. |
| 19 | # |
| 20 | # For those usages not covered by the Apache License, Version 2.0 please |
| 21 | # contact with: nfvlabs@tid.es |
| 22 | ## |
| 23 | |
| 24 | #Get configuration of a host for using it as a compute node |
| 25 | |
| 26 | function usage(){ |
| 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)." |
| 34 | exit 1 |
| 35 | } |
| 36 | |
| 37 | function get_hash_value() { echo `eval echo $\{\`echo $1[$2]\`\}`; } |
| 38 | |
| 39 | function get_mac(){ |
| 40 | seed=$1 |
| 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` |
| 47 | echo $mac |
| 48 | } |
| 49 | |
| 50 | |
| 51 | #check root privileges and non a root user behind |
| 52 | |
| 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" |
| 58 | NUMAS=2 |
| 59 | CORES=$3 |
| 60 | MEMORY=$4 |
| 61 | INTERFACES=$5 |
| 62 | |
| 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 |
| 67 | |
| 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` |
| 70 | |
| 71 | #in this developing/fake server all cores can be used |
| 72 | |
| 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>" |
| 77 | echo |
| 78 | echo "host:" |
| 79 | echo " name: $HOST_NAME" |
| 80 | echo " user: $1" |
| 81 | echo " ip_name: $2" |
| 82 | echo "host-data:" |
| 83 | echo " name: $HOST_NAME" |
| 84 | echo " user: $1" |
| 85 | echo " ip_name: $2" |
| 86 | echo " ranking: 100" |
| 87 | echo " description: $HOST_NAME" |
| 88 | echo " features: $FEATURES_LIST" |
| 89 | echo " numas:" |
| 90 | |
| 91 | numa=0 |
| 92 | last_iface=0 |
| 93 | iface_counter=0 |
| 94 | while [ $numa -lt $NUMAS ] |
| 95 | do |
| 96 | echo " - numa_socket: $numa" |
| 97 | #MEMORY |
| 98 | echo " hugepages: $((MEMORY/2-2))" |
| 99 | echo " memory: $((MEMORY/2))" |
| 100 | |
| 101 | #CORES |
| 102 | echo " cores:" |
| 103 | for cpu in $CPUS |
| 104 | do |
| 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" |
| 112 | done |
| 113 | |
| 114 | |
| 115 | #GENERATE INTERFACES INFORMATION AND PRINT IT |
| 116 | seed=$RANDOM |
| 117 | echo " interfaces:" |
| 118 | for ((iface=0;iface<$INTERFACES;iface+=2)) |
| 119 | do |
| 120 | name="iface$iface_counter" |
| 121 | bus=$((iface+last_iface)) |
| 122 | pci=`printf "0000:%02X:00.0" $bus` |
| 123 | mac=`get_mac $seed` |
| 124 | seed=$((seed+1)) |
| 125 | |
| 126 | echo " - source_name: $name" |
| 127 | echo " Mbps: 10000" |
| 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" |
| 132 | echo " sriovs:" |
| 133 | |
| 134 | for((nb_sriov=0;nb_sriov<8;nb_sriov++)) |
| 135 | do |
| 136 | pci=`printf "0000:%02X:10.%i" $bus $nb_sriov` |
| 137 | mac=`get_mac $seed` |
| 138 | seed=$((seed+1)) |
| 139 | echo " - mac: \"$mac\"" |
| 140 | echo " pci: \"$pci\"" |
| 141 | echo " source_name: $nb_sriov" |
| 142 | done |
| 143 | |
| 144 | iface_counter=$((iface_counter+1)) |
| 145 | done |
| 146 | last_iface=$(((numa+1)*127/NUMAS+5)) #made-up formula for more realistic pci numbers |
| 147 | |
| 148 | |
| 149 | numa=$((numa+1)) |
| 150 | done |
| 151 | |