start_enb_and_ue_virt.bash 9.18 KB
Newer Older
gauthier's avatar
gauthier committed
1 2
#!/bin/bash
################################################################################
gauthier's avatar
gauthier committed
3 4
#   OpenAirInterface
#   Copyright(c) 1999 - 2014 Eurecom
gauthier's avatar
gauthier committed
5
#
gauthier's avatar
gauthier committed
6 7 8 9
#    OpenAirInterface is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
gauthier's avatar
gauthier committed
10 11
#
#
gauthier's avatar
gauthier committed
12 13 14 15
#    OpenAirInterface is distributed in the hope that 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.
gauthier's avatar
gauthier committed
16
#
gauthier's avatar
gauthier committed
17 18 19 20 21 22 23 24
#    You should have received a copy of the GNU General Public License
#    along with OpenAirInterface.The full GNU General Public License is
#    included in this distribution in the file called "COPYING". If not,
#    see <http://www.gnu.org/licenses/>.
#
#  Contact Information
#  OpenAirInterface Admin: openair_admin@eurecom.fr
#  OpenAirInterface Tech : openair_tech@eurecom.fr
25
#  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
gauthier's avatar
gauthier committed
26
#
ghaddab's avatar
ghaddab committed
27
#  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
gauthier's avatar
gauthier committed
28 29
#
################################################################################
gauthier's avatar
gauthier committed
30
# file start_enb_and_ue.bash
gauthier's avatar
gauthier committed
31 32 33 34 35 36 37 38 39
# brief
# author Lionel Gauthier
# company Eurecom
# email: lionel.gauthier@eurecom.fr
###########################################
# INPUT OF THIS SCRIPT:
# THE DIRECTORY WHERE ARE LOCATED THE CONFIGURATION FILES
#########################################
# This script start  ENB+UE (all in one executable, on one host)
gauthier's avatar
gauthier committed
40
# MME+SP-GW executable have to be launched by your own (start_epc.bash) before this script is invoked.
gauthier's avatar
gauthier committed
41
#
gauthier's avatar
gauthier committed
42

gauthier's avatar
gauthier committed
43 44 45 46

###########################################################
# Parameters
###########################################################
47
declare MAKE_LTE_ACCESS_STRATUM_TARGET="oaisim LIBCONFIG_LONG=1 DEBUG=1 ENABLE_ITTI=1 USE_MME=R10 LINK_ENB_PDCP_TO_GTPV1U=1 NAS=1 SECU=1 Rel10=1 TRACE_RLC_AM_PDU=1 TRACE_RLC_UM_PDU=1"
gauthier's avatar
gauthier committed
48 49 50 51 52 53 54 55 56 57
declare MAKE_IP_DRIVER_TARGET="ue_ip.ko"
declare IP_DRIVER_NAME="ue_ip"
declare LTEIF="oip1"
declare UE_IPv4="10.0.0.8"
declare UE_IPv6="2001:1::8"
declare UE_IPv6_CIDR=$UE_IPv6"/64"
declare UE_IPv4_CIDR=$UE_IPv4"/24"

###########################################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
gauthier's avatar
gauthier committed
58 59 60
. $THIS_SCRIPT_PATH/utils.bash
. $THIS_SCRIPT_PATH/interfaces.bash
. $THIS_SCRIPT_PATH/networks.bash
gauthier's avatar
gauthier committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
###########################################################
if [ $# -eq 1 ]; then
    declare -x CONFIG_FILE_DIR=$1
    if [ ! -d $CONFIG_FILE_DIR ]; then
        echo_error "ERROR while invoking this script, as first argument to this script you have to provide the path to a directory (./CONF/VLAN.VIRTUAL.$HOSTNAME for example) containing valid epc and enb config files"
        exit 1
    fi
else
    echo_error "ERROR while invoking this script, as first argument to this script  you have to provide the path to a directory  (./CONF/VLAN.VIRTUAL.$HOSTNAME for example) containing valid epc and enb config files"
    exit 1
fi


#check_install_epc_software



cd $THIS_SCRIPT_PATH
#######################################################
# FIND CONFIG FILE
#######################################################
SEARCHED_CONFIG_FILE_ENB="enb*.conf"
CONFIG_FILE_ENB=`find $CONFIG_FILE_DIR -iname $SEARCHED_CONFIG_FILE_ENB`
if [ -f $CONFIG_FILE_ENB ]; then
    echo_warning "eNB config file found is now $CONFIG_FILE_ENB"
else
    echo_error "eNB config file not found, exiting"
    exit 1
fi

#######################################################
# SOURCE CONFIG FILE
#######################################################
rm -f /tmp/source.txt
VARIABLES="
           ENB_INTERFACE_NAME_FOR_S1_MME\|\
           ENB_IPV4_ADDRESS_FOR_S1_MME\|\
           ENB_INTERFACE_NAME_FOR_S1U\|\
           ENB_IPV4_ADDRESS_FOR_S1U"

VARIABLES=$(echo $VARIABLES | sed -e 's/\\r//g')
VARIABLES=$(echo $VARIABLES | tr -d ' ')
cat $CONFIG_FILE_ENB | grep -w "$VARIABLES"| tr -d " " | tr -d ";" > /tmp/source.txt
source /tmp/source.txt

declare ENB_IPV4_NETMASK_FOR_S1_MME=$(       echo $ENB_IPV4_ADDRESS_FOR_S1_MME        | cut -f2 -d '/')
declare ENB_IPV4_NETMASK_FOR_S1U=$(          echo $ENB_IPV4_ADDRESS_FOR_S1U        | cut -f2 -d '/')

ENB_IPV4_ADDRESS_FOR_S1_MME=$(               echo $ENB_IPV4_ADDRESS_FOR_S1_MME        | cut -f1 -d '/')
ENB_IPV4_ADDRESS_FOR_S1U=$(                  echo $ENB_IPV4_ADDRESS_FOR_S1U           | cut -f1 -d '/')


gauthier's avatar
gauthier committed
113 114
is_vlan_interface $ENB_INTERFACE_NAME_FOR_S1_MME \
                  $ENB_INTERFACE_NAME_FOR_S1U
gauthier's avatar
gauthier committed
115
if [ $? -eq 1 ]; then
gauthier's avatar
gauthier committed
116 117 118 119 120 121
    echo_success "Found VLAN network configuration"
    clean_enb_vlan_network
    build_enb_vlan_network
    test_enb_vlan_network
fi 

gauthier's avatar
gauthier committed
122 123 124 125 126 127

#######################################################
# USIM, NVRAM files
#######################################################
export NVRAM_DIR=$THIS_SCRIPT_PATH

128
if [ ! -f $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data ] || [ ! -f $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data ]; then
gauthier's avatar
gauthier committed
129
    if [ ! -f /tmp/nas_cleaned ]; then
130 131
        echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS veryveryclean"
        make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS veryveryclean
gauthier's avatar
gauthier committed
132
    fi
133 134
    echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS -f Makefile PROCESS=UE all"
    make  -f Makefile --debug=b --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS PROCESS=UE all
gauthier's avatar
gauthier committed
135 136
    rm .ue.nvram
    rm .usim.nvram
gauthier's avatar
gauthier committed
137
    touch /tmp/nas_cleaned
gauthier's avatar
gauthier committed
138
fi
gauthier's avatar
gauthier committed
139

gauthier's avatar
gauthier committed
140
if [ ! -f .ue.nvram ]; then
gauthier's avatar
gauthier committed
141
    echo_success "generate .ue_emm.nvram .ue.nvram"
142
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
gauthier's avatar
gauthier committed
143 144 145
fi

if [ ! -f .usim.nvram ]; then
gauthier's avatar
gauthier committed
146
    echo_success "generate .usim.nvram"
147
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
gauthier's avatar
gauthier committed
148
fi
149 150
$OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
$OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
gauthier's avatar
gauthier committed
151 152 153 154 155 156 157

##################################################
# LAUNCH eNB + UE executable
##################################################
pkill oaisim
bash_exec "rmmod $IP_DRIVER_NAME" > /dev/null 2>&1

gauthier's avatar
gauthier committed
158
echo_success "make $MAKE_IP_DRIVER_TARGET $MAKE_LTE_ACCESS_STRATUM_TARGET ....." 
gauthier's avatar
gauthier committed
159 160 161
#bash_exec "make --directory=$OPENAIR2_DIR $MAKE_IP_DRIVER_TARGET "
make --directory=$OPENAIR2_DIR $MAKE_IP_DRIVER_TARGET || exit 1

gauthier's avatar
gauthier committed
162

gauthier's avatar
gauthier committed
163
echo_success "make --debug=b --directory=$OPENAIR_TARGETS/SIMU/USER $MAKE_LTE_ACCESS_STRATUM_TARGET || exit 1" 
164 165
#make --directory=$OPENAIR_TARGETS/SIMU/USER $MAKE_LTE_ACCESS_STRATUM_TARGET -j`grep -c ^processor /proc/cpuinfo ` || exit 1
make --debug=b --directory=$OPENAIR_TARGETS/SIMU/USER $MAKE_LTE_ACCESS_STRATUM_TARGET || exit 1
gauthier's avatar
gauthier committed
166 167


gauthier's avatar
gauthier committed
168

gauthier's avatar
gauthier committed
169
echo_success "Bringup UE interface..."
gauthier's avatar
gauthier committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
bash_exec "insmod  $OPENAIR2_DIR/NETWORK_DRIVER/UE_IP/$IP_DRIVER_NAME.ko"

bash_exec "ip route flush cache"

#bash_exec "ip link set $LTEIF up"
sleep 1
#bash_exec "ip addr add dev $LTEIF $UE_IPv4_CIDR"
#bash_exec "ip addr add dev $LTEIF $UE_IPv6_CIDR"

sleep 1

bash_exec "sysctl -w net.ipv4.conf.all.log_martians=1"
assert "  `sysctl -n net.ipv4.conf.all.log_martians` -eq 1" $LINENO

echo "   Disabling reverse path filtering"
bash_exec "sysctl -w net.ipv4.conf.all.rp_filter=0"
assert "  `sysctl -n net.ipv4.conf.all.rp_filter` -eq 0" $LINENO


bash_exec "ip route flush cache"

# Check table 200 lte in /etc/iproute2/rt_tables
fgrep lte /etc/iproute2/rt_tables  > /dev/null 
if [ $? -ne 0 ]; then
    echo "200 lte " >> /etc/iproute2/rt_tables
fi
ip rule add fwmark 5 table lte
ip route add default dev $LTEIF table lte

gauthier's avatar
gauthier committed
199 200 201 202 203 204 205 206
echo_warning "Be careful of the lines below, for a specific virtual box setting" 
bash_exec "/sbin/iptables  -t mangle -F"
bash_exec "/sbin/iptables  -t nat -F"
bash_exec "/sbin/iptables  -t raw -F"
bash_exec "/sbin/iptables  -t filter -F"
bash_exec "/sbin/ip6tables -t mangle -F"
bash_exec "/sbin/ip6tables -t filter -F"
bash_exec "/sbin/ip6tables -t raw -F"
gauthier's avatar
gauthier committed
207 208
bash_exec "iptables -A OUTPUT  -o eth0 -p sctp  -j DROP"
bash_exec "iptables -A INPUT   -i eth0 -p sctp  -j DROP"
gauthier's avatar
gauthier committed
209
bash_exec "iptables -A FORWARD -i eth0 -p sctp  -j DROP"
gauthier's avatar
gauthier committed
210 211
bash_exec "iptables -A OUTPUT  -o eth1 -p sctp  -j DROP"
bash_exec "iptables -A INPUT   -i eth1 -p sctp  -j DROP"
gauthier's avatar
gauthier committed
212 213
bash_exec "iptables -A FORWARD -i eth1 -p sctp  -j DROP"

gauthier's avatar
gauthier committed
214 215
cd $THIS_SCRIPT_PATH/OUTPUT/$HOSTNAME
ITTI_LOG_FILE=itti_enb_ue.$HOSTNAME.log
gauthier's avatar
gauthier committed
216
#rotate_log_file $ITTI_LOG_FILE
gauthier's avatar
gauthier committed
217

gauthier's avatar
gauthier committed
218
STDOUT_LOG_FILE=stdout_enb_ue.$HOSTNAME.log
gauthier's avatar
gauthier committed
219
#rotate_log_file $STDOUT_LOG_FILE
gauthier's avatar
gauthier committed
220

gauthier's avatar
gauthier committed
221
rotate_log_file $STDOUT_LOG_FILE.filtered
gauthier's avatar
gauthier committed
222
#rotate_log_file tshark_enb_ue.$HOSTNAME.pcap
gauthier's avatar
gauthier committed
223 224 225

cd $THIS_SCRIPT_PATH

gauthier's avatar
gauthier committed
226
#nohup tshark -i $ENB_INTERFACE_NAME_FOR_S1_MME -i $ENB_INTERFACE_NAME_FOR_S1U -w OUTPUT/$HOSTNAME/tshark_enb_ue.$HOSTNAME.pcap &
gauthier's avatar
gauthier committed
227

gauthier's avatar
gauthier committed
228
# To start NAS connectivity: AT+CFUN=1
229
# nohup xterm -hold -e $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/UserProcess &
gauthier's avatar
gauthier committed
230

gauthier's avatar
gauthier committed
231 232 233
export MALLOC_TRACE=/tmp/malloc_trace.txt
touch /tmp/malloc_trace.txt
#--malloc-trace-enabled 
gauthier's avatar
gauthier committed
234 235
#-a
gdb --args $OPENAIR_TARGETS/SIMU/USER/oaisim -u1 -l9 -K OUTPUT/$HOSTNAME/$ITTI_LOG_FILE --enb-conf $CONFIG_FILE_ENB 2>&1 | tee OUTPUT/$HOSTNAME/$STDOUT_LOG_FILE 
gauthier's avatar
gauthier committed
236
# > OUTPUT/$HOSTNAME/$STDOUT_LOG_FILE 
gauthier's avatar
gauthier committed
237
# | tee OUTPUT/$HOSTNAME/$STDOUT_LOG_FILE 
gauthier's avatar
gauthier committed
238

gauthier's avatar
gauthier committed
239
#pkill tshark
gauthier's avatar
gauthier committed
240
echo_warning "oaisim ended, filtering stdout from oaisim"
gauthier's avatar
gauthier committed
241
cat OUTPUT/$HOSTNAME/$STDOUT_LOG_FILE | grep 'RRC\|S1AP\|SCTP\|NAS' | grep -v 'RRC_MAC_IN_SYNC_IND' | grep -v 'serving becomes better than threshold' > OUTPUT/$HOSTNAME/$STDOUT_LOG_FILE.filtered