build_oai.bash 27.1 KB
Newer Older
1 2 3 4 5 6 7
################################################################################
#   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
8
#    (at your option) anylater version.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#
#
#    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 build_oai.bash
30
# brief OAI automated build tool that can be used to install, compile, run OAI.
Lionel Gauthier's avatar
Lionel Gauthier committed
31
# author  Navid Nikaein, Lionel GAUTHIER
32
# company Eurecom
Lionel Gauthier's avatar
Lionel Gauthier committed
33
# email:  navid.nikaein@eurecom.fr, lionel.gauthier@eurecom.fr 
34 35 36 37 38 39 40 41 42
#

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

43
check_for_root_rights
44 45

#######################################
46
# Default PARAMETERS
47 48
######################################

49
#only one could be set at the time
Lionel Gauthier's avatar
Lionel Gauthier committed
50
declare BUILD_LTE="" # ENB, EPC, HSS, NONE
51 52 53 54 55 56 57

declare HW="EXMIMO" # EXMIMO, USRP, ETHERNET, NONE
declare TARGET="ALL" # ALL, SOFTMODEM, OAISIM, UNISIM, NONE
declare ENB_S1=1
declare REL="REL8" # REL8, REL10
declare RT="NONE" # RTAI, RT_PREMPT or RT_DISABLED, NONE
declare DEBUG=0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
58
declare CONFIG_FILE=" "
59
declare CONFIG_FILE_ACCESS_OK=0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
60
declare EXE_ARGUMENTS=" "
61
declare RUN_GDB=0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
62
declare RUN=0
63
declare DISABLE_CHECK_INSTALLED_SOFTWARE=0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
64
declare OAI_CLEAN=0
Lionel Gauthier's avatar
Lionel Gauthier committed
65
declare CLEAN_IPTABLES=0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
66
declare CLEAN_HSS=0
67 68 69

declare OAI_TEST=0
declare XFORMS=0
70

71
# script is not currently handling these params
72
declare EPC=0 # flag to build EPC
73

74 75 76 77 78 79
declare ITTI_ANALYZER=0
declare VCD_TIMING=0
declare WIRESHARK=0
declare TIME_MEAS=0
declare DOXYGEN=0
declare DEV=0
80 81 82 83 84

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}'`

Navid Nikaein's avatar
Navid Nikaein committed
85
############## script params #####################
86

Navid Nikaein's avatar
Navid Nikaein committed
87
if [ -f ./.lock_oaibuild ]; then 
88
    OAI_CLEAN=0
Navid Nikaein's avatar
Navid Nikaein committed
89
else 
90
    OAI_CLEAN=1
Navid Nikaein's avatar
Navid Nikaein committed
91 92
fi 
 
93 94 95 96 97
#for i in "$@"
#do 
#    echo "i is : $i"
#    case $i in

98

Lionel Gauthier's avatar
 
Lionel Gauthier committed
99 100
  until [ -z "$1" ]
  do
101 102 103 104 105 106 107 108 109 110 111 112 113 114
  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
Lionel Gauthier's avatar
 
Lionel Gauthier committed
115
            CLEAN_HSS=1
116 117 118 119
            echo "setting clean flag to: $OAI_CLEAN"
            echo "may check package installation, and recompile OAI"
            shift;
            ;;
Lionel Gauthier's avatar
Lionel Gauthier committed
120 121 122 123
       --clean-iptables)
            CLEAN_IPTABLES=1;
            shift;
            ;;
124 125
       -C | --config-file)
            CONFIG_FILE=$2
Lionel Gauthier's avatar
 
Lionel Gauthier committed
126 127 128 129
            # 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"
130
                CONFIG_FILE_ACCESS_OK=1
Lionel Gauthier's avatar
 
Lionel Gauthier committed
131 132 133 134
            else
                # may be absolute path 
                if [ -f $CONFIG_FILE ]; then
                    echo "setting config file to: $CONFIG_FILE"
135
                    CONFIG_FILE_ACCESS_OK=1
Lionel Gauthier's avatar
 
Lionel Gauthier committed
136 137 138 139 140 141
                else
                    echo "config file not found"
                    exit 1
                fi
            fi
            EXE_ARGUMENTS="$EXE_ARGUMENTS -O $CONFIG_FILE"
142 143 144 145 146 147 148 149 150 151 152 153 154
            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)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
155
            RT=$2
156 157 158 159
            echo "setting realtime flag to: $RT"
            shift 2 ;
            ;;
       -g | --run-with-gdb)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
160
            DEBUG=1
Lionel Gauthier's avatar
 
Lionel Gauthier committed
161
            RUN=1 
162 163
            RUN_GDB=1
            echo "Running with gdb"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
164
            shift;
165 166 167 168 169 170 171 172 173
            ;;
       -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) 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
174
            BUILD_LTE=$2
175 176
            echo "setting top-level build target to: $2"
            shift 2;
177
            echo > bin/install_log.txt
178 179 180 181 182 183 184 185 186 187 188 189
            ;;
       -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)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
190
            REL=$2 
191 192 193
            echo "setting release to: $REL"
            shift 2 ;
            ;;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
194 195 196
       -R | --run)
            RUN=1 
            echo "setting run to $RUN"
Lionel Gauthier's avatar
Lionel Gauthier committed
197
            shift;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
198
            ;;
199 200 201 202 203 204
       -s | --check)
            OAI_TEST=1
            echo "setting sanity check to: $OAI_TEST"
            shift;
            ;;
       -t | --enb-build-target)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
205 206
            TARGET=$2 
            echo "setting enb build target to: $TARGET"
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
            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
            echo "setting xforms to: $XFORMS"
            shift;
            ;;
       -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 ;
Navid Nikaein's avatar
Navid Nikaein committed
242
            # unknown option
243
            ;;
244
   esac
Navid Nikaein's avatar
Navid Nikaein committed
245 246
done

247 248 249
#####################
# create a bin dir
#####################
250
echo_info "1. Creating the bin dir ..." 
251 252 253 254 255 256
rm -rf bin
mkdir -m 777 -p bin 

build_date=`date +%Y_%m_%d`
oai_build_date="oai_built_${build_date}"
touch bin/${oai_build_date} 
Navid Nikaein's avatar
Navid Nikaein committed
257
touch bin/install_log.txt
258 259 260
################################
# cleanup first 
################################
261
#echo_info "3. Cleaning ..."
262

263 264 265 266
#$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
Navid Nikaein's avatar
Navid Nikaein committed
267

Lionel Gauthier's avatar
Lionel Gauthier committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
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
284
############################################
285
# setting and printing OAI envs, we should check here
286
############################################
287 288
    
echo_info "2. Setting the OAI PATHS ..."
289

Navid Nikaein's avatar
Navid Nikaein committed
290
set_openair_env 
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
cecho "OPENAIR_HOME    = $OPENAIR_HOME" $green
cecho "OPENAIR1_DIR    = $OPENAIR1_DIR" $green
cecho "OPENAIR2_DIR    = $OPENAIR2_DIR" $green
cecho "OPENAIR3_DIR    = $OPENAIR3_DIR" $green
cecho "OPENAIRCN_DIR   = $OPENAIRCN_DIR" $green
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}
echo "OPENAIRCN_DIR   = $OPENAIRCN_DIR"  >>  bin/${oai_build_date}
echo "OPENAIR_TARGETS = $OPENAIR_TARGETS"  >>  bin/${oai_build_date}

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

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 ..."
    
    
327 328 329
    SOFTMODEM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
    OAISIM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
    
Lionel Gauthier's avatar
 
Lionel Gauthier committed
330 331 332
    if [ $ENB_S1 -eq 1 ]; then 
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_PDCP_TO_GTPV1U=1  SECU=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES USE_MME=R10 ENABLE_ITTI=1 LINK_PDCP_TO_GTPV1U=1  SECU=1 "
333 334
    fi 
    
Lionel Gauthier's avatar
 
Lionel Gauthier committed
335 336 337
    if [ $DEBUG -eq 0 ]; then 
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES DISABLE_XER_PRINT=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES DISABLE_XER_PRINT=1 "
338 339
    fi 

340
    if [ $HW = "USRP" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
341
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USRP=1 "
342 343 344
    fi
    
    if [ $HW = "EXMIMO" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
345
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES EXMIMO=1 "
346 347 348
    fi
    
    if [ $HW = "ETHERNET" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
349
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES ETHERNET=1 "
350 351 352
    fi 
    
    if [ $ENB_S1 -eq 0 ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
353 354
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES NAS=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES NAS=1 "
355 356 357
    fi 
    
    if [ $REL = "REL8" ]; then
Lionel Gauthier's avatar
 
Lionel Gauthier committed
358 359
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel8=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel8=1 "
360
    else 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
361 362
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel10=1 "
        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel10=1 "
363 364 365
    fi
    
    if [ $RT = "RTAI" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
366 367 368 369 370 371 372
        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
373
    else 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
374 375
        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES RTAI=0 "
        RT="NONE"
376 377 378
    fi
    
    if [ $TARGET != "ALL" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
379 380 381
        if [ $TARGET  != "SOFTMODEM" ]; then 
            HW="NONE"
        fi
382 383
    fi
    
384
    if [ $UBUNTU_REL = "12.04" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
385 386 387 388 389 390
        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
391 392 393 394 395 396 397 398 399
    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}
    
    
400 401 402
############################################
# check the installation
############################################
403 404 405 406 407 408 409 410 411 412 413
    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 ..."
Lionel Gauthier's avatar
 
Lionel Gauthier committed
414
        touch ./.lock_oaibuild
415
    fi
416
    
417 418 419 420
############################################
# compile 
############################################

421
    echo_info "7. compiling and installing the OAI binaries ..."
422

423 424 425
    softmodem_compiled=1
    oaisim_compiled=1
    unisim_compiled=1
426
    
427
    if [ $TARGET = "ALL" ]; then
Lionel Gauthier's avatar
 
Lionel Gauthier committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        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" 


453
    else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
454
        if [ $TARGET == "SOFTMODEM" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
455 456 457 458 459 460
            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"
            
Lionel Gauthier's avatar
 
Lionel Gauthier committed
461
            if [ $HW == "EXMIMO" ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
462
                output=$(compile_exmimo2_driver   >> bin/install_log.txt  2>&1)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
            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" 
        
        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
486 487 488 489
    fi


############################################
490
# install 
491 492
############################################

493 494
    echo_info "8. Installing ..."
    
Lionel Gauthier's avatar
 
Lionel Gauthier committed
495
    if [ $softmodem_compiled -eq 0 ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
496 497 498
        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 )
499
    fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
500
    if [ $oaisim_compiled -eq 0 ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
501 502 503
        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 )
504
    fi 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
505
    if [ $unisim_compiled -eq  0 ]; then 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
506 507
        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}
508 509 510 511 512
    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"
    
513 514


515 516
}
build_epc(){
Navid Nikaein's avatar
 
Navid Nikaein committed
517 518 519

    epc_compiled=1

520
    echo_info "Note: this scripts tested only on Ubuntu 12.04 x64, 14.04 x64"
521 522 523 524

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

528 529 530 531 532 533 534 535 536 537 538
        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"
539 540 541 542 543 544
    fi

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

Navid Nikaein's avatar
 
Navid Nikaein committed
545 546 547 548
    echo_info "5. configure and compile epc"

    output=$(compile_epc $OAI_CLEAN  >> bin/install_log.txt  2>&1 )
    epc_compiled=$?
549 550 551 552
    if [ $epc_compiled -ne 0 ]; then
        echo_error "EPC compilation failed : check the installation log file bin/install_log.txt" 
        exit 1
    fi
Navid Nikaein's avatar
 
Navid Nikaein committed
553 554
    check_for_epc_executable
    echo_info "finished epc target: check the installation log file bin/install_log.txt" 
555 556 557 558 559

    if [ $CONFIG_FILE_ACCESS_OK -eq 0 ]; then
        echo_error "You have to provide a EPC config file"
        exit 1
    fi
560
    
561
    TEMP_FILE=`tempfile`
562 563 564 565 566
    VARIABLES=" S6A_CONF\|\
           REALM"

    VARIABLES=$(echo $VARIABLES | sed -e 's/\\r//g')
    VARIABLES=$(echo $VARIABLES | tr -d ' ')
567 568 569
    cat $CONFIG_FILE | grep -w "$VARIABLES"| tr -d " " | tr -d ";" > $TEMP_FILE
    source $TEMP_FILE
    rm -f $TEMP_FILE
570 571 572 573 574 575 576 577 578 579 580 581 582

    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

Navid Nikaein's avatar
 
Navid Nikaein committed
583 584 585 586 587 588
###########################################
# install the binary in bin
##########################################

    echo_info "6. install the binary file"

Lionel Gauthier's avatar
 
Lionel Gauthier committed
589
    if [ $epc_compiled -eq 0 ]; then 
590 591
        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}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
592
        cp -f $CONFIG_FILE  $OPENAIR_TARGETS/bin
593
        cp -f $OPENAIRCN_DIR/objs/UTILS/CONF/s6a.conf  $OPENAIR_TARGETS/bin/epc_s6a.conf
Navid Nikaein's avatar
 
Navid Nikaein committed
594
    fi
595 596 597
}

build_hss(){
598
    echo_info "Note: this script tested only for Ubuntu 12.04 x64 -> 14.04 x64"
599 600 601 602

######################################
# CHECK MISC SOFTWARES AND LIBS      #
######################################
Lionel Gauthier's avatar
 
Lionel Gauthier committed
603 604 605
    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
        echo_info "4. check the required packages for HSS"
        check_install_hss_software
Lionel Gauthier's avatar
 
Lionel Gauthier committed
606
        if [ $OAI_CLEAN -eq 1 ]; then
607
            check_install_freediamter
Lionel Gauthier's avatar
 
Lionel Gauthier committed
608 609 610 611
        else 
            if [ ! -d /usr/local/etc/freeDiameter ]; then
                check_install_freediamter
            fi
612
        fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
613 614
    else
        echo_info "4. Not checking the required packages for HSS"
615
    fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
616
    
Navid Nikaein's avatar
 
Navid Nikaein committed
617
  
618 619 620
######################################
# compile HSS                        #
######################################
Navid Nikaein's avatar
 
Navid Nikaein committed
621
    echo_info "5. compile HSS"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
622

Lionel Gauthier's avatar
 
Lionel Gauthier committed
623 624
     # Bad behaviour of $OAI_CLEAN with ./.lock_oaibuild ...
     output=$(compile_hss  $CLEAN_HSS >> bin/install_log.txt  2>&1 )
Navid Nikaein's avatar
 
Navid Nikaein committed
625
     hss_compiled=$?
626 627 628 629
     if [ $hss_compiled -eq 1 ]; then
         echo_error "Failed in compiling hss target: check the installation log file bin/install_log.txt"
         exit 1
     fi
Navid Nikaein's avatar
 
Navid Nikaein committed
630 631 632
     check_for_hss_executable
     echo_info "finished hss target: check the installation log file bin/install_log.txt" 
 
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
######################################
# Check certificates                 #
######################################
  
    TEMP_FILE=`tempfile`
    cat $OPENAIRCN_DIR/OPENAIRHSS/conf/hss_fd.conf | grep -w "Identity" | tr -d " " | tr -d ";" > $TEMP_FILE
    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/.*\.//')
    check_hss_s6a_certificate $HSS_REALM
    
649 650 651
######################################
# fill the HSS DB
######################################
Navid Nikaein's avatar
 
Navid Nikaein committed
652
     echo_info "6. create HSS database (for EURECOM SIM CARDS)"
Navid Nikaein's avatar
 
Navid Nikaein committed
653
     hss_db_created=1
Navid Nikaein's avatar
 
Navid Nikaein committed
654 655 656
     USER="hssadmin"
     PW=""
     output=$(create_hss_database $USER $PW )
Navid Nikaein's avatar
 
Navid Nikaein committed
657
     hss_db_created=$?
Navid Nikaein's avatar
 
Navid Nikaein committed
658
     if [ $hss_db_created = 0 ]; then
659
         echo_warning "hss DB not created"
Navid Nikaein's avatar
 
Navid Nikaein committed
660
     fi
Navid Nikaein's avatar
 
Navid Nikaein committed
661 662 663
######################################
# install hss
######################################
664

Navid Nikaein's avatar
 
Navid Nikaein committed
665
     echo_info "7. install the binary file"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
666 667 668
     if [ $hss_compiled -eq 0 ]; then
         echo_success "target hss built, DB created  and installed in the bin directory"
         echo "target hss built, DB created, and installed in the bin directory"  >>  bin/${oai_build_date}
Navid Nikaein's avatar
 
Navid Nikaein committed
669
         cp -rf $OPENAIRCN_DIR/OPENAIRHSS/conf  $OPENAIR_TARGETS/bin
670 671 672
         $SUDO cp $OPENAIR_TARGETS/bin/conf/hss_fd.local.conf /etc/openair-hss
         rm -f $OPENAIR_TARGETS/bin/openair-hss
         cp -pv $OPENAIRCN_DIR/OPENAIRHSS/objs/openair-hss $OPENAIR_TARGETS/bin/
Navid Nikaein's avatar
 
Navid Nikaein committed
673
     fi
674 675 676 677

######################################
# LAUNCH HSS                         #
######################################
678 679
     echo_info "8. run hss in $OPENAIR_TARGETS/bin/:  ./openair-hss -c conf/hss.local.conf"
     cd $OPENAIR_TARGETS/bin
Navid Nikaein's avatar
 
Navid Nikaein committed
680
     ./openair-hss -c conf/hss.local.conf
681 682
}

683

Navid Nikaein's avatar
Navid Nikaein committed
684
 
685 686 687 688
############################################
# set the build 
############################################

Lionel Gauthier's avatar
Lionel Gauthier committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
if [ x$BUILD_LTE == x ]; then
    : ${DIALOG_OK=0}
    : ${DIALOG_CANCEL=1}
    : ${DIALOG_HELP=2}
    : ${DIALOG_EXTRA=3}
    : ${DIALOG_ITEM_HELP=4}
    : ${DIALOG_ESC=255}

    : ${SIG_NONE=0}
    : ${SIG_HUP=1}
    : ${SIG_INT=2}
    : ${SIG_QUIT=3}
    : ${SIG_KILL=9}
    : ${SIG_TERM=15}
    input=`tempfile 2>/dev/null` || input=/tmp/input$$
    output=`tempfile 2>/dev/null` || output=/tmp/test$$
    trap "rm -f $input $output" $SIG_NONE $SIG_HUP $SIG_INT $SIG_TRAP $SIG_TERM
    cat >$input <<-EOF
ENB:  evolved Node B target
EPC:  Experimental Evolved Packet Core target
Lionel Gauthier's avatar
 
Lionel Gauthier committed
709
HSS:  Experimental Home Subscriber Server target
Lionel Gauthier's avatar
Lionel Gauthier committed
710 711 712 713 714 715
NONE: Do not build/run anything
EOF
    cat $input | sed -e 's/^/"/' -e 's/:/" "/g' -e 's/$/"/' >$output
    cat $output >$input
    
    BUILD_LTE="NONE"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
716
    dialog --clear --title "BUILD TARGET SELECTION" \
Lionel Gauthier's avatar
Lionel Gauthier committed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
            --menu "You did not choose a target \n\
    to build (optionaly to run) \n\
    You can use the UP/DOWN arrow keys, \n\
    the first letter of the choice as a hot key,\n\
    or the number keys 1-4 to choose an option.\n\
    \n\n\
        Choose the target:" 20 69 4 \
        --file $input 2> $output
    retval=$?
    tempfile=$output
    case $retval in
      $DIALOG_OK)
        BUILD_LTE=`cat $tempfile`
        ;;
      $DIALOG_CANCEL)
        ;;
      $DIALOG_HELP)
        ;;
      $DIALOG_EXTRA)
        ;;
      $DIALOG_ITEM_HELP)
        ;;
      $DIALOG_ESC)
        ;;
      *)
         ;;
    esac
fi

Navid Nikaein's avatar
 
Navid Nikaein committed
746
echo_info "3. set the top-level build target"
747
case "$BUILD_LTE" in
748 749 750 751 752 753 754 755 756
    'ENB')
         echo_success "build LTE eNB"
         build_enb
         ;;
    'EPC')
         echo_warning "build EPC(MME and xGW): Experimental"
         build_epc
         ;;
    'HSS')
757
         echo_warning "BUILD_LTE: $BUILD_LTE"
758 759 760
         echo_warning "build HSS: Experimental"
         build_hss 
         ;;
761
    'NONE')
762
         ;;
763
    *)
764
         ;;
765 766 767 768 769 770 771
esac

# Additional operation 

############################################
# Generate doxygen documentation
############################################
772

773
    if [ $DOXYGEN = 1 ]; then 
774 775 776
        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 "
777
    else 
778
        echo_info "9. Bypassing doxygen documentation ..."
779 780 781 782 783 784 785
    fi 


############################################
# testing
############################################
    
Lionel Gauthier's avatar
 
Lionel Gauthier committed
786
    if [ $OAI_TEST -eq 1 ]; then 
787 788
        echo_info "10. Testing ..."
        python $OPENAIR_TARGETS/TEST/OAI/test01.py
789
    else 
790
        echo_info "10. Bypassing the Tests ..."
791 792 793 794 795
    fi 
    
############################################
# run 
############################################
Lionel Gauthier's avatar
 
Lionel Gauthier committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
if [ $RUN -ne 0 ]; then 
    echo_info "11. Running ... To be completed"
    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
                echo "############# running ltesoftmodem #############"
                if [ $RUN_GDB -eq 0 ]; then 
                    $SUDO exec $OPENAIR_TARGETS/bin/lte-softmodem  `echo $EXE_ARGUMENTS`
                else
                    $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
Lionel Gauthier's avatar
 
Lionel Gauthier committed
816
            fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
817
            ;;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
818 819
        
        
Lionel Gauthier's avatar
 
Lionel Gauthier committed
820 821 822 823 824 825 826 827 828 829 830 831
        'EPC')
            echo "############# running epc #############"
            if [ $RUN_GDB -eq 0 ]; then
                $SUDO exec $OPENAIR_TARGETS/bin/oai_epc  `echo $EXE_ARGUMENTS`
            else
                $SUDO touch ~/.gdb_epc
                $SUDO echo "file $OPENAIR_TARGETS/bin/oai_epc" > ~/.gdb_epc
                $SUDO echo "set args $EXE_ARGUMENTS" >> ~/.gdb_epc
                $SUDO echo "run" >> ~/.gdb_epc
                $SUDO gdb -nh -x ~/.gdb_epc 2>&1 
            fi
            ;;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
832 833
        
        
Lionel Gauthier's avatar
 
Lionel Gauthier committed
834 835 836
        'HSS')
             echo_warning "TODO execute HSS: Experimental"
             ;;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
837 838
         
         
Lionel Gauthier's avatar
 
Lionel Gauthier committed
839 840
        'NONE')
             ;;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
841 842
         
         
Lionel Gauthier's avatar
 
Lionel Gauthier committed
843 844 845 846 847 848 849 850
        *)
             echo_error "Unknown option $BUILD_LTE: do not execute"
             ;;
    esac
else
    echo_info "11. No run requested, end of script"
    exit 0
fi
851

Lionel Gauthier's avatar
 
Lionel Gauthier committed
852