run_enb_ue_virt_s1 10.4 KB
Newer Older
gauthier's avatar
gauthier committed
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.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.openairinterface.org/?page_id=698
# *
# * 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 more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */

gauthier's avatar
gauthier committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
# file start_enb_ue_virt_s1
# 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)
# MME+SP-GW executable have to be launched by your own (run_hss, run_epc) before this script is invoked.
#



###########################################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
. $THIS_SCRIPT_PATH/build_helper
###########################################################

function trim2()
{
    local var=$@
    var="${var#"${var%%[![:space:]]*}"}"   # remove leading whitespace characters
    var="${var%"${var##*[![:space:]]}"}"   # remove trailing whitespace characters
    echo -n "$var"
}

function is_tun_interface()
{
  my_bool=1
  for var in "$@"
  do
    if [ "a$var" == "a" ]; then
      echo "0";
      return;
    fi
    if [[ "$var" != *tun* ]]; then
      echo "0";
      return;
    fi
  done
  echo "$my_bool"
}

gauthier's avatar
gauthier committed
68 69 70 71 72 73 74 75 76

function help()
{
  echo_error " "
  echo_error "Usage: start_enb_ue_virt_s1 [OPTION]..."
  echo_error "Run the eNB and/or UE executable with no hardware."
  echo_error " "
  echo_error "Options:"
  echo_error "Mandatory arguments to long options are mandatory for short options too."
77
  echo_error "  -a, --abstraction                       enable phy abstraction mode"
gauthier's avatar
gauthier committed
78
  echo_error "  -c, -C, --config-file  eNB_config_file  eNB config file, (see $OPENAIR_DIR/targets/PROJECTS/GENERIC-LTE-EPC/CONF)"
gauthier's avatar
ok  
gauthier committed
79
  echo_error "                                          Default eNB config file if not set is $1"
80
  echo_error "  -l, --log-level                         set the global log level (8:trace, 7:debug, 6:info, 4:warn, 3:error). Note that the log configuration is eNB config file is ignored for oaisim."
gauthier's avatar
gauthier committed
81 82 83
  echo_error "  -g, --gdb                               Run with GDB."
  echo_error "  -h, --help                              Print this help."
  echo_error "  -K, --itti-dump-file   filename         ITTI dump file containing all ITTI events occuring during EPC runtime.(can omit file name if last argument)"
gauthier's avatar
gauthier committed
84
  echo_error "  -m, --mscgen           directory        Generate mscgen output files in a directory"
gauthier's avatar
gauthier committed
85
  echo_error "  -V, --vcd                               Dump timings of processing in a GTKWave compliant file format."
gauthier's avatar
gauthier committed
86 87 88 89
  echo_error "  -W, --wireshark-l2                      Dump MAC frames for visualization with wireshark."
  echo_error "                                          You need to open Wireshark, open the preferences, and check try heuristics for the UDP protocol, MAC-LTE, RLC-LTE,"
  echo_error "                                          and PDCP-LTE. Then capture for all the interfaces with the following filters: s1ap or lte_rrc or mac-lte or rlc-lte"
  echo_error "                                          or pdcp-lte. Note the L2 pdus are transmitted to the local interface."
gauthier's avatar
gauthier committed
90
  echo_error "  -x, --xforms                            Run XFORMS scope windows."
knopp's avatar
knopp committed
91 92
  echo_error " "
  echo_error " A simple data traffic test example: ping -m 1 -I oip1 192.168.12.100"
gauthier's avatar
gauthier committed
93 94 95 96
}



gauthier's avatar
gauthier committed
97 98
function main()
{
gauthier's avatar
ok  
gauthier committed
99 100
  set_openair_env
  cecho "OPENAIR_DIR    = $OPENAIR_DIR" $green
gauthier's avatar
gauthier committed
101 102

  local -i run_gdb=0
gauthier's avatar
gauthier committed
103
  local -i run_mscgen=0
gauthier's avatar
gauthier committed
104
  local    exe_arguments=""
gauthier's avatar
ok  
gauthier committed
105 106
  local    DEFAULT_CONFIG_FILE_ENB=$OPENAIR_DIR/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.generic.oaisim.local_mme.conf
  local    CONFIG_FILE_ENB=$DEFAULT_CONFIG_FILE_ENB
gauthier's avatar
gauthier committed
107
  local    MSC_DIR="/tmp"
gauthier's avatar
gauthier committed
108 109 110 111
  
  until [ -z "$1" ]
    do
    case "$1" in
112 113 114 115 116 117
      -a | --abstraction )
	    abstraction_flag=1
	    echo "enabling abstraction mode"
	    exe_arguments="$exe_arguments -a"
            shift;
	    ;;      
gauthier's avatar
gauthier committed
118
      -c | -C | --config-file)
119
            CONFIG_FILE_ENB=$2
gauthier's avatar
gauthier committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        # may be relative path 
        if [ -f $(dirname $(readlink -f $0))/$CONFIG_FILE ]; then
          CONFIG_FILE_ENB=$(dirname $(readlink -f $0))/$CONFIG_FILE
          echo "setting config file to: $CONFIG_FILE"
          CONFIG_FILE_ACCESS_OK=1
        else
          # may be absolute path 
          if [ -f $CONFIG_FILE_ENB ]; then
            echo "setting config file to: $CONFIG_FILE_ENB"
          else
            echo_fatal "config file $CONFIG_FILE_ENB not found"
          fi
        fi
        shift 2;
        ;;
135 136 137 138 139
      -l | --log-level)
	echo "setting the log level to $2"
	exe_arguments="$exe_arguments -l $2"
        shift 2;
 	;;       
gauthier's avatar
gauthier committed
140 141 142 143 144 145
      -g | --gdb)
        run_gdb=1
        echo "setting GDB flag to: $GDB"
        shift;
        ;;
      -h | --help)
gauthier's avatar
ok  
gauthier committed
146
        help $DEFAULT_CONFIG_FILE_ENB
gauthier's avatar
gauthier committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
        shift;
        exit 0
        ;;
      -K | --itti-dump-file)
        ITTI_DUMP_FILE=$2
        # can omit file name if last arg on the line
        if [ "x$ITTI_DUMP_FILE" = "x" ]; then
          ITTI_DUMP_FILE="/tmp/itti_enb_ue_s1.log"
          shift 1;
        else
          shift 2;
        fi
        echo "setting ITTI dump file to: $ITTI_DUMP_FILE"
        exe_arguments="$exe_arguments -K $ITTI_DUMP_FILE"
        ;;      

gauthier's avatar
gauthier committed
163 164 165 166 167 168 169 170 171 172 173 174 175
      -m | --mscgen)
        MSC_DIR=$2
        # can omit file name if last arg on the line
        if [ -d  "$MSC_DIR" ]; then
          echo "setting mscgen log files to dir: $MSC_DIR"
          run_mscgen=1
          shift 2;
        else
          echo_error "Mscgen log dir does not exist"
          exit -1
        fi
        ;;      

gauthier's avatar
gauthier committed
176
      -V | --vcd)
177
        echo "setting gtk-wave output"
gauthier's avatar
gauthier committed
178 179 180
        exe_arguments="$exe_arguments -V /tmp/oai_gtk_wave.vcd"
        shift ;
        ;;
gauthier's avatar
gauthier committed
181 182 183 184 185
      -W | ----wireshark-l2)
        echo "setting l2 pcap dump output"
        exe_arguments="$exe_arguments -P wireshark"
        shift 2;
        ;;
186 187 188 189 190
      -x | --xforms)
        echo "running with xforms"
        exe_arguments="$exe_arguments --xforms"
        shift 1;
        ;;
gauthier's avatar
gauthier committed
191 192 193 194 195 196 197 198
      *)   
        echo "Unknown option $1"
        help
        exit 0
        ;;
    esac
  done

gauthier's avatar
ok  
gauthier committed
199 200 201
  # may use default config file
  exe_arguments="$exe_arguments --enb-conf $CONFIG_FILE_ENB"

gauthier's avatar
gauthier committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227


  #######################################################
  # 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 '/')


  is_tun=`is_tun_interface $ENB_INTERFACE_NAME_FOR_S1_MME  $ENB_INTERFACE_NAME_FOR_S1U`
#  if [ $is_tun = "1" ]; then
gauthier's avatar
 
gauthier committed
228 229 230 231 232 233
#    openvpn --mktun --dev $ENB_INTERFACE_NAME_FOR_S1U;sync
#    openvpn --mktun --dev $ENB_INTERFACE_NAME_FOR_S1_MME;sync
#    ip -4 addr add $ENB_IPV4_ADDRESS_FOR_S1U/$ENB_IPV4_NETMASK_FOR_S1U        dev $ENB_INTERFACE_NAME_FOR_S1U;sync
#    ip -4 addr add $ENB_IPV4_ADDRESS_FOR_S1_MME/$ENB_IPV4_NETMASK_FOR_S1_MME  dev $ENB_INTERFACE_NAME_FOR_S1_MME;sync
#    ifconfig  $ENB_INTERFACE_NAME_FOR_S1U up;sync
#    ifconfig  $ENB_INTERFACE_NAME_FOR_S1_MME up;sync
gauthier's avatar
gauthier committed
234 235 236 237 238 239 240 241
#    echo_success "Configured local eNB S1 tun interfaces"
#  else
#     echo_success "eNB S1 tun interfaces should be ethernet interfaces (no tunnels configured)"
#  fi

  ##################################################
  # LAUNCH eNB + UE executable
  ##################################################
gauthier's avatar
 
gauthier committed
242 243
  pkill oaisim
  rmmod ue_ip > /dev/null 2>&1
gauthier's avatar
gauthier committed
244 245

  echo_success "Bringup UE interface..."
gauthier's avatar
 
gauthier committed
246
  insmod  $OPENAIR_DIR/targets/bin/ue_ip.ko 
gauthier's avatar
gauthier committed
247

gauthier's avatar
 
gauthier committed
248
  ip route flush cache
gauthier's avatar
gauthier committed
249 250 251 252

  # Check table 200 lte in /etc/iproute2/rt_tables
  fgrep lte /etc/iproute2/rt_tables  > /dev/null
  if [ $? -ne 0 ]; then
Anta Huang's avatar
Anta Huang committed
253
    echo "200 lte " >> /etc/iproute2/rt_tables
gauthier's avatar
gauthier committed
254 255
  fi

gauthier's avatar
gauthier committed
256
  exe_arguments="$exe_arguments -s15 -AAWGN -y1 -b1 -u1 -Q0"
gauthier's avatar
gauthier committed
257 258 259
    
  cd  $OPENAIR_DIR/targets/bin
   
gauthier's avatar
gauthier committed
260 261
   
  if [ $run_mscgen -eq 1 ]; then 
gauthier's avatar
 
gauthier committed
262
    rm -f /tmp/openair.msc.*
gauthier's avatar
gauthier committed
263 264
  fi
   
gauthier's avatar
gauthier committed
265
  if [ $run_gdb -eq 0 ]; then 
266
    exec $OPENAIR_DIR/targets/bin/oaisim.Rel14 $exe_arguments | tee /tmp/enb_ue_s1.log.txt
gauthier's avatar
gauthier committed
267 268 269
  else
    touch      ~/.gdb_enb_ue_s1
    chmod 777  ~/.gdb_enb_ue_s1
270
    echo "file $OPENAIR_DIR/targets/bin/oaisim.Rel14" > ~/.gdb_enb_ue_s1
gauthier's avatar
gauthier committed
271 272 273
    echo "set args $exe_arguments" >> ~/.gdb_enb_ue_s1
    echo "run"                        >> ~/.gdb_enb_ue_s1
    cat ~/.gdb_enb_ue_s1
gauthier's avatar
 
gauthier committed
274
    gdb -n -x ~/.gdb_enb_ue_s1 
gauthier's avatar
gauthier committed
275
  fi
gauthier's avatar
gauthier committed
276 277 278 279
  
  if [ $run_mscgen -eq 1 ]; then 
    cd $MSC_DIR
    last_created_file=`ls -t mscgen* | head -1 | tr -d ':'`
280
    $OPENAIR_DIR/targets/SCRIPTS/msc_gen.py  --profile E_UTRAN
gauthier's avatar
gauthier committed
281 282 283 284 285 286 287 288 289 290
    sync
    last_created_file2=`ls -t mscgen* | head -1 | tr -d ':'`
        
    if [ x"$last_created_file" != x"$last_created_file2" ]; then
      if [ -f ./$last_created_file2/oai_mscgen_page_0.png ]; then 
        command -v eog 2>/dev/null &&  eog ./$last_created_file2/oai_mscgen_page_0.png
      fi
    fi 
  fi
  
gauthier's avatar
gauthier committed
291 292
}

gauthier's avatar
 
gauthier committed
293 294 295 296 297 298 299 300
sudo echo
is_sudo=$?
if [[ "$is_sudo" -ne 0 ]]; then
  echo_error "This script must be run by root or a sudo'er"
  echo
  exit 1
fi

gauthier's avatar
gauthier committed
301
main "$@"