run_enb_ue_virt_s1 8.02 KB
Newer Older
Lionel Gauthier's avatar
Lionel Gauthier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 68 69 70 71 72 73 74
#!/bin/bash
################################################################################
#   OpenAirInterface
#   Copyright(c) 1999 - 2014 Eurecom
#
#    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.
#
#
#    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.
#
#    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
#  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
#
#  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
#
################################################################################
# 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"
}

Lionel Gauthier's avatar
Lionel Gauthier committed
75 76 77 78 79 80 81 82 83 84

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."
  echo_error "  -c, -C, --config-file  eNB_config_file  eNB config file, (see $OPENAIR_DIR/targets/PROJECTS/GENERIC-LTE-EPC/CONF)"
Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
85
  echo_error "                                          Default eNB config file if not set is $1"
Lionel Gauthier's avatar
Lionel Gauthier committed
86 87 88 89 90 91 92 93 94
  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)"
  echo_error "  -V, --vcd                               Dump timings of processing in a GTKWave compliant file format."
  echo_error "  -x, --xforms                            Run XFORMS scope windows."
}



Lionel Gauthier's avatar
Lionel Gauthier committed
95 96
function main()
{
Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
97 98
  set_openair_env
  cecho "OPENAIR_DIR    = $OPENAIR_DIR" $green
Lionel Gauthier's avatar
Lionel Gauthier committed
99 100 101

  local -i run_gdb=0
  local    exe_arguments=""
Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
102 103
  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
Lionel Gauthier's avatar
Lionel Gauthier committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  
  until [ -z "$1" ]
    do
    case "$1" in
      -c | -C | --config-file)
        CONFIG_FILE_ENB=$2
        # 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;
        ;;
      -g | --gdb)
        run_gdb=1
        echo "setting GDB flag to: $GDB"
        shift;
        ;;
      -h | --help)
Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
131
        help $DEFAULT_CONFIG_FILE_ENB
Lionel Gauthier's avatar
Lionel Gauthier committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        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"
        ;;      

      -V | --vcd)
        "setting gtk-wave output"
        exe_arguments="$exe_arguments -V /tmp/oai_gtk_wave.vcd"
        shift ;
        ;;
      *)   
        echo "Unknown option $1"
        help
        exit 0
        ;;
    esac
  done

Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
161 162 163
  # may use default config file
  exe_arguments="$exe_arguments --enb-conf $CONFIG_FILE_ENB"

Lionel Gauthier's avatar
Lionel Gauthier committed
164 165 166 167 168 169 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219


  #######################################################
  # 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
#    $SUDO openvpn --mktun --dev $ENB_INTERFACE_NAME_FOR_S1U;sync
#    $SUDO openvpn --mktun --dev $ENB_INTERFACE_NAME_FOR_S1_MME;sync
#    $SUDO ip -4 addr add $ENB_IPV4_ADDRESS_FOR_S1U/$ENB_IPV4_NETMASK_FOR_S1U        dev $ENB_INTERFACE_NAME_FOR_S1U;sync
#    $SUDO ip -4 addr add $ENB_IPV4_ADDRESS_FOR_S1_MME/$ENB_IPV4_NETMASK_FOR_S1_MME  dev $ENB_INTERFACE_NAME_FOR_S1_MME;sync
#    $SUDO ifconfig  $ENB_INTERFACE_NAME_FOR_S1U up;sync
#    $SUDO ifconfig  $ENB_INTERFACE_NAME_FOR_S1_MME up;sync
#    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
  ##################################################
  $SUDO pkill oaisim
  $SUDO rmmod ue_ip > /dev/null 2>&1

  echo_success "Bringup UE interface..."
  $SUDO insmod  $OPENAIR_DIR/targets/bin/ue_ip.ko

  $SUDO 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
    $SUDO echo "200 lte " >> /etc/iproute2/rt_tables
  fi
  $SUDO ip rule add fwmark 5 table lte
  $SUDO ip route add default dev oip1 table lte

Lionel Gauthier's avatar
Lionel Gauthier committed
220
  exe_arguments="$exe_arguments -u1 -l9"
221 222 223
    
  cd  $OPENAIR_DIR/targets/bin
   
Lionel Gauthier's avatar
Lionel Gauthier committed
224 225 226 227 228 229 230 231 232
  if [ $run_gdb -eq 0 ]; then 
    exec $OPENAIR_DIR/targets/bin/oaisim $exe_arguments  
  else
    touch      ~/.gdb_enb_ue_s1
    chmod 777  ~/.gdb_enb_ue_s1
    echo "file $OPENAIR_DIR/targets/bin/oaisim" > ~/.gdb_enb_ue_s1
    echo "set args $exe_arguments" >> ~/.gdb_enb_ue_s1
    echo "run"                        >> ~/.gdb_enb_ue_s1
    cat ~/.gdb_enb_ue_s1
Lionel Gauthier's avatar
ok  
Lionel Gauthier committed
233
    gdb -n -x ~/.gdb_enb_ue_s1 
Lionel Gauthier's avatar
Lionel Gauthier committed
234
  fi
Lionel Gauthier's avatar
Lionel Gauthier committed
235 236 237
}

main "$@"