Commit c6a4c781 authored by gauthier's avatar gauthier
Browse files

TO BE CONTINUED

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5398 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent b79199b4
################################################################################
# Eurecom OpenAirInterface core network
# Copyright(c) 1999 - 2014 Eurecom
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
#
# Contact Information
# Openair Admin: openair_admin@eurecom.fr
# Openair Tech : openair_tech@eurecom.fr
# Forums : http://forums.eurecom.fsr/openairinterface
# Address : EURECOM,
# Campus SophiaTech,
# 450 Route des Chappes,
# CS 50193
# 06904 Biot Sophia Antipolis cedex,
# FRANCE
################################################################################
# file interfaces.bash
# brief
# author Lionel Gauthier
# company Eurecom
# email: lionel.gauthier@eurecom.fr
#
cidr2mask() {
local i mask=""
local full_octets=$(($1/8))
local partial_octet=$(($1%8))
for ((i=0;i<4;i+=1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2**(8-$partial_octet)))
else
mask+=0
fi
test $i -lt 3 && mask+=.
done
echo $mask
}
# example: netcalc 192.168.12.100 255.255.255.0
netcalc(){
local IFS='.' ip i
local -a oct msk
read -ra oct <<<"$1"
read -ra msk <<<"$2"
for i in ${!oct[@]}; do
ip+=( "$(( oct[i] & msk[i] ))" )
done
echo "${ip[*]}"
}
# example: s
bcastcalc(){
local IFS='.' ip i
local -a oct msk
read -ra oct <<<"$1"
read -ra msk <<<"$2"
for i in ${!oct[@]}; do
ip+=( "$(( oct[i] + ( 255 - ( oct[i] | msk[i] ) ) ))" )
done
echo "${ip[*]}"
}
is_real_interface() {
my_bool=1
for var in "$@"
do
if [ "a$var" == "a" ]; then
return 0
fi
if [ "a$var" == "anone" ]; then
return 0
fi
IF=`cat /etc/udev/rules.d/70-persistent-net.rules | grep $var | sed 's/^.*NAME=//' | tr -d '"'`
if [ "$IF" == "$var" ]; then
if [ "a${var:0:3}" != "aeth" ]; then
if [ "a${var:0:4}" != "awlan" ]; then
if [ "a${var:0:4}" != "awifi" ]; then
my_bool=0;
fi
fi
fi
fi
done
return $my_bool
}
is_vlan_interface() {
my_bool=1
for var in "$@"
do
if [ "a$var" == "a" ]; then
return 0
fi
if [[ $var == *.* ]]
then
interface_name=`echo $var | cut -f1 -d '.'`
vlan=`echo $var | cut -f2 -d '.'`
IF=`cat /etc/udev/rules.d/70-persistent-net.rules | grep $interface_name | sed 's/^.*NAME=//' | tr -d '"'`
if [ "$IF" == "$interface_name" ]; then
if [ "a${interface_name:0:3}" != "aeth" ]; then
if [ "a${interface_name:0:4}" != "awlan" ]; then
if [ "a${interface_name:0:4}" != "awifi" ]; then
return 0;
fi
fi
fi
fi
else
return 0;
fi
done
return $my_bool
}
is_tun_interface() {
my_bool=1
for var in "$@"
do
if [ "a$var" == "a" ]; then
return 0
fi
if [[ "$IF" != *tun* ]]; then
return 0;
fi
bus_info=`ethtool -i $var | grep bus-info | cut -d: -f2`
bus_info=trim2 $bus_info
if [[ "$bus_info" != *tun* ]]; then
return 0;
fi
done
return $my_bool
}
is_openvswitch_interface() {
for var in "$@"
do
if [ "a$var" == "a" ]; then
return 0
fi
if [ "a${var:0:3}" == "aeth" ]; then
return 0;
else
if [ "a${var:0:4}" == "awlan" ]; then
return 0;
else
if [ "a${var:0:4}" == "awifi" ]; then
return 0;
else
if [ "a${var:0:4}" == "anone" ]; then
return 0;
else
if [ "a${var:0:3}" == "atun" ]; then
return 0;
fi
fi
fi
fi
fi
done
return 1;
}
delete_tun_interface() {
is_tun_interface $1
if [ $? -eq 1 ]; then
ip link set $1 down > /dev/null 2>&1
openvpn --rmtun --dev $1 > /dev/null 2>&1
fi
}
create_tun_interface() {
is_tun_interface $1
if [ $? -eq 1 ]; then
openvpn --mktun --dev $1
fi
#ip link set $1 up
}
delete_openvswitch_interface() {
is_openvswitch_interface $1
if [ $? -eq 1 ]; then
ifconfig $1 down > /dev/null 2>&1
tunctl -d $1 > /dev/null 2>&1
fi
}
create_openvswitch_interface() {
is_openvswitch_interface $1
if [ $? -eq 1 ]; then
bash_exec "tunctl -t $1"
fi
}
# arg1 = interface name
# arg2 = ipv4 addr cidr
# arg3 = netmask cidr
set_interface_up() {
interface=$1
address=$2
cidr_netmask=$3
if [ "a${interface:0:4}" == "anone" ]; then
return;
fi
bash_exec "ifconfig $interface up"
sync
netmask=`cidr2mask $cidr_netmask`
broadcast=`bcastcalc $address $netmask`
bash_exec "ip -4 addr add $address/$cidr_netmask broadcast $broadcast dev $interface"
sync
}
get_mac_router() {
ping -c 1 router.eur > /dev/null || { echo_fatal "router.eur does not respond to ping" >&2 ; }
IP_ROUTER=`python -c 'import socket; print socket.gethostbyname("router.eur")'`
export MAC_ROUTER=`ip neigh show | grep $IP_ROUTER | cut -d ' ' -f5 | tr -d ':'`
echo_success "ROUTER MAC ADDRESS= $MAC_ROUTER"
}
This diff is collapsed.
#!/bin/bash
export ENB_VM_NAME='enb-vm-ubuntu-12.04.4-server-amd64'
export HSS_VM_NAME='hss-vm-ubuntu-12.04.4-server-amd64'
export OS_INSTALL_IMAGE="/root/ubuntu-12.04.4-server-amd64.iso"
export OS_TYPE="Ubuntu"
export HOST_BRIDGED_IF_NAME="eth1"
export DEFAULT_VIRTUAL_BOX_VM_PATH='/root/VirtualBox VMs'
export TRUNK_SHARED_FOLDER_NAME="shared_trunk"
###########################################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
source $THIS_SCRIPT_PATH/utils.bash
###########################################################
#
# +-----------+----------------+------+---------------------------------------+
# | COMPUTER 1| | eth1 | Physical |
# +-----------+ (nic1) +-+--+-+ Interface |
# | | | 'HOST_BRIDGED_IF_NAME' |
# | | | |
# | | | +-----------+ |
# | | | +------+ HSS | |
# | | +----------+ eth0 | (VM) | |
# | | +------+ | |
# | | | | |
# | | +-+------+--+ |
# | | |eth1 | |
# | | +--+---+ |
# | +------------------+ | |
# | | bridged network | host-only |
# | | | network |
# | | | 192.168.57/24 |
# | | | |
# | +--+---+ +--+-----+ |
# | |eth0 | |vboxnet1| |
# | +-+------+--+192.168.56.101 192.168.56.1+-+--------++ |
# | | eNB 0 +------+ +--------+ MME | |
# | | (VM) |eth1 +----------------+vboxnet0| S+P/GW | |
# | | +------+ host-only +--------+ | |
# | | | network | | |
# | | | 192.168.56/24 | | |
# | | LTE eNB 1 | | | |
# | | LTE UEs | | | |
# | +-----------+ +-----------+ |
# | |
# | |
# +---------------------------------------------------------------------------+
#
check_install_vbox_software
build_vbox_vm_enb() {
if [ $OS_TYPE ]; then
echo_success "OS_TYPE: $OS_TYPE"
else
echo_fatal "OS_TYPE bash variable must be set to any of the following values (The type of OS you want to install on your VM): `VBoxManage list ostypes | grep ID | cut -d: -f2 | tr -d ' ' | sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}'`"
fi
if [ $ENB_VM_NAME ]; then
echo_success "ENB_VM_NAME: $ENB_VM_NAME"
else
echo_fatal "ENB_VM_NAME bash variable must be set"
fi
if [ $OS_INSTALL_IMAGE ]; then
if [[ ! -e "$OS_INSTALL_IMAGE" ]] ; then
echo_fatal "$OS_INSTALL_IMAGE: File not found"
else
echo_success "OS_INSTALL_IMAGE: $OS_INSTALL_IMAGE"
fi
else
echo_fatal "OS_INSTALL_IMAGE bash variable must be set to a valid ISO OS installation file"
fi
bash_exec "VBoxManage unregistervm $ENB_VM_NAME --delete"
rm -Rf "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"
bash_exec "VBoxManage createvm --name $ENB_VM_NAME --register"
UUID=`VBoxManage showvminfo $ENB_VM_NAME | grep Hardware\ UUID | cut -d: -f2 | tr -d ' '`
echo ENB UUID=$UUID
bash_exec "VBoxManage modifyvm $UUID --ostype $OS_TYPE --memory 512 --vram 12 --cpus 1 \
--rtcuseutc on --cpuhotplug off --cpuexecutioncap 100 --pae on --hpet on \
--hwvirtex on --nestedpaging on \
--firmware bios --biosbootmenu messageandmenu --boot1 dvd --boot2 disk \
--nic1 bridged --nic2 hostonly --nic3 hostonly --nic4 hostonly \
--nictype1 82545EM --nictype2 82545EM --nictype3 82545EM --nictype4 82545EM \
--cableconnected1 on --cableconnected2 on --cableconnected3 off --cableconnected4 off \
--bridgeadapter1 $HOST_BRIDGED_IF_NAME \
--hostonlyadapter2 vboxnet0 \
--audio none \
--usb off --usbehci off"
# BRIDGED_MAC_ADDRESS=`vboxmanage showvminfo $UUID | grep Bridged\ Interface | sed 's/^.*MAC:\ //' | cut --delimiter=',' -f 1`
mkdir -p -m 777 "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/MKISO
rm -Rf "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/MKISO/*
chmod -Rf 777 "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/MKISO
# mkisofs -max-iso9660-filenames -untranslated-filenames -no-iso-translate -o "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/cd_guest_setup.iso "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/MKISO/
VBoxManage createhd --filename "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/"$ENB_VM_NAME".vdi --size 16384 --format VDI
VBoxManage storagectl $UUID --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on
VBoxManage storageattach $UUID --storagectl "IDE Controller" --type dvddrive --passthrough off --port 1 --device 0 --medium $OS_INSTALL_IMAGE
# VBoxManage storageattach $UUID --storagectl "IDE Controller" --type dvddrive --passthrough off --port 1 --device 1 --medium "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/cd_guest_setup.iso
VBoxManage storagectl $UUID --name "SATA Controller" --add sata --controller IntelAhci --sataportcount 4 --hostiocache off --bootable on
VBoxManage storageattach $UUID --storagectl "SATA Controller" --type hdd --port 0 --device 0 --medium "$DEFAULT_VIRTUAL_BOX_VM_PATH"/"$ENB_VM_NAME"/"$ENB_VM_NAME".vdi
bash_exec "VBoxManage sharedfolder add $ENB_VM_NAME --name $TRUNK_SHARED_FOLDER_NAME --hostpath $OPENAIR_HOME"
}
build_vbox_vm_hss() {
UUID=`VBoxManage clonevm --mode all --name $HSS_VM_NAME --register
`
HSS_UUID=`VBoxManage showvminfo $HSS_VM_NAME | grep Hardware\ UUID | cut -d: -f2 | tr -d ' '`
echo HSS_UUID=$HSS_UUID
bash_exec "VBoxManage modifyvm $HSS_UUID --ostype $OS_TYPE --memory 512 --vram 12 --cpus 1 \
--rtcuseutc on --cpuhotplug off --cpuexecutioncap 100 --pae on --hpet on \
--hwvirtex on --nestedpaging on \
--firmware bios --biosbootmenu messageandmenu --boot1 disk \
--nic1 bridged --nic2 hostonly --nic3 none --nic4 none \
--nictype1 82545EM --nictype2 virtio --nictype3 82545EM --nictype4 82545EM \
--cableconnected1 on --cableconnected2 on --cableconnected3 off --cableconnected4 off \
--bridgeadapter1 $HOST_BRIDGED_IF_NAME \
--hostonlyadapter2 vboxnet1 \
--audio none \
--usb off --usbehci off"
}
build_vms() {
build_vbox_vm_enb
build_vbox_vm_hss
}
create_shared_folder_openair_trunk() {
VBoxManage sharedfolder add "$ENB_VM_NAME" --transient --name "$TRUNK_SHARED_FOLDER_NAME" --hostpath "$OPENAIR_HOME"
#bash_exec "mount -t vboxsf $TRUNK_SHARED_FOLDER_NAME $OPENAIR_HOME"
}
build_vbox_vm_enb
create_shared_folder_openair_trunk
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment