build_oai.bash 27.7 KB
Newer Older
1 2 3 4 5
#/*
# * 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
6
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
# * 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
# */
21 22
################################################################################
# file build_oai.bash
23
# brief OAI automated build tool that can be used to install, compile, run OAI.
gauthier's avatar
gauthier committed
24
# author  Navid Nikaein, Lionel GAUTHIER
25
# company Eurecom
gauthier's avatar
gauthier committed
26
# email:  navid.nikaein@eurecom.fr, lionel.gauthier@eurecom.fr 
27 28 29 30 31 32 33 34 35
#

#!/bin/bash
################################
# include helper functions
################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
. $THIS_SCRIPT_PATH/build_helper.bash

36
check_for_root_rights
37 38

#######################################
39
# Default PARAMETERS
40
######################################
gauthier's avatar
gauthier committed
41 42
declare OAI_DB_ADMIN_USER_NAME="root"
declare OAI_DB_ADMIN_USER_PASSWORD="linux"
43

44
#only one could be set at the time
45
declare BUILD_LTE="NONE" # ENB, EPC, HSS
46 47 48 49 50

declare HW="EXMIMO" # EXMIMO, USRP, ETHERNET, NONE
declare TARGET="ALL" # ALL, SOFTMODEM, OAISIM, UNISIM, NONE
declare ENB_S1=1
declare REL="REL8" # REL8, REL10
nikaeinn's avatar
nikaeinn committed
51
declare RT="NONE" # RTAI, RT_PREMPT, NONE
52
declare DEBUG=0
gauthier's avatar
gauthier committed
53
declare CONFIG_FILE=" "
54
declare CONFIG_FILE_ACCESS_OK=0
gauthier's avatar
gauthier committed
55
declare EXE_ARGUMENTS=" "
56
declare RUN_GDB=0
gauthier's avatar
gauthier committed
57
declare RUN=0
58
declare DISABLE_CHECK_INSTALLED_SOFTWARE=0
gauthier's avatar
gauthier committed
59
declare OAI_CLEAN=0
gauthier's avatar
gauthier committed
60
declare CLEAN_IPTABLES=0
gauthier's avatar
gauthier committed
61
declare CLEAN_HSS=0
62 63 64

declare OAI_TEST=0
declare XFORMS=0
nikaeinn's avatar
nikaeinn committed
65

66
# script is not currently handling these params
67
declare EPC=0 # flag to build EPC
nikaeinn's avatar
nikaeinn committed
68

69 70 71 72 73 74
declare ITTI_ANALYZER=0
declare VCD_TIMING=0
declare WIRESHARK=0
declare TIME_MEAS=0
declare DOXYGEN=0
declare DEV=0
75

76 77 78
#EMULATION_DEV_INTERFACE="eth0"
#EMULATION_MULTICAST_GROUP=1
#EMULATION_DEV_ADDRESS=`ifconfig $EMULATION_DEV_INTERFACE | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
79

nikaeinn's avatar
nikaeinn committed
80
############## script params #####################
81

nikaeinn's avatar
nikaeinn committed
82
if [ -f ./.lock_oaibuild ]; then 
83
    OAI_CLEAN=0
nikaeinn's avatar
nikaeinn committed
84
else 
85
    OAI_CLEAN=1
nikaeinn's avatar
nikaeinn committed
86 87
fi 
 
88 89 90 91 92
#for i in "$@"
#do 
#    echo "i is : $i"
#    case $i in

93

gauthier's avatar
gauthier committed
94 95
  until [ -z "$1" ]
  do
96 97 98 99 100 101 102 103 104 105 106 107 108 109
  case "$1" in
       -a | --doxygen)
            DOXYGEN=1
            echo "setting doxygen flag to: $DOXYGEN"
            shift;
            ;;
       -b | --disable-s1)
            ENB_S1=0
            echo "disable eNB S1 flag"
            shift;
            ;;
       -c | --clean)
            rm -rf ./.lock_oaibuild
            OAI_CLEAN=1
gauthier's avatar
gauthier committed
110
            CLEAN_HSS=1
111 112 113 114
            echo "setting clean flag to: $OAI_CLEAN"
            echo "may check package installation, and recompile OAI"
            shift;
            ;;
gauthier's avatar
gauthier committed
115 116 117 118
       --clean-iptables)
            CLEAN_IPTABLES=1;
            shift;
            ;;
119 120
       -C | --config-file)
            CONFIG_FILE=$2
gauthier's avatar
gauthier committed
121 122 123 124
            # may be relative path 
            if [ -f $(dirname $(readlink -f $0))/$CONFIG_FILE ]; then
                CONFIG_FILE=$(dirname $(readlink -f $0))/$CONFIG_FILE
                echo "setting config file to: $CONFIG_FILE"
125
                CONFIG_FILE_ACCESS_OK=1
gauthier's avatar
gauthier committed
126 127 128 129
            else
                # may be absolute path 
                if [ -f $CONFIG_FILE ]; then
                    echo "setting config file to: $CONFIG_FILE"
130
                    CONFIG_FILE_ACCESS_OK=1
gauthier's avatar
gauthier committed
131 132 133 134 135 136
                else
                    echo "config file not found"
                    exit 1
                fi
            fi
            EXE_ARGUMENTS="$EXE_ARGUMENTS -O $CONFIG_FILE"
137 138 139 140 141 142 143 144 145 146 147 148 149
            shift 2;
            ;;
       -d | --debug)
            DEBUG=1
            echo "setting debug flag to: $DEBUG"
            shift;
            ;;
       -D | --disable-check-installed-software)
            DISABLE_CHECK_INSTALLED_SOFTWARE=1
            echo "disable check installed software"
            shift;
            ;;
       -e | --realtime)
gauthier's avatar
gauthier committed
150
            RT=$2
151 152 153 154
            echo "setting realtime flag to: $RT"
            shift 2 ;
            ;;
       -g | --run-with-gdb)
gauthier's avatar
gauthier committed
155
            DEBUG=1
gauthier's avatar
gauthier committed
156
            RUN=1 
157 158
            RUN_GDB=1
            echo "Running with gdb"
gauthier's avatar
gauthier committed
159
            shift;
160 161 162 163 164 165 166 167 168
            ;;
       -K | --itti-dump-file)
            ITTI_ANALYZER=1
            ITTI_DUMP_FILE=$2
            echo "setting ITTI dump file to: $ITTI_DUMP_FILE"
            EXE_ARGUMENTS="$EXE_ARGUMENTS -K $ITTI_DUMP_FILE"
            shift 2;
            ;;
       -l | --build-target) 
gauthier's avatar
gauthier committed
169
            BUILD_LTE=$2
170 171 172 173 174 175 176 177 178 179 180 181 182 183
            echo "setting top-level build target to: $2"
            shift 2;
            ;;
       -h | --help)
            print_help
            exit -1
            ;;
       -m | --build-from-makefile)
            BUILD_FROM_MAKEFILE=1
            set_build_from_makefile $BUILD_FROM_MAKEFILE
            echo "setting a flag to build from makefile to: $BUILD_FROM_MAKEFILE"
            shift;
            ;;
       -r | --3gpp-release)
gauthier's avatar
gauthier committed
184
            REL=$2 
185 186 187
            echo "setting release to: $REL"
            shift 2 ;
            ;;
gauthier's avatar
gauthier committed
188 189 190
       -R | --run)
            RUN=1 
            echo "setting run to $RUN"
gauthier's avatar
gauthier committed
191
            shift;
gauthier's avatar
gauthier committed
192
            ;;
193 194 195 196 197 198
       -s | --check)
            OAI_TEST=1
            echo "setting sanity check to: $OAI_TEST"
            shift;
            ;;
       -t | --enb-build-target)
gauthier's avatar
gauthier committed
199 200
            TARGET=$2 
            echo "setting enb build target to: $TARGET"
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
            shift 2;
            ;;
       -V | --vcd)
            echo "setting gtk-wave output"
            VCD_TIMING=1
            EXE_ARGUMENTS="$EXE_ARGUMENTS -V"
            shift ;
            ;;
       -w | --hardware)
            HW="$2" #"${i#*=}"
            echo "setting hardware to: $HW"
            shift 2 ;
            ;;
       -x | --xforms)
            XFORMS=1
gauthier's avatar
gauthier committed
216
            EXE_ARGUMENTS="$EXE_ARGUMENTS -d"
217 218 219
            echo "setting xforms to: $XFORMS"
            shift;
            ;;
220 221 222 223 224
       -p | --wireshark)
	  WIRESHARK=1
	  echo "enabling Wireshark interface to $WIRESHARK"
          shift;
          ;;
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
       -z | --defaults)
            echo "setting all parameters to: default"
            rm -rf ./.lock_oaibuild
            OAI_CLEAN=1
            HW="EXMIMO"
            TARGET="ALL" 
            ENB_S1=1
            REL="REL8" 
            RT="NONE"
            DEBUG=0
            ENB_CONFIG_FILE=$OPENAIR_TARGETS/"PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.conf"
            OAI_TEST=0
            shift ;
            ;;
       *)   
            echo "Unknown option $1"
            break ;
nikaeinn's avatar
nikaeinn committed
242
            # unknown option
243
            ;;
244
   esac
nikaeinn's avatar
nikaeinn committed
245 246
done

247 248 249
#####################
# create a bin dir
#####################
250
echo_info "1. Creating the bin dir ..." 
gauthier's avatar
gauthier committed
251
mkdir -m 777 bin 
252 253 254 255

build_date=`date +%Y_%m_%d`
oai_build_date="oai_built_${build_date}"
touch bin/${oai_build_date} 
gauthier's avatar
gauthier committed
256 257
chmod -f 777 bin/${oai_build_date}

nikaeinn's avatar
nikaeinn committed
258
touch bin/install_log.txt
gauthier's avatar
gauthier committed
259
chmod -f 777 bin/install_log.txt
260 261 262
################################
# cleanup first 
################################
263
#echo_info "3. Cleaning ..."
264

265 266 267 268
#$SUDO kill -9 `ps -ef | grep oaisim | awk '{print $2}'` 2>&1
#$SUDO kill -9 `ps -ef | grep lte-softmodem | awk '{print $2}'`  2>&1
#$SUDO kill -9 `ps -ef | grep dlsim | awk '{print $2}'`  2>&1
#$SUDO kill -9 `ps -ef | grep ulsim | awk '{print $2}'`  2>&1
nikaeinn's avatar
nikaeinn committed
269

gauthier's avatar
gauthier committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
if [ $CLEAN_IPTABLES -eq 1 ]; then 
    echo_info "Flushing iptables..."
    $SUDO modprobe ip_tables
    $SUDO modprobe x_tables
    $SUDO iptables -P INPUT ACCEPT
    $SUDO iptables -F INPUT
    $SUDO iptables -P OUTPUT ACCEPT
    $SUDO iptables -F OUTPUT
    $SUDO iptables -P FORWARD ACCEPT
    $SUDO iptables -F FORWARD
    $SUDO iptables -t nat -F
    $SUDO iptables -t mangle -F
    $SUDO iptables -t filter -F
    $SUDO iptables -t raw -F
    echo_info "Flushed iptables"
fi
286
############################################
287
# setting and printing OAI envs, we should check here
288
############################################
289 290
    
echo_info "2. Setting the OAI PATHS ..."
291

nikaeinn's avatar
nikaeinn committed
292
set_openair_env 
293 294 295 296
cecho "OPENAIR_HOME    = $OPENAIR_HOME" $green
cecho "OPENAIR1_DIR    = $OPENAIR1_DIR" $green
cecho "OPENAIR2_DIR    = $OPENAIR2_DIR" $green
cecho "OPENAIR3_DIR    = $OPENAIR3_DIR" $green
297
cecho "OPENAIR3_DIR   = $OPENAIR3_DIR" $green
298 299 300 301 302 303 304
cecho "OPENAIR_TARGETS = $OPENAIR_TARGETS" $green


echo "OPENAIR_HOME    = $OPENAIR_HOME" >>  bin/${oai_build_date}
echo "OPENAIR1_DIR    = $OPENAIR1_DIR"  >>  bin/${oai_build_date}
echo "OPENAIR2_DIR    = $OPENAIR2_DIR"  >>  bin/${oai_build_date}
echo "OPENAIR3_DIR    = $OPENAIR3_DIR"  >>  bin/${oai_build_date}
305
echo "OPENAIR3_DIR   = $OPENAIR3_DIR"  >>  bin/${oai_build_date}
306 307
echo "OPENAIR_TARGETS = $OPENAIR_TARGETS"  >>  bin/${oai_build_date}

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

build_enb(){

##########################################
# process parameters
#########################################

    echo_info "4. Process the parameters"

    echo_info "User-defined Parameters :  HW=$HW, TARGET=$TARGET, ENB_S1=$ENB_S1, REL=$REL, RT=$RT, DEBUG=$DEBUG XFORMS=$XFORMS"
    
    echo "User-defined Parameters :  HW=$HW, TARGET=$TARGET, ENB_S1=$ENB_S1, REL=$REL, RT=$RT, DEBUG=$DEBUG XFORMS=$XFORMS" >> bin/${oai_build_date}
    
 
############################################
# compilation directives 
############################################

    echo_info "5. building the compilation directives ..."
    
    
329 330 331
    SOFTMODEM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
    OAISIM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
    
gauthier's avatar
gauthier committed
332
    if [ $ENB_S1 -eq 1 ]; then 
333 334 335
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
        #OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
	OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES ENABLE_ITTI=1 LINK_ENB_PDCP_TO_GTPV1U=1  SECU=1 "
336 337
    fi 
    
gauthier's avatar
gauthier committed
338 339 340
    if [ $DEBUG -eq 0 ]; then 
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES DISABLE_XER_PRINT=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES DISABLE_XER_PRINT=1 "
341 342
    fi 

343
    if [ $HW = "USRP" ]; then 
gauthier's avatar
gauthier committed
344
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USRP=1 "
345 346
    fi
    
Wang's avatar
Wang committed
347 348 349 350
    if [ $HW = "ADRV9371_ZC706" ]; then 
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES ADRV9371_ZC706=1 "
    fi
    
351
    if [ $HW = "EXMIMO" ]; then 
gauthier's avatar
gauthier committed
352
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES EXMIMO=1 "
353 354 355
    fi
    
    if [ $HW = "ETHERNET" ]; then 
gauthier's avatar
gauthier committed
356
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES ETHERNET=1 "
357 358 359
    fi 
    
    if [ $ENB_S1 -eq 0 ]; then 
gauthier's avatar
gauthier committed
360 361
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES NAS=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES NAS=1 "
362 363 364
    fi 
    
    if [ $REL = "REL8" ]; then
gauthier's avatar
gauthier committed
365 366
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel8=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel8=1 "
367
    else 
gauthier's avatar
gauthier committed
368 369
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel10=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel10=1 "
370 371 372
    fi
    
    if [ $RT = "RTAI" ]; then 
gauthier's avatar
gauthier committed
373 374 375 376 377 378 379
        if [ ! -f /usr/realtime/modules/rtai_hal.ko ];   then
            echo_warning "RTAI doesn't seem to be installed"
            RT="NONE"
            SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES RTAI=0 "
        else 
            SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES HARD_RT=1 "
        fi
380
    else 
gauthier's avatar
gauthier committed
381 382
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES RTAI=0 "
        RT="NONE"
383 384 385
    fi
    
    if [ $TARGET != "ALL" ]; then 
gauthier's avatar
gauthier committed
386 387 388
        if [ $TARGET  != "SOFTMODEM" ]; then 
            HW="NONE"
        fi
389 390
    fi
    
391
    if [ $UBUNTU_REL = "12.04" ]; then 
gauthier's avatar
gauthier committed
392 393 394 395 396 397
        output=$(check_for_machine_type 2>&1) 
        MACHINE_ARCH=$?
        if [ $MACHINE_ARCH -eq 64 ]; then
            SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES LIBCONFIG_LONG=1 "
            OAISIM_DIRECTIVES="$OASIM_DIRECTIVES LIBCONFIG_LONG=1 "
        fi
398 399 400 401 402 403 404 405 406
    fi
    
    echo_success "SOFTMODEM Compilation directives: $SOFTMODEM_DIRECTIVES"
    echo_success "OAISIM Compilation directives:    $OAISIM_DIRECTIVES"
    
    echo "SOFTMODEM Compilation directives: $SOFTMODEM_DIRECTIVES" >>  bin/${oai_build_date}
    echo "OAISIM Compilation directive:    $OAISIM_DIRECTIVES" >>  bin/${oai_build_date}
    
    
407 408 409
############################################
# check the installation
############################################
410 411 412 413 414 415 416 417 418 419 420
    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
        echo_info "6. Checking the the required softwares/packages ..."

        check_install_oai_software  
        if [ $HW = "USRP" ]; then 
            check_install_usrp_uhd_driver 
        fi
        check_install_asn1c
        check_install_nettle
    else
        echo_info "6. Not checking the required softwares/packages ..."
gauthier's avatar
gauthier committed
421
        touch ./.lock_oaibuild
422
    fi
423
    
424 425 426 427
############################################
# compile 
############################################

428
    echo_info "7. compiling and installing the OAI binaries ..."
429

430 431 432
    softmodem_compiled=1
    oaisim_compiled=1
    unisim_compiled=1
433
    
434
    if [ $TARGET = "ALL" ]; then
gauthier's avatar
gauthier committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
        echo "############# compile_ltesoftmodem #############" >> bin/install_log.txt 
        output=$(compile_ltesoftmodem  >> bin/install_log.txt  2>&1 )
        softmodem_compiled=$?
        check_for_ltesoftmodem_executable
        echo_info "7.1 finished ltesoftmodem target : check the installation log file bin/install_log.txt" 

        echo "################ compile_oaisim #################"  >> bin/install_log.txt 
        output=$(compile_oaisim      >> bin/install_log.txt   2>&1 )
        oaisim_compiled=$?
        check_for_oaisim_executable
        echo_info "7.2 finished oaisim target : check the installation log file bin/install_log.txt" 

        echo "################## compile_unisim ##################"  >> bin/install_log.txt 
        output=$(compile_unisim      >> bin/install_log.txt  2>&1 )
        unisim_compiled=$?
        check_for_dlsim_executable
        check_for_ulsim_executable
        check_for_pucchsim_executable
        check_for_prachsim_executable
        check_for_pdcchsim_executable
        check_for_pbchsim_executable
        check_for_mbmssim_executable
        echo_info "7.3 finished unisim target : check the installation log file bin/install_log.txt" 


460
    else
gauthier's avatar
gauthier committed
461
        if [ $TARGET == "SOFTMODEM" ]; then 
gauthier's avatar
gauthier committed
462 463 464 465 466 467
            echo "############# compile_ltesoftmodem #############" >> bin/install_log.txt 
            output=$(compile_ltesoftmodem   >> bin/install_log.txt 2>&1 )
            softmodem_compiled=$?
            check_for_ltesoftmodem_executable
            echo_info "7.1 finished ltesoftmodem target: check the installation log file bin/install_log.txt"
            
gauthier's avatar
gauthier committed
468
            if [ $HW == "EXMIMO" ]; then 
gauthier's avatar
gauthier committed
469
                output=$(compile_exmimo2_driver   >> bin/install_log.txt  2>&1)
gauthier's avatar
gauthier committed
470 471 472 473 474 475 476 477
            fi
        fi
        if [ $TARGET = "OAISIM" ]; then 
            echo "################ compile_oaisim #################"  >> bin/install_log.txt 
            output=$(compile_oaisim   >> bin/install_log.txt 2>&1 )
            oaisim_compiled=$?	
            check_for_oaisim_executable
            echo_info "7.2 finished oaisim target: check the installation log file bin/install_log.txt" 
gauthier's avatar
gauthier committed
478 479 480 481 482 483 484
            
            if [ $ENB_S1 -eq 1 ]; then
                compile_nas_tools  2>&1
                nas_tools_compiled=$?  
                check_for_nas_tools_executable
                echo_info "7.2.1 finished nas ue target: check the installation log file bin/install_log.txt"
            fi
gauthier's avatar
gauthier committed
485 486 487 488 489 490 491 492 493 494 495 496 497 498
        fi
        if [ $TARGET = "UNISIM" ]; then 
           echo "################## compile_unisim ##################"  >> bin/install_log.txt 
            output=$(compile_unisim   >> bin/install_log.txt 2>&1 )
            unisim_compiled=$?
            check_for_dlsim_executable
            check_for_ulsim_executable
            check_for_pucchsim_executable
            check_for_prachsim_executable
            check_for_pdcchsim_executable
            check_for_pbchsim_executable
            check_for_mbmssim_executable
            echo_info "7.3 finished unisim target: check the installation log file bin/install_log.txt" 
        fi
499 500 501 502
    fi


############################################
nikaeinn's avatar
nikaeinn committed
503
# install 
504 505
############################################

506 507
    echo_info "8. Installing ..."
    
gauthier's avatar
gauthier committed
508
    if [ $softmodem_compiled -eq 0 ]; then 
gauthier's avatar
gauthier committed
509 510 511
        echo_success "target lte-softmodem built and installed in the bin directory"
        echo "target lte-softmodem built and installed in the bin directory"  >>  bin/${oai_build_date}
        output=$(install_ltesoftmodem $RT $HW $ENB_S1 )
512
    fi
gauthier's avatar
gauthier committed
513
    if [ $oaisim_compiled -eq 0 ]; then 
gauthier's avatar
gauthier committed
514 515 516
        echo_success "target oaisim built and installed in the bin directory"
        echo "target oaisim built and installed in the bin directory"  >>  bin/${oai_build_date}
        output=$(install_oaisim $ENB_S1 )
517
    fi 
gauthier's avatar
gauthier committed
518
    if [ $unisim_compiled -eq  0 ]; then 
gauthier's avatar
gauthier committed
519 520
        echo_success "target unisim built and installed in the bin directory"
        echo "target unisim built and installed in the bin directory"  >>  bin/${oai_build_date}
521 522 523 524 525
    fi 
    
    echo_info "build terminated, binaries are located in bin/"
    echo_info "build terminated, logs are located in bin/${oai_build_date} and bin/install_log.txt"
    
526 527


528 529
}
build_epc(){
nikaeinn's avatar
nikaeinn committed
530 531 532

    epc_compiled=1

gauthier's avatar
gauthier committed
533
    echo_info "Note: this scripts tested only on Ubuntu 14.04x64"
534 535 536 537

######################################
# CHECK MISC SOFTWARES AND LIBS      #
######################################
538 539
    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
        echo_info "4. Checking the the required softwares/packages for EPC..."
540

541 542 543 544 545 546 547 548 549 550 551
        check_install_epc_software  
        check_install_asn1c
        if [ $OAI_CLEAN -eq 1 ]; then
            check_install_freediamter
        else 
            if [ ! -d /usr/local/etc/freeDiameter ]; then
                check_install_freediamter
            fi
        fi
    else
        echo_info "4. Not checking the required softwares/packages for EPC"
552 553 554 555 556 557
    fi

###########################################
# configure and compile
##########################################

nikaeinn's avatar
nikaeinn committed
558 559
    echo_info "5. configure and compile epc"

gauthier's avatar
gauthier committed
560
    output=$(compile_epc $OAI_CLEAN  >> $OPENAIR_TARGETS/bin/install_log.txt  2>&1 )
nikaeinn's avatar
nikaeinn committed
561
    epc_compiled=$?
562 563 564 565
    if [ $epc_compiled -ne 0 ]; then
        echo_error "EPC compilation failed : check the installation log file bin/install_log.txt" 
        exit 1
    fi
nikaeinn's avatar
nikaeinn committed
566 567
    check_for_epc_executable
    echo_info "finished epc target: check the installation log file bin/install_log.txt" 
568 569 570 571 572

    if [ $CONFIG_FILE_ACCESS_OK -eq 0 ]; then
        echo_error "You have to provide a EPC config file"
        exit 1
    fi
573
    
574
    TEMP_FILE=`tempfile`
575
    VARIABLES=" S6A_CONF\|\
gauthier's avatar
gauthier committed
576
           HSS_HOSTNAME\|\
577 578 579 580
           REALM"

    VARIABLES=$(echo $VARIABLES | sed -e 's/\\r//g')
    VARIABLES=$(echo $VARIABLES | tr -d ' ')
581 582 583
    cat $CONFIG_FILE | grep -w "$VARIABLES"| tr -d " " | tr -d ";" > $TEMP_FILE
    source $TEMP_FILE
    rm -f $TEMP_FILE
584 585 586 587 588 589 590 591 592 593 594 595 596

    if [ x"$REALM" == "x" ]; then
        echo_error "Your config file do not contain a REALM for S6A configuration"
        exit 1
    fi
    if [ x"$S6A_CONF" != "x./epc_s6a.conf" ]; then
        echo_error "Your config file do not contain the good path for the S6A config file,"
        echo_error "accordingly to what is done in this script, it should be set to epc_s6a.conf"
        exit 1
    fi

    check_epc_s6a_certificate $REALM

nikaeinn's avatar
nikaeinn committed
597 598 599 600 601 602
###########################################
# install the binary in bin
##########################################

    echo_info "6. install the binary file"

gauthier's avatar
gauthier committed
603
    if [ $epc_compiled -eq 0 ]; then 
604 605
        echo_success "target epc built and installed in the bin directory"
        echo "target epc built and installed in the bin directory"  >>  bin/${oai_build_date}
gauthier's avatar
gauthier committed
606
        cp -f $CONFIG_FILE  $OPENAIR_TARGETS/bin
607
        cp -f $OPENAIR3_DIR/objs/UTILS/CONF/s6a.conf  $OPENAIR_TARGETS/bin/epc_s6a.conf
nikaeinn's avatar
nikaeinn committed
608
    fi
609 610 611
}

build_hss(){
612
    echo_info "Note: this script tested only for Ubuntu 12.04 x64 -> 14.04 x64"
613 614 615 616

######################################
# CHECK MISC SOFTWARES AND LIBS      #
######################################
gauthier's avatar
gauthier committed
617 618 619
    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
        echo_info "4. check the required packages for HSS"
        check_install_hss_software
gauthier's avatar
gauthier committed
620
        if [ $OAI_CLEAN -eq 1 ]; then
621
            check_install_freediamter
gauthier's avatar
gauthier committed
622 623 624 625
        else 
            if [ ! -d /usr/local/etc/freeDiameter ]; then
                check_install_freediamter
            fi
626
        fi
gauthier's avatar
gauthier committed
627 628
    else
        echo_info "4. Not checking the required packages for HSS"
629
    fi
gauthier's avatar
gauthier committed
630
    
nikaeinn's avatar
nikaeinn committed
631
  
632 633 634
######################################
# compile HSS                        #
######################################
nikaeinn's avatar
nikaeinn committed
635
    echo_info "5. compile HSS"
gauthier's avatar
gauthier committed
636

gauthier's avatar
gauthier committed
637
     # Bad behaviour of $OAI_CLEAN with ./.lock_oaibuild ...
gauthier's avatar
gauthier committed
638
     compile_hss $CLEAN_HSS
nikaeinn's avatar
nikaeinn committed
639 640
     hss_compiled=$?
     check_for_hss_executable
gauthier's avatar
gauthier committed
641
     echo_info "finished hss target" 
nikaeinn's avatar
nikaeinn committed
642
 
643 644 645 646 647
######################################
# Check certificates                 #
######################################
  
    TEMP_FILE=`tempfile`
648 649 650 651
    cat $OPENAIR3_DIR/OPENAIRHSS/conf/hss_fd.conf | grep -w "Identity" | tr -d " " | tr -d ";" > $TEMP_FILE
    cat $OPENAIR3_DIR/OPENAIRHSS/conf/hss.conf    | grep -w "MYSQL_user" | tr -d " " | tr -d ";" >> $TEMP_FILE
    cat $OPENAIR3_DIR/OPENAIRHSS/conf/hss.conf    | grep -w "MYSQL_pass" | tr -d " " | tr -d ";" >> $TEMP_FILE
    cat $OPENAIR3_DIR/OPENAIRHSS/conf/hss.conf    | grep -w "MYSQL_db" | tr -d " " | tr -d ";" >> $TEMP_FILE
652 653 654 655 656 657 658 659
    source $TEMP_FILE
    rm -f  $TEMP_FILE

    if [ x"$Identity" == "x" ]; then
        echo_error "Your config file do not contain a host identity for S6A configuration"
        exit 1
    fi
    HSS_REALM=$(echo $Identity | sed 's/.*\.//')
gauthier's avatar
gauthier committed
660 661 662 663
    HSS_HOSTNAME=${Identity%.$HSS_REALM}
    NEW_HOSTNAME=`hostname -s`
    if [ "x$HSS_HOSTNAME" != "x$NEW_HOSTNAME" ]; then
       echo_warning "Changing identity of HSS from <$HSS_HOSTNAME.$HSS_REALM> to <$NEW_HOSTNAME.$HSS_REALM>"
664
       sed -ibak "s/$HSS_HOSTNAME/$NEW_HOSTNAME/"  $OPENAIR3_DIR/OPENAIRHSS/conf/hss_fd.conf 
gauthier's avatar
gauthier committed
665
    fi
666 667
    check_hss_s6a_certificate $HSS_REALM
    
668 669 670
######################################
# fill the HSS DB
######################################
nikaeinn's avatar
nikaeinn committed
671
     echo_info "6. create HSS database (for EURECOM SIM CARDS)"
nikaeinn's avatar
nikaeinn committed
672
     hss_db_created=1
gauthier's avatar
gauthier committed
673
     create_hss_database $OAI_DB_ADMIN_USER_NAME $OAI_DB_ADMIN_USER_PASSWORD $MYSQL_user $MYSQL_pass $MYSQL_db
gauthier's avatar
gauthier committed
674 675
     if [ $? -eq 1 ]; then
         echo_fatal "hss DB not created"
nikaeinn's avatar
nikaeinn committed
676
     fi
677 678
}

679

nikaeinn's avatar
nikaeinn committed
680
 
gauthier's avatar
gauthier committed
681

nikaeinn's avatar
nikaeinn committed
682
echo_info "3. set the top-level build target"
683
case "$BUILD_LTE" in
684 685 686 687 688
    'ENB')
         echo_success "build LTE eNB"
         build_enb
         ;;
    'EPC')
689
         echo_success "build EPC(MME and xGW)"
690 691 692
         build_epc
         ;;
    'HSS')
693 694 695
        echo_success "build HSS"
        build_hss 
        ;;
696
    'NONE')
697
        ;;
698
    *)
699
        ;;
700 701 702 703 704 705 706
esac

# Additional operation 

############################################
# Generate doxygen documentation
############################################
707

708 709 710 711 712 713 714
if [ $DOXYGEN = 1 ]; then 
    echo_info "9. Generate doxygen documentation ..."
    doxygen $OPENAIR_TARGETS/DOCS/Doxyfile
    echo_info "9.1 use your navigator to open $OPENAIR_TARGETS/DOCS/html/index.html "
else 
    echo_info "9. Bypassing doxygen documentation ..."
fi 
715 716 717 718 719 720


############################################
# testing
############################################
    
721 722 723 724 725 726
if [ $OAI_TEST -eq 1 ]; then 
    echo_info "10. Running OAI pre commit tests (pre-ci) ..."
    python $OPENAIR_TARGETS/TEST/OAI/test01.py -l 
else 
    echo_info "10. Bypassing the Tests ..."
fi 
727 728 729 730
    
############################################
# run 
############################################
nikaeinn's avatar
nikaeinn committed
731

gauthier's avatar
gauthier committed
732
if [ $RUN -ne 0 ]; then 
gauthier's avatar
gauthier committed
733
    echo_info "11. Running ..."
gauthier's avatar
gauthier committed
734 735 736 737 738 739 740 741
    cd $OPENAIR_TARGETS/bin
    case "$BUILD_LTE" in
        'ENB')
            if [ $TARGET == "SOFTMODEM" ]; then 
                if [ $HW == "EXMIMO" ]; then 
                    $SUDO chmod 777 $OPENAIR_TARGETS/RT/USER/init_exmimo2.sh
                    $SUDO $OPENAIR_TARGETS/RT/USER/init_exmimo2.sh
                fi
742 743 744
		if [ $WIRESHARK -eq 1 ]; then 
		    EXE_ARGUMENTS="$EXE_ARGUMENTS -W"
		fi 
gauthier's avatar
gauthier committed
745 746
                echo "############# running ltesoftmodem #############"
                if [ $RUN_GDB -eq 0 ]; then 
knopp's avatar
knopp committed
747
                    $SUDO $OPENAIR_TARGETS/bin/lte-softmodem  `echo $EXE_ARGUMENTS`
gauthier's avatar
gauthier committed
748
                else
gauthier's avatar
gauthier committed
749
                    $SUDO setenv MALLOC_CHECK_ 2
gauthier's avatar
gauthier committed
750 751 752 753 754 755
                    $SUDO touch ~/.gdb_lte_softmodem
                    $SUDO echo "file $OPENAIR_TARGETS/bin/lte-softmodem" > ~/.gdb_lte_softmodem
                    $SUDO echo "set args $EXE_ARGUMENTS" >> ~/.gdb_lte_softmodem
                    $SUDO echo "run" >> ~/.gdb_lte_softmodem
                    $SUDO gdb -nh -x ~/.gdb_lte_softmodem 2>&1 
                fi
gauthier's avatar
gauthier committed
756 757 758 759
                
            elif [ $TARGET == "OAISIM" ]; then
            
                if [ $ENB_S1 -eq 0 ]; then
nikaeinn's avatar
nikaeinn committed
760
		    install_nasmesh
gauthier's avatar
gauthier committed
761 762
                else
                    # prepare NAS for UE
763 764
                    if [ ! -f .ue.nvram0 ]; then
                        echo_success "generate .ue_emm.nvram0 .ue.nvram0"
765
                        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
gauthier's avatar
gauthier committed
766 767
                    fi

768 769
                    if [ ! -f .usim.nvram0 ]; then
                        echo_success "generate .usim.nvram0"
770
                        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
gauthier's avatar
gauthier committed
771
                    fi
772 773
                    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
                    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
gauthier's avatar
gauthier committed
774 775 776 777

                    insmod  $OPENAIR2_DIR/NETWORK_DRIVER/UE_IP/ue_ip.ko
                    
                fi
778 779 780
                if [ $WIRESHARK -eq 1 ]; then 
		    EXE_ARGUMENTS="$EXE_ARGUMENTS -P wireshark"
		fi 
gauthier's avatar
gauthier committed
781 782 783 784 785 786 787 788 789 790
                if [ $RUN_GDB -eq 0 ]; then 
                    $SUDO exec $OPENAIR_TARGETS/bin/oaisim  `echo $EXE_ARGUMENTS`
                else
                    $SUDO setenv MALLOC_CHECK_ 2
                    $SUDO touch ~/.gdb_oaisim
                    $SUDO echo "file $OPENAIR_TARGETS/bin/lte-oaisim" > ~/.gdb_oaisim
                    $SUDO echo "set args $EXE_ARGUMENTS" >> ~/.gdb_oaisim
                    $SUDO echo "run" >> ~/.gdb_oaisim
                    $SUDO gdb -nh -x ~/.gdb_oaisim 2>&1 
                fi
gauthier's avatar
gauthier committed
791
            fi
gauthier's avatar
gauthier committed
792
            ;;
gauthier's avatar
gauthier committed
793 794
        
        
gauthier's avatar
gauthier committed
795
        'EPC')
gauthier's avatar
gauthier committed
796
            echo "############# running EPC #############"
gauthier's avatar
gauthier committed
797
            test_is_host_reachable $HSS_HOSTNAME.$REALM HSS
gauthier's avatar
gauthier committed
798
            if [ $RUN_GDB -eq 0 ]; then
nikaeinn's avatar
nikaeinn committed
799
                $SUDO $OPENAIR_TARGETS/bin/oai_epc  `echo $EXE_ARGUMENTS`
gauthier's avatar
gauthier committed
800
            else
nikaeinn's avatar
nikaeinn committed
801 802 803 804 805
                touch ~/.gdb_epc
                chmod 777 ~/.gdb_epc
                echo "file $OPENAIR_TARGETS/bin/oai_epc" > ~/.gdb_epc
                echo "set args $EXE_ARGUMENTS" >> ~/.gdb_epc
                echo "run" >> ~/.gdb_epc
gauthier's avatar
gauthier committed
806 807 808
                $SUDO gdb -nh -x ~/.gdb_epc 2>&1 
            fi
            ;;
gauthier's avatar
gauthier committed
809 810
        
        
gauthier's avatar
gauthier committed
811
        'HSS')
gauthier's avatar
gauthier committed
812
            echo "############# running HSS #############"
813
            cd $OPENAIR3_DIR/OPENAIRHSS/objs
gauthier's avatar
gauthier committed
814
            if [ $RUN_GDB -eq 0 ]; then
gauthier's avatar
gauthier committed
815
                $SUDO exec ./openair-hss -c ./conf/hss.conf
gauthier's avatar
gauthier committed
816
            else
nikaeinn's avatar
nikaeinn committed
817 818 819
                touch ~/.gdb_hss
                chmod 777 ~/.gdb_hss
                echo "file ./openair-hss" > ~/.gdb_hss
gauthier's avatar
gauthier committed
820
                echo "set args -c ./conf/hss.conf" >> ~/.gdb_hss
nikaeinn's avatar
nikaeinn committed
821
                echo "run" >> ~/.gdb_hss
gauthier's avatar
gauthier committed
822 823
                $SUDO gdb -nh -x ~/.gdb_hss 2>&1 
            fi
gauthier's avatar
gauthier committed
824
             ;;
gauthier's avatar
gauthier committed
825 826
         
         
gauthier's avatar
gauthier committed
827 828
        'NONE')
             ;;
gauthier's avatar
gauthier committed
829 830
         
         
gauthier's avatar
gauthier committed
831 832 833 834 835 836 837 838
        *)
             echo_error "Unknown option $BUILD_LTE: do not execute"
             ;;
    esac
else
    echo_info "11. No run requested, end of script"
    exit 0
fi
839

gauthier's avatar
gauthier committed
840