build_m5g 19.9 KB
Newer Older
nikaeinn's avatar
nikaeinn committed
1
2
#!/bin/bash
################################################################################
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Licensed to the Mosaic5G under one or more contributor license
# agreements. See the NOTICE file distributed with this
# work for additional information regarding copyright ownership.
# The Mosaic5G licenses this file to You under the
# Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
  
#   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 Mosaic5G:
#   	contact@mosaic-5g.io
nikaeinn's avatar
nikaeinn committed
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
#
#
################################################################################
# file build_m5g
# brief  Mosaic5G.io automated build and install tool 
# author  Navid Nikaein

export DEBIAN_FRONTEND=noninteractive


###################################
# colorful echos
###################################

black='\E[30m'
red='\E[31m'
green='\E[32m'
yellow='\E[33m'
blue='\E[1;34m'
magenta='\E[35m'
cyan='\E[36m'
white='\E[37m'
reset_color='\E[00m'
COLORIZE=1

cecho()  {  
    # Color-echo
    # arg1 = message
    # arg2 = color
    local default_msg="No Message."
    message=${1:-$default_msg}
    color=${2:-$green}
    [ "$COLORIZE" = "1" ] && message="$color$message$reset_color"
    echo -e "$message"
    return
}

echo_error()   { cecho "$*" $red          ;}
echo_fatal()   { cecho "$*" $red; exit -1 ;}
echo_warning() { cecho "$*" $yellow       ;}
echo_success() { cecho "$*" $green        ;}
echo_info()    { cecho "$*" $blue         ;}


################################
# Set the vars 
################################
SUDO='sudo -E'
ORIGIN_PATH=$PWD
m5g_path=$(dirname $(readlink -f $0))
nikaeinn's avatar
nikaeinn committed
71
72
m5g_bin=$m5g_path/bin
mkdir -p $m5g_bin
nikaeinn's avatar
nikaeinn committed
73

nikaeinn's avatar
nikaeinn committed
74
rtc_path=$m5g_path/flexran
nikaeinn's avatar
nikaeinn committed
75
rtc_bin=$rtc_path/build/rt_controller
76
rtc_branch=master
nikaeinn's avatar
nikaeinn committed
77

78
79
80
81
oai_ran_path=$m5g_path/oai-ran
oai_ran_build=$oai_ran_path/cmake_targets
oai_ran_bin=$oai_ran_path/targets/bin
oai_ran_branch=develop
82

83
84
85
86
87
88
oai_ue_path=$m5g_path/oai-ue
oai_ue_build=$oai_ue_path/cmake_targets
oai_ue_bin=$oai_ue_path/targets/bin
oai_ue_branch=develop


89
oai_cn_path=$m5g_path/oai-cn
nikaeinn's avatar
nikaeinn committed
90
oai_cn_build=$oai_cn_path/scripts
91
92
93
oai_cn_exec=$oai_cn_path/build
oai_cn_exec_name=''
oai_cn_branch=openair-cn-llmec
nikaeinn's avatar
nikaeinn committed
94
95

jox_path=$m5g_path/jox
nikaeinn's avatar
nikaeinn committed
96
jox_exec=$jox_path/scripts
nikaeinn's avatar
nikaeinn committed
97
98
99
100
jox_exec_name=jox
jox_branch=develop


nikaeinn's avatar
nikaeinn committed
101
102
llmec_path=$m5g_path/ll-mec
llmec_branch=develop
nikaeinn's avatar
nikaeinn committed
103
llmec_bin=$llmec_path/ll-mec
nikaeinn's avatar
nikaeinn committed
104

105
ovs_path=$m5g_path/ovs-gtp
nikaeinn's avatar
nikaeinn committed
106
107
108
ovs_branch=master
#ovs_bin=$ovs_path/ll-mec-

nikaeinn's avatar
nikaeinn committed
109
store_path=$m5g_path/store
nikaeinn's avatar
nikaeinn committed
110
store_sdk=$m5g_path/store/sdk
111
store_branch=develop
nikaeinn's avatar
nikaeinn committed
112

nikaeinn's avatar
nikaeinn committed
113
echo_info "Mosaic5G Path:           $m5g_path"
nikaeinn's avatar
nikaeinn committed
114
115
echo_info "FlexRAN Path:            $rtc_path"
echo_info "LL-MEC Path:             $llmec_path"
nikaeinn's avatar
nikaeinn committed
116
echo_info "OVS Path:                $ovs_path"
nikaeinn's avatar
nikaeinn committed
117
118
echo_info "Jox Path:                $jox_path"
echo_info "Store Path:              $store_path"
119
echo_info "OAI oai_ran Path:        $oai_ran_path"
120
121
echo_info "OAI oai_ue Path:         $oai_ue_path"
echo_info "OAI oai_cn Path:         $oai_cn_path"
nikaeinn's avatar
nikaeinn committed
122

nikaeinn's avatar
nikaeinn committed
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
os=$(grep "^ID=" /etc/os-release | sed "s/ID=//" | sed "s/\"//g")
os_release=$(grep "^VERSION_ID=" /etc/os-release | sed "s/VERSION_ID=//" | sed "s/\"//g")
os_dist=$os$os_release
echo_info "Detected OS Dist:        $os_dist"

case "$os" in
  fedora) os_base="fedora"; os_pm="dnf"; os_cmake="cmake" ;;
  rhel)   os_base="fedora"; os_pm="yum"; os_cmake="cmake3" ;;
  centos) os_base="fedora"; os_pm="yum"; os_cmake="cmake3" ;;
  debian) os_base="debian"; os_pm="apt-get"; os_cmake="cmake" ;;
  ubuntu) os_base="debian"; os_pm="apt-get"; os_cmake="cmake" ;;
esac

check_supported_os_dist() {
    case "$os_dist" in
        "ubuntu17.10") return 0 ;;
        "ubuntu17.04") return 0 ;;
        "ubuntu16.04") return 0 ;;
        "ubuntu14.04") return 0 ;;
        "fedora24")    return 0 ;;
        "rhel7")       return 0 ;;
        "centos7")     return 0 ;;
    esac
    return 1
}
nikaeinn's avatar
nikaeinn committed
149
150
pb_version=3

151
snap_revision=""
nikaeinn's avatar
nikaeinn committed
152
153
154
155
156
157
158
159
160
161
162
163
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
################################
# Function to killall the subprocesses when Ctrl-C Key is hit
###############################

function handle_ctrl_c(){
CURPID=$$
ppid=$$
arraycounter=1
echo_info "** Trapped CTRL-C. Killing all subprocesses now..."
while true
do
    FORLOOP=FALSE
    # Get all the child process id
    for i in `ps -ef| awk '$3 == '$ppid' { print $2 }'`
    do
        if [ $i -ne $CURPID ] ; then
            procid[$arraycounter]=$i
            arraycounter=`expr $arraycounter + 1`
            ppid=$i
            FORLOOP=TRUE
        fi
    done
    if [ "$FORLOOP" = "FALSE" ] ; then
        arraycounter=`expr $arraycounter - 1`
        ## We want to kill child process id first and then parent id's
        while [ $arraycounter -ne 0 ]
        do  
            echo "first we send ctrl-c to program"
            $SUDO kill -INT "${procid[$arraycounter]}"
            sleep 3
            echo "Now we force kill if that didn't work"
            $SUDO kill -9 "${procid[$arraycounter]}" >/dev/null
            arraycounter=`expr $arraycounter - 1`
        done
        exit
    fi
done
}

############################
# install additonal tools 
##########################

install_required_packages(){

197
198
199
200
    if ! check_supported_os_dist; then
        echo_error "Your distribution $os_dist is not supported by Mosaic5G !"
        exit 1
    fi
nikaeinn's avatar
nikaeinn committed
201
    
202
203
    $SUDO $os_pm  update -y
    $SUDO $os_pm install -y \
204
	  virt-what \
205
          snapcraft \
nikaeinn's avatar
nikaeinn committed
206
	  build-essential \
207
208
209
210
	  python-dev  \
	  python-pexpect \
	  python-pip  \
	  python-yaml \
211
	  libyaml-dev  \
nikaeinn's avatar
nikaeinn committed
212
213
214
215
216
	  python-tk    \
	  doxygen     \
	  nodejs-legacy \
	  npm \
	  curl 
217
218
    	  

nikaeinn's avatar
nikaeinn committed
219
220
    install_python_packages
    install_npm_packages
nikaeinn's avatar
nikaeinn committed
221
}
222

nikaeinn's avatar
nikaeinn committed
223
install_python_packages(){
224
225
226
227
228
229
230
    
    $SUDO pip install ipcalc
    $SUDO pip install matplotlib
    $SUDO pip install pyyaml
    $SUDO pip install tornado
    $SUDO pip install enum
    $SUDO pip install requests
nikaeinn's avatar
nikaeinn committed
231
    $SUDO pip install flask
232
233
234
    
}

nikaeinn's avatar
nikaeinn committed
235
236
237
238
install_npm_packages(){
    
    sudo npm install apidoc -g
}
nikaeinn's avatar
nikaeinn committed
239
install_optional_packages (){
240
241
    $SUDO $os_pm get update
    $SUDO $os_pm install -y \
nikaeinn's avatar
nikaeinn committed
242
243
244
245
246
247
248
	  check \
	  dialog \
	  gawk \
	  sshfs \
	  swig  \
	  tshark \
	  exuberant-ctags \
249
	  ntpdate \
nikaeinn's avatar
nikaeinn committed
250
251
252
	  tree \
	  htop \
	  python  \
253
	  vim \
nikaeinn's avatar
nikaeinn committed
254
255
256
257
258
259
260
261
262
263
	  emacs \
	  wireshark \
	  ccze \
	  iperf \
	  iperf3 \
	  mscgen \
	  gdb \
	  git \
	  ethtool \
	  meld \
264
265
266
267
	  hping3 \
	  jq  \
	  wget \
	  libyaml-dev \
nikaeinn's avatar
nikaeinn committed
268
269
270
271
272
	  iperf \
	  iproute \
	  iptables \
	  meld    \
	  gitk \
273
274
	  openssh-server \
	  screen 
275
	         
nikaeinn's avatar
nikaeinn committed
276
277
}

nikaeinn's avatar
nikaeinn committed
278
279


nikaeinn's avatar
nikaeinn committed
280
281
282
#######################################
# install and build mosaic5G.io platforms 
#######################################
nikaeinn's avatar
nikaeinn committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
install_ovs_kernel(){
    echo "installing the kernel 4.9.x"
    cd /tmp
    
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900_4.9.0-040900.201612111631_all.deb
    
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb
    
    wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb
    
    sudo dpkg -i *.deb

    cd -  
}

check_current_kernel(){

    required_kern_version="4.9.0-040900-generic"
    required_kern_major=`echo $required_kern_version | cut -d '.' -f1`
    required_kern_minor=`echo $required_kern_version | cut -d '.' -f2`

    current_kern_release=`uname -r`
    current_kern_major=`echo $current_kern_release | cut -d '.' -f1`
    current_kern_minor=`echo $current_kern_release | cut -d '.' -f2`
    
    if [ $current_kern_major -eq $required_kern_major ] && [ $current_kern_minor -eq $required_kern_minor ]; then
	REQUIRED_KERNEL_IS_INSTALLED="true"
    else
	REQUIRED_KERNEL_IS_INSTALLED="false"
    fi
    
}


nikaeinn's avatar
nikaeinn committed
317
318
build_rtc(){

nikaeinn's avatar
nikaeinn committed
319
    git submodule update flexran
320
321
322
    cd $rtc_path
    git checkout $rtc_branch
    echo_info "Cloned FlexRAN controller $rtc_branch branch"
nikaeinn's avatar
nikaeinn committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
    
    if [ "$kernel" == "generic" ]; then 
	build_args="$build_args -r"
    fi
   
    if [ -z $pb_version ] ; then
        build_args="$build_args -p $pb_version"
    fi

    if [ -z $bind_port ] ; then 
	exec_args="-p $bind_port"	
    fi 

    if [ -z $rest_port ] ; then
        exec_args="$exec_args -n $rest_port"
    fi
339
        
nikaeinn's avatar
nikaeinn committed
340
341
342
    export FLEXRAN_RTC_HOME=$rtc_path
    export FLEXRAN_RTC_EXEC=$rtc_exec
   
nikaeinn's avatar
nikaeinn committed
343
344
345
346
347
348
    ./tools/install_dependencies 
    ./build_flexran_rtc.sh $build_args

    cd $m5g_path
    cp $rtc_bin $m5g_bin
    echo_success "Built FlexRAN RTC branch $rtc_branch in $m5g_bin"
nikaeinn's avatar
nikaeinn committed
349
}
350
build_oai_ran(){
nikaeinn's avatar
nikaeinn committed
351

352
353
354
355
    git submodule update oai-ran 
    cd $oai_ran_path
    git checkout $oai_ran_branch
    cd $oai_ran_build
nikaeinn's avatar
nikaeinn committed
356
357
358
    ./build_oai -I  -w USRP
    ./build_oai -c -C --eNB  -w USRP 
    cd $m5g_path
359
360
    cp $oai_ran_bin $m5g_bin
    echo_success "Build OAI RAN $oai_ran_branch branch with FlexRAN agent in $oai_ran_bin"
nikaeinn's avatar
nikaeinn committed
361
}
362
363
364
365
366
367
368
369
370
371
372
373
build_oai_ue(){

    git submodule update oai-ue 
    cd $oai_ue_path
    git checkout $oai_ue_branch
    cd $oai_ue_build
    ./build_oai -I  -w USRP
    ./build_oai -c -C --UE  -w USRP 
    cd $m5g_path
    cp $oai_ue_bin $m5g_bin
    echo_success "Build OAI UE $oai_ue_branch branch in $oai_ue_bin"
}
nikaeinn's avatar
nikaeinn committed
374

375
build_oai_cn(){
nikaeinn's avatar
nikaeinn committed
376

377
378
379
    git submodule update oai-cn
    cd $oai_cn_path
    git checkout $oai_cn_branch
nikaeinn's avatar
nikaeinn committed
380
381
382
    cd $oai_cn_build
    ./build_hss -i -F -e
    ./build_hss 
nikaeinn's avatar
nikaeinn committed
383

nikaeinn's avatar
nikaeinn committed
384
385
386
387
388
389
    ./build_spgw -i -f
    ./build_spgw

    ./build_mme -i -f
    ./build_mme
    
nikaeinn's avatar
nikaeinn committed
390
    cd $m5g_path
391
    echo_success "Cloned OAI CN $oai_cn_branch branch with  ll-mec agent"
392
}
nikaeinn's avatar
nikaeinn committed
393
394
395

build_llmec(){

nikaeinn's avatar
nikaeinn committed
396
    git submodule update ll-mec
397
    cd $llmec_path
nikaeinn's avatar
nikaeinn committed
398
    git checkout $llmec_branch
nikaeinn's avatar
nikaeinn committed
399
400
401
402
403
    ./install_dependencies.sh
    ./build_ll-mec.sh -d 
    cd $m5g_path
    cp $llmec_bin $m5g_bin
    echo_success "Built LL-MEC $llmec_branch branch in $llmec_bin"
nikaeinn's avatar
nikaeinn committed
404
405
}

nikaeinn's avatar
nikaeinn committed
406
407
build_ovs_gtp(){

408
    git submodule update ovs-gtp
nikaeinn's avatar
nikaeinn committed
409
410
    cd $ovs_path
    git checkout $ovs_branch
411
    cd ovs_kernel_gtp
nikaeinn's avatar
nikaeinn committed
412
413

    check_current_kernel
nikaeinn's avatar
nikaeinn committed
414
    if [ "$REQUIRED_KERNEL_IS_INSTALLED" == "false" ]; then
nikaeinn's avatar
nikaeinn committed
415
416
417
418
419
420
421
422
423
424
	echo "You haven't installed kernel 4.9. Do you want to install it now?"
	echo -n 'y/n:'
	read install_kernel

	if [ "$install_kernel" == "y" ] ; then 
	    install_ovs_kernel
	    echo_info "You need to reboot"
	else
	    echo_info "You need to install kernel 4.9 to proceed with the installation of ovs-gtp"
	fi
nikaeinn's avatar
nikaeinn committed
425
	exit 0
nikaeinn's avatar
nikaeinn committed
426
427
428
429
430
431
432
433
434
435
    else
	echo_info "Required kernel is installed"
    fi
    sudo ./install.sh

    cd $ovs_path
    
    echo_info "Now, it is the time to set the config file so that you can run ovs-gtp"

    #cd $m5g_path
nikaeinn's avatar
nikaeinn committed
436
    # insert the module and check for GTP
nikaeinn's avatar
nikaeinn committed
437
    #echo_success "Built OVS $ovs_branch branch"
nikaeinn's avatar
nikaeinn committed
438
439
}

nikaeinn's avatar
nikaeinn committed
440
441
442
build_store(){

    git submodule update store 
443
    cd $store_path
nikaeinn's avatar
nikaeinn committed
444
    git checkout $store_branch
nikaeinn's avatar
nikaeinn committed
445
446
447
448
449
450
451
452
    cd $store_sdk
    mkdir -p docs
    doxygen
    apidoc -i lib/ -o ./docs/apidoc -f ".*\\.py$"
    echo_success "Generated the store $store_branch branch"

    cd $m5g_path
    echo_success "Cloned the store $store_branch branch"
nikaeinn's avatar
nikaeinn committed
453
}
454
455
456
457
458
build_jox(){

    git submodule update jox
    cd $jox_path
    git checkout $jox_branch
nikaeinn's avatar
nikaeinn committed
459
460
461
462
463
    #source ./joxenv
    echo_info "building JoX"
    ./script/build_jox -i
    ./script/build_jox -x
    
464
    cd -
nikaeinn's avatar
nikaeinn committed
465
    echo_success "Cloned JoX $jox_branch branch"
466
}
nikaeinn's avatar
nikaeinn committed
467

nikaeinn's avatar
nikaeinn committed
468
469
build_m5g (){
 
nikaeinn's avatar
nikaeinn committed
470
471
    #EDGE nodes
    build_oai_ran
472
    build_oai_ue
nikaeinn's avatar
nikaeinn committed
473
    build_rtc
nikaeinn's avatar
nikaeinn committed
474
475
476

    #CORE nodes
    build_oai_cn
nikaeinn's avatar
nikaeinn committed
477
    build_llmec
nikaeinn's avatar
nikaeinn committed
478
479
480
    build_ovs_gtp
    
    #Control apps and Orch
nikaeinn's avatar
nikaeinn committed
481
    build_store
482
    build_jox
nikaeinn's avatar
nikaeinn committed
483
484
}

485
486
487
snap_m5g_module(){
    echo "Snapping $1"
    snap list $1 &> /dev/null
488
489
490
491
492
    if [ $? -eq 0 ]; then
	op="refresh"
    else
	op="install"
    fi
493
494
495
    if [ "$snap_revision" != "" ]; then
	op="$op --revision=$snap_revision"
    fi
496
497
    echo "snap $op $1 --channel=edge --devmode"
    sudo snap $op $1 --channel=edge --devmode
498
    echo "-----------------------------------"
499
    echo "         $1 SNAP INFO         "
500
501
    echo "-----------------------------------"
    
502
    snap info $1
nikaeinn's avatar
nikaeinn committed
503
504
}

505
declare -a snaps=("oai-cn" "oai-ran" "oai-ue" "oai-tracer" "flexran" "ll-mec")
506
 
nikaeinn's avatar
nikaeinn committed
507
snap_m5g (){
508
509
510
511
512
513
514
515
516
517
518
    for s in "${snaps[@]}"
    do
	snap_m5g_module $s
    done
    echo""
    echo "-------------------------------------"
    echo "     Listing the installed snaps     "
    echo "-------------------------------------"
    echo ""
    snap list 
}
nikaeinn's avatar
nikaeinn committed
519
520

init_snap_m5g(){
521
    echo ""
nikaeinn's avatar
nikaeinn committed
522
523
524
525
526
    
}

init_build_m5g(){

nikaeinn's avatar
nikaeinn committed
527
    if [ ! -f  ./submodule_init ]; then
nikaeinn's avatar
nikaeinn committed
528
	git submodule init
nikaeinn's avatar
nikaeinn committed
529
	echo "yes"  > ./.submodule_init
nikaeinn's avatar
nikaeinn committed
530
531
532
533
534
535
536
    fi 
}

############################
# Clean all
###########################

537
clean_snaps(){
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

    if [ "$snap_revision" != "" ]; then
	op="$op --revision=$snap_revision"
    fi

    for s in "${snaps[@]}"
    do
	echo "removing snapping $s"
	sudo snap remove $op $s
    done
    echo ""
    echo "-------------------------------------"
    echo "Listing the current installed snaps  "
    echo "-------------------------------------"
    echo ""
    snap list
554
555
}

nikaeinn's avatar
nikaeinn committed
556
557
clean_all(){
    echo_info "cleaning "
558
    clean_snaps
nikaeinn's avatar
nikaeinn committed
559
560
561
562
563
564
565
}

############################
# manage options and helps
###########################
function print_help() {
  echo_info '
566
This program installs the Mosaic5G.io software platforms from snaps
nikaeinn's avatar
nikaeinn committed
567
568
569
570
571
or build a custom platform from the source file. 
You should have ubuntu 16.xx. Root password required.
Options
-h
   print this help
nikaeinn's avatar
nikaeinn committed
572
573
--clean-snaps
   Clean all the snaps"
nikaeinn's avatar
nikaeinn committed
574
575
-i | --install-required-pkg
   install required packages for build and/or snap process
nikaeinn's avatar
nikaeinn committed
576
577
-I | --install-all-packages
   Install both required and developper/optional/useful pachages 
578
579
580
581
-c | --build-oai-cn
   Builds OAI CN with the LL-MEC agent from source
-C | --snap-oai-cn
   install OAI CN with the LL-MEC agent from snap
nikaeinn's avatar
nikaeinn committed
582
583
584
585
586
587
588
589
590
591
592
-m | --build-m5g
   Builds all the Mosaic5G.io software plarforms from source 
-M | --snap-m5g
   Install all of the Mosaic5G.io platforms form snap
-j | --build-jox
   Builds JOX Orchestrator
-l | --build-llmec
   Builds lowlatency MEC platform from source
-L | --snap-llmec
   Install lowlatency MEC platform from snap
-f | --build-flexran
nikaeinn's avatar
nikaeinn committed
593
   Build FlexRAN realtime controller from source 
nikaeinn's avatar
nikaeinn committed
594
595
-F | --snap-flexran
   Install FlexRAN realtime controller from snap 
nikaeinn's avatar
nikaeinn committed
596
597
598
599
-o | --build-ovs-gtp
   Build OVS with GTP support in the kernel space from source 
-O | --snap-ovs-gtp
   Install OVS with GTP support from snap 
600
601
602
603
-r | --build-oai-ran
   Builds OAI RAN with the FlexRAN agent from source
-R | --snap-oai-ran
   install OAI RAN with the FlexRAN agent from snap
nikaeinn's avatar
nikaeinn committed
604
605
-s | --build-store
   Builds ans setup the store 
606
607
608
609
-u | --install-ue
   Install OAI UE from source 
-U | --snap-ue
   Install OAI UE from Snap
610
611
-v | --revision 
   Install specific revision of the snap. You must have developer access.
nikaeinn's avatar
nikaeinn committed
612
613
-p | --pb-version
   Set the protobuf version for FlexRAN RTC. Valid options 2 and 3.
614
615
-T | --snap-tracer
   Install OAI tracer from Snap
nikaeinn's avatar
nikaeinn committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
Usage:
- build_m5g -i -m : insatll all the sanps and run 
- build_m5g -i -j
'
}


function main() {
    until [ -z "$1" ]; do
	
	case "$1" in
	    --clean-snaps)
		CLEAN_SNAPS=1
		shift;;
630
631
632
633
	#    -k | --install-kernel)
	#	INSTALL_KERNEL=1
	#	echo_info "Will install the kernel"
	#	shift;;
nikaeinn's avatar
nikaeinn committed
634
635
636
637
	    -i | --install-required-pkg)
		INSTALL_PKG=1
		echo_info "Will install the required packages for build and snap process"
		shift;;
nikaeinn's avatar
nikaeinn committed
638
639
	    -I | --install-optional-packages)
		INSTALL_OPTIONAL=1
640
		echo_info "Will install optional/useful packages"
nikaeinn's avatar
nikaeinn committed
641
		shift;;
nikaeinn's avatar
nikaeinn committed
642
643
644
645
646
647
	    -m | --build-m5g)
		BUILD_M5G=1
		echo_info "Will build mosaic5G.io platforms from source"
		shift;;
	    -M | --snap-m5g)
		SNAP_M5G=1
648
		echo_info "Will install mosaic5G.io platforms from snaps"
nikaeinn's avatar
nikaeinn committed
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
		shift;;
	    -j | --build-jox)
		BUILD_JOX=1
		echo_info "Will build the environment for JOX"
		shift;;
	    -l | --build-llmec)
		BUILD_LLMEC=1
		echo_info "Will build ll-mec from source"
		shift;;
	    -L | --snap-llmec)
		SNAP_LLMEC=1
		echo_info "Will install ll-mec from snap"
		shift;;
	    -f | --build-flexran)
		BUILD_RTC=1
		echo_info "Will build FlexRAN Realtime Controller (RTC) from source"
		shift;;
	    -F | --snap-flexran)
		SNAP_RTC=1
		echo_info "Will install FlexRAN Realtime Controller (RTC) from snap"
		shift;;
nikaeinn's avatar
nikaeinn committed
670
671
672
673
674
675
676
677
	    -o | --build-ovs-gtp)
		BUILD_OVS_GTP=1
		echo_info "Will build OVS with GTP support in the kernel space from source"
		shift;;
	    -O | --snap-ovs-gtp)
		SNAP_OVS_GTP=1
		echo_info "Will install OVS with GTP from snap"
		shift;;
678
679
680
	    -r | --build-oai-ran)
		BUILD_OAI_RAN=1
		echo_info "Will buildOAI RAN with the FlexRAN Agent from source"
nikaeinn's avatar
nikaeinn committed
681
		shift;;
682
683
	    -R | --snap-oai-ran)
		SNAP_OAI_RAN=1
684
		echo_info "Will install OAI RAN with the FlexRAN Agent from snap"
nikaeinn's avatar
nikaeinn committed
685
		shift;;
nikaeinn's avatar
nikaeinn committed
686
687
688
689
	    -s | --build-store)
		BUILD_STORE=1
		echo_info "Will build Mosaic5G store" 
		shift;;
690
691
692
	    -c | --build-oai-cn)
		BUILD_OAI_CN=1
		echo_info "Will build OAI CN with the LL-MEC Agent from source"
nikaeinn's avatar
nikaeinn committed
693
		shift;;
694
695
696
	    -C | --snap-oai-cn)
		SNAP_OAI_CN=1
		echo_info "Will install OAI CN with the LL-MEC Agent from snap"
nikaeinn's avatar
nikaeinn committed
697
698
699
700
701
		shift;;
	    -p | --protobuf-version)
		echo "setting protobuf version to $2" 
		pb_version=$2
		shift 2;;
702
703
704
705
706
707
708
709
	    -u | --build-oai-ue )
		echo "Will install OAI UE from source" 
		BUILD_OAI_UE=1
		shift ;;
	    -U | --snap-oai-ue )
		echo "Will install OAI UE from snap" 
		SNAP_OAI_UE=1
		shift ;;
710
711
712
713
714
715
716
717
	    -v | --revision )
		echo "setting snap revision is set to $2" 
		snap_revision=$2
		shift 2;;
	    -T | --snap-tracer )
		echo "Will install OAI Tracer from snap" 
		SNAP_OAI_TRACER=1
		shift ;;
nikaeinn's avatar
nikaeinn committed
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
	    -h | --help)
		print_help
		exit 1;;
	    *)
		print_help
		if [ "$1" != "-h" -o "$1" != "--help" -o "$1" != "-help" ]; then 
		    echo_fatal "Unknown option $1"
		fi 
		break;;
	esac
    done
    
    if [ "$CLEAN_SNAPS" = "1" ] ; then
	clean_snaps
	echo_info "Remove all the previously installed snaps"
    fi
    
    if [ "$INSTALL_PKG" = "1" ] ; then
	install_required_packages
nikaeinn's avatar
nikaeinn committed
737
	echo_info "Installed the required packages"
nikaeinn's avatar
nikaeinn committed
738
    fi
nikaeinn's avatar
nikaeinn committed
739
740
741
742
743
744
745

    if [ "$INSTALL_OPTIONAL" = "1" ] ; then
	echo_info "Installing optional packages"
	install_optional_packages
	echo_info "Installed the optional packages"
    fi

nikaeinn's avatar
nikaeinn committed
746
747
748
749
750
751
752
753
754
755
756
    
    if [ "$BUILD_M5G" = "1" ] ; then
	echo_info "Build Customized MOSAIC5G.io Sotware Platforms"
	init_build_m5g
	build_m5g
    else
	init_build_m5g
	if [ "$BUILD_RTC" = "1" ] ; then
	    echo_info "Building FlexRAN realtime controller"
            build_rtc
	fi
757
758
759
	if [ "$BUILD_OAI_RAN" = "1" ] ; then
	    echo_info "Building OAI RAN with the FlexRAN Agent"
            build_oai_ran
nikaeinn's avatar
nikaeinn committed
760
	fi
761
762
763
764
765
766
767
768
	if [ "$BUILD_OAI_RAN" = "1" ] ; then
	    echo_info "Building OAI RAN with the FlexRAN Agent"
            build_oai_ran
	fi
	if [ "$BUILD_OAI_UE" = "1" ] ; then
	    echo_info "Building OAI UE"
            build_oai_ue
	fi
769
770
771
	if [ "$BUILD_OAI_CN" = "1" ] ; then
	    echo_info "Building OAI CN with the LL-MEC Agent"
            build_oai_cn
772
	fi
nikaeinn's avatar
nikaeinn committed
773
774
775
776
	if [ "$BUILD_LLMEC" = "1" ] ; then
	    echo_info "Building lowlatency MEC platforms"
            build_llmec
	fi
nikaeinn's avatar
nikaeinn committed
777
778
779
780
	if [ "$BUILD_OVS_GTP" = "1" ] ; then
	    echo_info "Building OVS with GTP"
            build_ovs_gtp
	fi
nikaeinn's avatar
nikaeinn committed
781
	if [ "$BUILD_JOX" = "1" ] ; then
nikaeinn's avatar
nikaeinn committed
782
	    echo_info "Building JOX orchestrator"
nikaeinn's avatar
nikaeinn committed
783
784
            build_jox
	fi
nikaeinn's avatar
nikaeinn committed
785
786
787
788
	if [ "$BUILD_STORE" = "1" ] ; then
	    echo_info "Building Store"
            build_store
	fi
nikaeinn's avatar
nikaeinn committed
789
790
791
792
793
794
795
796
797
798
    fi
    
    if [ "$SNAP_M5G" = "1" ] ; then
	echo_info "Snap MOSAIC5G.io Sotware Platforms"
	init_snap_m5g
	snap_m5g
    else
	init_snap_m5g
	if [ "$SNAP_RTC" = "1" ] ; then
	    echo_info "Snap FlexRAN realtime controller"
799
            snap_m5g_module "flexran"
nikaeinn's avatar
nikaeinn committed
800
	fi
801
802
	if [ "$SNAP_OAI_RAN" = "1" ] ; then
	    echo_info "Snap OAI RAN with the FlexRAN Agent"
803
804
805
806
807
            snap_m5g_module "oai-ran"
	fi
	if [ "$SNAP_OAI_UE" = "1" ] ; then
	    echo_info "Snap OAI UE"
            snap_m5g_module "oai-ue"
nikaeinn's avatar
nikaeinn committed
808
	fi
809
810
	if [ "$SNAP_OAI_CN" = "1" ] ; then
	    echo_info "Snap OAI CN with the LL-MEC Agent"
811
            snap_m5g_module "oai-cn"
nikaeinn's avatar
nikaeinn committed
812
813
814
	fi
	if [ "$SNAP_LLMEC" = "1" ] ; then
	    echo_info "Snap lowlatency MEC platforms"
815
            snap_m5g_module "ll-mec"
nikaeinn's avatar
nikaeinn committed
816
	fi
nikaeinn's avatar
nikaeinn committed
817
	if [ "$SNAP_OVS_GTP" = "1" ] ; then
818
819
	    echo_info "Snap OVS with GTP not yet supported !"
            #snap_ovs_gtp
nikaeinn's avatar
nikaeinn committed
820
	fi
821
822
	if [ "$SNAP_OAI_TRACER" = "1" ] ; then
	    echo_info "Snap OAI Tracer"
823
            snap_m5g_module "oai-tracer"
824
	fi
nikaeinn's avatar
nikaeinn committed
825
826
827
828
829
830
    fi
    
    
}

main "$@"