build_epc 9.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
################################################################################
#   OpenAirInterface
#   Copyright(c) 1999 - 2014 Eurecom
#
#    OpenAirInterface is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) anylater version.
#
#
#    OpenAirInterface is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with OpenAirInterface.The full GNU General Public License is
#    included in this distribution in the file called "COPYING". If not,
#    see <http://www.gnu.org/licenses/>.
#
#  Contact Information
#  OpenAirInterface Admin: openair_admin@eurecom.fr
#  OpenAirInterface Tech : openair_tech@eurecom.fr
#  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
#
#  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
#
################################################################################
# file build_epc
# brief
# author Lionel Gauthier
# company Eurecom
# email: lionel.gauthier@eurecom.fr
#
################################
# include helper functions
################################
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
source $THIS_SCRIPT_PATH/build_helper

function help()
{
  echo_error " "
  echo_error "Usage: build_epc [OPTION]..."
  echo_error "Build the EPC executable."
  echo_error " "
  echo_error "Options:"
  echo_error "Mandatory arguments to long options are mandatory for short options too."
  echo_error "  -c, --clean                               Clean the build generated files (build from scratch)"
  echo_error "  -d, --debug                               Compile with debug informations."
  echo_error "  -h, --help                                Print this help."
  echo_error "  -H, --hss                       hostname  HSS hostname (with FQDN), default is this host (hostname)."
  echo_error "  -i, --check-installed-software            Check installed software packages necessary to build and run EPC (support Ubuntu 14.04)."
  echo_error "  -r, --realm                     realm     Realm of the MME (if not specified, is extracted from this host FQDN)."
  echo_error "  -s, --transport-sctp-only                 Diameter use SCTP only (TCP disabled)."
  echo_error "  -S, --s6a-server                          MME act as a server on s6a interface (useful when HSS and MME/EPC run on the same host)."
  echo_error "  -t, --transport-tcp-only                  Diameter use TCP only (SCTP disabled)."
  echo_error "  -T, --transport-prefer-tcp                Diameter prefer TCP."
  echo_error "  -v, --verbose                             Build process verbose."
}



function main()
{
  local -i clean=0
  local -i verbose=0
  local -i s6a_server=0
  local    cmake_args=" "
  local    make_args="-j $NUM_CPU"
  local    realm=""
  local    hss_fqdn=""
  local    hss_hostname=""
  local    hss_ip=""
  local    REL="Rel10"


  until [ -z "$1" ]
    do
    case "$1" in
      -c | --clean)
        clean=1
        echo "Clean the build generated files (build from scratch)"
        shift;
        ;;
      -d | --debug)
        cmake_args="$cmake_args -DDEBUG=1"
        echo "Compile with debug informations"
        shift;
        ;;
      -h | --help)
        help
        shift;
        exit 0
        ;;
      -H | --hss)
        hss_fqdn=$2
        cmake_args="$cmake_args -DHSS_FQDN=$hss_fqdn"
        shift 2;
        ;;
      -i | --check-installed-software)
        echo "Check installed software packages necessary to build and run EPC (support Ubuntu 14.04):"
        check_install_epc_software
        exit 0
      ;;
      -r | --realm)
        echo "Realm: $2"
        realm=$2
        cmake_args="$cmake_args -DREALM=$realm"
        shift 2;
        ;;
      -s | --transport-sctp-only)
        echo "Diameter use SCTP (TCP disabled), this is the default option."
        cmake_args="$cmake_args -DTRANSPORT_option=No_TCP"
        shift;
        ;;
      -S | --s6a-server)
        echo "MME act as a server on s6a"
        s6a_server=1
        cmake_args="$cmake_args -DMME_S6A_IS_SERVER=1"
        shift 1;
        ;;
      -t | --transport-tcp-only)
        echo "Diameter use TCP (SCTP disabled)."
        cmake_args="$cmake_args -DTRANSPORT_option=No_SCTP"
        shift;
        ;;
      -T | --transport-prefer-tcp)
        echo "Diameter prefer TCP (TCP, SCTP enabled)."
        cmake_args="$cmake_args -DTRANSPORT_PREFER_TCP_option=Prefer_TCP"
        shift;
        ;;
      -v | --verbose)
        echo "Make build process verbose"
        cmake_args="$cmake_args -DCMAKE_VERBOSE_MAKEFILE=ON"
        make_args="VERBOSE=1 $make_args"
        verbose=1
        shift;
        ;;
      *)   
        echo "Unknown option $1"
        help
        exit 1
        ;;
    esac
  done

  # extra arguments processing
  if [[ z$hss_fqdn = z ]]; then
    hss_fqdn=`hostname --fqdn`
    cmake_args="$cmake_args -DHSS_FQDN=$hss_fqdn"
    if [[ z$realm = z ]]; then
      realm=$hss_fqdn
      realm=${realm#*.}
      cmake_args="$cmake_args -DREALM=$realm"
    fi
  else
    if [[ z$realm = z ]]; then
      realm=${hss_fqdn#*.}
      cmake_args="$cmake_args -DREALM=$realm"
    fi
  fi
  hss_hostname=${hss_fqdn%%.*}
  cmake_args="$cmake_args -DHSS_HOSTNAME=$hss_hostname"

  hss_ip=`resolveip --silent $hss_hostname`
  if [[ z$hss_ip = z ]]; then
    hss_ip=`resolveip --silent $hss_fqdn`
  fi
  if [[ z$hss_ip = z ]]; then
    echo_abort "Unable to get HSS IP addr of $hss_fqdn"
  fi
  cmake_args="$cmake_args -DHSS_IP=$hss_ip"

  set_openair_env 
  if [[ $verbose -eq 1 ]]; then
    cecho "OPENAIR_DIR    = $OPENAIR_DIR" $green
  fi
  
  # for conf files copy in this bash script
  if [ -d /usr/lib/freeDiameter ]; then
    export FREEDIAMETER_PREFIX=/usr
  else
    if [ -d /usr/local/lib/freeDiameter ]; then
      export FREEDIAMETER_PREFIX=/usr/local
    else
      echo_fatal "FreeDiameter prefix not found, install freeDiameter if EPC, HSS"
    fi
  fi
  
  
  
  local dbin=$OPENAIR_DIR/targets/bin
  local dlog=$OPENAIR_DIR/cmake_targets/log
  local dconf=$OPENAIR_DIR/targets/bin
  
  mkdir -m 777 -p $dbin $dlog

  ##############################################################################
  # Compile userspace executable
  ##############################################################################
  rm -f $OPENAIR_DIR/targets/bin/mme_gw
  cd $OPENAIR_DIR/cmake_targets/epc_build_oai
  if [ $clean -ne 0 ]; then
    if [[ $verbose -eq 1 ]]; then
      echo "Cleaning EPC"
    fi
    rm -Rf build 2>&1
210
211
212
213
214
215
216
217
218
219
    $SUDO rm -Rf $OPENAIR_TARGETS/CMAKE/EPC/MME_GW/build  2>&1
    $SUDO rm -f /usr/local/etc/freeDiameter/mme*    2>&1
    $SUDO rm -f /usr/local/etc/freeDiameter/epc*    2>&1
    $SUDO rm -f /usr/etc/freeDiameter/mme*    2>&1
    $SUDO rm -f /usr/etc/freeDiameter/epc*    2>&1
    $SUDO rm -f $OPENAIR_DIR/targets/bin/xt_GTPU*.ko    2>&1
    ($SUDO cd $OPENAIRCN_DIR/GTPV1-U/GTPUAH && make clean)
    ($SUDO cd $OPENAIRCN_DIR/GTPV1-U/GTPURH && make clean)
    $SUDO rm -f $OPENAIRCN_DIR/GTPV1-U/GTPUAH/Bin/* 2>&1
    $SUDO rm -f /lib/xtables/libxt_GTPU*.so             2>&1
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
    mkdir -m 777 -p -v build
  fi
  
  ##############################################################################
  # Compile kernel modules
  ##############################################################################
  # NO CMAKE FOR THAT, THIS CODE CAN DISAPEAR
  #cd $OPENAIRCN_DIR/GTPV1-U/GTPUAH;
  #make
  #if [ $? -ne 0 ]; then
  #  echo_error "Build GTPUAH module failed, exiting"
  #  return 1
  #else 
  #  $SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
  #  $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
  #fi
    
  #cd $OPENAIRCN_DIR/GTPV1-U/GTPURH;
  #make
  #if [ $? -ne 0 ]; then
  #  echo_error "Build GTPURH module failed, exiting"
  #  return 1
  #else 
  #  $SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
  #  $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
  #fi
  
  
  
  ##############################################################################
  # Compile EPC
  ##############################################################################
  cd $OPENAIR_DIR/cmake_targets/epc_build_oai
  #cd $OPENAIR_TARGETS/CMAKE/EPC/MME_GW
  if [ ! -d ./build ]; then
    mkdir -m 777 -p -v build
  fi
  cmake_file=./CMakeLists.txt
  cp $OPENAIR_DIR/cmake_targets/epc_build_oai/CMakeLists.template $cmake_file
  echo 'include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)' >> $cmake_file
  cd ./build
  cmake  $cmake_args ..
  #make $make_args -j $NUM_CPU
  #make install
  compilations \
      epc_build_oai mme_gw \
      mme_gw $dbin/mme_gw.$REL
  # Only integrated mme+sgw+pgw is operational today
  #    compilations \
  #  epc_build_oai oai_sgw \
  #  oai_sgw $dbin/oai_sgw.$REL
  compilations \
    epc_build_oai xt_GTPUAH_lib \
    libxt_GTPUAH_lib.so $dbin
  compilations \
    epc_build_oai xt_GTPURH_lib \
    libxt_GTPURH_lib.so $dbin
  compilations \
    epc_build_oai xt_GTPURH \
    CMakeFiles/xt_GTPURH/xt_GTPURH.ko $dbin
  compilations \
    epc_build_oai xt_GTPUAH \
    CMakeFiles/xt_GTPUAH/xt_GTPUAH.ko $dbin
    
  echo_info "Copying iptables libraries into system directory: /lib/xtables"
  if [ -f  $dbin/libxt_GTPURH_lib.so ] ; then
    $SUDO rm -f /lib/xtables/libxt_GTPURH.so /lib/xtables/libxt_GTPUAH.so
    $SUDO ln -s $dbin/libxt_GTPURH_lib.so /lib/xtables/libxt_GTPURH.so
    $SUDO ln -s $dbin/libxt_GTPUAH_lib.so /lib/xtables/libxt_GTPUAH.so
  else
    echo_fatal "not installed GTP-U iptables: binaries not found"
  fi
  # Do EPC
  if [ -f $OPENAIR_DIR/cmake_targets/epc_build_oai/build/mme_fd.conf ] ; then
    cp -uv $OPENAIR_DIR/cmake_targets/epc_build_oai/build/epc*.conf $dconf
    $SUDO cp -uv $OPENAIR_DIR/cmake_targets/epc_build_oai/build/mme_fd.conf  $FREEDIAMETER_PREFIX/etc/freeDiameter
  else
    echo_fatal "not installed EPC config files: not found"
  fi
    
}


main "$@"