Initial openvim v0.4.6 upload
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/scripts/configure-compute-node-RHEL7.1.sh b/scripts/configure-compute-node-RHEL7.1.sh
new file mode 100755
index 0000000..0fb4056
--- /dev/null
+++ b/scripts/configure-compute-node-RHEL7.1.sh
@@ -0,0 +1,528 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
+# July 2015
+
+# Personalize RHEL7.1 on compute nodes
+# Prepared to work with the following network card drivers:
+# tg3, igb drivers for management interfaces
+# ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces
+
+# To download:
+# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-RHEL7.1.sh
+# To execute:
+# chmod +x ./configure-compute-node-RHEL7.1.sh
+# sudo ./configure-compute-node-RHEL7.1.sh <user> <iface>
+
+# Assumptions:
+# All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...)
+# RHEL7.1 installed without /home partition and with the following packages selection:
+# @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools
+
+
+function usage(){
+ echo -e "Usage: sudo $0 [-y] <user-name> [ <iface-name> [<ip-address>|dhcp] ]"
+ echo -e " Configure compute host for VIM usage. (version 0.4). Params:"
+ echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
+ echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
+ echo -e " <iface-name> if suplied creates bridge interfaces on this interface, needed for openvim"
+ echo -e " ip or dhcp if suplied, configure the interface with this ip address (/24) or 'dhcp' "
+}
+
+
+#1 CHECK input parameters
+#1.1 root privileges
+[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1
+
+#1.2 input parameters
+FORCE=""
+while getopts "y" o; do
+ case "${o}" in
+ y)
+ FORCE="yes"
+ ;;
+ *)
+ usage
+ exit -1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+
+if [ $# -lt 1 ]
+then
+ usage
+ exit
+fi
+
+user_name=$1
+interface=$2
+ip_iface=$3
+
+if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null
+then
+ echo "Error: interface '$interface' is not present in the system"
+ usage
+ exit 1
+fi
+
+echo '
+#################################################################
+##### INSTALL NEEDED PACKETS #####
+#################################################################'
+
+# Required packages
+yum repolist
+yum check-update
+yum update -y
+yum install -y screen virt-manager ethtool gcc gcc-c++ xorg-x11-xauth xorg-x11-xinit xorg-x11-deprecated-libs libXtst guestfish hwloc libhugetlbfs-utils libguestfs-tools numactl
+# Selinux management
+yum install -y policycoreutils-python
+
+echo '
+#################################################################
+##### INSTALL USER #####
+#################################################################'
+
+# Add required groups
+groupadd -f nfvgroup
+groupadd -f libvirt #for other operating systems may be libvirtd
+
+# Adds user, default password same as name
+if grep -q "^${user_name}:" /etc/passwd
+then
+ #user exist, add to group
+ echo "adding user ${user_name} to groups libvirt,nfvgroup"
+ usermod -a -G libvirt,nfvgroup -g nfvgroup $user_name
+else
+ #create user if it does not exist
+ [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
+ if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
+ then
+ exit
+ fi
+ echo "creating and configuring user ${user_name}"
+ useradd -m -G libvirt,nfvgroup -g nfvgroup $user_name
+ #Password
+ if [ -z "$FORCE" ]
+ then
+ echo "Provide a password for $user_name"
+ passwd $user_name
+ else
+ echo -e "$user_name\n$user_name" | passwd --stdin $user_name
+ fi
+fi
+
+#Setting default libvirt URI for the user
+echo "Setting default libvirt URI for the user"
+echo "if test -x `which virsh`; then" >> /home/${user_name}/.bash_profile
+echo " export LIBVIRT_DEFAULT_URI=qemu:///system" >> /home/${user_name}/.bash_profile
+echo "fi" >> /home/${user_name}/.bash_profile
+
+echo '
+#################################################################
+##### INSTALL HUGEPAGES ISOLCPUS GRUB #####
+#################################################################'
+
+# Huge pages 1G auto mount
+mkdir -p /mnt/huge
+if ! grep -q "Huge pages" /etc/fstab
+then
+ echo "" >> /etc/fstab
+ echo "# Huge pages" >> /etc/fstab
+ echo "nodev /mnt/huge hugetlbfs pagesize=1GB 0 0" >> /etc/fstab
+ echo "" >> /etc/fstab
+fi
+
+# Huge pages reservation service
+if ! [ -f /usr/lib/systemd/system/hugetlb-gigantic-pages.service ]
+then
+ echo "configuring huge pages service"
+ cat > /usr/lib/systemd/system/hugetlb-gigantic-pages.service << EOL
+[Unit]
+Description=HugeTLB Gigantic Pages Reservation
+DefaultDependencies=no
+Before=dev-hugepages.mount
+ConditionPathExists=/sys/devices/system/node
+ConditionKernelCommandLine=hugepagesz=1G
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/lib/systemd/hugetlb-reserve-pages
+
+[Install]
+WantedBy=sysinit.target
+EOL
+fi
+# Grub virtualization options:
+
+# Get isolcpus
+isolcpus=`gawk 'BEGIN{pre=-2;}
+ ($1=="processor"){pro=$3;}
+ ($1=="core" && $4!=0){
+ if (pre+1==pro){endrange="-" pro}
+ else{cpus=cpus endrange sep pro; sep=","; endrange="";};
+ pre=pro;}
+ END{printf("%s",cpus endrange);}' /proc/cpuinfo`
+
+
+# Huge pages reservation file: reserving all memory apart from 4GB per NUMA node
+# Get the number of hugepages: all memory but 8GB reserved for the OS
+#totalmem=`dmidecode --type 17|grep Size |grep MB |gawk '{suma+=$2} END {print suma/1024}'`
+#hugepages=$(($totalmem-8))
+
+if ! [ -f /usr/lib/systemd/hugetlb-reserve-pages ]
+then
+ cat > /usr/lib/systemd/hugetlb-reserve-pages << EOL
+#!/bin/bash
+nodes_path=/sys/devices/system/node/
+if [ ! -d \$nodes_path ]; then
+ echo "ERROR: \$nodes_path does not exist"
+ exit 1
+fi
+
+reserve_pages()
+{
+ echo \$1 > \$nodes_path/\$2/hugepages/hugepages-1048576kB/nr_hugepages
+}
+
+# This example reserves all available memory apart from 4 GB for linux
+# using 1GB size. You can modify it to your needs or comment the lines
+# to avoid reserve memory in a numa node
+EOL
+ for f in /sys/devices/system/node/node?/meminfo
+ do
+ node=`head -n1 $f | gawk '($5=="kB"){print $2}'`
+ memory=`head -n1 $f | gawk '($5=="kB"){print $4}'`
+ memory=$((memory+1048576-1)) #memory must be ceiled
+ memory=$((memory/1048576)) #from `kB to GB
+ #if memory
+ [ $memory -gt 4 ] && echo "reserve_pages $((memory-4)) node$node" >> /usr/lib/systemd/hugetlb-reserve-pages
+ done
+
+ # Run the following commands to enable huge pages early boot reservation:
+ chmod +x /usr/lib/systemd/hugetlb-reserve-pages
+ systemctl enable hugetlb-gigantic-pages
+fi
+
+# Prepares the text to add at the end of the grub line, including blacklisting ixgbevf driver in the host
+textokernel="intel_iommu=on default_hugepagesz=1G hugepagesz=1G isolcpus=$isolcpus modprobe.blacklist=ixgbevf modprobe.blacklist=i40evf"
+
+# Add text to the kernel line
+if ! grep -q "intel_iommu=on default_hugepagesz=1G hugepagesz=1G" /etc/default/grub
+then
+ echo "adding cmdline ${textokernel}"
+ sed -i "/^GRUB_CMDLINE_LINUX=/s/\"\$/ ${textokernel}\"/" /etc/default/grub
+ # grub2 upgrade
+ grub2-mkconfig -o /boot/grub2/grub.cfg
+fi
+
+echo '
+#################################################################
+##### OTHER CONFIGURATION #####
+#################################################################'
+
+# Disable requiretty
+if ! grep -q "#openmano" /etc/sudoers
+then
+ cat >> /home/${user_name}/script_visudo.sh << EOL
+#!/bin/bash
+cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
+cat tmp > \$1
+rm tmp
+EOL
+ chmod +x /home/${user_name}/script_visudo.sh
+ echo "Disabling requitetty"
+ export EDITOR=/home/${user_name}/script_visudo.sh && sudo -E visudo
+ rm -f /home/${user_name}/script_visudo.sh
+fi
+
+#Configure polkint to run virsh as a normal user
+echo "Configuring polkint to run virsh as a normal user"
+cat >> /etc/polkit-1/localauthority/50-local.d/50-org.libvirt-access.pkla << EOL
+[libvirt Admin Access]
+Identity=unix-group:libvirt
+Action=org.libvirt.unix.manage
+ResultAny=yes
+ResultInactive=yes
+ResultActive=yes
+EOL
+
+# Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images. The OS installation
+# should have only a / partition with all possible space available
+
+echo " link /opt/VNF/images to /var/lib/libvirt/images"
+if [ "$user_name" != "" ]
+then
+ #mkdir -p /home/${user_name}/VNF_images
+ #chown -R ${user_name}:nfvgroup /home/${user_name}/VNF_images
+ #chmod go+x $HOME
+
+ # The orchestator needs to link the images folder
+ rm -f /opt/VNF/images
+ mkdir -p /opt/VNF/
+ ln -s /var/lib/libvirt/images /opt/VNF/images
+ chown -R ${user_name}:nfvgroup /opt/VNF
+ chown -R root:nfvgroup /var/lib/libvirt/images
+ chmod g+rwx /var/lib/libvirt/images
+
+ # Selinux management
+ #echo "configure Selinux management"
+ #semanage fcontext -a -t virt_image_t "/home/${user_name}/VNF_images(/.*)?"
+ #cat /etc/selinux/targeted/contexts/files/file_contexts.local |grep virt_image
+ #restorecon -R -v /home/${user_name}/VNF_images
+else
+ mkdir -p /opt/VNF/images
+ chmod o+rx /opt/VNF/images
+fi
+
+echo "creating local information /opt/VNF/images/hostinfo.yaml"
+echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
+echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
+echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
+echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
+if [ "$interface" != "" -a "$interface" != "em1" ]
+then
+ echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml
+ echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml
+fi
+chmod o+r /opt/VNF/images/hostinfo.yaml
+
+# deactivate memory overcommit
+echo "deactivate memory overcommit"
+service ksmtuned stop
+service ksm stop
+chkconfig ksmtuned off
+chkconfig ksm off
+
+
+# Libvirt options (uncomment the following)
+echo "configure Libvirt options"
+sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
+
+#creating the polkit grant access for libvirt user.
+#This does not work !!!! so commented. No way to get running without uncomented the auth_unix_rw = "none" line
+#
+#cat > /etc/polkit-1/localauthority/50-local.d/50-org.example-libvirt-remote-access.pkla << EOL
+#[libvirt Management Access]
+# Identity=unix-user:n2;unix-user:kk
+# Action=org.libvirt.unix.manage
+# ResultAny=yes
+# ResultInactive=yes
+# ResultActive=yes
+#EOL
+
+# Configuration change of qemu for the numatune bug issue
+# RHEL7.1: for this version should not be necesary - to revise
+#if ! grep -q "cgroup_controllers = [ \"cpu\", \"devices\", \"memory\", \"blkio\", \"cpuacct\" ]" /etc/libvirt/qemu.conf
+#then
+#cat /etc/libvirt/qemu.conf | awk '{print $0}($0~"#cgroup_controllers"){print "cgroup_controllers = [ \"cpu\", \"devices\", \"memory\", \"blkio\", \"cpuacct\" ]"}' > tmp
+#mv tmp /etc/libvirt/qemu.conf
+#fi
+
+echo '
+#################################################################
+##### NETWORK CONFIGURATION #####
+#################################################################'
+# Network config (if the second parameter is net)
+if [ -n "$interface" ]
+then
+
+ # Deactivate network manager
+ systemctl stop NetworkManager
+ systemctl disable NetworkManager
+
+ # For management and data interfaces
+ rm -f /etc/udev/rules.d/pci_config.rules # it will be created to define VFs
+
+ pushd /etc/sysconfig/network-scripts/
+
+ # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
+ echo "configuring iface $interface"
+ cat ifcfg-$interface | grep -e HWADDR -e UUID > $interface.tmp
+ echo "TYPE=Ethernet
+NAME=$interface
+DEVICE=$interface
+TYPE=Ethernet
+ONBOOT=yes
+NM_CONTROLLED=no
+MTU=9000
+BOOTPROTO=none
+IPV6INIT=no" >> $interface.tmp
+ mv $interface.tmp ifcfg-$interface
+
+ # Management interfaces
+# integrated_interfaces=""
+# nb_ifaces=0
+# for iface in `ifconfig -a | grep ":\ " | cut -f 1 -d":"| grep -v "_" | grep -v "\." | grep -v "lo" | sort`
+# do
+# driver=`ethtool -i $iface| awk '($0~"driver"){print $2}'`
+# if [ $driver != "ixgbe" ] && [ $driver != "bridge" ]
+# then
+# integrated_interfaces="$integrated_interfaces $iface"
+# nb_ifaces=$((nb_ifaces+1))
+# eval iface${nb_ifaces}=$iface
+# fi
+# done
+
+ #Create infrastructure bridge, normally used for connecting to compute nodes, openflow controller, ...
+ echo "DEVICE=virbrInf
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+USERCTL=no" > ifcfg-virbrInf
+
+ #Create VLAN for infrastructure bridge
+ echo "DEVICE=${interface}.1001
+ONBOOT=yes
+NM_CONTROLLED=no
+USERCTL=no
+VLAN=yes
+BOOTPROTO=none
+BRIDGE=virbrInf" > ifcfg-${interface}.1001
+
+
+ #Create bridge interfaces
+ echo "Creating bridge ifaces: "
+ for ((i=1;i<=20;i++))
+ do
+ i2digits=$i
+ [ $i -lt 10 ] && i2digits="0$i"
+ echo " virbrMan$i vlan 20$i2digits"
+ echo "DEVICE=virbrMan$i
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+USERCTL=no" > ifcfg-virbrMan$i
+
+#Without IP:
+#BOOTPROTO=static
+#IPADDR=10.10.10.$((i+209))
+#NETMASK=255.255.255.0" > ifcfg-virbrMan$i
+
+ # create the required interfaces to connect the bridges
+ echo "DEVICE=${interface}.20$i2digits
+ONBOOT=yes
+NM_CONTROLLED=no
+USERCTL=no
+VLAN=yes
+BOOTPROTO=none
+BRIDGE=virbrMan$i" > ifcfg-${interface}.20$i2digits
+ done
+
+ if [ -n "$ip_iface" ]
+ then
+ echo "configuring iface $iface interface with ip $ip_iface"
+ # Network interfaces
+ # 1Gbps interfaces are configured with ONBOOT=yes and static IP address
+ cat ifcfg-$iface | grep -e HWADDR -e UUID > $iface.tmp
+ echo "TYPE=Ethernet
+NAME=$iface
+DEVICE=$iface
+TYPE=Ethernet
+ONBOOT=yes
+NM_CONTROLLED=no
+IPV6INIT=no" >> $iface.tmp
+ [ $ip_iface = "dhcp" ] && echo -e "BOOTPROTO=dhcp\nDHCP_HOSTNAME=$HOSTNAME" >> $iface.tmp
+ [ $ip_iface != "dhcp" ] && echo -e "BOOTPROTO=static\nIPADDR=${ip_iface}\nNETMASK=255.255.255.0" >> $iface.tmp
+ mv $iface.tmp ifcfg-$iface
+ fi
+
+ for iface in `ifconfig -a | grep ": " | cut -f 1 -d":" | grep -v -e "_" -e "\." -e "lo" -e "virbr" -e "tap"`
+ do
+ # 10/40 Gbps interfaces
+ # Intel X520 cards: driver ixgbe
+ # Intel XL710 Fortville cards: driver i40e
+ driver=`ethtool -i $iface| awk '($0~"driver"){print $2}'`
+ if [ "$driver" = "i40e" -o "$driver" = "ixgbe" ]
+ then
+ echo "configuring dataplane iface $iface"
+
+ # Create 8 SR-IOV per PF by udev rules only for Fortville cards (i40e driver)
+ if [ "$driver" = "i40e" ]
+ then
+ pci=`ethtool -i $iface | awk '($0~"bus-info"){print $2}'`
+ echo "ACTION==\"add\", KERNEL==\"$pci\", SUBSYSTEM==\"pci\", RUN+=\"/usr/bin/bash -c 'echo 8 > /sys/bus/pci/devices/$pci/sriov_numvfs'\"" >> /etc/udev/rules.d/pci_config.rules
+ fi
+
+ # Configure PF to boot automatically and to have a big MTU
+ # 10Gbps interfaces are configured with ONBOOT=yes and MTU=2000
+ cat ifcfg-$iface | grep -e HWADDR -e UUID > $iface.tmp
+ echo "TYPE=Ethernet
+NAME=$iface
+DEVICE=$iface
+ONBOOT=yes
+MTU=9000
+NM_CONTROLLED=no
+IPV6INIT=no
+BOOTPROTO=none" >> $iface.tmp
+ mv $iface.tmp ifcfg-$iface
+ fi
+ done
+ popd
+fi
+
+
+# Activate 8 Virtual Functions per PF on Niantic cards (ixgbe driver)
+if [[ `lsmod | cut -d" " -f1 | grep "ixgbe" | grep -v vf` ]]
+then
+ if ! grep -q "ixgbe" /etc/modprobe.d/ixgbe.conf
+ then
+ echo "options ixgbe max_vfs=8" >> /etc/modprobe.d/ixgbe.conf
+ fi
+
+fi
+
+# Executes dracut to load drivers on boot
+echo "Regenerating initramfs"
+dracut --force
+
+# To define 8 VFs per PF we do it on rc.local, because the driver needs to be unloaded and loaded again
+#if ! grep -q "NFV" /etc/rc.local
+#then
+# echo "" >> /etc/rc.local
+# echo "# NFV" >> /etc/rc.local
+# echo "modprobe -r ixgbe" >> /etc/rc.local
+# echo "modprobe ixgbe max_vfs=8" >> /etc/rc.local
+# echo "" >> /etc/rc.local
+
+# chmod +x /etc/rc.d/rc.local
+
+#fi
+
+echo
+echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
+echo
+echo "Do not forget to copy the public ssh key into /home/${user_name}/.ssh/authorized_keys for authomatic login from openvim controller"
+echo
+
+echo "Reboot the system to make the changes effective"
+
diff --git a/scripts/configure-compute-node-RHEL7.2.sh b/scripts/configure-compute-node-RHEL7.2.sh
new file mode 100644
index 0000000..b68aebb
--- /dev/null
+++ b/scripts/configure-compute-node-RHEL7.2.sh
@@ -0,0 +1,560 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
+# 2016 March 18
+# Modified to run on grub2 and efi boot
+
+# Personalize RHEL7.2 on compute nodes
+# Prepared to work with the following network card drivers:
+# tg3, igb drivers for management interfaces
+# ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces
+
+# To download:
+# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-RHEL7.1.sh
+# To execute:
+# chmod +x ./configure-compute-node-RHEL7.1.sh
+# sudo ./configure-compute-node-RHEL7.1.sh <user> <iface>
+
+# Assumptions:
+# All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...)
+# RHEL7.2 installed without /home partition and with the following packages selection:
+# @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools
+
+# 2016 Aug 17 Antonio López
+# Changed virbrInf to virbrVIM, to reflect that this bridge is used to communicate with the VIM (OpenVIM)
+# Changed the vlan tag used by virbrVIM from 2000 to 1100
+
+function usage(){
+ echo -e "Usage: sudo $0 [-y] <user-name> [ <iface-name> [<ip-address>|dhcp] ]"
+ echo -e " Configure compute host for VIM usage. (version 0.4). Params:"
+ echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
+ echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
+ echo -e " <iface-name> if suplied creates bridge interfaces on this interface, needed for openvim"
+ echo -e " ip or dhcp if suplied, configure the interface with this ip address (/24) or 'dhcp' "
+}
+
+
+#1 CHECK input parameters
+#1.1 root privileges
+[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1
+
+#1.2 input parameters
+FORCE=""
+while getopts "y" o; do
+ case "${o}" in
+ y)
+ FORCE="yes"
+ ;;
+ *)
+ usage
+ exit -1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+
+if [ $# -lt 1 ]
+then
+ usage
+ exit
+fi
+
+user_name=$1
+interface=$2
+ip_iface=$3
+
+if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null
+then
+ echo "Error: interface '$interface' is not present in the system"
+ usage
+ exit 1
+fi
+
+echo '
+#################################################################
+##### INSTALL NEEDED PACKETS #####
+#################################################################'
+
+# Required packages
+yum repolist
+yum check-update
+yum update -y
+yum install -y screen virt-manager ethtool gcc gcc-c++ xorg-x11-xauth xorg-x11-xinit xorg-x11-deprecated-libs libXtst guestfish hwloc libhugetlbfs-utils libguestfs-tools numactl
+# Selinux management
+yum install -y policycoreutils-python
+
+echo '
+#################################################################
+##### INSTALL USER #####
+#################################################################'
+
+# Add required groups
+groupadd -f nfvgroup
+groupadd -f libvirt #for other operating systems may be libvirtd
+
+# Adds user, default password same as name
+if grep -q "^${user_name}:" /etc/passwd
+then
+ #user exist, add to group
+ echo "adding user ${user_name} to groups libvirt,nfvgroup"
+ usermod -a -G libvirt,nfvgroup -g nfvgroup $user_name
+else
+ #create user if it does not exist
+ [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
+ if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
+ then
+ exit
+ fi
+ echo "creating and configuring user ${user_name}"
+ useradd -m -G libvirt,nfvgroup -g nfvgroup $user_name
+ #Password
+ if [ -z "$FORCE" ]
+ then
+ echo "Provide a password for $user_name"
+ passwd $user_name
+ else
+ echo -e "$user_name\n$user_name" | passwd --stdin $user_name
+ fi
+fi
+
+#Setting default libvirt URI for the user
+echo "Setting default libvirt URI for the user"
+echo "if test -x `which virsh`; then" >> /home/${user_name}/.bash_profile
+echo " export LIBVIRT_DEFAULT_URI=qemu:///system" >> /home/${user_name}/.bash_profile
+echo "fi" >> /home/${user_name}/.bash_profile
+
+echo '
+#################################################################
+##### INSTALL HUGEPAGES ISOLCPUS GRUB #####
+#################################################################'
+
+# Huge pages 1G auto mount
+mkdir -p /mnt/huge
+if ! grep -q "Huge pages" /etc/fstab
+then
+ echo "" >> /etc/fstab
+ echo "# Huge pages" >> /etc/fstab
+ echo "nodev /mnt/huge hugetlbfs pagesize=1GB 0 0" >> /etc/fstab
+ echo "" >> /etc/fstab
+fi
+
+# Huge pages reservation service
+if ! [ -f /usr/lib/systemd/system/hugetlb-gigantic-pages.service ]
+then
+ echo "configuring huge pages service"
+ cat > /usr/lib/systemd/system/hugetlb-gigantic-pages.service << EOL
+[Unit]
+Description=HugeTLB Gigantic Pages Reservation
+DefaultDependencies=no
+Before=dev-hugepages.mount
+ConditionPathExists=/sys/devices/system/node
+ConditionKernelCommandLine=hugepagesz=1G
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/lib/systemd/hugetlb-reserve-pages
+
+[Install]
+WantedBy=sysinit.target
+EOL
+fi
+# Grub virtualization options:
+
+# Get isolcpus
+isolcpus=`gawk 'BEGIN{pre=-2;}
+ ($1=="processor"){pro=$3;}
+ ($1=="core" && $4!=0){
+ if (pre+1==pro){endrange="-" pro}
+ else{cpus=cpus endrange sep pro; sep=","; endrange="";};
+ pre=pro;}
+ END{printf("%s",cpus endrange);}' /proc/cpuinfo`
+
+
+# Huge pages reservation file: reserving all memory apart from 4GB per NUMA node
+# Get the number of hugepages: all memory but 8GB reserved for the OS
+#totalmem=`dmidecode --type 17|grep Size |grep MB |gawk '{suma+=$2} END {print suma/1024}'`
+#hugepages=$(($totalmem-8))
+
+if ! [ -f /usr/lib/systemd/hugetlb-reserve-pages ]
+then
+ cat > /usr/lib/systemd/hugetlb-reserve-pages << EOL
+#!/bin/bash
+nodes_path=/sys/devices/system/node/
+if [ ! -d \$nodes_path ]; then
+ echo "ERROR: \$nodes_path does not exist"
+ exit 1
+fi
+
+reserve_pages()
+{
+ echo \$1 > \$nodes_path/\$2/hugepages/hugepages-1048576kB/nr_hugepages
+}
+
+# This example reserves all available memory apart from 4 GB for linux
+# using 1GB size. You can modify it to your needs or comment the lines
+# to avoid reserve memory in a numa node
+EOL
+ for f in /sys/devices/system/node/node?/meminfo
+ do
+ node=`head -n1 $f | gawk '($5=="kB"){print $2}'`
+ memory=`head -n1 $f | gawk '($5=="kB"){print $4}'`
+ memory=$((memory+1048576-1)) #memory must be ceiled
+ memory=$((memory/1048576)) #from `kB to GB
+ #if memory
+ [ $memory -gt 4 ] && echo "reserve_pages $((memory-4)) node$node" >> /usr/lib/systemd/hugetlb-reserve-pages
+ done
+
+ # Run the following commands to enable huge pages early boot reservation:
+ chmod +x /usr/lib/systemd/hugetlb-reserve-pages
+ systemctl enable hugetlb-gigantic-pages
+fi
+
+# Prepares the text to add at the end of the grub line, including blacklisting ixgbevf driver in the host
+
+textokernel="intel_iommu=on default_hugepagesz=1G hugepagesz=1G isolcpus=$isolcpus modprobe.blacklist=ixgbevf modprobe.blacklist=i40evf"
+
+# Add text to the kernel line
+if ! grep -q "intel_iommu=on default_hugepagesz=1G hugepagesz=1G" /etc/default/grub
+then
+ echo "adding cmdline ${textokernel}"
+ sed -i "/^GRUB_CMDLINE_LINUX=/s/\"\$/ ${textokernel}\"/" /etc/default/grub
+
+ # grub2 upgrade
+
+ # BIOS based systems
+ grub2-mkconfig -o /boot/grub2/grub.cfg
+
+ # UEFI based systems
+ grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
+
+fi
+
+echo '
+#################################################################
+##### OTHER CONFIGURATION #####
+#################################################################'
+
+# Disable requiretty
+if ! grep -q "#openmano" /etc/sudoers
+then
+ cat >> /home/${user_name}/script_visudo.sh << EOL
+#!/bin/bash
+cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
+cat tmp > \$1
+rm tmp
+EOL
+ chmod +x /home/${user_name}/script_visudo.sh
+ echo "Disabling requitetty"
+ export EDITOR=/home/${user_name}/script_visudo.sh && sudo -E visudo
+ rm -f /home/${user_name}/script_visudo.sh
+fi
+
+#Configure polkint to run virsh as a normal user
+echo "Configuring polkint to run virsh as a normal user"
+cat >> /etc/polkit-1/localauthority/50-local.d/50-org.libvirt-access.pkla << EOL
+[libvirt Admin Access]
+Identity=unix-group:libvirt
+Action=org.libvirt.unix.manage
+ResultAny=yes
+ResultInactive=yes
+ResultActive=yes
+EOL
+
+# Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images. The OS installation
+# should have only a / partition with all possible space available
+
+echo " link /opt/VNF/images to /var/lib/libvirt/images"
+if [ "$user_name" != "" ]
+then
+ #mkdir -p /home/${user_name}/VNF_images
+ #chown -R ${user_name}:nfvgroup /home/${user_name}/VNF_images
+ #chmod go+x $HOME
+
+ # The orchestator needs to link the images folder
+ rm -f /opt/VNF/images
+ mkdir -p /opt/VNF/
+ ln -s /var/lib/libvirt/images /opt/VNF/images
+ chown -R ${user_name}:nfvgroup /opt/VNF
+ chown -R root:nfvgroup /var/lib/libvirt/images
+ chmod g+rwx /var/lib/libvirt/images
+
+ # Selinux management
+ #echo "configure Selinux management"
+ #semanage fcontext -a -t virt_image_t "/home/${user_name}/VNF_images(/.*)?"
+ #cat /etc/selinux/targeted/contexts/files/file_contexts.local |grep virt_image
+ #restorecon -R -v /home/${user_name}/VNF_images
+else
+ mkdir -p /opt/VNF/images
+ chmod o+rx /opt/VNF/images
+fi
+
+echo "creating local information /opt/VNF/images/hostinfo.yaml"
+echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
+echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
+echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
+echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
+if [ "$interface" != "" -a "$interface" != "em1" ]
+then
+ echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml
+ echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml
+fi
+chmod o+r /opt/VNF/images/hostinfo.yaml
+
+# deactivate memory overcommit
+echo "deactivate memory overcommit"
+service ksmtuned stop
+service ksm stop
+chkconfig ksmtuned off
+chkconfig ksm off
+
+
+# Libvirt options (uncomment the following)
+echo "configure Libvirt options"
+sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
+
+#creating the polkit grant access for libvirt user.
+#This does not work !!!! so commented. No way to get running without uncomented the auth_unix_rw = "none" line
+#
+#cat > /etc/polkit-1/localauthority/50-local.d/50-org.example-libvirt-remote-access.pkla << EOL
+#[libvirt Management Access]
+# Identity=unix-user:n2;unix-user:kk
+# Action=org.libvirt.unix.manage
+# ResultAny=yes
+# ResultInactive=yes
+# ResultActive=yes
+#EOL
+
+# Configuration change of qemu for the numatune bug issue
+# RHEL7.1: for this version should not be necesary - to revise
+#if ! grep -q "cgroup_controllers = [ \"cpu\", \"devices\", \"memory\", \"blkio\", \"cpuacct\" ]" /etc/libvirt/qemu.conf
+#then
+#cat /etc/libvirt/qemu.conf | awk '{print $0}($0~"#cgroup_controllers"){print "cgroup_controllers = [ \"cpu\", \"devices\", \"memory\", \"blkio\", \"cpuacct\" ]"}' > tmp
+#mv tmp /etc/libvirt/qemu.conf
+#fi
+
+echo '
+#################################################################
+##### NETWORK CONFIGURATION #####
+#################################################################'
+# Network config (if the second parameter is net)
+if [ -n "$interface" ]
+then
+
+ # Deactivate network manager
+ systemctl stop NetworkManager
+ systemctl disable NetworkManager
+
+ # For management and data interfaces
+ #rm -f /etc/udev/rules.d/pci_config.rules # it will be created to define VFs
+
+ pushd /etc/sysconfig/network-scripts/
+
+ # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
+ echo "configuring iface $interface"
+ cat ifcfg-$interface | grep -e HWADDR -e UUID > $interface.tmp
+ echo "TYPE=Ethernet
+NAME=$interface
+DEVICE=$interface
+TYPE=Ethernet
+ONBOOT=yes
+NM_CONTROLLED=no
+MTU=9000
+BOOTPROTO=none
+IPV6INIT=no" >> $interface.tmp
+ mv $interface.tmp ifcfg-$interface
+
+ # Management interfaces
+# integrated_interfaces=""
+# nb_ifaces=0
+# for iface in `ifconfig -a | grep ":\ " | cut -f 1 -d":"| grep -v "_" | grep -v "\." | grep -v "lo" | sort`
+# do
+# driver=`ethtool -i $iface| awk '($0~"driver"){print $2}'`
+# if [ $driver != "ixgbe" ] && [ $driver != "bridge" ]
+# then
+# integrated_interfaces="$integrated_interfaces $iface"
+# nb_ifaces=$((nb_ifaces+1))
+# eval iface${nb_ifaces}=$iface
+# fi
+# done
+
+ #Create infrastructure bridge, normally used for connecting to compute nodes, openflow controller, ...
+ echo "DEVICE=virbrVIM
+NAME=virbrVIM
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+MTU=9000
+USERCTL=no" > ifcfg-virbrVIM
+[[ $ip_iface != "dhcp" ]] && [[ $ip_iface != "" ]] && echo -e "BOOTPROTO=static\nIPADDR=${ip_iface}\nNETMASK=255.255.255.0" >> ifcfg-virbrVIM
+
+ #Create VLAN for infrastructure bridge
+ echo "DEVICE=${interface}.1100
+NAME=${interface}.1100
+ONBOOT=yes
+NM_CONTROLLED=no
+USERCTL=no
+VLAN=yes
+MTU=9000
+BOOTPROTO=none
+BRIDGE=virbrVIM" > ifcfg-${interface}.1100
+
+
+ #Create bridge interfaces
+ echo "Creating bridge ifaces: "
+ for ((i=1;i<=20;i++))
+ do
+ i2digits=$i
+ [ $i -lt 10 ] && i2digits="0$i"
+ echo " virbrMan$i vlan 20$i2digits"
+ echo "DEVICE=virbrMan$i
+NAME=virbrMan$i
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+MTU=9000
+USERCTL=no" > ifcfg-virbrMan$i
+
+#Without IP:
+#BOOTPROTO=static
+#IPADDR=10.10.10.$((i+209))
+#NETMASK=255.255.255.0" > ifcfg-virbrMan$i
+
+ # create the required interfaces to connect the bridges
+ echo "DEVICE=${interface}.20$i2digits
+NAME=${interface}.20$i2digits
+ONBOOT=yes
+NM_CONTROLLED=no
+USERCTL=no
+VLAN=yes
+BOOTPROTO=none
+MTU=9000
+BRIDGE=virbrMan$i" > ifcfg-${interface}.20$i2digits
+ done
+
+ iface=$interface
+ if [ -n "$ip_iface" ]
+ then
+ echo "configuring iface $iface interface with ip $ip_iface"
+ # Network interfaces
+ # 1Gbps interfaces are configured with ONBOOT=yes and static IP address
+ cat ifcfg-$iface | grep -e HWADDR -e UUID > $iface.tmp
+ echo "TYPE=Ethernet
+NAME=$iface
+DEVICE=$iface
+TYPE=Ethernet
+ONBOOT=yes
+NM_CONTROLLED=no
+MTU=9000
+IPV6INIT=no" >> $iface.tmp
+ [ $ip_iface = "dhcp" ] && echo -e "BOOTPROTO=dhcp\nDHCP_HOSTNAME=$HOSTNAME" >> $iface.tmp
+ [ $ip_iface != "dhcp" ] && echo -e "BOOTPROTO=static\nIPADDR=${ip_iface}\nNETMASK=255.255.255.0" >> $iface.tmp
+ mv $iface.tmp ifcfg-$iface
+ fi
+ # Script to create vfs
+ echo "#!/bin/bash" > /root/activate-vfs.sh
+ chmod +x /root/activate-vfs.sh
+ for iface in `ifconfig -a | grep ": " | cut -f 1 -d":" | grep -v -e "_" -e "\." -e "lo" -e "virbr" -e "tap"`
+ do
+ # 10/40 Gbps interfaces
+ # Intel X520 cards: driver ixgbe
+ # Intel XL710 Fortville cards: driver i40e
+ driver=`ethtool -i $iface| awk '($0~"driver"){print $2}'`
+ if [ "$driver" = "i40e" -o "$driver" = "ixgbe" ]
+ then
+ echo "configuring dataplane iface $iface"
+
+ # Create 8 SR-IOV per PF by udev rules only for Fortville cards (i40e driver)
+ if [ "$driver" = "i40e" ]
+ then
+ pci=`ethtool -i $iface | awk '($0~"bus-info"){print $2}'`
+ echo "echo 8 > /sys/bus/pci/devices/$pci/sriov_numvfs" >> /root/activate-vfs.sh
+ fi
+
+ # Configure PF to boot automatically and to have a big MTU
+ # 10Gbps interfaces are configured with ONBOOT=yes and MTU=2000
+ cat ifcfg-$iface | grep -e HWADDR -e UUID > $iface.tmp
+ echo "TYPE=Ethernet
+NAME=$iface
+DEVICE=$iface
+ONBOOT=yes
+MTU=9000
+NM_CONTROLLED=no
+IPV6INIT=no
+BOOTPROTO=none" >> $iface.tmp
+ mv $iface.tmp ifcfg-$iface
+ fi
+ done
+ popd
+fi
+# add entry in rc.local for activate-vfs
+grep -q 'touch /var/lock/subsys/local' '/etc/rc.d/rc.local'
+if [[ $? == 0 ]]
+then
+ echo "/root/activate-vfs.sh" >> /etc/rc.local
+fi
+
+
+
+# Activate 8 Virtual Functions per PF on Niantic cards (ixgbe driver)
+if [[ `lsmod | cut -d" " -f1 | grep "ixgbe" | grep -v vf` ]]
+then
+ if ! grep -q "ixgbe" /etc/modprobe.d/ixgbe.conf
+ then
+ echo "options ixgbe max_vfs=8" >> /etc/modprobe.d/ixgbe.conf
+ fi
+
+fi
+
+# Executes dracut to load drivers on boot
+echo "Regenerating initramfs"
+dracut --force
+
+# To define 8 VFs per PF we do it on rc.local, because the driver needs to be unloaded and loaded again
+#if ! grep -q "NFV" /etc/rc.local
+#then
+# echo "" >> /etc/rc.local
+# echo "# NFV" >> /etc/rc.local
+# echo "modprobe -r ixgbe" >> /etc/rc.local
+# echo "modprobe ixgbe max_vfs=8" >> /etc/rc.local
+# echo "" >> /etc/rc.local
+
+# chmod +x /etc/rc.d/rc.local
+
+#fi
+
+echo
+echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
+echo
+echo "Do not forget to copy the public ssh key of openvim user into /home/${user_name}/.ssh/authorized_keys for authomatic login from openvim controller"
+echo
+
+echo "Reboot the system to make the changes effective"
+
diff --git a/scripts/configure-compute-node-UBUNTU14.04.sh b/scripts/configure-compute-node-UBUNTU14.04.sh
new file mode 100755
index 0000000..9d7daa7
--- /dev/null
+++ b/scripts/configure-compute-node-UBUNTU14.04.sh
@@ -0,0 +1,478 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
+# June 2015
+
+# Personalize RHEL7.1 on compute nodes
+# Prepared to work with the following network card drivers:
+# tg3, igb drivers for management interfaces
+# ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces
+
+# To download:
+# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-RHEL7.1.sh
+# To execute:
+# chmod +x ./configure-compute-node-RHEL7.1.sh
+# sudo ./configure-compute-node-RHEL7.1.sh <user> <iface>
+
+# Assumptions:
+# All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...)
+# RHEL7.1 installed without /home partition and with the following packages selection:
+# @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools
+
+
+function usage(){
+ echo -e "Usage: sudo $0 [-y] <user-name> [ <iface-name> [<ip-address>|dhcp] ]"
+ echo -e " Configure compute host for VIM usage. (version 0.4). Params:"
+ echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
+ echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
+ echo -e " <iface-name> if suplied creates bridge interfaces on this interface, needed for openvim"
+ echo -e " ip or dhcp if suplied, configure the interface with this ip address (/24) or 'dhcp' "
+}
+
+
+#1 CHECK input parameters
+#1.1 root privileges
+[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1
+
+#1.2 input parameters
+FORCE=""
+while getopts "y" o; do
+ case "${o}" in
+ y)
+ FORCE="yes"
+ ;;
+ *)
+ usage
+ exit -1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+
+
+if [ $# -lt 1 ]
+then
+ usage
+ exit
+fi
+
+
+user_name=$1
+interface=$2
+ip_iface=$3
+
+if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null
+then
+ echo "Error: interface '$interface' is not present in the system"
+ usage
+ exit 1
+fi
+
+echo '
+#################################################################
+##### INSTALL NEEDED PACKETS #####
+#################################################################'
+
+# Required packages
+apt-get -y update
+#apt-get -y install grub-common screen virt-manager ethtool build-essential x11-common x11-utils x11-apps libguestfs-tools hwloc libguestfs-tools numactl vlan nfs-common nfs-kernel-server
+apt-get -y install grub-common screen virt-manager ethtool build-essential x11-common x11-utils libguestfs-tools hwloc libguestfs-tools numactl vlan nfs-common nfs-kernel-server
+
+echo "Remove unneeded packages....."
+apt-get -y autoremove
+# Selinux management
+#yum install -y policycoreutils-python
+
+
+
+echo '
+#################################################################
+##### INSTALL USER #####
+#################################################################'
+
+# Add required groups
+groupadd -f admin
+groupadd -f libvirt #for other operating systems may be libvirtd
+
+# Adds user, default password same as name
+if grep -q "^${user_name}:" /etc/passwd
+then
+ #user exist, add to group
+ echo "adding user ${user_name} to groups libvirt,admin"
+ usermod -a -G libvirt,admin -g admin $user_name
+else
+ #create user if it does not exist
+ [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
+ if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
+ then
+ exit
+ fi
+ echo "creating and configuring user ${user_name}"
+ useradd -m -G libvirt,admin -g admin $user_name
+ #Password
+ if [ -z "$FORCE" ]
+ then
+ echo "Provide a password for $user_name"
+ passwd $user_name
+ else
+ echo -e "$user_name\n$user_name" | passwd --stdin $user_name
+ fi
+fi
+
+# Allow admin users to access without password
+if ! grep -q "#openmano" /etc/sudoers
+then
+ cat >> /home/${user_name}/script_visudo.sh << EOL
+#!/bin/bash
+cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
+cat tmp > \$1
+rm tmp
+echo "" >> \$1
+echo "#openmano allow to group admin to grant root privileges without password" >> \$1
+echo "%admin ALL=(ALL) NOPASSWD: ALL" >> \$1
+EOL
+ chmod +x /home/${user_name}/script_visudo.sh
+ echo "allowing admin user to get root privileges withut password"
+ export EDITOR=/home/${user_name}/script_visudo.sh && sudo -E visudo
+ rm -f /home/${user_name}/script_visudo.sh
+fi
+
+
+echo '
+#################################################################
+##### INSTALL HUGEPAGES ISOLCPUS GRUB #####
+#################################################################'
+
+# Huge pages 1G auto mount
+mkdir -p /mnt/huge
+if ! grep -q "Huge pages" /etc/fstab
+then
+ echo "" >> /etc/fstab
+ echo "# Huge pages" >> /etc/fstab
+ echo "nodev /mnt/huge hugetlbfs pagesize=1GB 0 0" >> /etc/fstab
+ echo "" >> /etc/fstab
+fi
+
+# Grub virtualization options:
+
+# Get isolcpus
+isolcpus=`gawk 'BEGIN{pre=-2;}
+ ($1=="processor"){pro=$3;}
+ ($1=="core" && $4!=0){
+ if (pre+1==pro){endrange="-" pro}
+ else{cpus=cpus endrange sep pro; sep=","; endrange="";};
+ pre=pro;}
+ END{printf("%s",cpus endrange);}' /proc/cpuinfo`
+
+
+echo "CPUS: $isolcpus"
+
+# Huge pages reservation file: reserving all memory apart from 4GB per NUMA node
+# Get the number of hugepages: all memory but 8GB reserved for the OS
+#totalmem=`dmidecode --type 17|grep Size |grep MB |gawk '{suma+=$2} END {print suma/1024}'`
+#hugepages=$(($totalmem-8))
+
+if ! [ -f /usr/lib/systemd/hugetlb-reserve-pages ]
+then
+ cat > /usr/lib/systemd/hugetlb-reserve-pages << EOL
+#!/bin/bash
+nodes_path=/sys/devices/system/node/
+if [ ! -d \$nodes_path ]; then
+ echo "ERROR: \$nodes_path does not exist"
+ exit 1
+fi
+
+reserve_pages()
+{
+ echo \$1 > \$nodes_path/\$2/hugepages/hugepages-1048576kB/nr_hugepages
+}
+
+# This example reserves all available memory apart from 4 GB for linux
+# using 1GB size. You can modify it to your needs or comment the lines
+# to avoid reserve memory in a numa node
+EOL
+ for f in /sys/devices/system/node/node?/meminfo
+ do
+ node=`head -n1 $f | gawk '($5=="kB"){print $2}'`
+ memory=`head -n1 $f | gawk '($5=="kB"){print $4}'`
+ memory=$((memory+1048576-1)) #memory must be ceiled
+ memory=$((memory/1048576)) #from `kB to GB
+ #if memory
+ [ $memory -gt 4 ] && echo "reserve_pages $((memory-4)) node$node" >> /usr/lib/systemd/hugetlb-reserve-pages
+ done
+
+ # Run the following commands to enable huge pages early boot reservation:
+ chmod +x /usr/lib/systemd/hugetlb-reserve-pages
+ systemctl enable hugetlb-gigantic-pages
+fi
+
+# Prepares the text to add at the end of the grub line, including blacklisting ixgbevf driver in the host
+memtotal=`grep MemTotal /proc/meminfo | awk '{ print $2 }' `
+hpages=$(( ($memtotal/(1024*1024))-8 ))
+
+memtotal=$((memtotal+1048576-1)) #memory must be ceiled
+memtotal=$((memtotal/1048576)) #from `kB to GBa
+hpages=$((memtotal-8))
+[[ $hpages -lt 0 ]] $$ hpages=0
+
+
+echo "------> memtotal: $memtotal"
+
+textokernel="intel_iommu=on default_hugepagesz=1G hugepagesz=1G hugepages=$hpages isolcpus=$isolcpus modprobe.blacklist=ixgbevf modprobe.blacklist=i40evf"
+
+echo "Text to kernel: $textokernel"
+
+
+# Add text to the kernel line
+if ! grep -q "intel_iommu=on default_hugepagesz=1G hugepagesz=1G" /etc/default/grub
+then
+ echo ">>>>>>> adding cmdline ${textokernel}"
+ sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/s/\"\$/${textokernel}\"/" /etc/default/grub
+ # grub2 upgrade
+ #grub2-mkconfig -o /boot/grub2/grub.cfg
+ update-grub
+fi
+
+echo '
+#################################################################
+##### OTHER CONFIGURATION #####
+#################################################################'
+
+# Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images. The OS installation
+# should have only a / partition with all possible space available
+
+echo " link /opt/VNF/images to /var/lib/libvirt/images"
+if [ "$user_name" != "" ]
+then
+ #mkdir -p /home/${user_name}/VNF_images
+ #chown -R ${user_name}:admin /home/${user_name}/VNF_images
+ #chmod go+x $HOME
+
+ # The orchestator needs to link the images folder
+ rm -f /opt/VNF/images
+ mkdir -p /opt/VNF/
+ ln -s /var/lib/libvirt/images /opt/VNF/images
+ chown -R ${user_name}:admin /opt/VNF
+ chown -R root:admin /var/lib/libvirt/images
+ chmod g+rwx /var/lib/libvirt/images
+
+ # Selinux management
+ #echo "configure Selinux management"
+ #semanage fcontext -a -t virt_image_t "/home/${user_name}/VNF_images(/.*)?"
+ #cat /etc/selinux/targeted/contexts/files/file_contexts.local |grep virt_image
+ #restorecon -R -v /home/${user_name}/VNF_images
+else
+ mkdir -p /opt/VNF/images
+ chmod o+rx /opt/VNF/images
+fi
+
+echo "creating local information /opt/VNF/images/hostinfo.yaml"
+echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
+echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
+echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
+echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
+if [ "$interface" != "" -a "$interface" != "em1" ]
+then
+ echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml
+ echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml
+fi
+chmod o+r /opt/VNF/images/hostinfo.yaml
+
+# deactivate memory overcommit
+#echo "deactivate memory overcommit"
+#service ksmtuned stop
+#service ksm stop
+#chkconfig ksmtuned off
+#chkconfig ksm off
+
+
+# Libvirt options (uncomment the following)
+echo "configure Libvirt options"
+sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
+
+
+echo '
+#################################################################
+##### NETWORK CONFIGURATION #####
+#################################################################'
+# Network config (if the second parameter is net)
+echo "Interface ==> $interface"
+if [ -n "$interface" ]
+then
+
+
+ # For management and data interfaces
+ rm -f /etc/udev/rules.d/pci_config.rules # it will be created to define VFs
+
+
+ # Set ONBOOT=on and MTU=9000 on the interface used for the bridges
+ echo "configuring iface $interface"
+
+#MTU for interfaces and bridges
+MTU=9000
+
+cp /etc/network/interfaces interfaces.tmp
+
+
+ #Create infrastructure bridge, normally used for connecting to compute nodes, openflow controller, ...
+
+
+ #Create VLAN for infrastructure bridge
+
+ echo "
+######### CUTLINE #########
+
+auto ${interface}
+iface ${interface} inet static
+ mtu $MTU
+
+auto ${interface}.1001
+iface ${interface}.1001 inet static
+ mtu $MTU
+" >> interfaces.tmp
+
+ echo "ifconfig ${interface} mtu $MTU
+ ifconfig ${interface} up
+" > mtu.tmp
+
+
+ #Create bridge interfaces
+ echo "Creating bridge ifaces: "
+ for ((i=1;i<=20;i++))
+ do
+ i2digits=$i
+ [ $i -lt 10 ] && i2digits="0$i"
+ echo " virbrMan$i vlan 20$i2digits"
+
+ j=$i
+
+ echo "
+auto ${interface}.20$i2digits
+iface ${interface}.20$i2digits inet static
+ mtu $MTU
+
+auto virbrMan$j
+iface virbrMan$j inet static
+ bridge_ports ${interface}.20$i2digits
+ mtu $MTU
+" >> interfaces.tmp
+
+ echo "ifconfig ${interface}.20$i2digits mtu $MTU
+ifconfig virbrMan$j mtu $MTU
+ifconfig virbrMan$j up
+" >> mtu.tmp
+
+ done
+
+ echo "
+auto em2.1001
+iface em2.1001 inet static
+
+auto virbrInf
+iface virbrInf inet static
+ bridge_ports em2.1001
+" >> interfaces.tmp
+
+ echo "ifconfig em2.1001 mtu $MTU
+ifconfig virbrInf mtu $MTU
+ifconfig virbrInf up
+" >> mtu.tmp
+
+if ! grep -q "#### CUTLINE ####" /etc/network/interfaces
+then
+ echo "====== Copying interfaces.tmp to /etc/network/interfaces"
+ cp interfaces.tmp /etc/network/interfaces
+fi
+
+
+ #popd
+fi
+
+
+# Activate 8 Virtual Functions per PF on Niantic cards (ixgbe driver)
+if [[ `lsmod | cut -d" " -f1 | grep "ixgbe" | grep -v vf` ]]
+then
+ if ! grep -q "ixgbe" /etc/modprobe.d/ixgbe.conf
+ then
+ echo "options ixgbe max_vfs=8" >> /etc/modprobe.d/ixgbe.conf
+ fi
+
+fi
+
+# Set dataplane MTU
+
+echo "sleep 10" >> mtu.tmp
+
+interfaces=`ifconfig -a | grep ^p | cut -d " " -f 1`
+for ph in $interfaces
+do
+ echo "ifconfig $ph mtu $MTU" >> mtu.tmp
+ echo "ifconfig $ph up" >> mtu.tmp
+done
+
+
+
+cp mtu.tmp /etc/setmtu.sh
+chmod +x /etc/setmtu.sh
+
+# To define 8 VFs per PF we do it on rc.local, because the driver needs to be unloaded and loaded again
+#if ! grep -q "NFV" /etc/rc.local
+#then
+ echo "#!/bin/sh -e
+" > /etc/rc.local
+ echo "# NFV" >> /etc/rc.local
+ echo "modprobe -r ixgbe" >> /etc/rc.local
+ echo "modprobe ixgbe max_vfs=8" >> /etc/rc.local
+ echo "/etc/setmtu.sh" >> /etc/rc.local
+ echo "
+exit 0" >> /etc/rc.local
+ echo "" >> /etc/rc.local
+
+ chmod +x /etc/rc.d/rc.local
+
+#fi
+
+chmod a+rwx /var/lib/libvirt/images
+mkdir /usr/libexec/
+pushd /usr/libexec/
+ln -s /usr/bin/qemu-system-x86_64 qemu-kvm
+popd
+
+#Deactivating apparmor while looking for a better solution
+/etc/init.d/apparmor stop
+update-rc.d -f apparmor remove
+
+echo
+echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated"
+echo
+echo "Do not forget to copy the public ssh key into /home/${user_name}/.ssh/authorized_keys for authomatic login from openvim controller"
+echo
+
+echo "Reboot the system to make the changes effective"
+
+
diff --git a/scripts/configure-compute-node-develop.sh b/scripts/configure-compute-node-develop.sh
new file mode 100755
index 0000000..c378459
--- /dev/null
+++ b/scripts/configure-compute-node-develop.sh
@@ -0,0 +1,252 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+# v1.0: 2015 June
+# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno
+
+# Personalize RHEL7/CENTOS compute nodes for using openvim in 'development' mode:
+# not using huge pages neither isolcpus
+
+# To download:
+# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-develop.sh
+# To execute:
+# chmod +x ./configure-compute-node-develop.sh
+# sudo ./configure-compute-node-develop.sh <user> <iface>
+
+function usage(){
+ echo -e "Usage: sudo $0 [-y] <user-name> [ <iface-name> [<ip-address>|dhcp] ]"
+ echo -e " Configure compute host for VIM usage in mode 'development'. Params:"
+ echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password"
+ echo -e " <user-name> Create if not exist and configure this user for openvim to connect"
+ echo -e " <iface-name> if supplied creates bridge interfaces on this interface, needed for openvim"
+ echo -e " ip or dhcp if supplied, configure the interface with this ip address (/24) or 'dhcp' "
+}
+
+#1 CHECK input parameters
+#1.1 root privileges
+[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1
+
+#1.2 input parameters
+FORCE=""
+while getopts "y" o; do
+ case "${o}" in
+ y)
+ FORCE="yes"
+ ;;
+ *)
+ usage
+ exit -1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+
+if [ $# -lt 1 ]
+then
+ usage
+ exit
+fi
+
+user_name=$1
+interface=$2
+ip_iface=$3
+
+if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null
+then
+ echo "Error: interface '$interface' is not present in the system"
+ usage
+ exit 1
+fi
+
+echo '
+#################################################################
+##### INSTALL NEEDED PACKETS #####
+#################################################################'
+
+# Required packages
+yum repolist
+yum check-update
+yum update -y
+yum install -y screen virt-manager ethtool gcc gcc-c++ xorg-x11-xauth xorg-x11-xinit xorg-x11-deprecated-libs libXtst guestfish hwloc libhugetlbfs-utils libguestfs-tools
+# Selinux management
+yum install -y policycoreutils-python
+
+echo '
+#################################################################
+##### INSTALL USER #####
+#################################################################'
+
+# Add required groups
+groupadd -f admin
+groupadd -f libvirt #for other operating systems may be libvirtd
+
+# Adds user, default password same as name
+if grep -q "^${user_name}:" /etc/passwd
+then
+ #user exist, add to group
+ echo "adding user ${user_name} to groups libvirt,admin"
+ usermod -a -G libvirt,admin -g admin $user_name
+else
+ #create user if it does not exist
+ [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk
+ if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ]
+ then
+ exit
+ fi
+ echo "creating and configuring user ${user_name}"
+ useradd -m -G libvirt,admin -g admin $user_name
+ #Password
+ if [ -z "$FORCE" ]
+ then
+ echo "Provide a password for $user_name"
+ passwd $user_name
+ else
+ echo -e "$user_name\n$user_name" | passwd --stdin $user_name
+ fi
+fi
+
+# Allow admin users to access without password
+if ! grep -q "#openmano" /etc/sudoers
+then
+ cat >> /home/${user_name}/script_visudo.sh << EOL
+#!/bin/bash
+cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp
+cat tmp > \$1
+rm tmp
+echo "" >> \$1
+echo "#openmano allow to group admin to grant root privileges without password" >> \$1
+echo "%admin ALL=(ALL) NOPASSWD: ALL" >> \$1
+EOL
+ chmod +x /home/${user_name}/script_visudo.sh
+ echo "allowing admin user to get root privileges withut password"
+ export EDITOR=/home/${user_name}/script_visudo.sh && sudo -E visudo
+ rm -f /home/${user_name}/script_visudo.sh
+fi
+
+echo '
+#################################################################
+##### OTHER CONFIGURATION #####
+#################################################################'
+# Creates a folder to store images in the user home
+#Creates a link to the /home folder because in RHEL this folder is larger
+echo "creating compute node folder for local images /opt/VNF/images"
+if [ "$user_name" != "" ]
+then
+ mkdir -p /home/VNF_images
+ chown -R ${user_name}:admin /home/VNF_images
+ chmod go+x /home/VNF_images
+
+ # The orchestator needs to link the images folder
+ rm -f /opt/VNF/images
+ mkdir -p /opt/VNF/
+ ln -s /home/VNF_images /opt/VNF/images
+ chown -R ${user_name}:admin /opt/VNF
+
+else
+ mkdir -p /opt/VNF/images
+ chmod o+rx /opt/VNF/images
+fi
+
+echo "creating local information /opt/VNF/images/hostinfo.yaml"
+echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml
+echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml
+echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml
+echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml
+if [ "$interface" != "" -a "$interface" != "em1" ]
+then
+ echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml
+ echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml
+fi
+chmod o+r /opt/VNF/images/hostinfo.yaml
+
+# deactivate memory overcommit
+echo "deactivate memory overcommit"
+service ksmtuned stop
+service ksm stop
+chkconfig ksmtuned off
+chkconfig ksm off
+
+# Libvirt options (uncomment the following)
+echo "configure Libvirt options"
+sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf
+sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
+
+echo '
+#################################################################
+##### NETWORK CONFIGURATION #####
+#################################################################'
+# Network config (if the second parameter is net)
+if [ -n "$interface" ]
+then
+
+ # Deactivate network manager
+ #systemctl stop NetworkManager
+ #systemctl disable NetworkManager
+
+ pushd /etc/sysconfig/network-scripts/
+
+ #Create infrastructure bridge
+ echo "DEVICE=virbrInf
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+IPADDR=10.10.0.1
+NETMASK=255.255.255.0
+USERCTL=no" > ifcfg-virbrInf
+
+ #Create bridge interfaces
+ echo "Creating bridge ifaces: "
+ for ((i=1;i<=20;i++))
+ do
+ i2digits=$i
+ [ $i -lt 10 ] && i2digits="0$i"
+ echo " virbrMan$i"
+ echo "DEVICE=virbrMan$i
+TYPE=Bridge
+ONBOOT=yes
+DELAY=0
+NM_CONTROLLED=no
+USERCTL=no" > ifcfg-virbrMan$i
+
+ done
+
+ popd
+fi
+
+echo
+echo "Do not forget to create a folder where original virtual machine images are allocated (ex. $HOME/static_storage)"
+echo
+echo "Do not forget to allow openvim machine accessing directly to the host with ssh. Can be done by:"
+echo " Copy the public ssh key of the openvim user from $HOME/.ssh/id_dsa.pub (in openvim) into /home/${user_name}/.ssh/authorized_keys (in the host) for automatic login from openvim controller"
+echo " Or running on openvim machine 'ssh-keygen' (generate ssh keys) and 'ssh-copy-id <user>@<compute host>'"
+echo
+echo "Do not forget to perform an initial ssh login from openmano VM into the host so the openmano ssh host key is added to /home/${user_name}/.ssh/known_hosts"
+echo
+
+echo "Reboot the system to make the changes effective"
+
+
diff --git a/scripts/flow-logback.xml b/scripts/flow-logback.xml
new file mode 100644
index 0000000..91f000d
--- /dev/null
+++ b/scripts/flow-logback.xml
@@ -0,0 +1,38 @@
+<!--
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+-->
+
+<configuration scan="true">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%level [%logger:%thread] %msg%n</pattern>
+ </encoder>
+ </appender>
+ <root level="ERROR">
+ <appender-ref ref="STDOUT" />
+ </root>
+ <logger name="org" level="ERROR"/>
+ <logger name="LogService" level="ERROR"/> <!-- Restlet access logging -->
+ <logger name="net.floodlightcontroller" level="TRACE"/>
+ <logger name="net.floodlightcontroller.logging" level="ERROR"/>
+</configuration>
+
diff --git a/scripts/flow.properties b/scripts/flow.properties
new file mode 100644
index 0000000..86f0bfa
--- /dev/null
+++ b/scripts/flow.properties
@@ -0,0 +1,42 @@
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+floodlight.modules = net.floodlightcontroller.storage.memory.MemoryStorageSource,\
+net.floodlightcontroller.core.FloodlightProvider,\
+net.floodlightcontroller.threadpool.ThreadPool,\
+net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,\
+net.floodlightcontroller.firewall.Firewall,\
+net.floodlightcontroller.jython.JythonDebugInterface,\
+net.floodlightcontroller.counter.CounterStore,\
+net.floodlightcontroller.perfmon.PktInProcessingTime,\
+net.floodlightcontroller.ui.web.StaticWebRoutable
+
+#PORT API floodlight will listen to. Must match the 'of_controller_port' of openvimd.cfg
+net.floodlightcontroller.restserver.RestApiServer.port = 7070
+
+#PORT used by the switch to connect to floodlight
+net.floodlightcontroller.core.FloodlightProvider.openflowport = 6633
+net.floodlightcontroller.jython.JythonDebugInterface.port = 6655
+
+#timeout parameters
+net.floodlightcontroller.forwarding.Forwarding.idletimeout = 5
+net.floodlightcontroller.forwarding.Forwarding.hardtimeout = 0
+
diff --git a/scripts/flow.properties_v1.1 b/scripts/flow.properties_v1.1
new file mode 100644
index 0000000..eede49b
--- /dev/null
+++ b/scripts/flow.properties_v1.1
@@ -0,0 +1,36 @@
+floodlight.modules=\
+net.floodlightcontroller.jython.JythonDebugInterface,\
+net.floodlightcontroller.storage.memory.MemoryStorageSource,\
+net.floodlightcontroller.core.internal.FloodlightProvider,\
+net.floodlightcontroller.threadpool.ThreadPool,\
+net.floodlightcontroller.debugcounter.DebugCounterServiceImpl,\
+net.floodlightcontroller.perfmon.PktInProcessingTime,\
+net.floodlightcontroller.debugevent.DebugEventService,\
+net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,\
+net.floodlightcontroller.restserver.RestApiServer,\
+net.floodlightcontroller.topology.TopologyManager,\
+net.floodlightcontroller.forwarding.Forwarding,\
+net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager,\
+net.floodlightcontroller.ui.web.StaticWebRoutable,\
+net.floodlightcontroller.loadbalancer.LoadBalancer,\
+net.floodlightcontroller.firewall.Firewall,\
+net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl
+org.sdnplatform.sync.internal.SyncManager.authScheme=CHALLENGE_RESPONSE
+org.sdnplatform.sync.internal.SyncManager.keyStorePath=/etc/floodlight/auth_credentials.jceks
+org.sdnplatform.sync.internal.SyncManager.dbPath=/var/lib/floodlight/
+org.sdnplatform.sync.internal.SyncManager.port=6642
+net.floodlightcontroller.core.internal.FloodlightProvider.openflowPort=6653
+net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE
+net.floodlightcontroller.core.internal.OFSwitchManager.clearTablesOnInitialHandshakeAsMaster=YES
+net.floodlightcontroller.core.internal.OFSwitchManager.clearTablesOnEachTransitionToMaster=YES
+net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePath=/path/to/your/keystore-file.jks
+net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePassword=your-keystore-password
+net.floodlightcontroller.core.internal.OFSwitchManager.useSsl=NO
+net.floodlightcontroller.restserver.RestApiServer.keyStorePath=/path/to/your/keystore-file.jks
+net.floodlightcontroller.restserver.RestApiServer.keyStorePassword=your-keystore-password
+net.floodlightcontroller.restserver.RestApiServer.httpsNeedClientAuthentication=NO
+net.floodlightcontroller.restserver.RestApiServer.useHttps=NO
+net.floodlightcontroller.restserver.RestApiServer.useHttp=YES
+net.floodlightcontroller.restserver.RestApiServer.httpsPort=8081
+net.floodlightcontroller.restserver.RestApiServer.httpPort=8080
+
diff --git a/scripts/get_dhcp_lease.sh b/scripts/get_dhcp_lease.sh
new file mode 100755
index 0000000..d2f04c3
--- /dev/null
+++ b/scripts/get_dhcp_lease.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+awk '
+($1=="lease" && $3=="{"){ lease=$2; active="no"; found="no" }
+($1=="binding" && $2=="state" && $3=="active;"){ active="yes" }
+($1=="hardware" && $2=="ethernet" && $3==tolower("'$1';")){ found="yes" }
+($1=="client-hostname"){ name=$2 }
+($1=="}"){ if (active=="yes" && found=="yes"){ target_lease=lease; target_name=name}}
+END{printf("%s", target_lease)} #print target_name
+' /var/lib/dhcp/dhcpd.leases
+
diff --git a/scripts/host-add-develop.sh b/scripts/host-add-develop.sh
new file mode 100755
index 0000000..dce4bde
--- /dev/null
+++ b/scripts/host-add-develop.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#Get configuration of a host for using it as a compute node
+
+function usage(){
+ 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"
+ echo -e " - In case hostname is not specified it will be used the name of the machine where the script is run"
+ echo -e " - nb_cores must be an odd number and bigger or equal to 4."
+ 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."
+ echo -e " - nb_10GB_interfaces must be an odd number and bigger or equal to 4."
+ echo -e " - The output will be a server descriptor with two numas and resources (memory, cores and interfaces) equally distributed between them."
+ echo -e " - Each interface (physical funtion) will have defined 8 SR-IOV (virtual functions)."
+ exit 1
+}
+
+function get_hash_value() { echo `eval echo $\{\`echo $1[$2]\`\}`; }
+
+function get_mac(){
+ seed=$1
+ b1=$((seed%16)); seed=$((seed/16))
+ b2=$((seed%16)); seed=$((seed/16))
+ b3=$((seed%16)); seed=$((seed/16))
+ b4=$((seed%16)); seed=$((seed/16))
+ b5=$((seed%16)); seed=$((seed/16))
+ mac=`printf "%02X:%02X:%02X:%02X:%02X:%02X" 2 $b5 $b4 $b3 $b2 $b1`
+ echo $mac
+}
+
+
+#check root privileges and non a root user behind
+
+[ "$#" -lt "5" ] && echo "Missing parameters" && usage
+[ "$#" -gt "6" ] && echo "Too many parameters" && usage
+HOST_NAME=`cat /etc/hostname`
+[ "$#" -eq "6" ] && HOST_NAME=$6
+FEATURES_LIST="lps,dioc,hwsv,tlbps,ht,lps,64b,iommu"
+NUMAS=2
+CORES=$3
+MEMORY=$4
+INTERFACES=$5
+
+#Ensure the user input is big enough
+([ $((CORES%2)) -ne 0 ] || [ $CORES -lt 4 ] ) && echo -e "ERROR: Wrong number of cores\n" && usage
+([ $((MEMORY%2)) -ne 0 ] || [ $MEMORY -lt 16 ] ) && echo -e "ERROR: Wrong number of memory\n" && usage
+([ $((INTERFACES%2)) -ne 0 ] || [ $INTERFACES -lt 4 ] ) && echo -e "ERROR: Wrong number of interfaces\n" && usage
+
+#Generate a cpu topology for 4 numas with hyperthreading
+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`
+
+#in this developing/fake server all cores can be used
+
+echo "#This file was created by $0"
+echo "#for adding this compute node to openvim"
+echo "#copy this file to openvim controller and run"
+echo "#openvim host-add <this>"
+echo
+echo "host:"
+echo " name: $HOST_NAME"
+echo " user: $1"
+echo " ip_name: $2"
+echo "host-data:"
+echo " name: $HOST_NAME"
+echo " user: $1"
+echo " ip_name: $2"
+echo " ranking: 100"
+echo " description: $HOST_NAME"
+echo " features: $FEATURES_LIST"
+echo " numas:"
+
+numa=0
+last_iface=0
+iface_counter=0
+while [ $numa -lt $NUMAS ]
+do
+ echo " - numa_socket: $numa"
+#MEMORY
+ echo " hugepages: $((MEMORY/2-2))"
+ echo " memory: $((MEMORY/2))"
+
+#CORES
+ echo " cores:"
+ for cpu in $CPUS
+ do
+ PHYSICAL=`echo $cpu | cut -f 1 -d"-"`
+ CORE=`echo $cpu | cut -f 2 -d"-"`
+ THREAD=`echo $cpu | cut -f 3 -d"-"`
+ [ $PHYSICAL != $numa ] && continue #skip non physical
+ echo " - core_id: $CORE"
+ echo " thread_id: $THREAD"
+ [ $CORE -eq 0 ] && echo " status: noteligible"
+ done
+
+
+ #GENERATE INTERFACES INFORMATION AND PRINT IT
+ seed=$RANDOM
+ echo " interfaces:"
+ for ((iface=0;iface<$INTERFACES;iface+=2))
+ do
+ name="iface$iface_counter"
+ bus=$((iface+last_iface))
+ pci=`printf "0000:%02X:00.0" $bus`
+ mac=`get_mac $seed`
+ seed=$((seed+1))
+
+ echo " - source_name: $name"
+ echo " Mbps: 10000"
+ echo " pci: \"$pci\""
+ echo " mac: \"$mac\""
+ echo " switch_dpid: \"01:02:03:04:05:06\""
+ echo " switch_port: fake0/$iface_counter"
+ echo " sriovs:"
+
+ for((nb_sriov=0;nb_sriov<8;nb_sriov++))
+ do
+ pci=`printf "0000:%02X:10.%i" $bus $nb_sriov`
+ mac=`get_mac $seed`
+ seed=$((seed+1))
+ echo " - mac: \"$mac\""
+ echo " pci: \"$pci\""
+ echo " source_name: $nb_sriov"
+ done
+
+ iface_counter=$((iface_counter+1))
+ done
+ last_iface=$(((numa+1)*127/NUMAS+5)) #made-up formula for more realistic pci numbers
+
+
+ numa=$((numa+1))
+done
+
diff --git a/scripts/host-add.sh b/scripts/host-add.sh
new file mode 100755
index 0000000..cf2138d
--- /dev/null
+++ b/scripts/host-add.sh
@@ -0,0 +1,406 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#Get configuration of a host for using it as a compute node
+
+function usage(){
+ echo -e "usage: $0 user ip_name [>> host.yaml]\n Get host parameters and generated a yaml file to be used for openvim host-add"
+ exit 1
+}
+
+function load_vf_driver(){
+ local pf_driver=$1
+ if [[ `lsmod | cut -d" " -f1 | grep $pf_driver | grep -v vf` ]] && [[ ! `lsmod | cut -d" " -f1 | grep ${pf_driver}vf` ]]
+ then
+ >&2 echo "$pf_driver is loaded but not ${pf_driver}vf. This is required in order to properly add SR-IOV."
+ read -p "Do you want to load ${pf_driver}vf [Y/n] " load_driver
+ case $load_driver in
+ [nN]* ) exit 1;;
+ * ) >&2 echo "Loading ${pf_driver}vf..."
+ modprobe ${pf_driver}vf;
+ >&2 echo "Reloading ${pf_driver}..."
+ modprobe -r $pf_driver;
+ modprobe $pf_driver;;
+ esac
+ fi
+}
+
+function remove_vf_driver(){
+ local pf_driver=$1
+ if [[ `lsmod | cut -d" " -f1 | grep $pf_driver | grep -v vf` ]] && [[ `lsmod | cut -d" " -f1 | grep ${pf_driver}vf` ]]
+ then
+ >&2 echo "${pf_driver}vf is loaded. In order to ensure proper SR-IOV behavior the driver must be removed."
+ read -p "Do you want to remove ${pf_driver}vf now? [Y/n] " remove_driver
+ case $remove_driver in
+ [nN]* ) >&2 echo "OK. Remember to remove the driver prior start using the compute node executing:";
+ >&2 echo "modprobe -r ${pf_driver}vf";
+ >&2 echo "modprobe -r ${pf_driver}";
+ >&2 echo "modprobe ${pf_driver}";;
+ * ) >&2 echo "Removing ${pf_driver}vf..."
+ modprobe -r ${pf_driver}vf;
+ >&2 echo "Reloading ${pf_driver}..."
+ modprobe -r $pf_driver;
+ modprobe $pf_driver;;
+ esac
+ fi
+}
+
+function get_hash_value() { echo `eval echo $\{\`echo $1[$2]\`\}`; }
+
+function xmlpath_args()
+{
+ local expr="${1//\// }"
+ local path=()
+ local chunk tag data
+ local exit_code=1
+ local print_line=0
+ local closing_tag=0
+
+ while IFS='' read -r -d '<' chunk; do
+ data=arguments=""
+ IFS='>' read -r tag_arg data <<< "$chunk"
+ IFS=' ' read -r tag arguments <<< "$tag_arg"
+ #If last tag was single level remove it from path
+ if [[ $closing_tag -eq 1 ]]
+ then
+ unset path[${#path[@]}-1]
+ closing_tag=0
+ fi
+ #In case the tag is closed in the same line mark it
+ [[ $arguments = ?*'/' ]] && closing_tag=1
+ arguments="${arguments//\//}"
+ case "$tag" in
+ '?'*) ;;
+ '!--'*) ;;
+ ?*'/') ;;
+ '/'?*) unset path[${#path[@]}-1] ;;
+ ?*) path+=("$tag");;
+ esac
+
+ #echo "\"${path[@]}\" \"$expr\" \"$data\" \"$arguments\" $exit_code $print_line"
+
+ if [[ "${path[@]}" == "$expr" ]]
+ then
+ #If there is data print it and append arguments if any
+ if [ "$data" != "" ]
+ then
+ echo "$data $arguments"
+ #return code 0 means data was found
+ exit_code=0
+ continue
+ #if there is no data but there are arguments print arguments
+ elif [ "$arguments" != "" ]
+ then
+ echo "$arguments"
+ #return code 2 means no data but arguments were found
+ exit_code=2
+ continue
+ #otherwise switch flag to start/stop echoing each line until the tag is closed
+ elif [[ $exit_code -eq 1 ]]
+ then
+ print_line=$(((print_line+1)%2))
+ #return code 3 means that the whole xml segment is returned
+ exit_code=3
+ fi
+ fi
+ [[ $print_line == "1" ]] && echo "<"$chunk
+ done
+ return $exit_code
+}
+
+
+#check root privileges and non a root user behind
+
+[[ "$#" -lt "2" ]] && echo "Missing parameters" && usage
+load_vf_driver ixgbe
+load_vf_driver i40e
+
+HOST_NAME=`cat /etc/hostname`
+FEATURES=`grep "^flags" /proc/cpuinfo`
+FEATURES_LIST=""
+if echo $FEATURES | grep -q pdpe1gb ; then FEATURES_LIST="${FEATURES_LIST},lps"; fi
+if echo $FEATURES | grep -q dca ; then FEATURES_LIST="${FEATURES_LIST},dioc"; fi
+if echo $FEATURES | egrep -q "(vmx|svm)" ; then FEATURES_LIST="${FEATURES_LIST},hwsv"; fi
+if echo $FEATURES | egrep -q "(ept|npt)" ; then FEATURES_LIST="${FEATURES_LIST},tlbps"; fi
+if echo $FEATURES | grep -q ht ; then FEATURES_LIST="${FEATURES_LIST},ht"; fi
+if uname -m | grep -q x86_64 ; then FEATURES_LIST="${FEATURES_LIST},64b"; fi
+if cat /var/log/dmesg | grep -q -e Intel-IOMMU ; then FEATURES_LIST="${FEATURES_LIST},iommu"; fi
+FEATURES_LIST=${FEATURES_LIST#,}
+
+NUMAS=`gawk 'BEGIN{numas=0;}
+ ($1=="physical" && $2=="id" ){ if ($4+1>numas){numas=$4+1} };
+ END{printf("%d",numas);}' /proc/cpuinfo`
+
+CPUS=`gawk '($1=="processor"){pro=$3;}
+ ($1=="physical" && $2=="id"){ phy=$4;}
+ ($1=="core" && $2=="id"){printf " %d-%d-%d", phy,$4,pro;}' /proc/cpuinfo`
+
+if grep -q isolcpus /proc/cmdline
+then
+ isolcpus=`cat /proc/cmdline`
+ isolcpus=${isolcpus##*isolcpus=}
+ isolcpus=${isolcpus%% *}
+ isolcpus=${isolcpus//,/ }
+else
+ isolcpus=""
+fi
+
+
+#obtain interfaces information
+unset dpid
+read -p "Do you want to provide the interfaces connectivity information (datapathid/dpid of the switch and switch port id)? [Y/n] " conn_info
+case $conn_info in
+ [Nn]* ) prov_conn=false;;
+ * ) prov_conn=true;
+ read -p "What is the switch dapapathid/dpdi? (01:02:03:04:05:06:07:08) " dpid;
+ [[ -z $dpid ]] && dpid="01:02:03:04:05:06:07:08";
+ PORT_RANDOM=$RANDOM
+ iface_counter=0;;
+esac
+OLDIFS=$IFS
+IFS=$'\n'
+unset PF_list
+unset VF_list
+for device in `virsh nodedev-list --cap net | grep -v net_lo_00_00_00_00_00_00`
+do
+virsh nodedev-dumpxml $device > device_xml
+name=`xmlpath_args "device/capability/interface" < device_xml`
+name="${name// /}"
+address=`xmlpath_args "device/capability/address" < device_xml`
+address="${address// /}"
+parent=`xmlpath_args "device/parent" < device_xml`
+parent="${parent// /}"
+#the following line created variables 'speed' and 'state'
+eval `xmlpath_args "device/capability/link" < device_xml`
+virsh nodedev-dumpxml $parent > parent_xml
+driver=`xmlpath_args "device/driver/name" < parent_xml`
+[ $? -eq 1 ] && driver="N/A"
+driver="${driver// /}"
+
+#If the device is not up try to bring it up and reload state
+if [[ $state == 'down' ]] && ( [[ $driver == "ixgbe" ]] || [[ $driver == "i40e" ]] )
+then
+ >&2 echo "$name is down. Trying to bring it up"
+ ifconfig $name up
+ sleep 2
+ virsh nodedev-dumpxml $device > device_xml
+ eval `xmlpath_args "device/capability/link" < device_xml`
+fi
+
+if [[ $state == 'down' ]] && ( [[ $driver == "ixgbe" ]] || [[ $driver == "i40e" ]] )
+then
+ >&2 echo "Interfaces must be connected and up in order to properly detect the speed. You can provide this information manually or skip the interface"
+ keep_asking=true
+ skip_interface=true
+ unset speed
+ while $keep_asking; do
+ read -p "Do you want to skip interface $name ($address) [y/N] " -i "n" skip
+ case $skip in
+ [Yy]* ) keep_asking=false;;
+ * ) skip_interface=false;
+ default_speed="10000"
+ while $keep_asking; do
+ read -p "What is the speed of the interface expressed in Mbps? ($default_speed) " speed;
+ [[ -z $speed ]] && speed=$default_speed
+ [[ $speed =~ ''|*[!0-9] ]] && echo "The input must be an integer" && continue;
+ keep_asking=false ;
+ done;;
+ esac
+ done
+
+ $skip_interface && continue
+fi
+#the following line creates a 'node' variable
+eval `xmlpath_args "device/capability/numa" < parent_xml`
+#the following line creates the variable 'type'
+#in case the interface is a PF the value is 'virt_functions'
+#in case the interface is a VF the value is 'phys_function'
+type="N/A"
+eval `xmlpath_args "device/capability/capability" < parent_xml`
+#obtain pci
+#the following line creates the variables 'domain' 'bus' 'slot' and 'function'
+eval `xmlpath_args "device/capability/iommuGroup/address" < parent_xml`
+pci="${domain#*x}:${bus#*x}:${slot#*x}.${function#*x}"
+underscored_pci="${pci//\:/_}"
+underscored_pci="pci_${underscored_pci//\./_}"
+
+if ( [[ $driver == "ixgbe" ]] || [[ $driver == "i40e" ]] )
+then
+ underscored_pci="pf"$underscored_pci
+ PF_list[${#PF_list[@]}]=$underscored_pci
+ eval declare -A $underscored_pci
+ eval $underscored_pci["name"]=$name
+ eval $underscored_pci["numa"]=$node
+ eval $underscored_pci["mac"]=$address
+ eval $underscored_pci["speed"]=$speed
+ eval $underscored_pci["pci"]=$pci
+ #request switch port to the user if this information is being provided and include it
+ if $prov_conn
+ then
+ unset switch_port
+ read -p "What is the port name in the switch $dpid where port $name ($pci) is connected? (${name}-${PORT_RANDOM}/$iface_counter) " switch_port
+ [[ -z $switch_port ]] && switch_port="${name}-${PORT_RANDOM}/$iface_counter"
+ iface_counter=$((iface_counter+1))
+ eval $underscored_pci["dpid"]=$dpid
+ eval $underscored_pci["switch_port"]=$switch_port
+ fi
+
+ #Añado el pci de cada uno de los hijos
+ SRIOV_counter=0
+ for child in `xmlpath_args "device/capability/capability/address" < parent_xml`
+ do
+ SRIOV_counter=$((SRIOV_counter+1))
+ #the following line creates the variables 'domain' 'bus' 'slot' and 'function'
+ eval $child
+ eval $underscored_pci["SRIOV"$SRIOV_counter]="${domain#*x}_${bus#*x}_${slot#*x}_${function#*x}"
+ done
+ eval $underscored_pci["SRIOV"]=$SRIOV_counter
+
+#Si se trata de un SRIOV (tiene una capability con type 'phys_function')
+elif [[ $type == 'phys_function' ]]
+then
+ underscored_pci="vf"$underscored_pci
+ VF_list[${#VF_list[@]}]=$underscored_pci
+ eval declare -A $underscored_pci
+ eval $underscored_pci["source_name"]=$name
+ eval $underscored_pci["mac"]=$address
+ eval $underscored_pci["pci"]=$pci
+fi
+rm -f device_xml parent_xml
+done
+IFS=$OLDIFS
+
+echo "#This file was created by $0"
+echo "#for adding this compute node to openvim"
+echo "#copy this file to openvim controller and run"
+echo "#openvim host-add <this>"
+echo
+echo "host:"
+echo " name: $HOST_NAME"
+echo " user: $1"
+echo " ip_name: $2"
+echo "host-data:"
+echo " name: $HOST_NAME"
+echo " user: $1"
+echo " ip_name: $2"
+echo " ranking: 100"
+echo " description: $HOST_NAME"
+echo " features: $FEATURES_LIST"
+echo " numas:"
+
+numa=0
+while [[ $numa -lt $NUMAS ]]
+do
+ echo " - numa_socket: $numa"
+#MEMORY
+ if [ -f /sys/devices/system/node/node${numa}/hugepages/hugepages-1048576kB/nr_hugepages ]
+ then
+ echo " hugepages: " `cat /sys/devices/system/node/node${numa}/hugepages/hugepages-1048576kB/nr_hugepages`
+ else
+ #TODO hugepages of 2048kB size
+ echo " hugepages: 0"
+ fi
+ memory=`head -n1 /sys/devices/system/node/node${numa}/meminfo | gawk '($5=="kB"){print $4}'`
+ memory=$((memory+1048576-1)) #memory must be ceiled
+ memory=$((memory/1048576)) #from `kB to GB
+ echo " memory: $memory"
+
+#CORES
+ echo " cores:"
+ FIRST="-" #first item in a list start with "-" in yaml files, then it will set to " "
+ for cpu in $CPUS
+ do
+ PHYSICAL=`echo $cpu | cut -f 1 -d"-"`
+ CORE=`echo $cpu | cut -f 2 -d"-"`
+ THREAD=`echo $cpu | cut -f 3 -d"-"`
+ [[ $PHYSICAL != $numa ]] && continue #skip non physical
+ echo " - core_id: $CORE"
+ echo " thread_id: $THREAD"
+ #check if eligible
+ cpu_isolated="no"
+ for isolcpu in $isolcpus
+ do
+ isolcpu_start=`echo $isolcpu | cut -f 1 -d"-"`
+ isolcpu_end=`echo $isolcpu | cut -f 2 -d"-"`
+ if [ "$THREAD" -ge "$isolcpu_start" -a "$THREAD" -le "$isolcpu_end" ]
+ then
+ cpu_isolated="yes"
+ break
+ fi
+ done
+ [[ $cpu_isolated == "no" ]] && echo " status: noteligible"
+ FIRST=" "
+ done
+
+ #NIC INTERFACES
+ interfaces_nb=0
+ for ((i=0; i<${#PF_list[@]};i++))
+ do
+ underscored_pci=${PF_list[$i]}
+ pname=$(get_hash_value $underscored_pci "name")
+ pnuma=$(get_hash_value $underscored_pci "numa")
+ [[ $pnuma != $numa ]] && continue
+ pmac=$(get_hash_value $underscored_pci "mac")
+ ppci=$(get_hash_value $underscored_pci "pci")
+ pspeed=$(get_hash_value $underscored_pci "speed")
+ pSRIOV=$(get_hash_value $underscored_pci "SRIOV")
+ [[ $interfaces_nb -eq 0 ]] && echo " interfaces:"
+ interfaces_nb=$((interfaces_nb+1))
+ sriov_nb=0
+ echo " - source_name: $pname"
+ echo " Mbps: $pspeed"
+ echo " pci: \"$ppci\""
+ echo " mac: \"$pmac\""
+ if $prov_conn
+ then
+ pdpid=$(get_hash_value $underscored_pci "dpid")
+ pswitch_port=$(get_hash_value $underscored_pci "switch_port")
+ echo " switch_dpid: $pdpid"
+ echo " switch_port: $pswitch_port"
+ fi
+ for ((j=1;j<=$pSRIOV;j++))
+ do
+ childSRIOV="vfpci_"$(get_hash_value $underscored_pci "SRIOV"$j)
+ pname=$(get_hash_value $childSRIOV "source_name")
+ index=${pname##*_}
+ pmac=$(get_hash_value $childSRIOV "mac")
+ ppci=$(get_hash_value $childSRIOV "pci")
+ [[ $sriov_nb -eq 0 ]] && echo " sriovs:"
+ sriov_nb=$((sriov_nb+1))
+ echo " - mac: \"$pmac\""
+ echo " pci: \"$ppci\""
+ echo " source_name: $index"
+ done
+ done
+
+ numa=$((numa+1))
+done
+remove_vf_driver ixgbe
+remove_vf_driver i40e
+#Bring up all interfaces
+for ((i=0; i<${#PF_list[@]};i++))
+do
+ underscored_pci=${PF_list[$i]}
+ pname=$(get_hash_value $underscored_pci "name")
+ ifconfig $pname up
+done
diff --git a/scripts/initopenvim.sh b/scripts/initopenvim.sh
new file mode 100755
index 0000000..69f3667
--- /dev/null
+++ b/scripts/initopenvim.sh
@@ -0,0 +1,213 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#This script can be used as a basic test of openvim
+#stopping on an error
+#WARNING: It destroy the database content
+
+
+function usage(){
+ echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] <action>\n Deletes openvim content and add fake hosts, networks"
+ echo -e " <action> is a list of the following items (by default 'reset create')"
+ echo -e " reset reset the openvim database content"
+ echo -e " create creates fake hosts and networks"
+ echo -e " delete delete created items"
+ echo -e " delete-all delete vms. flavors, images, ..."
+ echo -e " OPTIONS:"
+ echo -e " -f --force : does not prompt for confirmation"
+ echo -e " -d --delete : same to action delete-all"
+ echo -e " --insert-bashrc insert the created tenant variables at"
+ echo -e " ~/.bashrc to be available by openvim CLI"
+ echo -e " -h --help : shows this help"
+}
+
+function is_valid_uuid(){
+ echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0
+ return 1
+}
+
+
+#detect if is called with a source to use the 'exit'/'return' command for exiting
+[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit"
+
+#check correct arguments
+force=""
+action_list=""
+insert_bashrc=""
+
+while [[ $# -gt 0 ]]
+do
+ argument="$1"
+ shift
+ if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] || [[ $argument == delete-all ]]
+ then
+ action_list="$action_list $argument"
+ continue
+ #short options
+ elif [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]]
+ then
+ index=0
+ while index=$((index+1)) && [[ $index -lt ${#argument} ]]
+ do
+ [[ ${argument:$index:1} == h ]] && usage && $_exit 0
+ [[ ${argument:$index:1} == f ]] && force=y && continue
+ [[ ${argument:$index:1} == d ]] && action_list="delete-all $action_list" && continue
+ echo "invalid option '${argument:$index:1}'? Type -h for help" >&2 && $_exit 1
+ done
+ continue
+ fi
+ #long options
+ [[ $argument == --help ]] && usage && $_exit 0
+ [[ $argument == --force ]] && force=y && continue
+ [[ $argument == --delete ]] && action_list="delete-all $action_list" && continue
+ [[ $argument == --insert-bashrc ]] && insert_bashrc=y && continue
+ echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1
+done
+
+DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+DIRvim=$(dirname $DIRNAME)
+export OPENVIM_HOST=localhost
+export OPENVIM_PORT=9080
+[[ $insert_bashrc == y ]] && echo -e "\nexport OPENVIM_HOST=localhost" >> ~/.bashrc
+[[ $insert_bashrc == y ]] && echo -e "\nexport OPENVIM_PORT=9080" >> ~/.bashrc
+#by default action should be reset and create
+[[ -z $action_list ]] && action_list="reset create"
+
+
+for action in $action_list
+do
+if [[ $action == "reset" ]]
+then
+ #ask for confirmation if argument is not -f --force
+ force_="y"
+ [[ $force != y ]] && read -e -p "WARNING: openvim database content will be lost!!! Continue(y/N)" force_
+ [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
+ echo "deleting deployed vm"
+ ${DIRvim}/openvim vm-delete -f | grep -q deleted && sleep 10 #give some time to get virtual machines deleted
+ echo "Stopping openvim"
+ $DIRNAME/service-openvim.sh stop
+ echo "Initializing databases"
+ $DIRvim/database_utils/init_vim_db.sh -u vim -p vimpw
+ echo "Starting openvim"
+ $DIRNAME/service-openvim.sh start
+
+elif [[ $action == delete-all ]]
+then
+ for t in `${DIRvim}/openvim tenant-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{printf("%s:%s",$1,$2)}'`
+ do
+ t_id=${t%%:*}
+ t_name=${t#*:}
+ [[ -z $t_id ]] && continue
+ export OPENVIM_TENANT=${t_id}
+ for what in vm image flavor port net
+ do
+ items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'`
+ if [[ -n $items ]]
+ then
+ [[ $force == y ]] && echo deleting openvim ${what}s from tenant ${t_name}
+ [[ $force != y ]] && read -e -p "Delete openvim ${what}s from tenant ${t_name}?(y/N) " force_
+ [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
+ for item in $items
+ do
+ echo -n "$item "
+ ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1
+ done
+ fi
+ done
+ ${DIRvim}/openvim tenant-delete -f $t_id || ! echo "fail" >&2 || $_exit 1
+ for what in host
+ do
+ items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'`
+ if [[ -n $items ]]
+ then
+ [[ $force == y ]] && echo deleting openvim ${what}s
+ [[ $force != y ]] && read -e -p "Delete openvim ${what}s?(y/N) " force_
+ [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit
+ for item in $items
+ do
+ echo -n "$item "
+ ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1
+ done
+ fi
+ done
+
+ done
+elif [[ $action == "delete" ]]
+then
+ ${DIRvim}/openvim net-delete -f default || echo "fail"
+ ${DIRvim}/openvim net-delete -f macvtap:em1 || echo "fail"
+ ${DIRvim}/openvim net-delete -f shared_bridge_net || echo "fail"
+ ${DIRvim}/openvim net-delete -f data_net || echo "fail"
+ ${DIRvim}/openvim host-remove -f fake-host-0 || echo "fail"
+ ${DIRvim}/openvim host-remove -f fake-host-1 || echo "fail"
+ ${DIRvim}/openvim host-remove -f fake-host-2 || echo "fail"
+ ${DIRvim}/openvim host-remove -f fake-host-3 || echo "fail"
+ result=`openvim tenant-list TEST-admin`
+ vimtenant=`echo $result |gawk '{print $1}'`
+ #check a valid uuid is obtained
+ is_valid_uuid $vimtenant || ! echo "Tenant TEST-admin not found. Already delete?" >&2 || $_exit 1
+ export OPENVIM_TENANT=$vimtenant
+ ${DIRvim}/openvim tenant-delete -f TEST-admin || echo "fail"
+ echo
+
+elif [[ $action == "create" ]]
+then
+ echo "Adding example hosts"
+ ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example0.json || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example1.json || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example2.json || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example3.json || ! echo "fail" >&2 || $_exit 1
+ echo "Adding example nets"
+ ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example0.yaml || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example1.yaml || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example2.yaml || ! echo "fail" >&2 || $_exit 1
+ ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example3.yaml || ! echo "fail" >&2 || $_exit 1
+
+ printf "%-50s" "Creating openvim tenant 'TEST-admin': "
+ result=`openvim tenant-create '{"tenant": {"name":"TEST-admin", "description":"admin"}}'`
+ vimtenant=`echo $result |gawk '{print $1}'`
+ #check a valid uuid is obtained
+ ! is_valid_uuid $vimtenant && echo "FAIL" && echo " $result" && $_exit 1
+ echo " $vimtenant"
+ export OPENVIM_TENANT=$vimtenant
+ [[ $insert_bashrc == y ]] && echo -e "\nexport OPENVIM_TENANT=$vimtenant" >> ~/.bashrc
+
+ echo
+ #echo "Check virtual machines are deployed"
+ #vms_error=`openvim vm-list | grep ERROR | wc -l`
+ #vms=`openvim vm-list | wc -l`
+ #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1
+ #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1
+fi
+done
+
+echo
+echo DONE
+#echo "Listing VNFs"
+#openvim vnf-list
+#echo "Listing scenarios"
+#openvim scenario-list
+#echo "Listing scenario instances"
+#openvim instance-scenario-list
+
+
diff --git a/scripts/install-floodlight.sh b/scripts/install-floodlight.sh
new file mode 100755
index 0000000..506d5c1
--- /dev/null
+++ b/scripts/install-floodlight.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#ONLY TESTED for Ubuntu 14.10 14.04, CentOS7 and RHEL7
+#Get needed packages, to run floodlight
+
+function usage(){
+ echo -e "usage: sudo $0 \n Install floodlight v0.9 in ./floodlight-0.90"
+}
+
+function install_packages(){
+ [ -x /usr/bin/apt-get ] && apt-get install -y $*
+ [ -x /usr/bin/yum ] && yum install -y $*
+
+ #check properly installed
+ for PACKAGE in $*
+ do
+ PACKAGE_INSTALLED="no"
+ [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
+ [ -x /usr/bin/yum ] && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
+ if [ "$PACKAGE_INSTALLED" = "no" ]
+ then
+ echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
+ exit -1
+ fi
+ done
+}
+
+#check root privileges and non a root user behind
+[ "$1" == "-h" -o "$1" == "--help" ] && usage && exit 0
+[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && usage >&2 && exit -1
+[ -z "$SUDO_USER" -o "$SUDO_USER" = "root" ] && echo "Must be runned with sudo from a non root user" >&2 && usage >&2 && exit -1
+
+echo "This script will update repositories and Installing FloodLight."
+echo "It will install Java and other packages, that takes a while to download"
+read -e -p "Do you agree on download and install FloodLight from http://www.projectfloodlight.org upon the owner license? (y/N)" KK
+[[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && exit 0
+
+#Discover Linux distribution
+#try redhat type
+[ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
+#if not assuming ubuntu type
+[ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
+if [ "$_DISTRO" == "Ubuntu" ]
+then
+ _RELEASE="14"
+ if ! lsb_release -rs | grep -q "14."
+ then
+ read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+elif [ "$_DISTRO" == "CentOS" ]
+then
+ _RELEASE="7"
+ if ! cat /etc/redhat-release | grep -q "7."
+ then
+ read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+elif [ "$_DISTRO" == "Red" ]
+then
+ _RELEASE="7"
+ if ! cat /etc/redhat-release | grep -q "7."
+ then
+ read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ]
+ _DISTRO_DISCOVER=$_DISTRO
+ [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14"
+ [ -x /usr/bin/yum ] && _DISTRO="CentOS" && _RELEASE="7"
+ read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+fi
+
+
+
+echo '
+#################################################################
+##### UPDATE REPOSITORIES #####
+#################################################################'
+[ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
+
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
+
+echo '
+#################################################################
+##### DOWNLOADING AND CONFIGURE FLOODLIGHT #####
+#################################################################'
+ #Install Java JDK and Ant packages at the VM
+ [ "$_DISTRO" == "Ubuntu" ] && install_packages "build-essential default-jdk ant python-dev screen wget" #TODO revise if packages are needed apart from ant
+ [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_package " ant screen wget"
+
+ #floodlight 0.9
+ echo "downloading v0.90 from the oficial page"
+ su $SUDO_USER -c 'wget https://github.com/floodlight/floodlight/archive/v0.90.tar.gz'
+ su $SUDO_USER -c 'tar xvzf v0.90.tar.gz'
+ #floodlight 1.1
+ #echo "downloading v1.1 from the oficial page"
+ #su $SUDO_USER -c 'wget https://github.com/floodlight/floodlight/archive/v1.1.tar.gz'
+ #su $SUDO_USER -c 'tar xvzf v01.1.tar.gz'
+
+ #Configure Java environment variables. It is seem that is not needed!!!
+ #export JAVA_HOME=/usr/lib/jvm/default-java" >> /home/${SUDO_USER}/.bashr
+ #export PATH=$PATH:$JAVA_HOME
+ #echo "export JAVA_HOME=/usr/lib/jvm/default-java" >> /home/${SUDO_USER}/.bashrc
+ #echo "export PATH=$PATH:$JAVA_HOME" >> /home/${SUDO_USER}/.bashrc
+
+ #Compile floodlight
+ pushd ./floodlight-0.90
+ #pushd ./floodlight-1.1
+ su $SUDO_USER -c 'ant'
+ export FLOODLIGHT_PATH=$(pwd)
+ popd
+
+echo '
+#################################################################
+##### CONFIGURE envioronment #####
+#################################################################'
+#insert into .bashrc
+ echo " inserting FLOODLIGHT_PATH at .bashrc"
+ su $SUDO_USER -c "echo 'export FLOODLIGHT_PATH=\"${FLOODLIGHT_PATH}\"' >> ~/.bashrc"
+
+echo
+echo "Done! you may need to logout and login again for loading the configuration"
+echo " If your have installed openvim, run './openvim/scripts/service-floodlight.sh start' for starting floodlight in a screen"
+
+
+
diff --git a/scripts/install-openvim.sh b/scripts/install-openvim.sh
new file mode 100755
index 0000000..fbf0fb5
--- /dev/null
+++ b/scripts/install-openvim.sh
@@ -0,0 +1,260 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#ONLY TESTED for Ubuntu 14.10 14.04, CentOS7 and RHEL7
+#Get needed packages, source code and configure to run openvim
+#Ask for database user and password if not provided
+# $1: database user
+# $2: database password
+
+function usage(){
+ echo -e "usage: sudo $0 [db-user [db-passwd]]\n Install source code in ./openvim"
+}
+
+function install_packages(){
+ [ -x /usr/bin/apt-get ] && apt-get install -y $*
+ [ -x /usr/bin/yum ] && yum install -y $*
+
+ #check properly installed
+ for PACKAGE in $*
+ do
+ PACKAGE_INSTALLED="no"
+ [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
+ [ -x /usr/bin/yum ] && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
+ if [ "$PACKAGE_INSTALLED" = "no" ]
+ then
+ echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
+ exit -1
+ fi
+ done
+}
+
+#check root privileges and non a root user behind
+[ "$1" == "-h" -o "$1" == "--help" ] && usage && exit 0
+[ "$USER" != "root" ] && echo "Needed root privileges" >&2 && usage >&2 && exit -1
+[ -z "$SUDO_USER" -o "$SUDO_USER" = "root" ] && echo "Must be runned with sudo from a non root user" >&2 && usage >&2 && exit -1
+
+
+#Discover Linux distribution
+#try redhat type
+[ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
+#if not assuming ubuntu type
+[ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
+if [ "$_DISTRO" == "Ubuntu" ]
+then
+ _RELEASE="14"
+ if ! lsb_release -rs | grep -q "14."
+ then
+ read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+elif [ "$_DISTRO" == "CentOS" ]
+then
+ _RELEASE="7"
+ if ! cat /etc/redhat-release | grep -q "7."
+ then
+ read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+elif [ "$_DISTRO" == "Red" ]
+then
+ _RELEASE="7"
+ if ! cat /etc/redhat-release | grep -q "7."
+ then
+ read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+ fi
+else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ]
+ _DISTRO_DISCOVER=$_DISTRO
+ [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14"
+ [ -x /usr/bin/yum ] && _DISTRO="CentOS" && _RELEASE="7"
+ read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
+ [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
+fi
+
+
+
+echo '
+#################################################################
+##### UPDATE REPOSITORIES #####
+#################################################################'
+[ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
+
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
+[ "$_DISTRO" == "CentOS" ] && sudo yum install -y epel-release
+[ "$_DISTRO" == "Red" ] && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm \
+ && sudo rpm -ivh epel-release-7-5.noarch.rpm && sudo yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
+
+
+echo '
+#################################################################
+##### INSTALL REQUIRED PACKAGES #####
+#################################################################'
+[ "$_DISTRO" == "Ubuntu" ] && install_packages "mysql-server"
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "mariadb mariadb-server"
+
+if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
+then
+ #start services. By default CentOS does not start services
+ service mariadb start
+ service httpd start
+ systemctl enable mariadb
+ systemctl enable httpd
+ read -e -p "Do you want to configure mariadb (recomended if not done before) (Y/n)" KK
+ [ "$KK" != "n" -a "$KK" != "no" ] && mysql_secure_installation
+
+ read -e -p "Do you want to set firewall to grant web access port 80,443 (Y/n)" KK
+ [ "$KK" != "n" -a "$KK" != "no" ] &&
+ firewall-cmd --permanent --zone=public --add-service=http &&
+ firewall-cmd --permanent --zone=public --add-service=https &&
+ firewall-cmd --reload
+fi
+
+#check and ask for database user password. Must be done after database instalation
+[ -n "$1" ] && DBUSER=$1
+[ -z "$1" ] && DBUSER=root
+[ -n "$2" ] && DBPASSWD="-p$2"
+[ -z "$2" ] && DBPASSWD=""
+echo -e "\nCheking database connection and ask for credentials"
+while ! echo "" | mysql -u$DBUSER $DBPASSWD
+do
+ [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
+ [ -z "$logintry" ] && echo -e "\nProvide database credentials"
+ read -e -p "database user? ($DBUSER) " DBUSER_
+ [ -n "$DBUSER_" ] && DBUSER=$DBUSER_
+ read -e -s -p "database password? (Enter for not using password) " DBPASSWD_
+ [ -n "$DBPASSWD_" ] && DBPASSWD="-p$DBPASSWD_"
+ [ -z "$DBPASSWD_" ] && DBPASSWD=""
+ logintry="yes"
+done
+
+echo '
+#################################################################
+##### INSTALL PYTHON PACKAGES #####
+#################################################################'
+[ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-libvirt python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests git screen wget"
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML libvirt-python MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests git screen wget"
+
+#The only way to install python-bottle on Centos7 is with easy_install or pip
+[ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle
+
+echo '
+#################################################################
+##### DOWNLOAD SOURCE #####
+#################################################################'
+su $SUDO_USER -c 'git clone https://github.com/nfvlabs/openvim.git openvim'
+#Unncoment to use a concrete branch, if not main branch
+#pushd openvim
+#su $SUDO_USER -c 'git checkout v0.4'
+#popd
+
+echo '
+#################################################################
+##### CREATE DATABASE #####
+#################################################################'
+mysqladmin -u$DBUSER $DBPASSWD create vim_db
+
+echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql -u$DBUSER $DBPASSWD
+echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql -u$DBUSER $DBPASSWD
+
+echo "vim database"
+su $SUDO_USER -c './openvim/database_utils/init_vim_db.sh -u vim -p vimpw'
+
+
+if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
+then
+ echo '
+#################################################################
+##### CONFIGURE firewalld #####
+#################################################################'
+ read -e -p "Configure firewalld for openvimd port 9080? (Y/n)" KK
+ if [ "$KK" != "n" -a "$KK" != "no" ]
+ then
+ #Creates a service file for openvim
+ echo '<?xml version="1.0" encoding="utf-8"?>
+<service>
+ <short>openvimd</short>
+ <description>openvimd service</description>
+ <port protocol="tcp" port="9080"/>
+</service>' > /etc/firewalld/services/openvimd.xml
+ #put proper permissions
+ pushd /etc/firewalld/services > /dev/null
+ restorecon openvim
+ chmod 640 openvim
+ popd > /dev/null
+ #Add the openvim service to the default zone permanently and reload the firewall configuration
+ firewall-cmd --permanent --add-service=openvim > /dev/null
+ firewall-cmd --reload > /dev/null
+ echo "done."
+ else
+ echo "skipping."
+ fi
+fi
+
+echo '
+#################################################################
+##### CONFIGURE openvim CLIENTS #####
+#################################################################'
+#creates a link at ~/bin
+su $SUDO_USER -c 'mkdir -p ~/bin'
+rm -f /home/${SUDO_USER}/bin/openvim
+rm -f /home/${SUDO_USER}/bin/openflow
+rm -f /home/${SUDO_USER}/bin/service-openvim
+rm -f /home/${SUDO_USER}/bin/initopenvim
+rm -f /home/${SUDO_USER}/bin/service-floodlight
+rm -f /home/${SUDO_USER}/bin/service-opendaylight
+rm -f /home/${SUDO_USER}/bin/get_dhcp_lease.sh
+ln -s ${PWD}/openvim/openvim /home/${SUDO_USER}/bin/openvim
+ln -s ${PWD}/openvim/openflow /home/${SUDO_USER}/bin/openflow
+ln -s ${PWD}/openvim/scripts/service-openvim.sh /home/${SUDO_USER}/bin/service-openvim
+ln -s ${PWD}/openvim/scripts/initopenvim.sh /home/${SUDO_USER}/bin/initopenvim
+ln -s ${PWD}/openvim/scripts/service-floodlight.sh /home/${SUDO_USER}/bin/service-floodlight
+ln -s ${PWD}/openvim/scripts/service-opendaylight.sh /home/${SUDO_USER}/bin/service-opendaylight
+ln -s ${PWD}/openvim/scripts/get_dhcp_lease.sh /home/${SUDO_USER}/bin/get_dhcp_lease.sh
+
+#insert /home/<user>/bin in the PATH
+#skiped because normally this is done authomatically when ~/bin exist
+#if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin"
+#then
+# echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
+# su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc'
+#fi
+
+#configure arg-autocomplete for this user
+#in case of minmal instalation this package is not installed by default
+[[ "$_DISTRO" == "CentOS" || "$_DISTRO" == "Red" ]] && yum install -y bash-completion
+#su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d'
+su $SUDO_USER -c 'activate-global-python-argcomplete --user'
+if ! grep -q bash_completion.d/python-argcomplete.sh /home/${SUDO_USER}/.bashrc
+then
+ echo " inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc"
+ su $SUDO_USER -c 'echo ". /home/${USER}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc'
+fi
+
+echo
+echo "Done! you may need to logout and login again for loading the configuration"
+echo " Run './openvim/scripts/service-openvim.sh start' for starting openvim in a screen"
+
+
+
diff --git a/scripts/openvim-report.sh b/scripts/openvim-report.sh
new file mode 100755
index 0000000..951634d
--- /dev/null
+++ b/scripts/openvim-report.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#It generates a report for debugging
+
+DIRNAME=$(readlink -f ${BASH_SOURCE[0]})
+DIRNAME=$(dirname $DIRNAME )
+OVCLIENT=$DIRNAME/../openvim
+
+#get screen log files at the beginning
+echo
+echo "-------------------------------"
+echo "log files"
+echo "-------------------------------"
+echo
+echo "cat $DIRNAME/../logs/openvim.log*"
+cat $DIRNAME/../logs/openvim.log*
+echo
+echo
+
+#get version
+echo
+echo "-------------------------------"
+echo "version"
+echo "-------------------------------"
+echo "cat $DIRNAME/../openvimd.py|grep ^__version__"
+cat $DIRNAME/../openvimd.py|grep ^__version__
+echo
+echo
+
+#get configuration files
+echo "-------------------------------"
+echo "Configuration files"
+echo "-------------------------------"
+echo "cat $DIRNAME/../openvimd.cfg"
+cat $DIRNAME/../openvimd.cfg
+echo
+
+#get list of items
+for verbose in "" "-vvv"
+do
+ echo "-------------------------------"
+ echo "OPENVIM$verbose"
+ echo "-------------------------------"
+ echo "$OVCLIENT config"
+ $OVCLIENT config
+ echo "-------------------------------"
+ echo "$OVCLIENT tenant-list $verbose"
+ $OVCLIENT tenant-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT host-list $verbose"
+ $OVCLIENT host-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT net-list $verbose"
+ $OVCLIENT net-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT port-list $verbose"
+ $OVCLIENT port-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT flavor-list $verbose"
+ $OVCLIENT flavor-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT image-list $verbose"
+ $OVCLIENT image-list $verbose
+ echo "-------------------------------"
+ echo "$OVCLIENT vm-list $verbose"
+ $OVCLIENT vm-list $verbose
+ echo "-------------------------------"
+ echo
+
+done
+echo
diff --git a/scripts/service-floodlight.sh b/scripts/service-floodlight.sh
new file mode 100755
index 0000000..b7130a6
--- /dev/null
+++ b/scripts/service-floodlight.sh
@@ -0,0 +1,163 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#launch floodlight inside a screen. It assumes shell variable $FLOODLIGHT_PATH
+# contain the installation path
+
+
+DIRNAME=$(readlink -f ${BASH_SOURCE[0]})
+DIRNAME=$(dirname $DIRNAME )
+DIR_OM=$(dirname $DIRNAME )
+
+function usage(){
+ echo -e "Usage: $0 start|stop|restart|status"
+ echo -e " Launch|Removes|Restart|Getstatus floodlight on a screen"
+ echo -e " Shell variable FLOODLIGHT_PATH must indicate floodlight installationpath"
+}
+
+function kill_pid(){
+ #send TERM signal and wait 5 seconds and send KILL signal ir still running
+ #PARAMS: $1: PID of process to terminate
+ kill $1 #send TERM signal
+ WAIT=5
+ while [ $WAIT -gt 0 ] && ps -o pid -U $USER -u $USER | grep -q $1
+ do
+ sleep 1
+ WAIT=$((WAIT-1))
+ [ $WAIT -eq 0 ] && echo -n "sending SIGKILL... " && kill -9 $1 #kill when count reach 0
+ done
+ echo "done"
+
+}
+
+#obtain parameters
+#om_action="start" #uncoment to get a default action
+for param in $*
+do
+ [ "$param" == "start" -o "$param" == "stop" -o "$param" == "restart" -o "$param" == "status" ] && om_action=$param && continue
+ [ "$param" == "openflow" -o "$param" == "flow" -o "$param" == "floodlight" ] && continue
+ [ "$param" == "-h" -o "$param" == "--help" ] && usage && exit 0
+
+ #if none of above, reach this line because a param is incorrect
+ echo "Unknown param '$param' type $0 --help" >&2
+ exit -1
+done
+
+#check action is provided
+[ -z "$om_action" ] && usage >&2 && exit -1
+
+ om_cmd="floodlight.jar"
+ om_name="floodlight"
+
+ #obtain PID of program
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+
+ #status
+ if [ "$om_action" == "status" ]
+ then
+ [ -n "$component_id" ] && echo " $om_name running, pid $component_id"
+ [ -z "$component_id" ] && echo " $om_name stopped"
+ fi
+
+ #stop
+ if [ "$om_action" == "stop" -o "$om_action" == "restart" ]
+ then
+ #terminates program
+ [ -n "$component_id" ] && echo -n " stopping $om_name ... " && kill_pid $component_id
+ component_id=""
+ #terminates screen
+ if screen -wipe | grep -Fq .flow
+ then
+ screen -S flow -p 0 -X stuff "exit\n"
+ sleep 1
+ fi
+ fi
+
+ #start
+ if [ "$om_action" == "start" -o "$om_action" == "restart" ]
+ then
+ [[ -z $FLOODLIGHT_PATH ]] && echo "FLOODLIGHT_PATH shell variable must indicate floodlight installation path" >&2 && exit -1
+ #calculates log file name
+ logfile=""
+ mkdir -p $DIR_OM/logs && logfile=$DIR_OM/logs/openflow.log || echo "can not create logs directory $DIR_OM/logs"
+ #check already running
+ [ -n "$component_id" ] && echo " $om_name is already running. Skipping" && continue
+ #create screen if not created
+ echo -n " starting $om_name ... "
+ if ! screen -wipe | grep -Fq .flow
+ then
+ pushd ${FLOODLIGHT_PATH} > /dev/null
+ screen -dmS flow bash
+ sleep 1
+ popd > /dev/null
+ else
+ echo -n " using existing screen 'flow' ... "
+ screen -S flow -p 0 -X log off
+ screen -S flow -p 0 -X stuff "cd ${FLOODLIGHT_PATH}\n"
+ sleep 1
+ fi
+ #move old log file index one number up and log again in index 0
+ if [[ -n $logfile ]]
+ then
+ for index in 8 7 6 5 4 3 2 1
+ do
+ [[ -f ${logfile}.${index} ]] && mv ${logfile}.${index} ${logfile}.$((index+1))
+ done
+ [[ -f ${logfile} ]] && mv ${logfile} ${logfile}.1
+ screen -S flow -p 0 -X logfile ${logfile}
+ screen -S flow -p 0 -X log on
+ fi
+ #launch command to screen
+ screen -S flow -p 0 -X stuff "java -Dlogback.configurationFile=${DIRNAME}/flow-logback.xml -jar ./target/floodlight.jar -cf ${DIRNAME}/flow.properties_v0.9\n"
+ #check if is running
+ [[ -n $logfile ]] && timeout=120 #2 minute
+ [[ -z $logfile ]] && timeout=20
+ while [[ $timeout -gt 0 ]]
+ do
+ #check if is running
+ #echo timeout $timeout
+ #if ! ps -f -U $USER -u $USER | grep -v grep | grep -q ${om_cmd}
+ log_lines=0
+ [[ -n $logfile ]] && log_lines=`head ${logfile} | wc -l`
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+ if [[ -z $component_id ]]
+ then #process not started or finished
+ [[ $log_lines -ge 2 ]] && echo -n "ERROR, it has exited." && break
+ #started because writted serveral lines at log so report error
+ fi
+ [[ -n $logfile ]] && grep -q "Listening for switch connections" ${logfile} && sleep 1 && break
+ sleep 1
+ timeout=$((timeout -1))
+ done
+ if [[ -n $logfile ]] && [[ $timeout == 0 ]]
+ then
+ echo -n "timeout!"
+ else
+ echo -n "running on 'screen -x flow'."
+ fi
+ [[ -n $logfile ]] && echo " Logging at '${logfile}'" || echo
+ fi
+
+
+
+
diff --git a/scripts/service-opendaylight.sh b/scripts/service-opendaylight.sh
new file mode 100755
index 0000000..3c060c6
--- /dev/null
+++ b/scripts/service-opendaylight.sh
@@ -0,0 +1,164 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#launch opendaylight inside a screen. It assumes shell variable $OPENDAYLIGHT_PATH
+# contain the installation path
+
+
+DIRNAME=$(readlink -f ${BASH_SOURCE[0]})
+DIRNAME=$(dirname $DIRNAME )
+DIR_OM=$(dirname $DIRNAME )
+
+function usage(){
+ echo -e "Usage: $0 start|stop|restart|status"
+ echo -e " Launch|Removes|Restart|Getstatus opendaylight on a screen"
+ echo -e " Shell variable OPENDAYDLIGHT_PATH must indicate opendaylight installation path"
+}
+
+function kill_pid(){
+ #send TERM signal and wait 5 seconds and send KILL signal ir still running
+ #PARAMS: $1: PID of process to terminate
+ kill $1 #send TERM signal
+ WAIT=5
+ while [ $WAIT -gt 0 ] && ps -o pid -U $USER -u $USER | grep -q $1
+ do
+ sleep 1
+ WAIT=$((WAIT-1))
+ [ $WAIT -eq 0 ] && echo -n "sending SIGKILL... " && kill -9 $1 #kill when count reach 0
+ done
+ echo "done"
+
+}
+
+#obtain parameters
+#om_action="start" #uncoment to get a default action
+for param in $*
+do
+ [ "$param" == "start" -o "$param" == "stop" -o "$param" == "restart" -o "$param" == "status" ] && om_action=$param && continue
+ [ "$param" == "openflow" -o "$param" == "flow" -o "$param" == "opendaylight" ] && continue
+ [ "$param" == "-h" -o "$param" == "--help" ] && usage && exit 0
+
+ #if none of above, reach this line because a param is incorrect
+ echo "Unknown param '$param' type $0 --help" >&2
+ exit -1
+done
+
+#check action is provided
+[ -z "$om_action" ] && usage >&2 && exit -1
+
+ om_cmd="./karaf"
+ om_name="opendaylight"
+
+ #obtain PID of program
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+
+ #status
+ if [ "$om_action" == "status" ]
+ then
+ [ -n "$component_id" ] && echo " $om_name running, pid $component_id"
+ [ -z "$component_id" ] && echo " $om_name stopped"
+ fi
+
+ #stop
+ if [ "$om_action" == "stop" -o "$om_action" == "restart" ]
+ then
+ #terminates program
+ [ -n "$component_id" ] && echo -n " stopping $om_name ... " && kill_pid $component_id
+ component_id=""
+ #terminates screen
+ if screen -wipe | grep -Fq .flow
+ then
+ screen -S flow -p 0 -X stuff "exit\n"
+ sleep 1
+ fi
+ fi
+
+ #start
+ if [ "$om_action" == "start" -o "$om_action" == "restart" ]
+ then
+ [[ -z $OPENDAYDLIGHT_PATH ]] && echo "OPENDAYDLIGHT_PATH shell variable must indicate opendaylight installation path" >&2 && exit -1
+ #calculates log file name
+ logfile=""
+ mkdir -p $DIR_OM/logs && logfile=$DIR_OM/logs/openflow.log && logfile_console=$DIR_OM/logs/openflow_console.log || echo "can not create logs directory $DIR_OM/logs"
+ #check already running
+ [ -n "$component_id" ] && echo " $om_name is already running. Skipping" && continue
+ #create screen if not created
+ echo -n " starting $om_name ... "
+ if ! screen -wipe | grep -Fq .flow
+ then
+ pushd ${OPENDAYDLIGHT_PATH}/bin > /dev/null
+ screen -dmS flow bash
+ sleep 1
+ popd > /dev/null
+ else
+ echo -n " using existing screen 'flow' ... "
+ screen -S flow -p 0 -X log off
+ screen -S flow -p 0 -X stuff "cd ${OPENDAYDLIGHT_PATH}/bin\n"
+ sleep 1
+ fi
+ #move old log file index one number up and log again in index 0
+ if [[ -n $logfile ]]
+ then
+ for index in .9 .8 .7 .6 .5 .4 .3 .2 .1 ""
+ do
+ rm -f ${logfile}${index}
+ ln -s ${OPENDAYDLIGHT_PATH}/data/log/karaf.log${index} ${logfile}${index}
+ done
+ rm -rf ${logfile_console}
+ screen -S flow -p 0 -X logfile ${logfile_console}
+ screen -S flow -p 0 -X log on
+ fi
+ #launch command to screen
+ screen -S flow -p 0 -X stuff "${om_cmd}\n"
+ #check if is running
+ [[ -n $logfile ]] && timeout=120 #2 minute
+ [[ -z $logfile ]] && timeout=20
+ while [[ $timeout -gt 0 ]]
+ do
+ #check if is running
+ #echo timeout $timeout
+ #if ! ps -f -U $USER -u $USER | grep -v grep | grep -q ${om_cmd}
+ log_lines=0
+ [[ -n $logfile_console ]] && log_lines=`head ${logfile_console} | wc -l`
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+ if [[ -z $component_id ]]
+ then #process not started or finished
+ [[ $log_lines -ge 2 ]] && echo -n "ERROR, it has exited." && break
+ #started because writted serveral lines at log so report error
+ fi
+ [[ -n $logfile_console ]] && grep -q "Listening on port" ${logfile_console} && sleep 1 && break
+ sleep 1
+ timeout=$((timeout -1))
+ done
+ if [[ -n $logfile_console ]] && [[ $timeout == 0 ]]
+ then
+ echo -n "timeout!"
+ else
+ echo -n "running on 'screen -x flow'."
+ fi
+ [[ -n $logfile ]] && echo " Logging at '${logfile}'" || echo
+ fi
+
+
+
+
diff --git a/scripts/service-openvim.sh b/scripts/service-openvim.sh
new file mode 100755
index 0000000..aaa9a27
--- /dev/null
+++ b/scripts/service-openvim.sh
@@ -0,0 +1,180 @@
+#!/bin/bash
+
+##
+# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
+# This file is part of openmano
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+#launch openvim (andr floodlight) inside a screen.
+#It assumes a relative path '..' for openvim
+#for floodlight, the variable FLOODLIGHT_PATH indicates the installation path
+
+
+DIRNAME=$(readlink -f ${BASH_SOURCE[0]})
+DIRNAME=$(dirname $DIRNAME )
+DIR_OM=$(dirname $DIRNAME )
+#[[ -z $FLOODLIGHT_PATH ]] && FLOODLIGHT_PATH=$(dirname ${DIR_OM})/floodlight-1.1
+#[[ -z $FLOODLIGHT_PATH ]] && FLOODLIGHT_PATH=$(dirname ${DIR_OM})/floodlight-0.90
+
+function usage(){
+ echo -e "Usage: $0 [openvim/vim] [floodlight/flow] start|stop|restart|status"
+ echo -e " Launch|Removes|Restart|Getstatus openvim (by default) or/and floodlight on a screen"
+ echo -e " For floodlight variable FLOODLIGHT_PATH must indicate installation path"
+}
+
+function kill_pid(){
+ #send TERM signal and wait 5 seconds and send KILL signal ir still running
+ #PARAMS: $1: PID of process to terminate
+ kill $1 #send TERM signal
+ WAIT=5
+ while [ $WAIT -gt 0 ] && ps -o pid -U $USER -u $USER | grep -q $1
+ do
+ sleep 1
+ WAIT=$((WAIT-1))
+ [ $WAIT -eq 0 ] && echo -n "sending SIGKILL... " && kill -9 $1 #kill when count reach 0
+ done
+ echo "done"
+
+}
+
+#obtain parameters
+om_list=""
+#om_action="start" #uncoment to get a default action
+for param in $*
+do
+ [ "$param" == "start" -o "$param" == "stop" -o "$param" == "restart" -o "$param" == "status" ] && om_action=$param && continue
+ [ "$param" == "openvim" -o "$param" == "vim" ] && om_list="$om_list vim" && continue
+ [ "$param" == "openmano" -o "$param" == "mano" ] && continue #allow and ingore for backwards compatibility
+ [ "$param" == "openflow" -o "$param" == "flow" -o "$param" == "floodlight" ] && om_list="flow $om_list" && continue
+ [ "$param" == "-h" -o "$param" == "--help" ] && usage && exit 0
+ #note flow that it must be the first element, because openvim relay on this
+
+ #if none of above, reach this line because a param is incorrect
+ echo "Unknown param '$param' type $0 --help" >&2
+ exit -1
+done
+
+#check action is provided
+[ -z "$om_action" ] && usage >&2 && exit -1
+
+#if no componenets supplied assume all
+[ -z "$om_list" ] && om_list="vim"
+
+for om_component in $om_list
+do
+ [ "${om_component}" == "flow" ] && om_cmd="floodlight.jar" && om_name="floodlight" && om_dir=$FLOODLIGHT_PATH
+ [ "${om_component}" == "vim" ] && om_cmd="openvimd.py" && om_name="openvim " && om_dir=${DIR_OM}
+ #obtain PID of program
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+
+ #status
+ if [ "$om_action" == "status" ]
+ then
+ [ -n "$component_id" ] && echo " $om_name running, pid $component_id"
+ [ -z "$component_id" ] && echo " $om_name stopped"
+ fi
+
+ #stop
+ if [ "$om_action" == "stop" -o "$om_action" == "restart" ]
+ then
+ #terminates program
+ [ -n "$component_id" ] && echo -n " stopping $om_name ... " && kill_pid $component_id
+ component_id=""
+ #terminates screen
+ if screen -wipe | grep -Fq .$om_component
+ then
+ screen -S $om_component -p 0 -X stuff "exit\n"
+ sleep 1
+ fi
+ fi
+
+ #start
+ if [ "$om_action" == "start" -o "$om_action" == "restart" ]
+ then
+ [[ -z $FLOODLIGHT_PATH ]] && [[ $om_component == flow ]] &&
+ echo "FLOODLIGHT_PATH shell variable must indicate floodlight installation path" >&2 && exit -1
+ #calculates log file name
+ logfile=""
+ mkdir -p $DIR_OM/logs && logfile=$DIR_OM/logs/open${om_component}.log || echo "can not create logs directory $DIR_OM/logs"
+ #check already running
+ [ -n "$component_id" ] && echo " $om_name is already running. Skipping" && continue
+ #create screen if not created
+ echo -n " starting $om_name ... "
+ if ! screen -wipe | grep -Fq .${om_component}
+ then
+ pushd ${om_dir} > /dev/null
+ screen -dmS ${om_component} bash
+ sleep 1
+ popd > /dev/null
+ else
+ echo -n " using existing screen '${om_component}' ... "
+ screen -S ${om_component} -p 0 -X log off
+ screen -S ${om_component} -p 0 -X stuff "cd ${om_dir}\n"
+ sleep 1
+ fi
+ #move old log file index one number up and log again in index 0
+ if [[ -n $logfile ]]
+ then
+ for index in 8 7 6 5 4 3 2 1
+ do
+ [[ -f ${logfile}.${index} ]] && mv ${logfile}.${index} ${logfile}.$((index+1))
+ done
+ [[ -f ${logfile} ]] && mv ${logfile} ${logfile}.1
+ screen -S ${om_component} -p 0 -X logfile ${logfile}
+ screen -S ${om_component} -p 0 -X log on
+ fi
+ #launch command to screen
+ #[ "${om_component}" != "flow" ] && screen -S ${om_component} -p 0 -X stuff "cd ${DIR_OM}/open${om_component}\n" && sleep 1
+ [ "${om_component}" == "flow" ] && screen -S flow -p 0 -X stuff "java -Dlogback.configurationFile=${DIRNAME}/flow-logback.xml -jar ./target/floodlight.jar -cf ${DIRNAME}/flow.properties_v0.9\n"
+ #[ "${om_component}" == "flow" ] && screen -S flow -p 0 -X stuff "java -Dlogback.configurationFile=${DIRNAME}/flow-logback.xml -jar ./target/floodlight.jar -cf ${DIRNAME}/flow.properties_v1.1\n" && sleep 5
+ [ "${om_component}" != "flow" ] && screen -S ${om_component} -p 0 -X stuff "./${om_cmd}\n"
+ #check if is running
+ [[ -n $logfile ]] && timeout=120 #2 minute
+ [[ -z $logfile ]] && timeout=20
+ while [[ $timeout -gt 0 ]]
+ do
+ #check if is running
+ #echo timeout $timeout
+ #if ! ps -f -U $USER -u $USER | grep -v grep | grep -q ${om_cmd}
+ log_lines=0
+ [[ -n $logfile ]] && log_lines=`head ${logfile} | wc -l`
+ component_id=`ps -o pid,cmd -U $USER -u $USER | grep -v grep | grep ${om_cmd} | awk '{print $1}'`
+ if [[ -z $component_id ]]
+ then #process not started or finished
+ [[ $log_lines -ge 2 ]] && echo -n "ERROR, it has exited." && break
+ #started because writted serveral lines at log so report error
+ fi
+ [[ -n $logfile ]] && [[ ${om_component} == flow ]] && grep -q "Listening for switch connections" ${logfile} && sleep 1 && break
+ [[ -n $logfile ]] && [[ ${om_component} != flow ]] && grep -q "open${om_component}d ready" ${logfile} && break
+ sleep 1
+ timeout=$((timeout -1))
+ done
+ if [[ -n $logfile ]] && [[ $timeout == 0 ]]
+ then
+ echo -n "timeout!"
+ else
+ echo -n "running on 'screen -x ${om_component}'."
+ fi
+ [[ -n $logfile ]] && echo " Logging at '${logfile}'" || echo
+ fi
+done
+
+
+
+