diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py
index ffd93d79cfda1b24cf3e0ff0daf09017d97a47cc..db51f2647c9da88c281d35fa0c45864a1d9aaccb 100644
--- a/ci-scripts/cls_containerize.py
+++ b/ci-scripts/cls_containerize.py
@@ -342,6 +342,8 @@ class Containerize():
 		if self.ranAllowMerge and forceBaseImageBuild:
 			mySSH.command(self.cli + ' image rm ' + baseImage + ':' + baseTag + ' || true', '\$', 30)
 		mySSH.command(self.cli + ' image rm ran-build:' + imageTag + ' || true','\$', 5)
+		# Cleaning any created tmp volume
+		mySSH.command(self.cli + ' volume prune --force || true','\$', 15)
 		mySSH.close()
 		ZipFile('build_log_' + self.testCase_id + '.zip').extractall('.')
 
@@ -595,6 +597,8 @@ class Containerize():
 			mySSH.command('docker rm -f ' + containerName, '\$', 30)
 		# Forcing the down now to remove the networks and any artifacts
 		mySSH.command('docker-compose --file ci-docker-compose.yml down', '\$', 5)
+		# Cleaning any created tmp volume
+		mySSH.command('docker volume prune --force || true', '\$', 20)
 
 		mySSH.close()
 
@@ -754,6 +758,11 @@ class Containerize():
 			logging.error('\u001B[1m Undeploying OAI Object(s) FAILED\u001B[0m')
 			return
 
+		# Cleaning any created tmp volume
+		cmd = 'docker volume prune --force || true'
+		logging.debug(cmd)
+		deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
+
 		HTML.CreateHtmlTestRow('n/a', 'OK', CONST.ALL_PROCESSES_OK)
 		logging.info('\u001B[1m Undeploying OAI Object(s) PASS\u001B[0m')
 
diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index bf3bb2b017ce4bb01b0753576eeb95a9157232ce..f2eda66fc0e02e128b014f106185f37ea5e34baa 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1541,6 +1541,10 @@ set(PHY_LDPC_CL_SRC
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
 )
+add_custom_target( nrLDPC_decoder_kernels_CL
+                   COMMAND gcc ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c -dD -DNRLDPC_KERNEL_SOURCE -E -o ${CMAKE_CURRENT_BINARY_DIR}/nrLDPC_decoder_kernels_CL.clc
+                   SOURCES ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c
+)
 
 set(PHY_NR_CODINGIF
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_load.c;
@@ -1551,6 +1555,7 @@ add_library(ldpc_optim MODULE ${PHY_LDPC_OPTIM_SRC} )
 add_library(ldpc_optim8seg MODULE ${PHY_LDPC_OPTIM8SEG_SRC} )
 add_library(ldpc_cl MODULE ${PHY_LDPC_CL_SRC} )
 target_link_libraries(ldpc_cl OpenCL)
+add_dependencies(ldpc_cl nrLDPC_decoder_kernels_CL)
 
 if (CUDA_FOUND)
   cuda_add_library(ldpc_cuda MODULE ${PHY_LDPC_CUDA_SRC} )
@@ -2767,7 +2772,6 @@ target_link_libraries (test5Gnas LIB_5GNAS_GNB CONFIG_LIB minimal_lib )
 ###################################################
 
 add_executable(lte-softmodem
-  ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-enb.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/ru_control.c
@@ -2882,7 +2886,6 @@ target_link_libraries(du_test
 add_executable(oairu
   ${OPENAIR_TARGETS}/RT/USER/lte-ru.c
   ${OPENAIR_TARGETS}/RT/USER/ru_control.c
-  ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c
   ${OPENAIR_TARGETS}/ARCH/COMMON/record_player.c
   ${OPENAIR_DIR}/executables/softmodem-common.c
@@ -2910,7 +2913,6 @@ target_link_libraries (oairu pthread m ${CONFIG_LIB} rt ${CMAKE_DL_LIBS} ${T_LIB
 #######################################
 
 add_executable(lte-uesoftmodem
-  ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c
   ${OPENAIR_TARGETS}/RT/USER/lte-ue.c
   ${OPENAIR_TARGETS}/RT/USER/lte-uesoftmodem.c
   ${OPENAIR_DIR}/executables/softmodem-common.c
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index b427b161e584365149c72593f79fce80e9ac5794..2dc03967f67fa9caf2320936036f60ec6c9875ef 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -707,7 +707,7 @@ function main() {
 
     # generate USIM data
     if [ -f $dbin/conf2uedata ]; then
-      install_nas_tools $conf_nvram_path $gen_nvram_path
+      install_nas_tools $conf_nvram_path $gen_nvram_path "$dlog/conf2uedata.txt"
       echo_info "Copying UE specific part to $DIR/$build_dir/build"
       cp -Rvf $dbin/.ue_emm.nvram0 $DIR/$build_dir/build
       cp -Rvf $dbin/.ue.nvram0 $DIR/$build_dir/build
diff --git a/cmake_targets/install_external_packages.ubuntu20 b/cmake_targets/install_external_packages.ubuntu20
index f0314ca575eb32faf6776aa3027b58b8f2f2e6fd..0023c8d3c853d55f54d5b751a226355bf3698282 100755
--- a/cmake_targets/install_external_packages.ubuntu20
+++ b/cmake_targets/install_external_packages.ubuntu20
@@ -452,17 +452,6 @@ install_asn1c_from_source(){
     ) > "$asn1_install_log" 2>&1
 }
 
-#################################################
-# 2. compile
-################################################
-
-install_nas_tools() {
-    echo_success "generate .ue_emm.nvram .ue.nvram"
-    ./nvram --gen -c "$1" -o "$2"
-    ./usim --gen -c "$1" -o "$2"
-}
-
-
 ################################
 # set_openair_env
 ###############################
diff --git a/cmake_targets/nas_sim_tools/CMakeLists.txt b/cmake_targets/nas_sim_tools/CMakeLists.txt
index 308c71be4c2d3112234d6066191d6d6779aa4610..739e55a33efbadba951af67da2af96f9666815cd 100755
--- a/cmake_targets/nas_sim_tools/CMakeLists.txt
+++ b/cmake_targets/nas_sim_tools/CMakeLists.txt
@@ -15,6 +15,7 @@ set(CMAKE_C_FLAGS
 set(OPENAIR_DIR     $ENV{OPENAIR_DIR})
 set(OPENAIR3_DIR    $ENV{OPENAIR_DIR}/openair3)
 include_directories (${OPENAIR_DIR}/openair2/COMMON)
+include_directories (${OPENAIR_DIR})
 
 set(CONF2UEDATA_LIB_SRC
     ${OPENAIR_DIR}/openair3/NAS/TOOLS/conf_emm.c
diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper
index 06f32183b7feb3a9b9d1da3c56d78a3100354a92..a23d4eca9dd4ef7b6ceb06648c8c7546ade40642 100755
--- a/cmake_targets/tools/build_helper
+++ b/cmake_targets/tools/build_helper
@@ -892,20 +892,10 @@ install_asn1c_from_source(){
 ################################################
 
 install_nas_tools() {
-  if [ ! -f .ue.nvram0 ]; then
-    echo_success "generate .ue_emm.nvram .ue.nvram"
-    ./nvram --gen -c $1 -o $2
-  else
-    [ ./nvram -nt .ue.nvram0 -o ./nvram -nt .ue_emm.nvram0 ] && ./nvram --gen -c $1 -o $2
-  fi
-
-  if [ ! -f .usim.nvram0 ]; then
-    echo_success "generate .usim.nvram"
-    ./usim --gen -c $1 -o $2
-  else
-    [ ./usim -nt .usim.nvram0 ] && ./usim --gen -c $1 -o $2
-  fi
-
+  echo_success "generate .ue_emm.nvram .ue.nvram"
+  ./nvram --gen -c $1 -o $2 > "$3"
+  echo_success "generate .usim.nvram"
+  ./usim --gen -c $1 -o $2 >> "$3"
 }
 
 
diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c
index b961a5db671fc24a5d845e3c041f46129971611a..d336c1f2293f64bb3a5a878a0be4fb3f09312d13 100644
--- a/common/config/config_load_configmodule.c
+++ b/common/config/config_load_configmodule.c
@@ -224,11 +224,9 @@ configmodule_interface_t *load_configmodule(int argc,
     cfgparam = getenv("OAI_CONFIGMODULE");
   }
 
-  /* default different for UE and softmodem because UE doesn't use config file*/
+  /* default different for UE and softmodem because UE may run without config file */
   /* and -O option is not mandatory for UE                                    */
   /* phy simulators behave as UE                                              */
-  /* test of exec name would better be replaced by a parameter to the l       */
-  /* oad_configmodule function */
   if (cfgparam == NULL) {
     tmpflags = tmpflags | CONFIG_NOOOPT;
 
@@ -254,9 +252,14 @@ configmodule_interface_t *load_configmodule(int argc,
   }
 
   cfgptr = calloc(sizeof(configmodule_interface_t),1);
+  /* argv_info is used to memorize command line options which have been recognized */
+  /* and to detect unrecognized command line options which might have been specified */
   cfgptr->argv_info = calloc(sizeof(int32_t), argc);
+  /* argv[0] is the exec name, always Ok */
   cfgptr->argv_info[0] |= CONFIG_CMDLINEOPT_PROCESSED;
 
+  /* when OoptIdx is >0, -O option has been detected at position OoptIdx 
+   *  we must memorize arv[OoptIdx is Ok                                  */ 
   if (OoptIdx >= 0) {
     cfgptr->argv_info[OoptIdx] |= CONFIG_CMDLINEOPT_PROCESSED;
     cfgptr->argv_info[OoptIdx+1] |= CONFIG_CMDLINEOPT_PROCESSED;
diff --git a/common/utils/LOG/DOC/log.md b/common/utils/LOG/DOC/log.md
index 4b3e5981e1da3b4205bdc7f126fd92773d65730f..4d97e3845d77f533033512ec4a13660392d3ca69 100644
--- a/common/utils/LOG/DOC/log.md
+++ b/common/utils/LOG/DOC/log.md
@@ -8,7 +8,7 @@ By default, this facility is included at build-time and activated at run-time. T
 ```bash
 /build_oai --disable-T-Tracer
 ```
--  To use the the T-Tracer instead of the console logging facility, use the command line option *T_stdout*.  *T_stdout* is a boolean option, which, when set to 0 (false) disable the console logging facility. All stdout messages are then sent to the T-Tracer.
+-  To use the the T-Tracer, use the command line option *T_stdout*. When set to 0, it disables the console logging facility. All stdout messages are then sent to the T-Tracer. When set to 1 (the default), the logs are output to the linux console and no T trace is generated. When set to 2 both console logging and T traces are activated.
 
 ## Documentation
 
diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index d6444454245ee823e3a9967a7b82b3038474cdc5..350337b61be638ee3f7f20a8e441f9ea50f94c56 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -428,12 +428,12 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 
 #  if T_TRACER
 /* per component, level dependent macros */
-#    define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR    ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x)     ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x))   ;}} while (0)
-#    define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0)
+#    define LOG_E(c, x...) do { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x))  ; if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR    ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x)    ;} } while (0)
+#    define LOG_W(c, x...) do { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)); if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x);} } while (0)
 #    define LOG_A LOG_I
-#    define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO   ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x)    ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x))    ;}} while (0)
-#    define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x)   ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x))   ;}} while (0)
-#    define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x)   ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x))   ;}} while (0)
+#    define LOG_I(c, x...) do { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x))   ; if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO   ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x)   ;} } while (0)
+#    define LOG_D(c, x...) do { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x))  ; if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x)  ;} } while (0)
+#    define LOG_T(c, x...) do { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x))  ; if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x)  ;} } while (0)
 #    define VLOG(c,l, f, args) do { if (T_stdout) { if( g_log->log_component[c].level >= l  ) vlogRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, l, f, args)   ;} } while (0)
 /* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
 #    define LOG_DUMPMSG(c, f, b, s, x...) do {  if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x)  ;}   while (0)  /* */
diff --git a/common/utils/T/T.c b/common/utils/T/T.c
index 8ee359b77f491518e4aa934851f087bc040175c7..49742bf600795016afb6f168003bcfd2d31137a2 100644
--- a/common/utils/T/T.c
+++ b/common/utils/T/T.c
@@ -217,6 +217,11 @@ void T_Config_Init(void) {
                          sizeof(ttraceparams) / sizeof(paramdef_t),
                          NULL);
 
-  if (T_stdout == 0)
+  if (T_stdout < 0 || T_stdout > 2) {
+    printf("fatal error: T_stdout = %d but only values 0, 1, or 2 are allowed\n", T_stdout);
+    exit(1);
+  }
+
+  if (T_stdout == 0 || T_stdout == 2)
     T_init(T_port, 1-T_nowait, T_dont_fork);
 }
diff --git a/common/utils/T/T.h b/common/utils/T/T.h
index 626dbafd2586840657e515ca66a6f5ab8776080b..014294505454bd8640fa55525812e6c0dccf543e 100644
--- a/common/utils/T/T.h
+++ b/common/utils/T/T.h
@@ -100,7 +100,7 @@ extern int T_stdout;
                      20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)(__VA_ARGS__)
 #define TN_N(n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,\
              n18,n19,n20,n21,n22,n23,n24,n25,n26,n27,n28,n29,n30,n31,n32,n,...) T##n
-#define T(...) do { if (T_stdout == 0) TN(__VA_ARGS__); } while (0)
+#define T(...) do { if (T_stdout == 0 || T_stdout == 2) TN(__VA_ARGS__); } while (0)
 
 /* type used to send arbitrary buffer data */
 typedef struct {
@@ -607,7 +607,7 @@ extern int *T_active;
     {"T_port",                     CONFIG_HLP_TPORT,      0,                iptr:&T_port,        defintval:TTRACER_DEFAULT_PORTNUM, TYPE_INT,   0},\
     {"T_nowait",                   CONFIG_HLP_NOTWAIT,    PARAMFLAG_BOOL,   iptr:&T_nowait,      defintval:0,                       TYPE_INT,   0},\
     {"T_dont_fork",                CONFIG_HLP_TNOFORK,    PARAMFLAG_BOOL,   iptr:&T_dont_fork,   defintval:0,                       TYPE_INT,   0},\
-    {"T_stdout",                   CONFIG_HLP_STDOUT,     PARAMFLAG_BOOL,   iptr:&T_stdout,      defintval:1,                       TYPE_INT,   0},\
+    {"T_stdout",                   CONFIG_HLP_STDOUT,     0,                iptr:&T_stdout,      defintval:1,                       TYPE_INT,   0},\
   }
 
 
diff --git a/common/utils/system.c b/common/utils/system.c
index 93b13f03f26f5a7df026b1771d43632037eb02f9..d8970631446dc4b112b65af896f111120b40fcf5 100644
--- a/common/utils/system.c
+++ b/common/utils/system.c
@@ -211,6 +211,19 @@ void start_background_system(void) {
   background_system_process();
 }
 
+int rt_sleep_ns (uint64_t x)
+{
+  struct timespec myTime;
+  clock_gettime(CLOCK_MONOTONIC, &myTime);
+  myTime.tv_sec += x/1000000000ULL;
+  myTime.tv_nsec = x%1000000000ULL;
+  if (myTime.tv_nsec>=1000000000) {
+    myTime.tv_nsec -= 1000000000;
+    myTime.tv_sec++;
+  }
+
+  return clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &myTime, NULL);
+}
 
 void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){
   pthread_attr_t attr;
@@ -260,11 +273,128 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name,
   pthread_attr_destroy(&attr);
 }
 
+// Legacy, pthread_create + thread_top_init() should be replaced by threadCreate
+// threadCreate encapsulates the posix pthread api
+void thread_top_init(char *thread_name,
+		     int affinity,
+		     uint64_t runtime,
+		     uint64_t deadline,
+		     uint64_t period) {
+  
+#ifdef DEADLINE_SCHEDULER
+  struct sched_attr attr;
+
+  unsigned int flags = 0;
+
+  attr.size = sizeof(attr);
+  attr.sched_flags = 0;
+  attr.sched_nice = 0;
+  attr.sched_priority = 0;
+
+  attr.sched_policy   = SCHED_DEADLINE;
+  attr.sched_runtime  = runtime;
+  attr.sched_deadline = deadline;
+  attr.sched_period   = period; 
+
+  if (sched_setattr(0, &attr, flags) < 0 ) {
+    perror("[SCHED] eNB tx thread: sched_setattr failed\n");
+    fprintf(stderr,"sched_setattr Error = %s",strerror(errno));
+    exit(1);
+  }
+
+#else //LOW_LATENCY
+  int policy, s, j;
+  struct sched_param sparam;
+  char cpu_affinity[1024];
+  cpu_set_t cpuset;
+  int settingPriority = 1;
+
+  /* Set affinity mask to include CPUs 2 to MAX_CPUS */
+  /* CPU 0 is reserved for UHD threads */
+  /* CPU 1 is reserved for all RX_TX threads */
+  /* Enable CPU Affinity only if number of CPUs > 2 */
+  CPU_ZERO(&cpuset);
+
+#ifdef CPU_AFFINITY
+  if (affinity == 0) {
+    LOG_W(HW,"thread_top_init() called with affinity==0, but overruled by #ifdef CPU_AFFINITY\n");
+  }
+  else if (get_nprocs() > 2)
+  {
+    for (j = 2; j < get_nprocs(); j++)
+      CPU_SET(j, &cpuset);
+    s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+    if (s != 0)
+    {
+      perror( "pthread_setaffinity_np");
+      exit_fun("Error setting processor affinity");
+    }
+  }
+#else //CPU_AFFINITY
+  if (affinity) {
+    LOG_W(HW,"thread_top_init() called with affinity>0, but overruled by #ifndef CPU_AFFINITY.\n");
+  }
+#endif //CPU_AFFINITY
+
+  /* Check the actual affinity mask assigned to the thread */
+  s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
+  if (s != 0)
+  {
+    perror( "pthread_getaffinity_np");
+    exit_fun("Error getting processor affinity ");
+  }
+  memset(cpu_affinity,0,sizeof(cpu_affinity));
+  for (j = 0; j < 1024; j++)
+  {
+    if (CPU_ISSET(j, &cpuset))
+    {  
+      char temp[1024];
+      sprintf (temp, " CPU_%d", j);
+      strcat(cpu_affinity, temp);
+    }
+  }
+
+  if (checkIfFedoraDistribution())
+    if (checkIfGenericKernelOnFedora())
+      if (checkIfInsideContainer())
+        settingPriority = 0;
+
+  if (settingPriority) {
+    memset(&sparam, 0, sizeof(sparam));
+    sparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
+    policy = SCHED_FIFO;
+  
+    s = pthread_setschedparam(pthread_self(), policy, &sparam);
+    if (s != 0) {
+      perror("pthread_setschedparam : ");
+      exit_fun("Error setting thread priority");
+    }
+  
+    s = pthread_getschedparam(pthread_self(), &policy, &sparam);
+    if (s != 0) {
+      perror("pthread_getschedparam : ");
+      exit_fun("Error getting thread priority");
+    }
+
+    pthread_setname_np(pthread_self(), thread_name);
+
+    LOG_I(HW, "[SCHED][eNB] %s started on CPU %d, sched_policy = %s , priority = %d, CPU Affinity=%s \n",thread_name,sched_getcpu(),
+                     (policy == SCHED_FIFO)  ? "SCHED_FIFO" :
+                     (policy == SCHED_RR)    ? "SCHED_RR" :
+                     (policy == SCHED_OTHER) ? "SCHED_OTHER" :
+                     "???",
+                     sparam.sched_priority, cpu_affinity );
+  }
+
+#endif //LOW_LATENCY
+}
+
+
 // Block CPU C-states deep sleep
-void configure_linux(void) {
+void set_latency_target(void) {
   int ret;
   static int latency_target_fd=-1;
-  uint32_t latency_target_value=10; // in microseconds
+  uint32_t latency_target_value=2; // in microseconds
   if (latency_target_fd == -1) {
     if ( (latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR)) != -1 ) {
       ret = write(latency_target_fd, &latency_target_value, sizeof(latency_target_value));
diff --git a/common/utils/system.h b/common/utils/system.h
index c76fef9144a7c9cf64e78015046a020df416faf5..c25c2a6f1f7a6030776ee78292ceca8e4246036c 100644
--- a/common/utils/system.h
+++ b/common/utils/system.h
@@ -43,10 +43,9 @@ int background_system(char *command);
 void start_background_system(void);
 
 void set_latency_target(void);
-void configure_linux(void);
 
-void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority);
- 
+void threadCreate(pthread_t *t, void *(*func)(void *), void *param, char *name, int affinity, int priority);
+
 #define SCHED_OAI SCHED_RR
 #define OAI_PRIORITY_RT_LOW sched_get_priority_min(SCHED_OAI)
 #define OAI_PRIORITY_RT ((sched_get_priority_min(SCHED_OAI)+sched_get_priority_max(SCHED_OAI))/2)
@@ -65,7 +64,7 @@ void thread_top_init(char *thread_name,
 int checkIfFedoraDistribution(void);
 int checkIfGenericKernelOnFedora(void);
 int checkIfInsideContainer(void);
-
+int rt_sleep_ns (uint64_t x);
 #ifdef __cplusplus
 }
 #endif
diff --git a/common/utils/utils.c b/common/utils/utils.c
index 3f32881393b0934b8abd234fa96b08f6fa7a74d7..16402c1057fc052a628c6c61187fdcf456ed2f6d 100644
--- a/common/utils/utils.c
+++ b/common/utils/utils.c
@@ -7,23 +7,7 @@
 #include <errno.h>
 #include "utils.h"
 
-void *calloc_or_fail(size_t size) {
-  void *ptr = calloc(1, size);
-  if (ptr == NULL) {
-    fprintf(stderr, "[UE] Failed to calloc %zu bytes", size);
-    exit(EXIT_FAILURE);
-  }
-  return ptr;
-}
 
-void *malloc_or_fail(size_t size) {
-  void *ptr = malloc(size);
-  if (ptr == NULL) {
-    fprintf(stderr, "[UE] Failed to malloc %zu bytes", size);
-    exit(EXIT_FAILURE);
-  }
-  return ptr;
-}
 
 const char *hexdump(const void *data, size_t data_len, char *out, size_t out_len)
 {
diff --git a/common/utils/utils.h b/common/utils/utils.h
index d4337e71a6b7162164f92b2bbb1f2a264500a2b1..5963ae0c8e03b0e9652c5954fc053123078fa90a 100644
--- a/common/utils/utils.h
+++ b/common/utils/utils.h
@@ -1,15 +1,112 @@
 #ifndef _UTILS_H
 #define _UTILS_H
 
-#include <stdint.h>
-#include <sys/types.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <common/utils/assertions.h>
+
+#ifdef MALLOC_TRACE
+#define malloc myMalloc
+#endif
+
 #define sizeofArray(a) (sizeof(a)/sizeof(*(a)))
-void *calloc_or_fail(size_t size);
-void *malloc_or_fail(size_t size);
+
+#define cmax(a,b)  ((a>b) ? (a) : (b))
+#define cmax3(a,b,c) ((cmax(a,b)>c) ? (cmax(a,b)) : (c))
+#define cmin(a,b)  ((a<b) ? (a) : (b))
+
+#ifdef __cplusplus
+#ifdef min
+#undef min
+#undef max
+#endif
+#else
+#define max(a,b) cmax(a,b)
+#define min(a,b) cmin(a,b)
+#endif
+
+#ifndef malloc16
+#  ifdef __AVX2__
+#    define malloc16(x) memalign(32,x+32)
+#  else
+#    define malloc16(x) memalign(16,x+16)
+#  endif
+#endif
+#define free16(y,x) free(y)
+#define bigmalloc malloc
+#define bigmalloc16 malloc16
+#define openair_free(y,x) free((y))
+#define PAGE_SIZE 4096
+
+#define free_and_zero(PtR) do {     \
+    if (PtR) {           \
+      free(PtR);         \
+      PtR = NULL;        \
+    }                    \
+  } while (0)
+
+static inline void *malloc16_clear( size_t size ) {
+#ifdef __AVX2__
+  void *ptr = memalign(32, size+32);
+#else
+  void *ptr = memalign(16, size+16);
+#endif
+  DevAssert(ptr);
+  memset( ptr, 0, size );
+  return ptr;
+}
+
+
+static inline void *calloc_or_fail(size_t size) {
+  void *ptr = calloc(1, size);
+
+  if (ptr == NULL) {
+    fprintf(stderr, "[UE] Failed to calloc %zu bytes", size);
+    exit(EXIT_FAILURE);
+  }
+
+  return ptr;
+}
+
+static inline void *malloc_or_fail(size_t size) {
+  void *ptr = malloc(size);
+
+  if (ptr == NULL) {
+    fprintf(stderr, "[UE] Failed to malloc %zu bytes", size);
+    exit(EXIT_FAILURE);
+  }
+
+  return ptr;
+}
+
+#if !defined (msg)
+# define msg(aRGS...) LOG_D(PHY, ##aRGS)
+#endif
+#ifndef malloc16
+#  ifdef __AVX2__
+#    define malloc16(x) memalign(32,x)
+#  else
+#    define malloc16(x) memalign(16,x)
+#  endif
+#endif
+
+#define free16(y,x) free(y)
+#define bigmalloc malloc
+#define bigmalloc16 malloc16
+#define openair_free(y,x) free((y))
+#define PAGE_SIZE 4096
+
+#define PAGE_MASK 0xfffff000
+#define virt_to_phys(x) (x)
+
 const char *hexdump(const void *data, size_t data_len, char *out, size_t out_len);
 
 // Converts an hexadecimal ASCII coded digit into its value. **
diff --git a/docker/Dockerfile.phySim.rhel8.2 b/docker/Dockerfile.phySim.rhel8.2
index 0e76a12805e1128f8e7b5b7e915cbf5ec1e9512b..141a80cb50d80052e41cafdaf18415e8e5080bd6 100644
--- a/docker/Dockerfile.phySim.rhel8.2
+++ b/docker/Dockerfile.phySim.rhel8.2
@@ -27,6 +27,10 @@
 
 FROM ran-base:latest AS phy-sim-build
 
+RUN rm -Rf /oai-ran
+WORKDIR /oai-ran
+COPY . .
+
 #run build_oai to build the target image
 RUN /bin/sh oaienv && \ 
     cd cmake_targets && \
diff --git a/executables/main-ocp.c b/executables/main-ocp.c
index ab31eaaa4f17e10059d67b8334019039fd72be67..04315a4d57f3939e9187a7cf5b0a20113614039e 100644
--- a/executables/main-ocp.c
+++ b/executables/main-ocp.c
@@ -1150,7 +1150,7 @@ int main ( int argc, char **argv ) {
 #if T_TRACER
   T_Config_Init();
 #endif
-  configure_linux();
+  set_latency_target();
   set_softmodem_sighandler();
   cpuf=get_cpu_freq_GHz();
   set_taus_seed (0);
diff --git a/executables/nr-ru.c b/executables/nr-ru.c
index a2539a3adfaba2b4b487d312bee4a3d48d54a63c..c8cce5f9a1fdc19d33b805976f188f392d9b01dd 100644
--- a/executables/nr-ru.c
+++ b/executables/nr-ru.c
@@ -77,6 +77,7 @@ static int DEFBFW[] = {0x00007fff};
 
 #include "T.h"
 #include "nfapi_interface.h"
+#include <nfapi/oai_integration/vendor_ext.h>
 
 extern volatile int oai_exit;
 
@@ -1335,24 +1336,22 @@ void *ru_thread( void *param ) {
   
 
   while (!oai_exit) {
-    // these are local subframe/frame counters to check that we are in synch with the fronthaul timing.
-    // They are set on the first rx/tx in the underly FH routines.
-    slot_start = timespec_add(slot_start,slot_duration);
-    struct timespec curr_time;
-    clock_gettime(CLOCK_MONOTONIC, &curr_time);
-
-    struct timespec sleep_time;
-
-    if((slot_start.tv_sec > curr_time.tv_sec) || (slot_start.tv_sec == curr_time.tv_sec && slot_start.tv_nsec > curr_time.tv_nsec)){
-      sleep_time = timespec_sub(slot_start,curr_time);
+    
+    if (NFAPI_MODE==NFAPI_MODE_VNF) {
+      // We should make a VNF main loop with proper tasks calls in case of VNF
+      slot_start = timespec_add(slot_start,slot_duration);
+      struct timespec curr_time;
+      clock_gettime(CLOCK_MONOTONIC, &curr_time);
       
-      usleep(sleep_time.tv_nsec * 1e-3); 
-    }
-    else{//continue
+      struct timespec sleep_time;
+      
+      if((slot_start.tv_sec > curr_time.tv_sec) || (slot_start.tv_sec == curr_time.tv_sec && slot_start.tv_nsec > curr_time.tv_nsec)){
+	sleep_time = timespec_sub(slot_start,curr_time);
+	
+	usleep(sleep_time.tv_nsec * 1e-3); 
+      }
     }
-
-   // clock_gettime(CLOCK_MONOTONIC, &curr_time);
-    //printf("sfn:%d, slot:%d, start time %d.%d slot start %d.%d \n",frame,slot,curr_time.tv_sec,curr_time.tv_nsec,slot_start.tv_sec,slot_start.tv_nsec);
+    
     if (slot==(fp->slots_per_frame-1)) {
       slot=0;
       frame++;
diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 62bef5a34d6f38aa081886afcdffdfcbc4b634ed..2b8335167ac7fe3626ed278d76b79d8bac2e163f 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -656,7 +656,7 @@ int main( int argc, char **argv ) {
   memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS);
   memset(tx_max_power,0,sizeof(int)*MAX_NUM_CCs);
   logInit();
-  configure_linux();
+  set_latency_target();
   printf("Reading in command-line options\n");
   get_options ();
 
diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index 46c1cff49164800efa411fdf5464838b3fcc3a73..05f9efae3cd9919d96b5805b23414e7d3af4570e 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -698,6 +698,16 @@ void processSlotRX(void *arg) {
   int tx_slot_type = nr_ue_slot_select(cfg, proc->frame_tx, proc->nr_slot_tx);
   uint8_t gNB_id = 0;
 
+  if (IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa) {
+    /* send tick to RLC and PDCP every ms */
+    if (proc->nr_slot_rx % UE->frame_parms.slots_per_subframe == 0) {
+      void nr_rlc_tick(int frame, int subframe);
+      void nr_pdcp_tick(int frame, int subframe);
+      nr_rlc_tick(proc->frame_rx, proc->nr_slot_rx / UE->frame_parms.slots_per_subframe);
+      nr_pdcp_tick(proc->frame_rx, proc->nr_slot_rx / UE->frame_parms.slots_per_subframe);
+    }
+  }
+
   if (rx_slot_type == NR_DOWNLINK_SLOT || rx_slot_type == NR_MIXED_SLOT){
 
     if(UE->if_inst != NULL && UE->if_inst->dl_indication != NULL) {
@@ -720,14 +730,6 @@ void processSlotRX(void *arg) {
       protocol_ctxt_t ctxt;
       PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, UE->Mod_id, ENB_FLAG_NO, mac->crnti, proc->frame_rx, proc->nr_slot_rx, 0);
       pdcp_run(&ctxt);
-
-      /* send tick to RLC and PDCP every ms */
-      if (proc->nr_slot_rx % UE->frame_parms.slots_per_subframe == 0) {
-        void nr_rlc_tick(int frame, int subframe);
-        void nr_pdcp_tick(int frame, int subframe);
-        nr_rlc_tick(proc->frame_rx, proc->nr_slot_rx / UE->frame_parms.slots_per_subframe);
-        nr_pdcp_tick(proc->frame_rx, proc->nr_slot_rx / UE->frame_parms.slots_per_subframe);
-      }
     }
     // calling UL_indication to schedule things other than PUSCH (eg, PUCCH)
     rxtxD->ue_sched_mode = NOT_PUSCH;
diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index ac89bcfd4ea87665841005e63c63649025505fb0..c718b7a15cff4f973fa5586680c54501b9a53287 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -84,6 +84,7 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include "executables/thread-common.h"
 
 #include "nr_nas_msg_sim.h"
+#include <openair1/PHY/MODULATION/nr_modulation.h>
 
 extern const char *duplex_mode[];
 THREAD_STRUCT thread_struct;
@@ -522,7 +523,7 @@ int main( int argc, char **argv ) {
     // init UE_PF_PO and mutex lock
     pthread_mutex_init(&ue_pf_po_mutex, NULL);
     memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs);
-    configure_linux();
+    set_latency_target();
     mlockall(MCL_CURRENT | MCL_FUTURE);
 
     if(IS_SOFTMODEM_DOSCOPE) {
diff --git a/executables/ocp-gnb.c b/executables/ocp-gnb.c
index 7b4b1c6680eb1c9f8a6230b60d928b43f77447d2..462a07c7073884df12af47c2830efa59abe9bc32 100644
--- a/executables/ocp-gnb.c
+++ b/executables/ocp-gnb.c
@@ -920,7 +920,7 @@ int main( int argc, char **argv ) {
 #  define PACKAGE_VERSION "UNKNOWN"
 #endif
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
-  configure_linux();
+  set_latency_target();
   get_options ();
   get_common_options(SOFTMODEM_GNB_BIT );
   AssertFatal(!CONFIG_ISFLAGSET(CONFIG_ABORT),"Getting configuration failed\n");
diff --git a/openair1/PHY/CODING/DOC/LDPCImplementation.md b/openair1/PHY/CODING/DOC/LDPCImplementation.md
index c5411540b61a6c99bfbde094eb5d769690ca9737..a82c2040740dc1b3ab0597d44b575505b2e3f709 100644
--- a/openair1/PHY/CODING/DOC/LDPCImplementation.md
+++ b/openair1/PHY/CODING/DOC/LDPCImplementation.md
@@ -24,12 +24,33 @@ loading `libldpc_cl.so` instead of `libldpc.so`:
 
 `make ldpc_cl`
 
-`cp ../../../openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.cl`
+This command creates the `libldpc_cl.so` shared library. To perform this build successfully, only the OpenCL header `(/usr/include/CL/opencl.h)` and library `(/usr/lib/x86_64-linux-gnu/libOpenCL.so)`are required, they implement OpenCL API support which is not hardware dependent.
+
+```
+Scanning dependencies of target nrLDPC_decoder_kernels_CL
+Built target nrLDPC_decoder_kernels_CL
+Scanning dependencies of target ldpc_cl
+Building C object CMakeFiles/ldpc_cl.dir/usr/local/oai/oai-develop/openairinterface5g/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c.o
+In file included from /usr/include/CL/cl.h:32,
+                 from /usr/include/CL/opencl.h:38,
+                 from /usr/local/oai/oai-develop/openairinterface5g/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c:49:
+/usr/include/CL/cl_version.h:34:9: note: #pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)
+ #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)")
+         ^~~~~~~
+
+Building C object CMakeFiles/ldpc_cl.dir/usr/local/oai/oai-develop/openairinterface5g/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c.o
+Linking C shared module libldpc_cl.so
+Built target ldpc_cl
+
+```
+
+At runtime, to successfully use hardware acceleration via OpenCL, you need to install vendor specific packages which deliver the required drivers and tools to make use of their GPU (Nvidia, Intel...) , fpga (Xilinx, Intel) or CPU (Intel, AMD, ARM...) through OpenCL. 
 
 `./nr-softmodem -O  libconfig:gnb.band78.sa.fr1.106PRB.usrpb210.conf:dbgl5 --rfsim --rfsimulator.serveraddr server  --sa --log_config.gtpu_log_level info  --loader.ldpc.shlibversion _cl`
 
-``` [LOADER] library libldpc_cl.so successfully loaded
+``` 
 ------------------------------------------------
+[LOADER] library libldpc_cl.so successfully loaded
 [HW]   Platform 0, OpenCL profile FULL_PROFILE
 [HW]   Platform 0, OpenCL version OpenCL 2.1 LINUX
 [HW]   Device 0 is  available
@@ -62,8 +83,9 @@ loading `libldpc_cl.so` instead of `libldpc.so`:
 
 `./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa -O libconfig:/usr/local/oai/conf/nrue_sim.conf:dbgl5  --nokrnmod --loader.ldpc.shlibversion _cl --log_config.hw_log_level info`
 
-```[CONFIG] shlibversion set to  _cl from command line
+```
 ............................................................
+[CONFIG] shlibversion set to  _cl from command line
 [CONFIG] loader.ldpc 1 options set from command line
 [LOADER] library libldpc_cl.so successfully loaded
 [HW]   Platform 0, OpenCL profile FULL_PROFILE
@@ -94,7 +116,6 @@ loading `libldpc_cl.so` instead of `libldpc.so`:
 [HW]   Device 0, max Work Items size for dimension: 1 512
 [HW]   Device 0, max Work Items size for dimension: 2 512 
 ------------------------------------------------------------
-​```
 ```
 
 A mechanism to select ldpc implementation is also available in the `ldpctest` phy simulator via the `-v`option, which can be used to specify the version of the ldpc shared library to be used.
@@ -103,7 +124,9 @@ A mechanism to select ldpc implementation is also available in the `ldpctest` ph
 
 Loading libldpc_cuda.so, the cuda implementation of the ldpc decoder:
 
-```$ ./ldpctest -v _cuda
+```
+$ ./ldpctest -v _cuda
+ldpctest -v _cuda
 Initializing random number generator, seed 0
 block length 8448: 
 n_trials 1: 
@@ -119,18 +142,16 @@ log init done
 [CONFIG] loader.ldpc: 1/2 parameters successfully set 
 [LOADER] library libldpc_cuda.so successfully loaded
 ...................................
-​```
 ```
 
+
 Loading libldpc_cl.so, the opencl implementation of the ldpc decoder:
 
 `make ldpc_cl`
 
-`cp ../../../openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.cl`
 
-`./ldpctest -v _cl`
-
-```$ ./ldpctest -v _cl
+```
+$ ./ldpctest -v _cl
 Initializing random number generator, seed 0
 block length 8448: 
 n_trials 1: 
@@ -164,7 +185,6 @@ log init done
 [HW]   Device 0, max Work Items size for dimension: 1 512
 [HW]   Device 0, max Work Items size for dimension: 2 512
 ................................
-​```
 ```
 
 
@@ -174,6 +194,6 @@ Libraries implementing the LDPC algorithms must be named `libldpc<_version>.so`,
 
 `libldpc_cuda.so`has been tested with the `ldpctest` executable, usage from the softmodem's has to be tested.
 
-`libldpc_cl`is under development.
+`libldpc_cl.so`is under development.
 
 [oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)
diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
index aff707a1d5e74c7833f5e4782690d05df3220b30..371deba3f28546e5a01f0107c03f88e2fa6b8c14 100644
--- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c
+++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
@@ -514,7 +514,7 @@ int main(int argc, char *argv[])
   unsigned char qbits=8;
   unsigned int decoded_errors[10000]; // initiate the size of matrix equivalent to size of SNR
   int c,i=0, i1 = 0;
-
+  int loglvl=OAILOG_WARNING;
   int n_trials = 1;
   double SNR_step = 0.1;
 
@@ -525,8 +525,11 @@ int main(int argc, char *argv[])
   n_iter_stats_t dec_iter[3];
 
   short BG=0,Zc,Kb=0;
-
-  while ((c = getopt (argc, argv, "q:r:s:S:l:G:n:d:i:t:u:hv:")) != -1)
+  if ( load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) == 0) {
+    exit_fun(" Error, configuration module init failed\n");
+  } // must be done before specific options parsing to prevent errasing them
+  
+  while ((c = getopt (argc, argv, "q:r:s:S:l:L:G:n:d:i:t:u:hv:")) != -1)
     switch (c)
     {
       case 'q':
@@ -544,6 +547,10 @@ int main(int argc, char *argv[])
       case 'l':
         block_length = atoi(optarg);
         break;
+
+      case 'L':
+        loglvl = atoi(optarg);
+        break;
 		
       case 'G':
         ldpc_version="_cuda";
@@ -581,10 +588,11 @@ int main(int argc, char *argv[])
               printf("BG1 (blocklength > 3840): 1/3, 2/3, 22/25 (8/9) \n");
               printf("BG2 (blocklength <= 3840): 1/5, 1/3, 2/3 \n\n");
               printf("-h This message\n");
+              printf("-L <log level, 0(errors), 1(warning), 2(info) 3(debug) 4 (trace)>\n");              
               printf("-q Quantization bits, Default: 8\n");
               printf("-r Nominator rate, (1, 2, 22), Default: 1\n");
               printf("-d Denominator rate, (3, 5, 25), Default: 1\n");
-              printf("-l Block length (l > 3840 -> BG1, rest BG2 ), Default: 8448\n");
+              printf("-l Block length (l > 3840 -> BG1, rest BG2 ), Default: 8448\n");              
 			  printf("-G give 1 to run cuda for LDPC, Default: 0\n");
               printf("-n Number of simulation trials, Default: 1\n");
               //printf("-M MCS2 for TB 2\n");
@@ -603,6 +611,8 @@ int main(int argc, char *argv[])
   printf("n_trials %d: \n", n_trials);
   printf("SNR0 %f: \n", SNR0);
 
+  logInit();
+  set_glog(loglvl);
 
   if (ldpc_version != NULL)
     load_nrLDPClib(ldpc_version);
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c
index 58e6b507afd979f1db9fa4e13d3c11b5ca58b811..c60286ab3a27b343d99a609f65715b398677ac36 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_CL.c
@@ -25,32 +25,37 @@
 * \version 1.0
 * \note initial implem - translation of cuda version
 */
+
+
+#define MAX_ITERATION 2
+#define MC	1
+
+#define MAX_OCLDEV   10
+#define MAX_OCLRUNTIME 5
+
+typedef struct{
+  char x;
+  char y;
+  short value;
+} h_element;
+
+#ifdef NRLDPC_KERNEL_SOURCE
+#include "nrLDPC_decoder_kernels_CL.c"
+#else
 /* uses HW  component id for log messages ( --log_config.hw_log_level <warning| info|debug|trace>) */
 #include <stdio.h>
 #include <unistd.h>
-#include <cuda_runtime.h>
+#include <sys/stat.h>
 #include <CL/opencl.h>
 #include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
 #include "PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h"
 #include "assertions.h"
 #include "common/utils/LOG/log.h"
 
-#define MAX_ITERATION 2
-#define MC	1
-
-#define MAX_OCLDEV   10
-#define MAX_OCLRUNTIME 5
-
-
 #define CLSETKERNELARG(A,B,C,D) \
 rt=clSetKernelArg(A,B,C,D) ;\
 AssertFatal(rt == CL_SUCCESS, "Error %d setting kernel argument index %d\n" , (int)rt, B);
 
-typedef struct{
-  char x;
-  char y;
-  short value;
-} h_element;
 #include "../nrLDPC_decoder_LYC/bgs/BG1_compact_in_C.h"
 
 typedef struct{
@@ -213,20 +218,31 @@ void get_CompilErr(cl_program program, int pltf) {
 
 }
 
-size_t load_source(char **source_str) {
-	int MAX_SOURCE_SIZE=(500*132);
+size_t load_source(char **source_str, char *filename) {
     FILE *fp;
+    struct stat st ;
     size_t source_size;
- 
-    fp = fopen("nrLDPC_decoder_kernels_CL.cl", "r");
-    AssertFatal(fp,"failed to open cl source: %s\n",strerror(errno));
+    char *src= NULL;
     
-    *source_str = (char*)malloc(MAX_SOURCE_SIZE);
-    source_size = fread( *source_str, 1, MAX_SOURCE_SIZE, fp);
-    fclose( fp );
-    return source_size;
+  if (filename == NULL) {
+	src = "nrLDPC_decoder_kernels_CL.clc";
+  } else {
+	src = filename;
+  }
+  fp = fopen(src, "r");
+  AssertFatal(fp,"failed to open cl source %s: %s\n",src,strerror(errno));
+
+  fstat(fileno(fp), &st);
+  source_size = st.st_size;    
+  *source_str = (char*)malloc(source_size);
+  source_size = fread( *source_str, 1, source_size, fp);
+  fclose( fp );
+  LOG_I(HW,"Loaded kernel sources from %s %u bytes\n", (filename==NULL)?"embedded cl code":src,(unsigned int)source_size );
+  return source_size;
 }
 
+
+
 /* from here: entry points in decoder shared lib */
 int ldpc_autoinit(void) {   // called by the library loader 
   cl_platform_id platforms[10];
@@ -284,11 +300,11 @@ int ldpc_autoinit(void) {   // called by the library loader
         ocl.runtime[i].dev_tmp = clCreateBuffer(ocl.runtime[i].context, CL_MEM_READ_ONLY|CL_MEM_HOST_WRITE_ONLY, 68*384, NULL, (cl_int *)&rt);
         AssertFatal(rt == CL_SUCCESS, "Error %d creating buffer dev_tmp for platform %i \n" , (int)rt, i);      
         char *source_str;
-        size_t source_size=load_source(&source_str);      
+        size_t source_size=load_source(&source_str,"nrLDPC_decoder_kernels_CL.clc");      
         cl_program program = clCreateProgramWithSource(ocl.runtime[i].context, 1, 
                                                        (const char **)&source_str, (const size_t *)&source_size,  (cl_int *)&rt);
         AssertFatal(rt == CL_SUCCESS, "Error %d creating program for platform %i \n" , (int)rt, i); 
-        rt = clBuildProgram(program, ocl.runtime[i].num_devices,ocl.runtime[i].devices, NULL, NULL, NULL);  
+        rt = clBuildProgram(program, ocl.runtime[i].num_devices,ocl.runtime[i].devices, NULL /* compile options */, NULL, NULL);  
         if (rt == CL_BUILD_PROGRAM_FAILURE) {
           get_CompilErr(program,i);
 	    } 
@@ -434,3 +450,4 @@ int32_t nrLDPC_decod(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_
 	return MAX_ITERATION;
 	
 }
+#endif //NRLDPC_KERNEL_SOURCE
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.cl b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.c
similarity index 98%
rename from openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.cl
rename to openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.c
index d5e2fa569559c227ee2a558ae32b5202b50b470b..42b25e41c0eb745539d143c6c07aafa49a216560 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.cl
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder_kernels_CL.c
@@ -29,16 +29,7 @@
 * \note initial implem - translation of cuda version
 * \warning
 */
-#define define MAX_ITERATION 2
-#define MC	1
 
-#define INT32_MAX 2147483647
-
-typedef struct{
-  char x;
-  char y;
-  short value;
-} h_element;
 
 //__global char dev_dt [46*68*384];
 //__local char *dev_t;
@@ -46,7 +37,7 @@ typedef struct{
 //__global unsigned char dev_tmp[68*384];
 
 
-
+#define INT32_MAX 2147483647
 
 //__constant h_element dev_h_compact1[46*19] = {};  // used in kernel 1
 //__constant h_element dev_h_compact2[68*30] = {};  // used in kernel 2
@@ -299,4 +290,3 @@ __kernel void pack_decoded_bit(__global unsigned char * dev_llr, __global unsign
 		}
 	}
 }
-
diff --git a/openair1/PHY/CODING/nrLDPC_load.c b/openair1/PHY/CODING/nrLDPC_load.c
index 23e5032badcddd69ad2a1d51288f0f57454b7a98..3049070cd653f9b99f458babc3485f227bd679e2 100644
--- a/openair1/PHY/CODING/nrLDPC_load.c
+++ b/openair1/PHY/CODING/nrLDPC_load.c
@@ -46,14 +46,14 @@ static loader_shlibfunc_t shlib_fdesc[3];
 
 /* arguments used when called from phy simulators exec's which do not use the config module */
 /* arg is used to initialize the config module so that the loader works as expected */
-char *arg[64]={"ldpctest","-O","cmdlineonly::dbgl0",NULL,NULL};
+char *arg[64]={"ldpctest",NULL};
 
 int load_nrLDPClib(char *version) {
 	 char *ptr = (char*)config_get_if();
 	 char libname[64]="ldpc";
 
      if ( ptr==NULL )  {// phy simulators, config module possibly not loaded
-     	 load_configmodule(0,(char **)NULL,CONFIG_ENABLECMDLINEONLY) ;
+     	 load_configmodule(1,arg,CONFIG_ENABLECMDLINEONLY) ;
      	 logInit();
      }	 
      shlib_fdesc[0].fname = "nrLDPC_decod";
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index fd5cc962b154847d431c5323493ec06229420839..0c727e1287651a2ff9e9ddd5f8e03f0e03a99756 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -32,6 +32,7 @@
 #include "PHY/NR_REFSIG/ul_ref_seq_nr.h"
 #include "PHY/NR_REFSIG/refsig_defs_ue.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
+#include <openair1/PHY/MODULATION/nr_modulation.h>
 
 #if 0
 void phy_config_harq_ue(module_id_t Mod_id,
diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c
index 347155ed3b08d5393bc59abc1662b0582be2cc08..35bc28d9c111f67aada20fa34a9984b65b04d2af 100644
--- a/openair1/PHY/INIT/nr_parms.c
+++ b/openair1/PHY/INIT/nr_parms.c
@@ -250,11 +250,9 @@ int nr_init_frame_parms(nfapi_nr_config_request_scf_t* cfg,
   int Ncp = NFAPI_CP_NORMAL;
   int mu = cfg->ssb_config.scs_common.value;
 
-#if DISABLE_LOG_X
-  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, fp->N_RB_DL, Ncp);
-#else
+
   LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, fp->N_RB_DL, Ncp);
-#endif
+
 
   if (Ncp == NFAPI_CP_EXTENDED)
     AssertFatal(mu == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, mu);
@@ -343,11 +341,8 @@ int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *fp,
 
   AssertFatal(fp->ul_CarrierFreq == (fp->dl_CarrierFreq + uplink_frequency_offset), "Disagreement in uplink frequency for band %d: ul_CarrierFreq = %lu Hz vs expected %lu Hz\n", fp->nr_band, fp->ul_CarrierFreq, fp->dl_CarrierFreq + uplink_frequency_offset);
 
-#if DISABLE_LOG_X
-  printf("Initializing UE frame parms for mu %d, N_RB %d, Ncp %d\n",fp->numerology_index, fp->N_RB_DL, Ncp);
-#else
   LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",fp->numerology_index, fp->N_RB_DL, Ncp);
-#endif
+
 
   if (Ncp == NFAPI_CP_EXTENDED)
     AssertFatal(fp->numerology_index == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, fp->numerology_index);
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
index b5bcb0848d4d489f6ba862f21f81ddc74aba7fec..3ccbd8ca35ad7218ffccebfee25c00fd35816261 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
@@ -42,7 +42,6 @@
 #include "common/utils/LOG/log.h"
 #include "targets/RT/USER/lte-softmodem.h"
 #include <syscall.h>
-#include "targets/RT/USER/rt_wrapper.h"
 #include <common/utils/threadPool/thread-pool.h>
 
 //#define DEBUG_DLSCH_CODING
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/pcfich_ue.c b/openair1/PHY/LTE_UE_TRANSPORT/pcfich_ue.c
index 66ed4593d88f886996e6788a533f384e503fbd08..67d811b753f10b5d9fb2bf3fca90cc8156ced96f 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/pcfich_ue.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/pcfich_ue.c
@@ -44,14 +44,14 @@ void pcfich_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
                          int16_t *d)
 {
 
-  uint8_t reset = 1;
-  uint32_t x1 = 0;
-  uint32_t s = 0;
+  uint32_t i;
+  uint8_t reset;
+  uint32_t x1=0, x2=0, s=0;
 
-  // x1 is set in lte_gold_generic
-  uint32_t x2 = ((((2*frame_parms->Nid_cell)+1)*(1+subframe))<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.7.1
+  reset = 1;
+  x2 = ((((2*frame_parms->Nid_cell)+1)*(1+subframe))<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.7.1
 
-  for (uint32_t i=0; i<32; i++) {
+  for (i=0; i<32; i++) {
     if ((i&0x1f)==0) {
       s = lte_gold_generic(&x1, &x2, reset);
       //printf("lte_gold[%d]=%x\n",i,s);
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index 28dd5ab21924dd546b829e7d6ccb6c5ba93ff1fb..681a9eae16b11946a8aa0d85722e68f275caab47 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -1174,7 +1174,7 @@ int nr_rx_pusch(PHY_VARS_gNB *gNB,
 
   uint8_t aarx, aatx;
   uint32_t nb_re_pusch, bwp_start_subcarrier;
-  int avgs;
+  int avgs = 0;
 
   NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
   nfapi_nr_pusch_pdu_t *rel15_ul = &gNB->ulsch[ulsch_id][0]->harq_processes[harq_pid]->ulsch_pdu;
diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
index 8844a530afe2dbba066d7f02a8d3b2c16a421a20..22c8ff0b0ec99d1dc09a4b0e5a5126d4582e6595 100644
--- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c
+++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
@@ -302,7 +302,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB,
   int32_t corr_re[1+frame_parms->nb_antennas_rx][2];
   int32_t corr_im[1+frame_parms->nb_antennas_rx][2];
   //int32_t no_corr = 0;
-  int seq_index;
+  int seq_index = 0;
   int64_t temp;
 
   for(i=0;i<nr_sequences;i++){
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index b8cd59eeadf5af4f4dc5dcf07b1bf4aee9edef84..95c451fa1a1b5a6085aa700e3deb161008fa8410 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -642,7 +642,6 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
   if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD))
     LOG_I(PHY,"Segmentation: C %d, K %d\n",harq_process->C,harq_process->K);
 
-  opp_enabled=1;
   Kr = harq_process->K; // [hna] overwrites this line "Kr = p_decParams->Z*kb"
   Kr_bytes = Kr>>3;
   offset = 0;
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
index 0894ae91669193c0d64ec30f1826e7696885e25d..b4edae972a574df3de9d1b6da02a753e91e11c8e 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
@@ -379,13 +379,10 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
   len = (pilots==1)? ((config_type==NFAPI_NR_DMRS_TYPE1)?nb_rb*(12-6*dlsch0_harq->n_dmrs_cdm_groups): nb_rb*(12-4*dlsch0_harq->n_dmrs_cdm_groups)):(nb_rb*12);
 
   stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-  printf("[AbsSFN %u.%d] Slot%d Symbol %d type %d: Pilot/Data extraction %5.2f \n",
-	 frame,nr_slot_rx,slot,symbol,type,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-  LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d type %d: Pilot/Data extraction %5.2f \n",
-	frame,nr_slot_rx,slot,symbol,type,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+  if (cpumeas(CPUMEAS_GETSTATE))
+    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d type %d: Pilot/Data extraction %5.2f \n",
+	  frame,nr_slot_rx,slot,symbol,type,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
+
   
   start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
   n_tx = dlsch0_harq->Nl;
@@ -402,11 +399,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
                          nb_rb_pdsch);
 
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-    printf("[AbsSFN %u.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
+
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
   if (first_symbol_flag==1) {
     if (beamforming_mode==0){
@@ -463,11 +458,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
 #endif
 
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-    printf("[AbsSFN %u.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,nr_slot_rx,slot,symbol,first_symbol_flag,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,nr_slot_rx,slot,symbol,first_symbol_flag,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,nr_slot_rx,slot,symbol,first_symbol_flag,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 // Now channel compensation
@@ -515,11 +507,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
   }
 
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-    printf("[AbsSFN %u.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n", frame, nr_slot_rx, slot, symbol, pdsch_vars[gNB_id]->log2_maxh, proc->channel_level, ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp  %5.2f \n", frame, nr_slot_rx, slot, symbol, pdsch_vars[gNB_id]->log2_maxh, proc->channel_level, ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp  %5.2f \n", frame, nr_slot_rx, slot, symbol, pdsch_vars[gNB_id]->log2_maxh, proc->channel_level, ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
+
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 
   if (frame_parms->nb_antennas_rx > 1) {
@@ -574,11 +564,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
   }
   
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-    printf("[AbsSFN %u.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
+
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
   /* Store the valid DL RE's */
     pdsch_vars[gNB_id]->dl_valid_re[symbol-1] = len;
@@ -657,11 +645,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
     }
 
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#if DISABLE_LOG_X
-    printf("[AbsSFN %u.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#else
-    LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: LLR Computation  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: LLR Computation  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 
 // Please keep it: useful for debugging
 #ifdef DEBUG_PDSCH_RX
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
index 767edf9cc65a29f730ce1484b74b33c47ba1dc03..2963ad5010f476f12af63a67930931e711b7c616 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
@@ -353,21 +353,15 @@ int nr_initial_sync(UE_nr_rxtx_proc_t *proc,
   if( (abs(ue->common_vars.freq_offset) > 150) && (ret == 0) )
   {
 	  ret=-1;
-#if DISABLE_LOG_X
-	  printf("Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset);
-#else
 	  LOG_E(HW, "Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset);
-#endif
   }*/
 
   if (ret==0) {  // PBCH found so indicate sync to higher layers and configure frame parameters
 
     //#ifdef DEBUG_INITIAL_SYNCH
-#if DISABLE_LOG_X
-    printf("[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
-#else
+
     LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
-#endif
+
     //#endif
 
     if (ue->UE_scan_carrier == 0) {
diff --git a/openair1/PHY/TOOLS/calibration_test.c b/openair1/PHY/TOOLS/calibration_test.c
index 53baf83d41dbaab0834f88219300ce6fabfe4c43..5dced270604cfa0ec5f8b6a40a4886d2758d9021 100644
--- a/openair1/PHY/TOOLS/calibration_test.c
+++ b/openair1/PHY/TOOLS/calibration_test.c
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
   get_common_options(SOFTMODEM_GNB_BIT );
   config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL);
   CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP);
-  configure_linux();
+  set_latency_target();
 
     
   int N_RB=50;
diff --git a/openair1/PHY/TOOLS/lte_enb_scope.c b/openair1/PHY/TOOLS/lte_enb_scope.c
index 8d333d9730647f8dca40f1008ae162de02265b42..33772a5d0d428468f9a422fd4d221afecc124424 100644
--- a/openair1/PHY/TOOLS/lte_enb_scope.c
+++ b/openair1/PHY/TOOLS/lte_enb_scope.c
@@ -49,9 +49,15 @@ void reset_stats(FL_OBJECT *button, long arg) {
   int i,j,k;
   PHY_VARS_eNB *phy_vars_eNB = RC.eNB[0][0];
 
-  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
-    for (k=0; k<NUMBER_OF_DLSCH_MAX; k++) { //harq_processes
-      for (j=0; j<phy_vars_eNB->dlsch[k][0]->Mlimit; j++) {
+  printf("XXX %d %d %d\n",
+	 sizeofArray(phy_vars_eNB->UE_stats),
+	 sizeofArray( phy_vars_eNB->UE_stats[i].dlsch_NAK),
+	 sizeofArray( *phy_vars_eNB->UE_stats[i].dlsch_NAK)
+	 );
+
+  for (i=0; i<sizeofArray(phy_vars_eNB->UE_stats); i++) {
+    for (k=0; k<sizeofArray(phy_vars_eNB->UE_stats[i].dlsch_NAK); k++) { //harq_processes
+      for (j=0; j<sizeofArray(*phy_vars_eNB->UE_stats[i].dlsch_NAK); j++) {
         phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0;
         phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0;
         phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0;
@@ -67,7 +73,6 @@ void reset_stats(FL_OBJECT *button, long arg) {
   }
 }
 
-
 static void *scope_thread_eNB(void *arg) {
   struct sched_param sched_param;
   int UE_id, CC_id;
@@ -75,7 +80,6 @@ static void *scope_thread_eNB(void *arg) {
   sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1;
   sched_setscheduler(0, SCHED_FIFO,&sched_param);
   printf("Scope thread has priority %d\n",sched_param.sched_priority);
-
   while (!oai_exit) {
     ue_cnt=0;
 
diff --git a/openair1/PHY/TOOLS/time_meas.c b/openair1/PHY/TOOLS/time_meas.c
index 1b62687f7ef8cbeaf842c680499222068f08cd02..353f170434a2d4ddbc2cff2d6d4b2a5704186cda 100644
--- a/openair1/PHY/TOOLS/time_meas.c
+++ b/openair1/PHY/TOOLS/time_meas.c
@@ -51,24 +51,7 @@ double get_cpu_freq_GHz(void)
   return cpu_freq_GHz;
 }
 
-int cpumeas(int action)
-{
-  switch (action) {
-    case CPUMEAS_ENABLE:
-      opp_enabled = 1;
-      break;
-
-    case CPUMEAS_DISABLE:
-      opp_enabled = 0;
-      break;
 
-    case CPUMEAS_GETSTATE:
-    default:
-      break;
-  }
-
-  return opp_enabled;
-}
 
 void print_meas_now(time_stats_t *ts,
                     const char *name,
diff --git a/openair1/PHY/TOOLS/time_meas.h b/openair1/PHY/TOOLS/time_meas.h
index bb2bb3d2764c94ab694cbd52787d4f453ed5d5d1..56d8299470df7983645700c32e83fa3cd885910b 100644
--- a/openair1/PHY/TOOLS/time_meas.h
+++ b/openair1/PHY/TOOLS/time_meas.h
@@ -115,7 +115,24 @@ static inline uint32_t rdtsc_oai(void) {
 #define CPUMEAS_DISABLE  0
 #define CPUMEAS_ENABLE   1
 #define CPUMEAS_GETSTATE 2
-int cpumeas(int action);
+static inline int cpumeas(int action) {
+  switch (action) {
+    case CPUMEAS_ENABLE:
+      opp_enabled = 1;
+      break;
+
+    case CPUMEAS_DISABLE:
+      opp_enabled = 0;
+      break;
+
+    case CPUMEAS_GETSTATE:
+    default:
+      break;
+  }
+
+  return opp_enabled;
+}
+
 static inline void start_meas(time_stats_t *ts) {
   if (opp_enabled) {
     if (ts->meas_flag==0) {
diff --git a/openair1/PHY/impl_defs_top.h b/openair1/PHY/impl_defs_top.h
index 31b98996057b1a677d1c2cfed93d6ceff0750417..ad68bc5769113e0f067ddf66188d410184e13537 100644
--- a/openair1/PHY/impl_defs_top.h
+++ b/openair1/PHY/impl_defs_top.h
@@ -107,11 +107,10 @@
  * @}
  */
 
+#include <common/utils/utils.h>
 #include "defs_eNB.h"
 #include "types.h"
 
-
-
 /** @addtogroup _PHY_STRUCTURES_
  * @{
 */
@@ -315,50 +314,6 @@ typedef struct {
 #include "openairinterface5g_limits.h"
 #include "assertions.h"
 
-#define cmax(a,b)  ((a>b) ? (a) : (b))
-#define cmax3(a,b,c) ((cmax(a,b)>c) ? (cmax(a,b)) : (c))
-#define cmin(a,b)  ((a<b) ? (a) : (b))
-
-#ifdef __cplusplus
-#ifdef min
-#undef min
-#undef max
-#endif
-#else
-#define max(a,b) cmax(a,b)
-#define min(a,b) cmin(a,b)
-#endif
-
-#ifndef malloc16
-#  ifdef __AVX2__
-#    define malloc16(x) memalign(32,x+32)
-#  else
-#    define malloc16(x) memalign(16,x+16)
-#  endif
-#endif
-#define free16(y,x) free(y)
-#define bigmalloc malloc
-#define bigmalloc16 malloc16
-#define openair_free(y,x) free((y))
-#define PAGE_SIZE 4096
-#define free_and_zero(PtR) do { \
-      if (PtR) {           \
-        free(PtR);         \
-        PtR = NULL;        \
-      }                    \
-    } while (0)
-static inline void* malloc16_clear( size_t size )
-{
-#ifdef __AVX2__
-  void* ptr = memalign(32, size+32);
-#else
-  void* ptr = memalign(16, size+16);
-#endif
-  DevAssert(ptr);
-  memset( ptr, 0, size );
-  return ptr;
-}
-
 #endif //__PHY_IMPLEMENTATION_DEFS_H__ 
 /**@} 
 */
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index fa9cb746f25390f07cb3fea7f9c5f5c269a3b26c..73200d4d9938aa60b8bcd847deced4e327b9c5ca 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -855,8 +855,8 @@ int nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int gNB_
       } else AssertFatal(1==0,"Not RA_PDSCH, SI_PDSCH or PDSCH\n");
 
       stop_meas(&ue->dlsch_llr_stats_parallelization[proc->thread_id][slot]);
-      LOG_D(PHY, "[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",frame_rx,nr_slot_rx,m,ue->dlsch_llr_stats_parallelization[proc->thread_id][slot].p_time/(cpuf*1000.0));
-
+      if (cpumeas(CPUMEAS_GETSTATE))
+        LOG_D(PHY, "[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",frame_rx,nr_slot_rx,m,ue->dlsch_llr_stats_parallelization[proc->thread_id][slot].p_time/(cpuf*1000.0));
       if(first_symbol_flag) {
         proc->first_symbol_available = 1;
       }
@@ -1031,14 +1031,13 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
 
     LOG_D(PHY, "In %s DL PDU length in bits: %d, in bytes: %d \n", __FUNCTION__, dlsch0->harq_processes[harq_pid]->TBS, dlsch0->harq_processes[harq_pid]->TBS / 8);
 
-
-
-
-      stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-    LOG_D(PHY, " --> Unscrambling for CW0 %5.3f\n",
-          (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-    LOG_D(PHY, "AbsSubframe %d.%d --> LDPC Decoding for CW0 %5.3f\n",
-          frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
+    stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
+    if (cpumeas(CPUMEAS_GETSTATE))  {
+      LOG_D(PHY, " --> Unscrambling for CW0 %5.3f\n",
+            (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+      LOG_D(PHY, "AbsSubframe %d.%d --> LDPC Decoding for CW0 %5.3f\n",
+            frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
+    }
 
     if(is_cw1_active) {
       // start ldpc decode for CW 1
@@ -1090,21 +1089,15 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
         LOG_T(PHY,"CWW sequential dlsch decoding, ret1 = %d\n", ret1);
       }
 
-
       stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-
-      LOG_D(PHY, " --> Unscrambling for CW1 %5.3f\n",
-            (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-      LOG_D(PHY, "AbsSubframe %d.%d --> ldpc Decoding for CW1 %5.3f\n",
-            frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
-      LOG_D(PHY,"AbsSubframe %d.%d --> ldpc Decoding for CW1 %5.3f\n",
-            frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
-
-      LOG_D(PHY, "harq_pid: %d, TBS expected dlsch1: %d \n", harq_pid, dlsch1->harq_processes[harq_pid]->TBS);
+      if (cpumeas(CPUMEAS_GETSTATE)) {
+        LOG_D(PHY, " --> Unscrambling for CW1 %5.3f\n",
+              (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+        LOG_D(PHY, "AbsSubframe %d.%d --> ldpc Decoding for CW1 %5.3f\n",
+              frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
+        }
+    LOG_D(PHY, "harq_pid: %d, TBS expected dlsch1: %d \n", harq_pid, dlsch1->harq_processes[harq_pid]->TBS);
     }
-
-    LOG_D(PHY," ------ end ldpc decoder for AbsSubframe %d.%d ------ decoded in %d \n", frame_rx, nr_slot_rx, ret);
-
     //  send to mac
     if (ue->if_inst && ue->if_inst->dl_indication) {
       ue->if_inst->dl_indication(&dl_indication, ul_time_alignment);
@@ -1412,8 +1405,8 @@ void *UE_thread_slot1_dl_processing(void *arg) {
 
 
     stop_meas(&ue->ue_front_end_per_slot_stat[proc->thread_id][1]);
-    LOG_D(PHY, "[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,nr_slot_rx,ue->ue_front_end_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
-
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,nr_slot_rx,ue->ue_front_end_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
 
     //wait until pdcch is decoded
     uint32_t wait = 0;
@@ -1502,7 +1495,8 @@ void *UE_thread_slot1_dl_processing(void *arg) {
     //printf("Set available LLR slot1 to 1 AbsSubframe %d.%d \n",frame_rx,nr_slot_rx);
 
     stop_meas(&ue->pdsch_procedures_per_slot_stat[proc->thread_id][1]);
-    LOG_D(PHY, "[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,nr_slot_rx,ue->pdsch_procedures_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
+    if (cpumeas(CPUMEAS_GETSTATE))
+      LOG_D(PHY, "[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,nr_slot_rx,ue->pdsch_procedures_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
 
     if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
       LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
@@ -1871,9 +1865,10 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 			   dlsch_parallel);
 
   stop_meas(&ue->dlsch_procedures_stat[proc->thread_id]);
-  LOG_D(PHY, "[SFN %d] Slot1:       Pdsch Proc %5.2f\n",nr_slot_rx,ue->pdsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
-  LOG_D(PHY, "[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",nr_slot_rx,ue->dlsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
-
+  if (cpumeas(CPUMEAS_GETSTATE)) {
+    LOG_D(PHY, "[SFN %d] Slot1:       Pdsch Proc %5.2f\n",nr_slot_rx,ue->pdsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
+    LOG_D(PHY, "[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",nr_slot_rx,ue->dlsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
+  }
 
   // deactivate dlsch once dlsch proc is done
   ue->dlsch[proc->thread_id][gNB_id][0]->active = 0;
@@ -1948,6 +1943,8 @@ if (nr_slot_rx==9) {
  }
 
 stop_meas(&ue->generic_stat);
+if (cpumeas(CPUMEAS_GETSTATE))
+  LOG_D(PHY,"after tubo until end of Rx %5.2f \n",ue->generic_stat.p_time/(cpuf*1000.0));
 
 #ifdef EMOS
 phy_procedures_emos_UE_RX(ue,slot,gNB_id);
@@ -1957,7 +1954,9 @@ phy_procedures_emos_UE_RX(ue,slot,gNB_id);
 VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT);
 
 stop_meas(&ue->phy_proc_rx[proc->thread_id]);
-LOG_D(PHY, "------FULL RX PROC [SFN %d]: %5.2f ------\n",nr_slot_rx,ue->phy_proc_rx[proc->thread_id].p_time/(cpuf*1000.0));
+if (cpumeas(CPUMEAS_GETSTATE))
+  LOG_D(PHY, "------FULL RX PROC [SFN %d]: %5.2f ------\n",nr_slot_rx,ue->phy_proc_rx[proc->thread_id].p_time/(cpuf*1000.0));
+
 
 //#endif //pdsch
 
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c
index 833207a40861239e242ed59949801b108308da1f..c1443700f331362add8263ef43c598f9ed6eb282 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim.c
@@ -1234,7 +1234,7 @@ int main(int argc, char **argv) {
       break;
   }
 
-  for (k=0; k<NUMBER_OF_UE_MAX; k++) {
+  for (k=0; k<NUMBER_OF_DLSCH_MAX; k++) {
     // Create transport channel structures for 2 transport blocks (MIMO)
     for (i=0; i<2; i++) {
       eNB->dlsch[k][i] = new_eNB_dlsch(Kmimo,8,Nsoft,N_RB_DL,0,&eNB->frame_parms);
@@ -1247,6 +1247,17 @@ int main(int argc, char **argv) {
       eNB->dlsch[k][i]->rnti = n_rnti+k;
     }
   }
+  
+  for (int i=0;i<NUMBER_OF_ULSCH_MAX; i++) {
+    
+    LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH %d/%d\n",i,NUMBER_OF_ULSCH_MAX);
+    eNB->ulsch[i] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,eNB->frame_parms.N_RB_UL, 0);
+    
+    if (!eNB->ulsch[i]) {
+      LOG_E(PHY,"Can't get eNB ulsch structures\n");
+      exit(-1);
+    }
+  }
 
   /* allocate memory for both subframes (only one is really used
    * but there is now "copy_harq_proc_struct" which needs both
@@ -1815,12 +1826,12 @@ int main(int argc, char **argv) {
         if (t_rx > 2000 )
           n_rx_dropped++;
 
-        appendVarArray(table_tx, &t_tx);
-        appendVarArray(table_tx_ifft, &t_tx_ifft);
-        appendVarArray(table_rx, &t_rx );
-        appendVarArray(table_rx_fft, &t_rx_fft );
-        appendVarArray(table_rx_demod, &t_rx_demod );
-        appendVarArray(table_rx_dec, &t_rx_dec );
+        appendVarArray(&table_tx, &t_tx);
+        appendVarArray(&table_tx_ifft, &t_tx_ifft);
+        appendVarArray(&table_rx, &t_rx );
+        appendVarArray(&table_rx_fft, &t_rx_fft );
+        appendVarArray(&table_rx_demod, &t_rx_demod );
+        appendVarArray(&table_rx_dec, &t_rx_dec );
       }   //trials
 
       // round_trials[0]: number of code word : goodput the protocol
diff --git a/openair1/SIMULATION/LTE_PHY/dummy_functions.c b/openair1/SIMULATION/LTE_PHY/dummy_functions.c
index 120e4845d92608ccc11c9f30080030fc70f8e103..fcbab51f4b4f7cb662178e084706982e74b7e042 100644
--- a/openair1/SIMULATION/LTE_PHY/dummy_functions.c
+++ b/openair1/SIMULATION/LTE_PHY/dummy_functions.c
@@ -86,12 +86,6 @@ int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP, uint8_t CC_id) { return(0);}
 
 int8_t get_deltaP_rampup(module_id_t module_idP, uint8_t CC_id) { return(0);}
 
-void thread_top_init(char *thread_name,
-                     int affinity,
-                     uint64_t runtime,
-                     uint64_t deadline,
-                     uint64_t period) {}
-
 int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { return(0);}
 int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { return(0); }
 
diff --git a/openair1/SIMULATION/LTE_PHY/mbmssim.c b/openair1/SIMULATION/LTE_PHY/mbmssim.c
index 53c15ccc89c287ec2a70a3456495126372ef8f99..31c3b47227aa680235300adbc7bcfe5ebbaa8d09 100644
--- a/openair1/SIMULATION/LTE_PHY/mbmssim.c
+++ b/openair1/SIMULATION/LTE_PHY/mbmssim.c
@@ -1971,12 +1971,12 @@ int main(int argc, char **argv) {
         if (t_rx > 2000 )
           n_rx_dropped++;
 
-        appendVarArray(table_tx, &t_tx);
-        appendVarArray(table_tx_ifft, &t_tx_ifft);
-        appendVarArray(table_rx, &t_rx );
-        appendVarArray(table_rx_fft, &t_rx_fft );
-        appendVarArray(table_rx_demod, &t_rx_demod );
-        appendVarArray(table_rx_dec, &t_rx_dec );
+        appendVarArray(&table_tx, &t_tx);
+        appendVarArray(&table_tx_ifft, &t_tx_ifft);
+        appendVarArray(&table_rx, &t_rx );
+        appendVarArray(&table_rx_fft, &t_rx_fft );
+        appendVarArray(&table_rx_demod, &t_rx_demod );
+        appendVarArray(&table_rx_dec, &t_rx_dec );
       }   //trials
 
       // round_trials[0]: number of code word : goodput the protocol
diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c
index 39593a640c487eba7b90448a89a4589e3c810664..1b1058535e6fc6d77c931d37e0bd6dfc9aed1d2b 100644
--- a/openair1/SIMULATION/LTE_PHY/ulsim.c
+++ b/openair1/SIMULATION/LTE_PHY/ulsim.c
@@ -743,7 +743,7 @@ int main(int argc, char **argv) {
   UE2eNB->max_Doppler = maxDoppler;
 
   // NN: N_RB_UL has to be defined in ulsim
-  for (int k=0; k<NUMBER_OF_UE_MAX; k++) eNB->ulsch[k] = new_eNB_ulsch(max_turbo_iterations,N_RB_DL,0);
+  for (int k=0; k<NUMBER_OF_ULSCH_MAX; k++) eNB->ulsch[k] = new_eNB_ulsch(max_turbo_iterations,N_RB_DL,0);
 
   UE->ulsch[0]   = new_ue_ulsch(N_RB_DL,0);
   printf("ULSCH %p\n",UE->ulsch[0]);
@@ -1279,14 +1279,14 @@ int main(int argc, char **argv) {
           n_rx_dropped++;
 
         if (trials < 1000) {
-         appendVarArray(table_tx, &t_tx);
-         appendVarArray(table_tx_ifft, &t_tx_ifft);
-         appendVarArray(table_tx_mod, &t_tx_mod );
-         appendVarArray(table_tx_enc, &t_tx_enc );
-         appendVarArray(table_rx, &t_rx );
-         appendVarArray(table_rx_fft, &t_rx_fft );
-         appendVarArray(table_rx_demod, &t_rx_demod );
-         appendVarArray(table_rx_dec, &t_rx_dec );
+         appendVarArray(&table_tx, &t_tx);
+         appendVarArray(&table_tx_ifft, &t_tx_ifft);
+         appendVarArray(&table_tx_mod, &t_tx_mod );
+         appendVarArray(&table_tx_enc, &t_tx_enc );
+         appendVarArray(&table_rx, &t_rx );
+         appendVarArray(&table_rx_fft, &t_rx_fft );
+         appendVarArray(&table_rx_demod, &t_rx_demod );
+         appendVarArray(&table_rx_dec, &t_rx_dec );
        }
       }   //trials
 
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index b9f7b383712d1290b38965da2b11e9a914a1dcf7..92777730fff2911dedef972dc63f07e073b23157 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -402,7 +402,7 @@ int main(int argc, char **argv)
   NR_UE_MAC_INST_t *UE_mac;
   int cyclic_prefix_type = NFAPI_CP_NORMAL;
   int run_initial_sync=0;
-  int loglvl=OAILOG_INFO;
+  int loglvl=OAILOG_WARNING;
 
   //float target_error_rate = 0.01;
   int css_flag=0;
@@ -647,6 +647,7 @@ int main(int argc, char **argv)
       printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",
              argv[0]);
       printf("-h This message\n");
+      printf("-L <log level, 0(errors), 1(warning), 2(info) 3(debug) 4 (trace)>\n");  
       //printf("-p Use extended prefix mode\n");
       //printf("-d Use TDD\n");
       printf("-n Number of frames to simulate\n");
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index db8d54f86d601b7470c79a7fa3ebdf0b02e7d7c3..ceeded145a09d1d00b5d4ba49fa2525ef7bc610d 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -275,7 +275,7 @@ int main(int argc, char **argv)
 
   //unsigned char frame_type = 0;
   NR_DL_FRAME_PARMS *frame_parms;
-  int loglvl = OAILOG_INFO;
+  int loglvl = OAILOG_WARNING;
   //uint64_t SSB_positions=0x01;
   uint16_t nb_symb_sch = 12;
   int start_symbol = 0;
@@ -603,6 +603,7 @@ int main(int argc, char **argv)
       //printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n");
       printf("-F Input filename (.txt format) for RX conformance testing\n");
       printf("-G Offset of samples to read from file (0 default)\n");
+      printf("-L <log level, 0(errors), 1(warning), 2(info) 3(debug) 4 (trace)>\n"); 
       printf("-M Multiple SSB positions in burst\n");
       printf("-N Nid_cell\n");
       printf("-O oversampling factor (1,2,4,8,16)\n");
@@ -643,7 +644,7 @@ int main(int argc, char **argv)
   else if (N_RB_UL == 106) bandwidth = 40;
   else if (N_RB_UL == 32) bandwidth = 50;
   else { printf("Add N_RB_UL %d\n",N_RB_UL); exit(-1); }
-			   
+  LOG_I( PHY,"++++++++++++++++++++++++++++++++++++++++++++++%i+++++++++++++++++++++++++++++++++++++++++",loglvl);  
   if (openair0_cfg[0].threequarter_fs == 1) sampling_frequency*=.75;
 
   UE2gNB = new_channel_desc_scm(n_tx, n_rx, channel_model,
diff --git a/openair2/COMMON/openair_defs.h b/openair2/COMMON/openair_defs.h
index 4d8d50606c814a6e6ccc77ebbfbba93686c19042..cdda6a7e87fe98509e777ac767fff2b111897d88 100644
--- a/openair2/COMMON/openair_defs.h
+++ b/openair2/COMMON/openair_defs.h
@@ -24,26 +24,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#if !defined (msg)
-# define msg(aRGS...) LOG_D(PHY, ##aRGS)
-#endif
-#ifndef malloc16
-#  ifdef __AVX2__
-#    define malloc16(x) memalign(32,x)
-#  else
-#    define malloc16(x) memalign(16,x)
-#  endif
-#endif
-#define free16(y,x) free(y)
-#define bigmalloc malloc
-#define bigmalloc16 malloc16
-#define openair_free(y,x) free((y))
-#define PAGE_SIZE 4096
-
-#define PAGE_MASK 0xfffff000
-#define virt_to_phys(x) (x)
-
-#define cmax(a,b)  ((a>b) ? (a) : (b))
-#define cmin(a,b)  ((a<b) ? (a) : (b))
+#include <common/utils/utils.h>
 #endif // /*__openair_DEFS_H__ */
 
diff --git a/openair2/SIMULATION/NR_RRC/itti_sim.c b/openair2/SIMULATION/NR_RRC/itti_sim.c
index e3792dca77d19425940a700569b816874c93997f..28de1ca3b83823a5b8f9e1da13e0fe9b808d10e6 100644
--- a/openair2/SIMULATION/NR_RRC/itti_sim.c
+++ b/openair2/SIMULATION/NR_RRC/itti_sim.c
@@ -546,7 +546,7 @@ int main( int argc, char **argv )
 #endif
 
   logInit();
-  //configure_linux();
+  //set_latency_target();
   printf("Reading in command-line options\n");
   get_options ();
 
diff --git a/openair2/UTIL/LISTS/list.h b/openair2/UTIL/LISTS/list.h
index b88c581deab6ecb65ee6c0e251d4abbf034184cf..079c723ebf7739727d2f50c8ccda7672bd326949 100644
--- a/openair2/UTIL/LISTS/list.h
+++ b/openair2/UTIL/LISTS/list.h
@@ -48,6 +48,8 @@
 
 
 #include "UTIL/MEM/mem_block.h"
+#include <common/utils/assertions.h>
+
 
 //-----------------------------------------------------------------------------
 void         list_init (list_t* , char *);
@@ -126,10 +128,13 @@ static inline void * dataArray(varArray_t * input) {
   return input+1;
 }
 
-static inline void appendVarArray(varArray_t * input, void* data) {
+static inline void appendVarArray(varArray_t ** inputPtr, void* data) {
+  varArray_t *input=*inputPtr;
   if (input->size>=input->mallocedSize) {
      input->mallocedSize+=input->increment;
-     input=(varArray_t *)realloc(input,sizeof(varArray_t)+input->mallocedSize*input->atomSize);
+     *inputPtr=(varArray_t *)realloc(input,sizeof(varArray_t)+input->mallocedSize*input->atomSize);
+     AssertFatal(*inputPtr, "no memory left");
+     input=*inputPtr;
   }
   memcpy((uint8_t*)(input+1)+input->atomSize*input->size++, data, input->atomSize);
 }
diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c
index 13945998d754faa5f0f490099a992baaa8ee5667..013e542689a54ea0982bbde323c1154d71f5ed7b 100644
--- a/targets/ARCH/rfsimulator/simulator.c
+++ b/targets/ARCH/rfsimulator/simulator.c
@@ -820,7 +820,8 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
 
   AssertFatal((rfsimulator->epollfd = epoll_create1(0)) != -1,"");
 
-  //randominit(0);
+  // we need to call randominit() for telnet server (use gaussdouble=>uniformrand)
+  randominit(0);
   set_taus_seed(0);
   /* look for telnet server, if it is loaded, add the channel modeling commands to it */
   add_telnetcmd_func_t addcmd = (add_telnetcmd_func_t)get_shlibmodule_fptr("telnetsrv", TELNET_ADDCMD_FNAME);
diff --git a/targets/RT/USER/TOOLS/thread_ipc.c b/targets/RT/USER/TOOLS/thread_ipc.c
deleted file mode 100644
index 7eda3e843175e816fac2eed8987556e616e3b4b8..0000000000000000000000000000000000000000
--- a/targets/RT/USER/TOOLS/thread_ipc.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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
- * the OAI Public License, Version 1.1  (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.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
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <pthread.h>
-#include <sched.h>
-
-#include "thread_ipc.h"
-
-g_thread_ipc_t thread_ipc = {0};
-
-void loop_buffer_reset(buffer_t *loop_buf)
-{
-  int i;
-
-  for (i = 0; i < BUFFERMAX; i++) {
-    loop_buf[i].subframe_num = -1;
-  }
-
-  return;
-}
-
-static void loop_buffer_init(loop_buffer_op_t *loop_buffer)
-{
-  loop_buffer->packet_num = 0;
-  loop_buffer->isfull = 0;
-  loop_buffer->isempty = 1;
-
-  pthread_mutex_init(&loop_buffer->buffer_mutex, NULL);
-
-  pthread_cond_init(&loop_buffer->full_cond, NULL);
-  pthread_cond_init(&loop_buffer->empty_cond, NULL);
-
-  loop_buffer_reset(loop_buffer->loop_buf);
-
-  return;
-}
-
-static void sync_buffer_init(sync_buffer_t *sync_buffer)
-{
-  sync_buffer->decoding_subframe_num = 0;
-  pthread_mutex_init(&sync_buffer->buffer_mutex, NULL);
-
-  return;
-}
-
-int thread_ipc_init(void)
-{
-  //printf("recv %d\n", thread_ipc.sync_buffer.decoding_subframe_num);
-  thread_ipc.ue_sync_state = 0;
-  thread_ipc.rx_timestamp = 0;
-  thread_ipc.tx_timestamp = 0;
-  thread_ipc.current_subframe = 0;
-
-  pthread_mutex_init(&thread_ipc.dl_decode_mutex, NULL);
-  pthread_mutex_lock(&thread_ipc.dl_decode_mutex);
-
-  pthread_mutex_init(&thread_ipc.ul_send_mutex, NULL);
-  pthread_mutex_lock(&thread_ipc.ul_send_mutex);
-
-  pthread_mutex_init(&thread_ipc.sync_mutex, NULL);
-  pthread_mutex_lock(&thread_ipc.sync_mutex);
-
-  loop_buffer_init(&thread_ipc.loop_buffer);
-  sync_buffer_init(&thread_ipc.sync_buffer);
-
-  return 0;
-}
-
-int thread_ipc_deinit(void)
-{
-  pthread_mutex_destroy(&thread_ipc.ul_send_mutex);
-  pthread_mutex_destroy(&thread_ipc.sync_mutex);
-  pthread_mutex_destroy(&thread_ipc.dl_decode_mutex);
-
-  pthread_mutex_destroy(&thread_ipc.loop_buffer.buffer_mutex);
-  pthread_cond_destroy(&thread_ipc.loop_buffer.full_cond);
-  pthread_cond_destroy(&thread_ipc.loop_buffer.empty_cond);
-
-  pthread_mutex_destroy(&thread_ipc.sync_buffer.buffer_mutex);
-
-  return 0;
-}
-
-int set_thread_attr(pthread_attr_t *attr, int policy, int priority, int cpuid)
-{
-  struct sched_param param;
-  cpu_set_t cpu_info;
-
-  pthread_attr_init(attr);
-
-  if (pthread_attr_setschedpolicy(attr, policy) != 0) {
-    perror("pthread_attr_setschedpolicy");
-    return -1;
-  }
-
-  param.sched_priority = priority;
-
-  if (pthread_attr_setschedparam(attr, &param) != 0) {
-    perror("pthread_attr_setschedparam");
-    return -1;
-  }
-
-  CPU_ZERO(&cpu_info);
-  CPU_SET(cpuid, &cpu_info);
-
-  if (pthread_attr_setaffinity_np(attr,sizeof(cpu_set_t),&cpu_info)) {
-    perror("pthread_attr_setaffinity_np");
-    return -1;
-  }
-
-  if (pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED) != 0) {
-    perror("pthread_attr_setinheritsched");
-    return -1;
-  }
-
-  return 0;
-}
-
-
-int find_subframe_num(unsigned long long current_subframe_num, buffer_t *buf, int *flag)
-{
-  long long tmp;
-  int i;
-
-  tmp = current_subframe_num;
-
-  for ( i = 0; i < HIGHBUFFER + 1; i++) {
-    if(tmp == buf[i].subframe_num) {
-      return i;
-    } else if (tmp < buf[i].subframe_num) {
-      *flag = 1;
-    }
-  }
-
-  return -1;
-}
-
-int ue_unsync_thread_ipc_reset(void)
-{
-  thread_ipc.ue_sync_state = 0;
-
-  pthread_mutex_lock(&thread_ipc.loop_buffer.buffer_mutex);
-
-  if (thread_ipc.loop_buffer.isempty) {
-    pthread_cond_signal(&thread_ipc.loop_buffer.empty_cond);
-  }
-
-  if (thread_ipc.loop_buffer.isfull) {
-    pthread_cond_signal(&thread_ipc.loop_buffer.full_cond);
-  }
-
-  thread_ipc.loop_buffer.packet_num = 0;
-  thread_ipc.loop_buffer.isfull = 0;
-  thread_ipc.loop_buffer.isempty = 1;
-
-  loop_buffer_reset(thread_ipc.loop_buffer.loop_buf);
-  pthread_mutex_unlock(&thread_ipc.loop_buffer.buffer_mutex);
-
-  thread_ipc.current_subframe = 0;
-
-  return 0;
-}
-void bind_thread2kernel(int cpu_id)
-{
-  cpu_set_t mask;
-  cpu_set_t get;
-  int i;
-  int num = sysconf(_SC_NPROCESSORS_CONF);
-  //printf("system has %d processor(s) by super\n", num);
-  CPU_ZERO(&mask);
-  CPU_SET(cpu_id, &mask);
-
-  if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
-    fprintf(stderr, "set thread affinity failed\n");
-  }
-
-  /*CPU_ZERO(&get);
-  if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
-          fprintf(stderr, "get thread affinity failed\n");
-  }
-  for (i = 0; i < num; i++) {
-          if (CPU_ISSET(i, &get)) {
-                  printf("thread %d is running in processor %d\n", (int)pthread_self(), i);
-          }
-  }
-  if (CPU_ISSET(cpu_id, &get)) {
-    printf("thread %d is running in processor %d by super\n", (int)pthread_self(), cpu_id);
-    }*/
-}
-void get_thread2kernel(void)
-{
-  cpu_set_t get;
-  int i;
-  int num = sysconf(_SC_NPROCESSORS_CONF);
-  printf("system has %d processor(s) by super\n", num);
-  CPU_ZERO(&get);
-
-  if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
-    fprintf(stderr, "get thread affinity failed\n");
-  }
-
-  for (i = 0; i < num; i++) {
-    if (CPU_ISSET(i, &get)) {
-      printf("The thread %d is running in processor %d by super\n", (int)pthread_self(), i);
-    }
-  }
-}
-
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index f20f8267ed7950890dae31411ed6bb0ca12a61a5..0b6b0b3a757ab61da2546348aa2b392e8118efda 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -48,8 +48,6 @@
 
 #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
 
-#include "rt_wrapper.h"
-
 #include "assertions.h"
 
 
@@ -101,7 +99,6 @@ extern RAN_CONTEXT_t RC;
 //#define USRP_DEBUG 1
 struct timing_info_t {
   //unsigned int frame, hw_slot, last_slot, next_slot;
-  RTIME time_min, time_max, time_avg, time_last, time_now;
   //unsigned int mbox0, mbox1, mbox2, mbox_target;
   unsigned int n_samples;
 } timing_info;
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 20644388c85473a2a940305730b3cf45be4f6bf5..8ad610f1af7f8911a27e2f17b45f0e3fc4fdea9b 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -44,7 +44,6 @@
 #include <execinfo.h>
 #include <getopt.h>
 #include <sys/sysinfo.h>
-#include "rt_wrapper.h"
 
 #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
 
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 8cc693623b227eb07cfc79653d8a56a407f9563a..85e493f19485493bbe14cbe517337d22bbba0b1a 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -34,7 +34,6 @@
 #define _GNU_SOURCE             /* See feature_test_macros(7) */
 #include <sched.h>
 
-#include "rt_wrapper.h"
 #include <common/utils/msc/msc.h>
 
 
@@ -518,13 +517,6 @@ static  void wait_nfapi_init(char *thread_name) {
 
 int main ( int argc, char **argv )
 {
-  set_priority(79);
-  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
-  {
-    fprintf(stderr, "mlockall: %s\n", strerror(errno));
-    return EXIT_FAILURE;
-  }
-
   int i;
   int CC_id = 0;
   int ru_id;
@@ -537,8 +529,8 @@ int main ( int argc, char **argv )
   }
 
   mode = normal_txrx;
-  set_latency_target();
   logInit();
+  set_latency_target();
   printf("Reading in command-line options\n");
   get_options ();
 
@@ -573,13 +565,10 @@ int main ( int argc, char **argv )
   init_opt();
   // to make a graceful exit when ctrl-c is pressed
   set_softmodem_sighandler();
-  check_clock();
 #ifndef PACKAGE_VERSION
 #  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
 #endif
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
-  printf("Runtime table\n");
-  fill_modeled_runtime_table(runtime_phy_rx,runtime_phy_tx);
 
   /* Read configuration */
   if (RC.nb_inst > 0) {
diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h
index 4154d6c8db1cd0e44e324972dadb161dd60aff4f..cf35a13fe907d851156ded04b32c9847123a9163 100644
--- a/targets/RT/USER/lte-softmodem.h
+++ b/targets/RT/USER/lte-softmodem.h
@@ -6,7 +6,6 @@
 #include <fcntl.h>
 #include <getopt.h>
 #include <linux/sched.h>
-#include "rt_wrapper.h"
 #include <sched.h>
 #include <signal.h>
 #include <stdint.h>
@@ -21,7 +20,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "threads_t.h"
-#include "rt_wrapper.h"
 #include "../../ARCH/COMMON/common_lib.h"
 //#undef MALLOC
 #include "assertions.h"
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 70e4677943168994f6c709e4cada76f0cc8e63c9..1643ca36ca71a2df537170e0c9d6e6bd8470e542 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -31,7 +31,6 @@
  */
 #include "lte-softmodem.h"
 
-#include "rt_wrapper.h"
 #include "system.h"
 
 #include "LAYER2/MAC/mac.h"
diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c
index dcbecc85acb42b4b5b7d0788c7b10c454dc1d00f..4395694bf40823415794a57a8ca4d7d01fbc7b0c 100644
--- a/targets/RT/USER/lte-uesoftmodem.c
+++ b/targets/RT/USER/lte-uesoftmodem.c
@@ -34,9 +34,6 @@
 #define _GNU_SOURCE             /* See feature_test_macros(7) */
 #include <sched.h>
 
-#include "rt_wrapper.h"
-
-
 #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
 
 #include "assertions.h"
@@ -542,12 +539,6 @@ AssertFatal(false,"");
 }
 
 int main( int argc, char **argv ) {
-  set_priority(79);
-  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
-  {
-    fprintf(stderr, "mlockall: %s\n", strerror(errno));
-    return EXIT_FAILURE;
-  }
 
   int CC_id;
   uint8_t  abstraction_flag=0;
@@ -565,8 +556,8 @@ int main( int argc, char **argv ) {
 
   mode = normal_txrx;
   memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS);
-  set_latency_target();
   logInit();
+  set_latency_target();
   printf("Reading in command-line options\n");
 
   for (int i=0; i<MAX_NUM_CCs; i++) tx_max_power[i]=23;
@@ -629,7 +620,6 @@ int main( int argc, char **argv ) {
   pdcp_pc5_socket_init();
   // to make a graceful exit when ctrl-c is pressed
   set_softmodem_sighandler();
-  check_clock();
 #ifndef PACKAGE_VERSION
 #  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
 #endif
@@ -663,52 +653,6 @@ int main( int argc, char **argv ) {
 
   cpuf=get_cpu_freq_GHz();
 
-
-#if 0 // #ifndef DEADLINE_SCHEDULER
-
-  printf("NO deadline scheduler\n");
-  /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */
-  cpu_set_t cpuset;
-  int s;
-  char cpu_affinity[1024];
-  CPU_ZERO(&cpuset);
-#ifdef CPU_AFFINITY
-  int j;
-  if (get_nprocs() > 2) {
-    for (j = 2; j < get_nprocs(); j++)
-      CPU_SET(j, &cpuset);
-
-    s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
-
-    if (s != 0) {
-      perror( "pthread_setaffinity_np");
-      exit_fun("Error setting processor affinity");
-    }
-    LOG_I(HW, "Setting the affinity of main function to all CPUs, for device library to use CPU 0 only!\n");
-  }
-
-#endif
-  /* Check the actual affinity mask assigned to the thread */
-  s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
-
-  if (s != 0) {
-    perror( "pthread_getaffinity_np");
-    exit_fun("Error getting processor affinity ");
-  }
-
-  memset(cpu_affinity, 0, sizeof(cpu_affinity));
-
-  for (int j = 0; j < CPU_SETSIZE; j++) {
-    if (CPU_ISSET(j, &cpuset)) {
-      char temp[1024];
-      sprintf(temp, " CPU_%d ", j);
-      strcat(cpu_affinity, temp);
-    }
-  }
-
-  LOG_I(HW, "CPU Affinity of main() function is... %s\n", cpu_affinity);
-#endif
-
   if (create_tasks_ue(NB_UE_INST) < 0) {
     printf("cannot create ITTI tasks\n");
     exit(-1); // need a softer mode
diff --git a/targets/RT/USER/rt_wrapper.c b/targets/RT/USER/rt_wrapper.c
deleted file mode 100644
index da3a2d3cfe2ea9456b409ee992db3fda92ee2c8f..0000000000000000000000000000000000000000
--- a/targets/RT/USER/rt_wrapper.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * 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
- * the OAI Public License, Version 1.1  (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.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
- */
-
-/*! \file rt_wrapper.h
-* \brief provides a wrapper for the timing function, runtime calculations for real-time opeartions depending on weather RTAI or DEADLINE_SCHEDULER kernels are used or not
-* \author F. Kaltenberger and Navid Nikaein
-* \date 2013
-* \version 0.1
-* \company Eurecom
-* \email: florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
-* \note
-* \warning
-*/
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sched.h>
-#include <linux/sched.h>
-#include <signal.h>
-#include <execinfo.h>
-#include <getopt.h>
-#include <sys/sysinfo.h>
-#include "rt_wrapper.h"
-#include "system.h"
-#include <errno.h>
-#include <common/utils/msc/msc.h>
-
-#include "openair1/PHY/defs_common.h"
-
-static int latency_target_fd = -1;
-static int32_t latency_target_value = 0;
-/* Latency trick - taken from cyclictest.c
- * if the file /dev/cpu_dma_latency exists,
- * open it and write a zero into it. This will tell
- * the power management system not to transition to
- * a high cstate (in fact, the system acts like idle=poll)
- * When the fd to /dev/cpu_dma_latency is closed, the behavior
- * goes back to the system default.
- *
- * Documentation/power/pm_qos_interface.txt
- */
-void set_latency_target(void) {
-  struct stat s;
-  int ret;
-
-  if (stat("/dev/cpu_dma_latency", &s) == 0) {
-    latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR);
-
-    if (latency_target_fd == -1)
-      return;
-
-    ret = write(latency_target_fd, &latency_target_value, 4);
-
-    if (ret == 0) {
-      printf("# error setting cpu_dma_latency to %d!: %s\n", latency_target_value, strerror(errno));
-      close(latency_target_fd);
-      return;
-    }
-
-    printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value);
-  }
-}
-
-
-struct timespec interval, next, now, res;
-clockid_t clock_id = CLOCK_MONOTONIC; //other options are CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID
-RTIME rt_get_time_ns (void)
-{
-  clock_gettime(clock_id, &now);
-  return(now.tv_sec*1e9+now.tv_nsec);
-}
-
-int rt_sleep_ns (RTIME x)
-{
-  int ret;
-  clock_gettime(clock_id, &now);
-  interval.tv_sec = x/((RTIME)1000000000);
-  interval.tv_nsec = x%((RTIME)1000000000);
-  //rt_printk("sleeping for %d sec and %d ns\n",interval.tv_sec,interval.tv_nsec);
-  next = now;
-  next.tv_sec += interval.tv_sec;
-  next.tv_nsec += interval.tv_nsec;
-
-  if (next.tv_nsec>=1000000000) {
-    next.tv_nsec -= 1000000000;
-    next.tv_sec++;
-  }
-
-  ret = clock_nanosleep(clock_id, TIMER_ABSTIME, &next, NULL);
-
-  /*
-  if (ret==EFAULT)
-    rt_printk("rt_sleep_ns returned EFAULT (%d), reqested %d sec and %d ns\n",ret,next.tv_sec,next.tv_nsec);
-  if (ret==EINVAL)
-    rt_printk("rt_sleep_ns returned EINVAL (%d), reqested %d sec and %d ns\n",ret,next.tv_sec,next.tv_nsec);
-  if (ret==EINTR)
-    rt_printk("rt_sleep_ns returned EINTR (%d), reqested %d sec and %d ns\n",ret,next.tv_sec,next.tv_nsec);
-  */
-
-  return(ret);
-}
-
-void check_clock(void)
-{
-  if (clock_getres(clock_id, &res)) {
-    printf("clock_getres failed");
-  } else {
-    printf("reported resolution = %lld ns\n", (long long int) ((int) 1e9 * res.tv_sec) + (long long int) res.tv_nsec);
-  }
-}
-
-uint16_t cell_processing_dl[6]={10,15,24,42,80,112};
-uint16_t platform_processing_dl=20; // upperbound for GPP, LXC, DOCKER and KVM
-uint16_t user_processing_dl_a[6]={2,4,5,7,10,12};
-uint16_t user_processing_dl_b[6]={10, 15, 25, 70, 110, 150};
-uint16_t user_processing_dl_err[6]={20, 40, 60, 90, 120, 160};
-uint16_t protocol_processing_dl[6]={150, 250, 350, 450, 650, 800}; // assumption: max MCS 27 --> gives an upper bound for the transport block size : to be measured 
-
-uint16_t cell_processing_ul[6]={10,15,24,42,80,112};
-uint16_t platform_processing_ul=30; // upperbound for GPP, LXC, DOCKER and KVM
-uint16_t user_processing_ul_a[6]={5, 9, 12, 24, 33, 42};
-uint16_t user_processing_ul_b[6]={20, 30, 40, 76, 140, 200};
-uint16_t user_processing_ul_err[6]={15, 25, 32, 60, 80, 95};
-uint16_t protocol_processing_ul[6]={100, 200, 300, 400, 550, 700}; // assumption: max MCS 16 --> gives an upper bound for the transport block size 
-
-int fill_modeled_runtime_table(uint16_t runtime_phy_rx[29][6],
-			       uint16_t runtime_phy_tx[29][6]){
-  //double cpu_freq;
-  //cpu_freq = get_cpu_freq_GHz();
-  // target_dl_mcs
-  // target_ul_mcs
-  // frame_parms[0]->N_RB_DL
-  int i,j;
-  memset(runtime_phy_rx,0,sizeof(uint16_t)*29*6);
-  memset(runtime_phy_tx,0,sizeof(uint16_t)*29*6);
-  /* only the BBU/PHY procesing time */ 
-  for (i=0;i<29;i++){
-    for (j=0;j<6;j++){
-      runtime_phy_rx[i][j] = cell_processing_ul[j] + platform_processing_ul + user_processing_ul_err[j] + user_processing_ul_a[j]*i+  user_processing_ul_b[j];
-      runtime_phy_tx[i][j] = cell_processing_dl[j] + platform_processing_dl + user_processing_dl_err[j] + user_processing_dl_a[j]*i+  user_processing_dl_b[j];
-    }
-  }
-  return 0;
-}
- 
-// int runtime_upper_layers[6]; // values for different RBs
-// int runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
-// int runtime_phy_tx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100]
-
-// target_dl_mcs
-  // target_ul_mcs
-  // frame_parms[0]->N_RB_DL
-  //runtime_upper_layers[6]; // values for different RBs
-  // int runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100] 
-  // int runtime_phy_tx[29][6]
-
-double get_runtime_tx(int tx_subframe, uint16_t runtime_phy_tx[29][6], uint32_t mcs, int N_RB_DL,double cpuf,int nb_tx_antenna){
-   int i;	
-   double runtime;
-   //printf("cpuf =%lf  \n",cpuf);
-   switch(N_RB_DL){
-   case 6:
-     i = 0;
-     break;
-   case 15:
-     i = 1;
-     break;
-   case 25:
-     i = 2;
-     break;
-   case 50:
-     i = 3;
-     break;
-   case 75:
-     i = 4;
-     break;
-   case 100:
-     i = 5;
-     break;
-   default:
-     i = 3;
-     break;
-   }			
-   
-   runtime = ( (3.2/cpuf)*(double)runtime_phy_tx[mcs][i] + (3.2/cpuf)*(double)protocol_processing_dl[i])/1000 ;
-   printf("Setting tx %d runtime value (ms) = %lf\n",tx_subframe,runtime);
-   
-   return runtime;	
- }
- 
-double get_runtime_rx(int rx_subframe, uint16_t runtime_phy_rx[29][6], uint32_t mcs, int N_RB_DL,double cpuf,int nb_rx_antenna){
-   int i;	
-   double runtime;
-   
-   //printf("N_RB_DL=%d  cpuf =%lf  \n",N_RB_DL, cpuf);
-   switch(N_RB_DL){
-   case 6:
-     i = 0;
-     break;
-   case 15:
-     i = 1;
-     break;
-   case 25:
-     i = 2;
-     break;
-   case 50:
-     i = 3;
-     break;
-   case 75:
-     i = 4;
-     break;
-   case 100:
-     i = 5;
-     break;
-   default:
-     i = 3;
-     break;
-   }			
-   
-   runtime = ((3.2/cpuf)*(double)runtime_phy_rx[mcs][i] + (3.2/cpuf)*(double)protocol_processing_ul[i])/1000 ;
-   printf("Setting rx %d runtime value (ms) = %lf \n",rx_subframe, runtime);
-   
-   return runtime;	
-}
-
-#ifdef DEADLINE_SCHEDULER
-int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags)
-{
-
-  return syscall(__NR_sched_setattr, pid, attr, flags);
-}
-
-
-int sched_getattr(pid_t pid,struct sched_attr *attr,unsigned int size, unsigned int flags)
-{
-
-  return syscall(__NR_sched_getattr, pid, attr, size, flags);
-}
-
-#endif
-
-void thread_top_init(char *thread_name,
-		     int affinity,
-		     uint64_t runtime,
-		     uint64_t deadline,
-		     uint64_t period) {
-  
-  MSC_START_USE();
-
-#ifdef DEADLINE_SCHEDULER
-  struct sched_attr attr;
-
-  unsigned int flags = 0;
-
-  attr.size = sizeof(attr);
-  attr.sched_flags = 0;
-  attr.sched_nice = 0;
-  attr.sched_priority = 0;
-
-  attr.sched_policy   = SCHED_DEADLINE;
-  attr.sched_runtime  = runtime;
-  attr.sched_deadline = deadline;
-  attr.sched_period   = period; 
-
-  if (sched_setattr(0, &attr, flags) < 0 ) {
-    perror("[SCHED] eNB tx thread: sched_setattr failed\n");
-    fprintf(stderr,"sched_setattr Error = %s",strerror(errno));
-    exit(1);
-  }
-
-#else //LOW_LATENCY
-  int policy, s, j;
-  struct sched_param sparam;
-  char cpu_affinity[1024];
-  cpu_set_t cpuset;
-  int settingPriority = 1;
-
-  /* Set affinity mask to include CPUs 2 to MAX_CPUS */
-  /* CPU 0 is reserved for UHD threads */
-  /* CPU 1 is reserved for all RX_TX threads */
-  /* Enable CPU Affinity only if number of CPUs > 2 */
-  CPU_ZERO(&cpuset);
-
-#ifdef CPU_AFFINITY
-  if (affinity == 0) {
-    LOG_W(HW,"thread_top_init() called with affinity==0, but overruled by #ifdef CPU_AFFINITY\n");
-  }
-  else if (get_nprocs() > 2)
-  {
-    for (j = 2; j < get_nprocs(); j++)
-      CPU_SET(j, &cpuset);
-    s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
-    if (s != 0)
-    {
-      perror( "pthread_setaffinity_np");
-      exit_fun("Error setting processor affinity");
-    }
-  }
-#else //CPU_AFFINITY
-  if (affinity) {
-    LOG_W(HW,"thread_top_init() called with affinity>0, but overruled by #ifndef CPU_AFFINITY.\n");
-  }
-#endif //CPU_AFFINITY
-
-  /* Check the actual affinity mask assigned to the thread */
-  s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
-  if (s != 0)
-  {
-    perror( "pthread_getaffinity_np");
-    exit_fun("Error getting processor affinity ");
-  }
-  memset(cpu_affinity,0,sizeof(cpu_affinity));
-  for (j = 0; j < 1024; j++)
-  {
-    if (CPU_ISSET(j, &cpuset))
-    {  
-      char temp[1024];
-      sprintf (temp, " CPU_%d", j);
-      strcat(cpu_affinity, temp);
-    }
-  }
-
-  if (checkIfFedoraDistribution())
-    if (checkIfGenericKernelOnFedora())
-      if (checkIfInsideContainer())
-        settingPriority = 0;
-
-  if (settingPriority) {
-    memset(&sparam, 0, sizeof(sparam));
-    sparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
-    policy = SCHED_FIFO;
-  
-    s = pthread_setschedparam(pthread_self(), policy, &sparam);
-    if (s != 0) {
-      perror("pthread_setschedparam : ");
-      exit_fun("Error setting thread priority");
-    }
-  
-    s = pthread_getschedparam(pthread_self(), &policy, &sparam);
-    if (s != 0) {
-      perror("pthread_getschedparam : ");
-      exit_fun("Error getting thread priority");
-    }
-
-    pthread_setname_np(pthread_self(), thread_name);
-
-    LOG_I(HW, "[SCHED][eNB] %s started on CPU %d, sched_policy = %s , priority = %d, CPU Affinity=%s \n",thread_name,sched_getcpu(),
-                     (policy == SCHED_FIFO)  ? "SCHED_FIFO" :
-                     (policy == SCHED_RR)    ? "SCHED_RR" :
-                     (policy == SCHED_OTHER) ? "SCHED_OTHER" :
-                     "???",
-                     sparam.sched_priority, cpu_affinity );
-  }
-
-#endif //LOW_LATENCY
-
-  mlockall(MCL_CURRENT | MCL_FUTURE);
-
-}
-
-
diff --git a/targets/RT/USER/rt_wrapper.h b/targets/RT/USER/rt_wrapper.h
deleted file mode 100644
index 32554d9e17990a2de5f532834a292368ca03429b..0000000000000000000000000000000000000000
--- a/targets/RT/USER/rt_wrapper.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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
- * the OAI Public License, Version 1.1  (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.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
- */
-
-/*! \file rt_wrapper.h
-* \brief provides a wrapper for the timing function for real-time opeartions. It also implements an API for the SCHED_DEADLINE kernel scheduler.
-* \author F. Kaltenberger and Navid Nikaein
-* \date 2013
-* \version 0.1
-* \company Eurecom
-* \email: florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr
-* \note
-* \warning This code will be removed when a legacy libc API becomes available.
-*/
-
-#ifndef _RT_WRAPPER_H_
-#define _RT_WRAPPER_H_
-
-#define _GNU_SOURCE
-#include <time.h>
-#include <errno.h>
-#include <stdint.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <pthread.h>
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <syscall.h>
-#include <math.h>
-#include <sched.h> 
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sched.h>
-#include <linux/sched.h>
-#include <signal.h>
-#include <execinfo.h>
-#include <getopt.h>
-#include <sys/sysinfo.h>
-
-#include "common/utils/LOG/log_extern.h"
-#include "msc.h"
-
-#define RTIME long long int
-
-#define rt_printk printf
-
-void set_latency_target(void);
-
-RTIME rt_get_time_ns (void);
-
-int rt_sleep_ns (RTIME x);
-
-void check_clock(void);
-
-int fill_modeled_runtime_table(uint16_t runtime_phy_rx[29][6],uint16_t runtime_phy_tx[29][6]);
-
-double get_runtime_tx(int tx_subframe, uint16_t runtime_phy_tx[29][6],uint32_t mcs, int N_RB_DL,double cpuf,int nb_tx_antenna);
-
-double get_runtime_rx(int rx_subframe, uint16_t runtime_phy_rx[29][6], uint32_t mcs, int N_RB_DL,double cpuf,int nb_rx_antenna);
-/**
- * see https://www.kernel.org/doc/Documentation/scheduler/sched-deadline.txt  or
- * http://www.blaess.fr/christophe/2014/04/05/utiliser-un-appel-systeme-inconnu-de-la-libc/
- */
-#ifdef DEADLINE_SCHEDULER
-
-#define gettid() syscall(__NR_gettid)
-
-#define SCHED_DEADLINE  6
-
-/* XXX use the proper syscall numbers */
-#ifdef __x86_64__
-#define __NR_sched_setattr   314
-#define __NR_sched_getattr   315
-#endif
-
-#ifdef __i386__
-#define __NR_sched_setattr   351
-#define __NR_sched_getattr   352
-#endif
-
-struct sched_attr {
-  __u32 size;
-
-  __u32 sched_policy;
-  __u64 sched_flags;
-
-  /* SCHED_NORMAL, SCHED_BATCH */
-  __s32 sched_nice;
-
-  /* SCHED_FIFO, SCHED_RR */
-  __u32 sched_priority;
-
-  /* SCHED_DEADLINE (nsec) */
-  __u64 sched_runtime;
-  __u64 sched_deadline;
-  __u64 sched_period;
-};
-
-int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags);
-
-int sched_getattr(pid_t pid,struct sched_attr *attr,unsigned int size, unsigned int flags);
-
-#endif
-
-#define gettid() syscall(__NR_gettid) // for gettid
-
-
-void thread_top_init(char *thread_name,
-		     int affinity,
-		     uint64_t runtime,
-		     uint64_t deadline,
-		     uint64_t period);
-
-#endif
diff --git a/targets/RT/USER/ru_control.c b/targets/RT/USER/ru_control.c
index 95b5ce6155bec826e009b221ad2881359349e496..7280c785232af9346402aa07e37ca6861ed16a1e 100644
--- a/targets/RT/USER/ru_control.c
+++ b/targets/RT/USER/ru_control.c
@@ -42,7 +42,6 @@
 #include <execinfo.h>
 #include <getopt.h>
 #include <sys/sysinfo.h>
-#include "rt_wrapper.h"
 
 #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
 
diff --git a/targets/build_helper.bash b/targets/build_helper.bash
deleted file mode 100755
index 9c98ef85b0173ce4f9bac95a529d0363f727f8c1..0000000000000000000000000000000000000000
--- a/targets/build_helper.bash
+++ /dev/null
@@ -1,1315 +0,0 @@
-#/*
-# * 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
-# * the OAI Public License, Version 1.1  (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.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
-# */
-################################################################################
-# file build_helper.bash
-# brief
-# author Lionel Gauthier and Navid Nikaein
-# company Eurecom
-# email: lionel.gauthier@eurecom.fr and navid.nikaein@eurecom.fr
-#
-#######################################
-#            Helper Func
-######################################
-
-declare ROOT_UID=0
-declare E_NOTROOT=67
-declare NUM_CPU=`cat /proc/cpuinfo | grep processor | wc -l`
-declare OAI_INSTALLED=1
-declare PWD=`pwd`
-declare USER=`whoami`
-declare BUILD_FROM_MAKEFILE=0
-declare SUDO=''
-declare PW=''
-declare UBUNTU_REL=`lsb_release -r | cut  -f2`
-declare UBUNTU_REL_NAME=`lsb_release -cs`
-
-set_build_from_makefile(){
-    BUILD_FROM_MAKEFILE=$1
-}
-
-check_for_root_rights() {
-
-  #  if [[ $EUID -ne $ROOT_EUID ]]; then
-    if [ $USER != "root" ]; then
-        SUDO="sudo -E "
-        echo "Run as a sudoers"
-        return 1
-    else
-        echo  "Run as a root"
-        return 0
-    fi
-}
-
-test_install_package() {
-  # usage: test_install_package package_name
-
- if [ $# -eq 1 ]; then
-      dpkg -s "$1" > /dev/null 2>&1 && {
-          echo "$1 is installed."
-      } || {
-          echo "$1 is not installed."
-          OAI_INSTALLED=0
-          $SUDO apt-get install -y $@
-      }
-  fi
-}
-
-test_uninstall_package() {
-
- if [ $# -eq 1 ]; then
-      dpkg -s "$1" > /dev/null 2>&1 && {
-          $SUDO apt-get remove --assume-yes $1
-          echo "$1 is uninstalled."
-      } || {
-          echo "$1 is not installed."
-      }
-  fi
-}
-test_command_install_script() {
-  # usage: test_command_install_script searched_binary script_to_be_invoked_if_binary_not_found
-  command -v $1 >/dev/null 2>&1 || { echo_warning "Program $1 is not installed. Trying installing it." >&2; bash $2; command -v $1 >/dev/null 2>&1 || { echo_fatal "Program $1 is not installed. Aborting." >&2; };}
-  echo_success "$1 available"
-}
-
-
-check_for_machine_type(){
-    MACHINE_TYPE=`uname -m`
-    if [ ${MACHINE_TYPE} = "x86_64" ]; then
-        return 64  # 64-bit stuff here
-    else
-        if [ ${MACHINE_TYPE} = "i686" ]; then
-            return 32 # 32-bit stuff here
-        else
-            return -1
-        fi
-    fi
-}
-
-####################################################
-## OAI related functions
-#####################################################
-
-####################################################
-# 1. install the required packages
-####################################################
-
-make_certs(){
-
- # for certtificate generation
-    rm -rf demoCA
-    mkdir -m 777 -p demoCA
-    echo 01 > demoCA/serial
-    touch demoCA/index.txt
-
-    echo "creating the certificate"
-
-    user=$(whoami)
-    HOSTNAME=$(hostname -f)
-
-    echo "Creating certificate for user '$HOSTNAME'"
-
-# CA self certificate
-    openssl req  -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
-
-   # openssl genrsa -out user.key.pem 1024
-    openssl genrsa -out hss.key.pem 1024
-    #openssl req -new -batch -out user.csr.pem -key user.key.pem -subj /CN=$HOSTNAME.eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
-    openssl req -new -batch -out hss.csr.pem -key hss.key.pem -subj /CN=hss.eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
-    openssl ca -cert cacert.pem -keyfile cakey.pem -in hss.csr.pem -out hss.cert.pem -outdir . -batch
-
-    if [ ! -d /usr/local/etc/freeDiameter ];  then
-        echo "Creating non existing directory: /usr/local/etc/freeDiameter/"
-        $SUDO mkdir /usr/local/etc/freeDiameter/
-    fi
-
-    echo "Copying *.pem to /usr/local/etc/freeDiameter/"
-    $SUDO cp *.pem /usr/local/etc/freeDiameter/
-    mv *.pem bin/
-
-# openssl genrsa -out ubuntu.key.pem 1024
-# openssl req -new -batch -x509 -out ubuntu.csr.pem -key ubuntu.key.pem -subj /CN=ubuntu.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests
-# openssl ca -cert cacert.pem -keyfile cakey.pem -in ubuntu.csr.pem -out ubuntu.cert.pem -outdir . -batch
-
-}
-
-check_install_nettle(){
-    if [ ! -f ./.lock_oaibuild ]; then
-	if [ $UBUNTU_REL = "12.04" ]; then
-	    test_uninstall_package nettle-dev
-	    test_uninstall_package nettle-bin
-
-	    if [ ! -d /usr/local/src/ ]; then
-		echo "/usr/local/src/ doesn't exist please create one"
-		exit -1
-	    fi
-
-	    if [ ! -w /usr/local/src/ ];  then
-		echo "You don't have permissions to write to /usr/local/src/, installing as a sudoer"
-		#	exit -1
-	    fi
-
-	    cd /usr/local/src/
-
-	    echo "Downloading nettle archive"
-
-	    if [ -f nettle-2.5.tar.gz ]; then
-		$SUDO rm -f nettle-2.5.tar.gz
-	    fi
-	    if [ -f nettle-2.5.tar ]; then
-		$SUDO rm -f nettle-2.5.tar
-	    fi
-	    if [ -d nettle-2.5 ];  then
-		$SUDO rm -rf nettle-2.5/
-	    fi
-
-
-	    $SUDO wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
-	    $SUDO gunzip nettle-2.5.tar.gz
-	    $SUDO echo "Uncompressing nettle archive"
-	    $SUDO tar -xf nettle-2.5.tar
-	    cd nettle-2.5/
-	    $SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
-	    if [ $? -ne 0 ]; then
-		exit -1
-	    fi
-	    echo "Compiling nettle"
-	    $SUDO make -j $NUM_CPU
-	    $SUDO make check
-	    $SUDO make install
-	    cd ../
-	fi
-    fi
-}
-
-check_install_freediamter(){
-
-    if [ $UBUNTU_REL = "12.04" ]; then
-
-	if [ ! -d /usr/local/src/ ]; then
-	    echo "/usr/local/src/ doesn't exist please create one"
-	    exit -1
-	fi
-
-	if [ ! -w /usr/local/src/ ];  then
-	    echo "You don't have permissions to write to /usr/local/src/, installing as a sudoer"
-#	exit -1
-	fi
-
-	cd /usr/local/src/
-
-	echo "Downloading nettle archive"
-
-	if [ -f nettle-2.5.tar.gz ]; then
-	    $SUDO rm -f nettle-2.5.tar.gz
-	fi
-	if [ -f nettle-2.5.tar ]; then
-	    $SUDO rm -f nettle-2.5.tar
-	fi
-	if [ -d nettle-2.5 ];  then
-	    $SUDO rm -rf nettle-2.5/
-	fi
-
-
-	$SUDO wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
-	$SUDO gunzip nettle-2.5.tar.gz
-	$SUDO echo "Uncompressing nettle archive"
-	$SUDO tar -xf nettle-2.5.tar
-	cd nettle-2.5/
-	$SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
-	if [ $? -ne 0 ]; then
-	    exit -1
-	fi
-	echo "Compiling nettle"
-	$SUDO make -j $NUM_CPU
-	$SUDO make check
-	$SUDO make install
-	cd ../
-    fi
-
-    echo "Downloading gnutls archive"
-
-    if [ -f gnutls-3.1.23.tar.xz ];  then
-	$SUDO rm -f gnutls-3.1.23.tar.xz
-    fi
-    if [ -d gnutls-3.1.23/ ];  then
-	$SUDO rm -rf gnutls-3.1.23/
-    fi
-
-    test_uninstall_package libgnutls-dev
-
-    $SUDO wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz
-    $SUDO tar -xf gnutls-3.1.23.tar.xz
-    echo "Uncompressing gnutls archive ($PWD)"
-    cd gnutls-3.1.23/
-    $SUDO ./configure --prefix=/usr
-    if [ $? -ne 0 ];   then
-	exit -1
-    fi
-    echo "Compiling gnutls"
-    $SUDO make -j $NUM_CPU
-    $SUDO make install
-    cd ../
-
-    echo "Downloading freeDiameter archive"
-
-    if [ -f 1.1.5.tar.gz ];  then
-	$SUDO rm -f 1.1.5.tar.gz
-    fi
-    if [ -d freeDiameter-1.1.5/ ];   then
-	$SUDO rm -rf freeDiameter-1.1.5/
-    fi
-
-    $SUDO wget http://www.freediameter.net/hg/freeDiameter/archive/1.1.5.tar.gz
-    $SUDO tar -xzf 1.1.5.tar.gz
-    echo "Uncompressing freeDiameter archive"
-    cd freeDiameter-1.1.5
-    $SUDO patch -p1 < $OPENAIR3_DIR/S6A/freediameter/freediameter-1.1.5.patch
-    $SUDO mkdir build
-    cd build
-    $SUDO cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ../
-    if [ $? -ne 0 ];  then
-	exit -1
-    fi
-    echo "Compiling freeDiameter"
-    $SUDO make -j $NUM_CPU
-#make help
-    $SUDO make test
-    $SUDO sudo make install
-
-#    make_certs
-
-}
-
-
-test_is_host_reachable() {
-    ping -c 1 $1 > /dev/null || { echo_fatal "$2 host $1 does not respond to ping" >&2 ; }
-    echo_success "$2 host $1 is reachable"
-}
-
-
-check_epc_s6a_certificate() {
-    if [ -d /usr/local/etc/freeDiameter ]
-    then
-        if [ -f /usr/local/etc/freeDiameter/user.cert.pem ]
-        then
-            full_hostname=`cat /usr/local/etc/freeDiameter/user.cert.pem | grep "Subject" | grep "CN" | cut -d '=' -f6`
-            if [ a$full_hostname == a`hostname`.${1:-'eur'} ]
-            then
-                echo_success "EPC S6A: Found valid certificate in /usr/local/etc/freeDiameter"
-                return 0
-            fi
-        fi
-    fi
-    echo_error "EPC S6A: Did not find valid certificate in /usr/local/etc/freeDiameter"
-    echo_warning "EPC S6A: generatting new certificate in /usr/local/etc/freeDiameter..."
-    cd $OPENAIR3_DIR/S6A/freediameter
-    ./make_certs.sh ${1:-'eur'}
-    if [ $# -lt 2 ] ; then
-        check_epc_s6a_certificate ${1:-'eur'}  2
-        return $?
-    else
-       exit 1
-    fi
-}
-
-
-check_hss_s6a_certificate() {
-    if [ -d /usr/local/etc/freeDiameter ]; then
-        if [ -f /usr/local/etc/freeDiameter/hss.cert.pem ];  then
-            full_hostname=`cat /usr/local/etc/freeDiameter/hss.cert.pem | grep "Subject" | grep "CN" | cut -d '=' -f6`
-            if [ a$full_hostname == a`hostname`.${1:-'eur'} ]
-            then
-                echo_success "HSS S6A: Found valid certificate in /usr/local/etc/freeDiameter"
-                return 0
-            else
-                echo_error "Bad hss hostname found in cert file: "$full_hostname " hostname is "`hostname`
-            fi
-        fi
-    fi
-    echo_error "S6A: Did not find valid certificate in /usr/local/etc/freeDiameter"
-    echo_warning "S6A: generatting new certificate in /usr/local/etc/freeDiameter..."
-    cd $OPENAIR3_DIR/OPENAIRHSS/conf
-    ./make_certs.sh ${1:-'eur'}
-    if [ $# -lt 2 ] ; then
-        check_hss_s6a_certificate ${1:-'eur'} 2
-        return $?
-    else
-       exit 1
-    fi
-}
-
-check_install_usrp_uhd_driver(){
-    if [ ! -f /etc/apt/sources.list.d/ettus.list ] ; then
-        $SUDO bash -c 'echo "deb http://files.ettus.com/binaries/uhd/repo/uhd/ubuntu/`lsb_release -cs` `lsb_release -cs` main" >> /etc/apt/sources.list.d/ettus.list'
-        $SUDO apt-get update
-    fi
-    $SUDO apt-get install -t $UBUNTU_REL_NAME uhd
-    test_install_package python
-    test_install_package libboost-all-dev
-    test_install_package libusb-1.0-0-dev
-    #test_install_package uhd
-}
-
-check_install_oai_software() {
-
-    if [ ! -f ./.lock_oaibuild ]; then
-        $SUDO apt-get update
-        if [ $UBUNTU_REL = "12.04" ]; then
-            test_uninstall_package nettle-dev
-            test_uninstall_package nettle-bin
-        else
-            test_install_package nettle-dev
-            test_install_package nettle-bin
-        fi
-        test_install_package autoconf
-        test_install_package automake
-        test_install_package bison
-        test_install_package build-essential
-        test_install_package dialog
-        test_install_package flex
-        test_install_package gawk
-        test_install_package gcc
-        test_install_package gdb
-        test_install_package make
-        test_install_package cmake
-        test_install_package openssh-client
-        test_install_package openssh-server
-        sudo service ssh start
-        test_install_package unzip
-        test_install_package autoconf
-        test_install_package automake
-        test_install_package bison
-        test_install_package build-essential
-        test_install_package check
-        test_install_package ethtool
-        test_install_package flex
-        test_install_package g++
-        test_install_package gawk
-        test_install_package gcc
-        test_install_package gccxml
-        test_install_package gdb
-        test_install_package guile-2.0-dev
-        test_install_package iperf
-        test_install_package iproute
-        test_install_package iptables
-        test_install_package libatlas-base-dev
-        test_install_package libatlas-dev
-        test_install_package libblas3gf
-        test_install_package libblas-dev
-        test_install_package liblapack-dev
-        test_install_package liblapack-dev
-#	if [ $MACHINE_ARCH = 64 ]; then
-            test_install_package libconfig8-dev
-#	else
-#            test_install_package libconfig-dev
-#	fi
-        test_install_package libforms-bin
-        test_install_package libforms-dev
-        test_install_package libgcrypt11-dev
-        test_install_package libgmp-dev
-        test_install_package libgtk-3-dev
-        test_install_package libidn11-dev
-        test_install_package libidn2-0-dev
-        test_install_package libpgm-dev
-        test_install_package libpgm-5.1-0
-        test_install_package libpthread-stubs0-dev
-        test_install_package libsctp1
-        test_install_package libsctp-dev
-        test_install_package libtasn1-3-dev
-        test_install_package libxml2
-        test_install_package libxml2-dev
-#       test_install_package linux-headers-`uname -r`
-        test_install_package openssl
-        test_install_package libssl-dev
-        test_install_package pkg-config
-        test_install_package python-dev
-        test_install_package python-pexpect
-        test_install_package sshfs
-        test_install_package subversion
-        test_install_package valgrind
-        test_install_package doxygen
-        test_install_package graphviz
-
-#        test_install_package libboost-all-dev
-
-        if [ $OAI_INSTALLED = 1 ]; then
-            touch ./.lock_oaibuild
-        fi
-
-     else
-        echo_info "All the required packages installed: skip"
-    fi
-
-}
-
-check_install_hss_software() {
-    if [ ! -f ./.lock_oaibuild ]; then
-        $SUDO apt-get update
-        if [ $UBUNTU_REL = "12.04" ]; then
-            test_uninstall_package nettle-dev
-            test_uninstall_package nettle-bin
-        else
-            test_install_package nettle-dev
-            test_install_package nettle-bin
-        fi
-	test_install_package autoconf
-	test_install_package automake
-	test_install_package bison
-	test_install_package build-essential
-	test_install_package cmake
-	test_install_package cmake-curses-gui
-    test_install_package dialog
-    test_install_package dkms
-	test_install_package flex
-	test_install_package gawk
-	test_install_package gcc
-	test_install_package gdb
-	test_install_package guile-2.0-dev
-	test_install_package g++
-	test_install_package libgmp-dev
-	test_install_package libgcrypt11-dev
-	test_install_package libidn11-dev
-	test_install_package libidn2-0-dev
-	test_install_package libmysqlclient-dev
-	test_install_package libtasn1-3-dev
-	test_install_package libsctp1
-	test_install_package libsctp-dev
-	test_install_package libxml2-dev
-#	test_install_package linux-headers-`uname -r`
-	test_install_package make
-	test_install_package mysql-client
-	test_install_package mysql-server-core-5.5
-	test_install_package mysql-server
-	test_install_package openssh-client
-	test_install_package openssh-server
-        sudo service ssh start
-	test_install_package phpmyadmin
-	test_install_package python-dev
-	test_install_package sshfs
-	test_install_package swig
-	test_install_package unzip
-#	test_install_package nettle-bin
-#	test_install_package nettle-dev
-	test_install_package valgrind
-
-	if [ $OAI_INSTALLED = 1 ]; then
-	    touch ./.lock_oaibuild
-	fi
-
-    else
-	echo_info "All the required packages installed: skip"
-    fi
-
-}
-
-check_install_epc_software() {
-
-    if [ ! -f ./.lock_oaibuild ]; then
-        $SUDO apt-get update
-        if [ $UBUNTU_REL = "12.04" ]; then
-            test_uninstall_package nettle-dev
-            test_uninstall_package nettle-bin
-        else
-            test_install_package nettle-dev
-            test_install_package nettle-bin
-        fi
-        test_install_package autoconf
-        test_install_package automake
-        test_install_package bison
-        test_install_package build-essential
-        test_install_package check
-        test_install_package cmake
-        test_install_package cmake-curses-gui
-        test_install_package dialog
-        test_install_package ethtool
-        test_install_package flex
-        test_install_package g++
-        test_install_package gawk
-        test_install_package gcc
-        test_install_package gccxml
-        test_install_package gdb
-        test_install_package guile-2.0-dev
-        test_install_package gtkwave
-        test_install_package iperf
-        test_install_package iproute
-        test_install_package iptables
-        test_install_package iptables-dev
-        test_install_package libatlas-base-dev
-        test_install_package libatlas-dev
-        test_install_package libblas
-        test_install_package libblas-dev
-#       if [ $MACHINE_ARCH = 64 ]; then
-            test_install_package libconfig8-dev
-#        else
-#            test_install_package libconfig-dev
-#       fi
-        test_install_package libforms-bin
-        test_install_package libforms-dev
-        test_install_package libgcrypt11-dev
-        test_install_package libgmp-dev
-        test_install_package libgtk-3-dev
-        test_install_package libidn11-dev
-        test_install_package libidn2-0-dev
-        test_install_package libmysqlclient-dev
-        test_install_package libpgm-dev
-        test_install_package libpthread-stubs0-dev
-        test_install_package libsctp1
-        test_install_package libsctp-dev
-        test_install_package libssl-dev
-        test_install_package libtasn1-3-dev
-        test_install_package libtool
-        test_install_package libxml2
-        test_install_package libxml2-dev
-#        test_install_package linux-headers-`uname -r`
-        test_install_package make
-        test_install_package openssh-client
-        test_install_package openssh-server
-        $SUDO service ssh start
-        test_install_package openssl
-        test_install_package openvpn
-        test_install_package pkg-config
-        test_install_package python-dev
-        test_install_package sshfs
-        test_install_package subversion
-        test_install_package swig
-        test_install_package tshark
-        test_install_package uml-utilities
-        test_install_package unzip
-        test_install_package valgrind
-        test_install_package vlan
-
-        if [ $OAI_INSTALLED = 1 ]; then
-            touch ./.lock_oaibuild
-        fi
-
-    else
-        echo_info "All the required packages installed: skip"
-    fi
-
-}
-
-check_install_asn1c(){
-
-    test_command_install_script   "asn1c" "$OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO"
-
-    # One mor check about version of asn1c
-    ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE="ASN.1 Compiler, v0.9.24"
-    ASN1C_COMPILER_VERSION_MESSAGE=`asn1c -h 2>&1 | grep -i ASN\.1\ Compiler`
-    ##ASN1C_COMPILER_VERSION_MESSAGE=`trim $ASN1C_COMPILER_VERSION_MESSAGE`
-    if [ "$ASN1C_COMPILER_VERSION_MESSAGE" != "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE" ]; then
-      #  diff <(echo -n "$ASN1C_COMPILER_VERSION_MESSAGE") <(echo -n "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE")
-        echo_error "Version of asn1c is not the required one, do you want to install the required one (overwrite installation) ? (Y/n)"
-        echo_error "$ASN1C_COMPILER_VERSION_MESSAGE"
-        while read -r -n 1 -s answer; do
-            if [[ $answer = [YyNn] ]]; then
-                [[ $answer = [Yy] ]] && $OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO
-                [[ $answer = [Nn] ]] && echo_error "Version of asn1c is not the required one, exiting." && exit 1
-                break
-            fi
-        done
-    fi
-
-}
-
-#################################################
-# 2. compile
-################################################
-compile_hss() {
-    cd $OPENAIR3_DIR/OPENAIRHSS
-
-    if [ "$1" -eq 1 ]; then
-        echo_info "build a clean HSS"
-        rm -rfv obj*
-        rm -rfv m4
-        rm -rfv .autom4*
-        rm -fv configure
-    fi
-
-    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
-
-    if [ ! -n "$OBJ_DIR" ]; then
-        OBJ_DIR="objs"
-        mkdir --verbose -m 777 ./$OBJ_DIR
-    else
-        OBJ_DIR=`basename $OBJ_DIR`
-    fi
-
-    if [ ! -f "$OBJ_DIR"/Makefile ]; then
-        if [ ! -d m4 ]; then
-            mkdir --verbose -m 777 m4
-        fi
-        echo_success "Invoking autogen"
-        ./autogen.sh
-        if [ $? -ne 0 ]; then
-            return 1
-        fi
-        cd $OBJ_DIR
-        echo_success "Invoking configure"
-        ../configure
-        if [ $? -ne 0 ]; then
-            return 1
-        fi
-    else
-        cd $OBJ_DIR
-    fi
-
-    if [ -f Makefile ];  then
-        echo_success "Compiling..."
-        make ; #-j $NUM_CPU
-        if [ $? -ne 0 ]; then
-            echo_error "Build failed, exiting"
-            return 1
-        else
-            return 0
-        fi
-    else
-        echo_error "Configure failed, aborting"
-    fi
-    return 1
-}
-
-
-compile_epc() {
-    cd $OPENAIR3_DIR
-    if [ $1 = 1 ]; then
-        echo_info "build a clean EPC"
-        bash_exec "rm -rf objs"
-    fi
-    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
-    if [ ! -n "$OBJ_DIR" ]; then
-        OBJ_DIR="objs"
-        bash_exec "mkdir -m 777 ./$OBJ_DIR"
-        echo_success "Created $OBJ_DIR directory"
-    else
-        OBJ_DIR=`basename $OBJ_DIR`
-    fi
-    if [ ! -f $OBJ_DIR/Makefile ]; then
-        if [ ! -n "m4" ]; then
-            mkdir -m 777 m4
-        fi
-        bash_exec "autoreconf -i -f"
-        echo_success "Invoking autogen"
-        bash_exec "libtoolize"
-        bash_exec "./autogen.sh"
-        cd ./$OBJ_DIR
-        echo_success "Invoking configure"
-        if [ $DEBUG -ne 0 ]; then
-            ../configure --enable-debug --enable-standalone-epc --enable-gtp1u-in-kernel LDFLAGS=-L/usr/local/lib
-        else
-            ../configure                --enable-standalone-epc --enable-gtp1u-in-kernel LDFLAGS=-L/usr/local/lib
-        fi
-    else
-        cd ./$OBJ_DIR
-    fi
-
-#    pkill oai_epc
-#    pkill tshark
-
-    if [ -f Makefile ]; then
-        echo_success "Compiling..."
-        make -j $NUM_CPU
-        if [ $? -ne 0 ]; then
-            echo_error "Build failed, exiting"
-            return 1
-        else
-            cp -pf ./OAI_EPC/oai_epc  $OPENAIR_TARGETS/bin
-        fi
-    else
-        echo_error "Configure failed, exiting"
-        return 1
-    fi
-
-    cd $OPENAIR3_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 $OPENAIR3_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
-    return 0
-}
-
-compile_exmimo2_driver() {
-    cd $OPENAIR_TARGETS/ARCH/EXMIMO/DRIVER/eurecom && make clean && make   || exit 1
-    cd $OPENAIR_TARGETS/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT && make clean && make   || exit 1
-    # TO DO CHECKS...
-}
-
-
-compile_ltesoftmodem() {
-    cd $OPENAIR_TARGETS/RT/USER
-    if [ -f Makefile ];  then
-        rm -f ./lte-softmodem
-        echo "LTE softmodem compiling directives: $SOFTMODEM_DIRECTIVES"
-        if [ $OAI_CLEAN -ne 0 ]; then
-            echo "Cleaning LTE softmodem"
-            make cleanall > /dev/null 2>&1
-        fi
-        make -j $NUM_CPU $SOFTMODEM_DIRECTIVES
-        if [ $? -ne 0 ]; then
-            # to locate easily compilation error in log file
-            make  $SOFTMODEM_DIRECTIVES
-        fi
-        if [ $? -ne 0 ]; then
-            if [ ! -f ./lte-softmodem ]; then
-                echo_error "Build lte-softmodem failed, returning"
-                return 1
-            else
-                cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
-                return 0
-            fi
-        else
-            cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
-            return 0
-        fi
-    else
-        echo_error "make file for oai softmodem not found, returning"
-        return 1
-    fi
-}
-
-compile_oaisim() {
-    cd $OPENAIR_TARGETS/SIMU/USER
-    if [ -f Makefile ]; then
-        echo "Compiling for oaisim  target ($OAISIM_DIRECTIVES)"
-        make cleanall > /dev/null
-        make -j $NUM_CPU $OAISIM_DIRECTIVES
-        if [ $? -ne 0 ]; then
-            echo_error "Build oaisim failed, returning"
-            return 1
-        else
-            cp -pf ./oaisim $OPENAIR_TARGETS/bin
-            return 0
-        fi
-    else
-        echo_error "Makefile not found for oaisim target, returning"
-        return 1
-    fi
-}
-
-compile_unisim() {
-    cd $OPENAIR1_DIR/SIMULATION/LTE_PHY
-    if [ -f Makefile ]; then
-        echo "Compiling for UNISIM target ..."
-        make cleanall
-        make  -j $NUM_CPU all
-        if [ $? -ne 0 ]; then
-            echo_error "Build unisim failed, returning"
-            return 1
-        else
-            cp -pf ./dlsim     $OPENAIR_TARGETS/bin
-            cp -pf ./ulsim     $OPENAIR_TARGETS/bin
-            cp -pf ./pucchsim  $OPENAIR_TARGETS/bin
-            cp -pf ./prachsim  $OPENAIR_TARGETS/bin
-            cp -pf ./pdcchsim  $OPENAIR_TARGETS/bin
-            cp -pf ./pbchsim   $OPENAIR_TARGETS/bin
-            cp -pf ./mbmssim   $OPENAIR_TARGETS/bin
-            return 0
-        fi
-    else
-        echo_error "Configure failed, exiting"
-        return 1
-    fi
-}
-
-compile_nas_tools() {
-
-    export NVRAM_DIR=$OPENAIR_TARGETS/bin
-
-    cd $NVRAM_DIR
-
-        if [ ! -f /tmp/nas_cleaned ]; then
-            echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools veryveryclean"
-            make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools veryveryclean
-        fi
-        echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all"
-        make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all
-        rm .ue.nvram0
-        rm .usim.nvram0
-        touch /tmp/nas_cleaned
-}
-
-
-compile_ue_ip_nw_driver() {
-    cd $OPENAIR2_DIR && make ue_ip.ko
-}
-
-################################################
-# 1. check if the executable functions exist
-###############################################
-
-check_for_ltesoftmodem_executable() {
-    if [ ! -f $OPENAIR_TARGETS/RT/USER/lte-softmodem ];   then
-        echo_error "Cannot find lte-softmodem executable object in directory $OPENAIR_TARGETS/RT/USER"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-        exit 1
-    fi
-}
-
-check_for_epc_executable() {
-    if [ ! -f $OPENAIR3_DIR/objs/OAI_EPC/oai_epc ]; then
-        echo_error "Cannot find oai_epc executable object in directory $OPENAIR3_DIR/objs/OAI_EPC/"
-        echo_fatal "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
-    fi
-}
-
-check_for_hss_executable() {
-    if [ ! -f $OPENAIR3_DIR/OPENAIRHSS/objs/openair-hss ]; then
-        echo_error "Cannot find openair-hss executable object in directory $OPENAIR3_DIR/OPENAIRHSS/objs/"
-        echo_fatal "Please make sure you have compiled OAI HSS"
-    fi
-}
-
-check_for_sgw_executable() {
-    if [ ! -f $OPENAIR3_DIR/objs/OAI_SGW/oai_sgw ]; then
-        echo_error "Cannot find oai_sgw executable object in directory $OPENAIR3_DIR/OPENAIRMME/objs/OAI_SGW/"
-        echo_fatal "Please make sure you have compiled OAI EPC without --enable-standalone-epc option"
-    fi
-}
-
-check_for_oaisim_executable() {
-    if [ ! -f $OPENAIR_TARGETS/SIMU/USER/oaisim ]; then
-        echo_error "Cannot find oaisim executable object in directory $OPENAIR_TARGETS/SIMU/USER"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_dlsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/dlsim ];  then
-        echo_error "Cannot find dlsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_ulsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/ulsim ]; then
-        echo_error "Cannot find ulsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_pucchsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pucchsim ]; then
-        echo_error "Cannot find pucchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_prachsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/prachsim ]; then
-        echo_error "Cannot find prachsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_pdcchsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pdcchsim ]; then
-        echo_error "Cannot find pdcchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_pbchsim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pbchsim ]; then
-        echo_error "Cannot find pbchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_mbmssim_executable() {
-    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/mbmssim ]; then
-        echo_error "Cannot find mbmssim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
-        echo_error "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-check_for_nas_ue_executable() {
-    if [ ! -f $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/UserProcess ]; then
-        echo_error "Cannot find UserProcess executable object in directory  $OPENAIR3_DIR/NAS/EURECOM-NAS/bin"
-        echo_fatal "Check the compilation logs in bin/install_log.txt"
-    fi
-}
-
-################################################
-# 1. check if the executable functions exist
-###############################################
-
-# arg1 is RT
-# arg2 is HW
-# arg3 is ENB_S1
-install_ltesoftmodem() {
-    # RT
-    if [ $1 = "RTAI" ]; then
-        if [ ! -f /tmp/init_rt_done.tmp ]; then
-            echo_info "  8.1 Insert RTAI modules"
-            $SUDO insmod /usr/realtime/modules/rtai_hal.ko     > /dev/null 2>&1
-            $SUDO insmod /usr/realtime/modules/rtai_sched.ko   > /dev/null 2>&1
-            $SUDO insmod /usr/realtime/modules/rtai_sem.ko     > /dev/null 2>&1
-            $SUDO insmod /usr/realtime/modules/rtai_fifos.ko   > /dev/null 2>&1
-            $SUDO insmod /usr/realtime/modules/rtai_mbx.ko     > /dev/null 2>&1
-            $SUDO touch /tmp/init_rt_done.tmp
-            $SUDO chmod 666 /tmp/init_rt_done.tmp
-        else
-            echo_warning "  8.1 RTAI modules already inserted"
-        fi
-    fi
-    #HW
-    if [ $2 = "EXMIMO" ]; then
-	echo_info "  8.2 [EXMIMO] creating RTAI fifos"
-	for i in `seq 0 64`; do
-	    have_rtfX=`ls /dev/ |grep -c rtf$i`;
-	    if [ "$have_rtfX" -eq 0 ] ; then
-		$SUDO mknod -m 666 /dev/rtf$i c 150 $i;
-	    fi;
-	done
-	echo_info "  8.3 [EXMIMO] Build lte-softmodemdrivers"
-	cd $OPENAIR_TARGETS/ARCH/EXMIMO/DRIVER/eurecom && make clean && make  # || exit 1
-	cd $OPENAIR_TARGETS/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT && make clean && make  # || exit 1
-
-	echo_info "  8.4 [EXMIMO] Setup RF card"
-	cd $OPENAIR_TARGETS/RT/USER
-	. ./init_exmimo2.sh
-    else
-	if [ $2 = "USRP" ]; then
-	    echo_info "  8.2 [USRP] "
-	fi
-
-    fi
-
-    # ENB_S1
-    if [ $3 = 0 ]; then
-        cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
-        cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
-    fi
-
-}
-
-# arg1 is ENB_S1 'boolean'
-install_oaisim() {
-   if [ $1 = 0 ]; then
-       cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
-       cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
-   else
-       compile_ue_ip_nw_driver
-       install_nas_tools
-   fi
-
-}
-
-
-install_nas_tools() {
-    cd $OPENAIR_TARGETS/bin
-    if [ ! -f .ue.nvram0 ]; then
-        echo_success "generate .ue_emm.nvram0 .ue.nvram0"
-        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
-    fi
-
-    if [ ! -f .usim.nvram0 ]; then
-        echo_success "generate .usim.nvram0"
-        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
-    fi
-    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
-    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
-}
-
-install_nasmesh(){
-    echo_success "LOAD NASMESH IP DRIVER FOR UE AND eNB"
-    (cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make)
-    (cd $OPENAIR2_DIR && make clean && make nasmesh_netlink_address_fix.ko)
-    $SUDO rmmod nasmesh
-    $SUDO insmod $OPENAIR2_DIR/NAS/DRIVER/MESH/nasmesh.ko
-}
-
-##################################
-# create HSS DB
-################################
-
-# arg 1 is mysql user      (root)
-# arg 2 is mysql password  (linux)
-# arg 3 is hss username    (hssadmin)
-# arg 4 is hss password    (admin)
-# arg 5 is database name   (oai_db)
-create_hss_database(){
-    EXPECTED_ARGS=5
-    E_BADARGS=65
-    MYSQL=`which mysql`
-    rv=0
-    if [ $# -ne $EXPECTED_ARGS ]
-    then
-        echo_fatal "Usage: $0 dbuser dbpass hssuser hsspass databasename"
-        rv=1
-    fi
-
-    set_openair_env
-
-    # removed %
-    #Q1="GRANT ALL PRIVILEGES ON *.* TO '$3'@'%' IDENTIFIED BY '$4' WITH GRANT OPTION;"
-    Q1="GRANT ALL PRIVILEGES ON *.* TO '$3'@'localhost' IDENTIFIED BY '$4' WITH GRANT OPTION;"
-    Q2="FLUSH PRIVILEGES;"
-    SQL="${Q1}${Q2}"
-    $MYSQL -u $1 --password=$2 -e "$SQL"
-    if [ $? -ne 0 ]; then
-       echo_error "$3 permissions failed"
-       return 1
-    else
-       echo_success "$3 permissions succeeded"
-    fi
-
-
-    Q1="CREATE DATABASE IF NOT EXISTS ${BTICK}$5${BTICK};"
-    SQL="${Q1}"
-    $MYSQL -u $3 --password=$4 -e "$SQL"
-    if [ $? -ne 0 ]; then
-       echo_error "$5 creation failed"
-       return 1
-    else
-       echo_success "$5 creation succeeded"
-    fi
-
-
-    # test if tables have been created
-    mysql -u $3 --password=$4  -e "desc $5.users" > /dev/null 2>&1
-
-    if [ $? -eq 1 ]; then
-        $MYSQL -u $3 --password=$4 $5 < $OPENAIR3_DIR/OPENAIRHSS/db/oai_db.sql
-        if [ $? -ne 0 ]; then
-            echo_error "$5 tables creation failed"
-            return 1
-        else
-            echo_success "$5 tables creation succeeded"
-        fi
-    fi
-
-    return 0
-}
-
-################################
-# set_openair_env
-###############################
-set_openair_env(){
-
-    fullpath=`readlink -f $BASH_SOURCE`
-    [ -f "/.$fullpath" ] || fullpath=`readlink -f $PWD/$fullpath`
-    openair_path=${fullpath%/targets/*}
-    openair_path=${openair_path%/openair3/*}
-    openair_path=${openair_path%/openair[123]/*}
-
-    export OPENAIR_DIR=$openair_path
-    export OPENAIR_HOME=$openair_path
-    export OPENAIR1_DIR=$openair_path/openair1
-    export OPENAIR2_DIR=$openair_path/openair2
-    export OPENAIR3_DIR=$openair_path/openair3
-    export OPENAIR3_DIR=$openair_path/openair3
-    export OPENAIR_TARGETS=$openair_path/targets
-
-}
-
-########################################
-### print help
-######################################
-
-print_help(){
-    echo_success "Name : build_oai  - install and build OAI"
-    echo_success "Usage: build_oai.bash -a -b -c -d -e RTAI -m -r REL8 -s -t OAISIM -w EXMIMO -x"
-    echo_success "-a | --doxygen                          : Enable doxygen for documentation (default disabled)"
-    echo_success "-b | --disable-s1                       : Disable S1 interface for eNB (default enabled)"
-    echo_success "-c | --clean                            : Enable clean OAI build (default disabled)"
-    echo_success "-C | --config-file                      : Set the config file local path"
-    echo_success "-d | --debug                            : Enable debug mode (default disabled)"
-    echo_success "-D | --disable-check-installed-software : Disable the checking of installed software (default is check)"
-    echo_success "-e | --realtime                         : Set realtime mode: RTAI, NONE (default NONE)"
-    echo_success "-g | --run-with-gdb                     : Run the executable built by this script with gdb"
-    echo_success "-K | --itti-dump-file                   : Set the execution events trace file"
-    echo_success "-l | --build-target                     : Set the LTE build target: ENB,EPC,HSS,NONE (default ENB)"
-    echo_success "-m | --build-from-makefile              : Enable build from the makefile (default disabled)"
-    echo_success "-r | --3gpp-release                     : Set the release: REL8, REL10 (default REL8)"
-    echo_success "-p | --wireshark                        : enable wireshark interface for L2 pdus"
-    echo_success "-R | --run                              : Run the executable built by this script"
-    echo_success "-s | --check                            : Enable OAI testing and sanity check (default disabled)"
-    echo_success "-t | --enb-build-target                 : Set the eNB build target: ALL, SOFTMODEM,OAISIM,UNISIM (default ALL)"
-    echo_success "-V | --vcd                              : Log vcd events"
-    echo_success "-w | --hardware                         : Set the hardware platform: EXMIMO, USRP (also installs UHD driver), ETHERNET, NONE, (default EXMIMO)"
-    echo_success "-x | --xforms                           : Enable xforms (default disabled)"
-    echo_success "-z | --defaults                         : Set the default build options"
-}
-
-print_help_perf(){
-    echo_success "Name : perf_oai  generate traffic and evaluate the performance "
-    echo_success "Usage: perf_oai.bash -l ITG "
-    echo_success "-l | --perf-app               : Set Performance evaluation app: ITGS, ITGD,PING, OTG-OAISIM, OTG-CBA, (default PING)"
-    echo_success "-m | --owd                    : enable D-ITG one-way-delay meter (default disabled)"
-    echo_success "-e | --duration               : set the duration of the experiment (default 60000ms)"
-    echo_success "-i | --idt-dist               : set the distribution of the inter-departure time: CONSTANT, UNIFORM,EXPONENTIAL (default CONSTANT)"
-    echo_success "-s | --ps-dist                : set the distribution of the inter-departure time (default CONSTANT, available options: UNIFORM,EXPONENTIAL)"
-    echo_success "-d | --dst                    : set the destination address (default 127.0.0.1)"
-    echo_success "-p | --dst-port               : set the destination address (default NONE)"
-    echo_success "-t | --test                   : enable test mode to validate the functionality (default disabled)"
-    echo_success "-k | --keep-log-file          : keep the log files (default disabled)"
-
-}
-###############################
-## echo and  family
-###############################
-black='\E[30m'
-red='\E[31m'
-green='\E[32m'
-yellow='\E[33m'
-blue='\E[34m'
-magenta='\E[35m'
-cyan='\E[36m'
-white='\E[37m'
-reset_color='\E[00m'
-
-
-cecho()   # Color-echo
-# arg1 = message
-# arg2 = color
-{
-    local default_msg="No Message."
-    message=${1:-$default_msg}
-    color=${2:-$green}
-    if [ $BUILD_FROM_MAKEFILE = 0 ]; then
-	echo -e -n "$color$message$reset_color"
-	echo
-    else
-	echo "$message"
-    fi
-    return
-}
-
-echo_error() {
-    local my_string=""
-    until [ -z "$1" ]
-    do
-        my_string="$my_string$1"
-        shift
-        done
-        cecho "$my_string" $red
-}
-
-echo_fatal() {
-    local my_string=""
-    until [ -z "$1" ]
-    do
-        my_string="$my_string$1"
-        shift
-        done
-        echo_error "$my_string"
-    exit -1
-}
-
-echo_warning() {
-    local my_string=""
-    until [ -z "$1" ]
-    do
-        my_string="$my_string$1"
-        shift
-    done
-    cecho "$my_string" $yellow
-}
-
-echo_success() {
-    local my_string=""
-    until [ -z "$1" ]
-    do
-        my_string="$my_string$1"
-        shift
-    done
-    cecho "$my_string" $green
-}
-echo_info() {
-    local my_string=""
-    until [ -z "$1" ]
-    do
-        my_string="$my_string$1"
-        shift
-    done
-    cecho "$my_string" $blue
-}
-
-bash_exec() {
-    output=$($1 2>&1)
-    result=$?
-    if [ $result -eq 0 ]; then
-        echo_success "$1"
-    else
-        echo_error "$1: $output"
-    fi
-}
-
-
-wait_process_started () {
-    if  [ -z "$1" ]; then
-        echo_error "WAITING FOR PROCESS START: NO PROCESS"
-        return 1
-    fi
-    ps -C $1 > /dev/null 2>&1
-    while [ $? -ne 0 ]; do
-        echo_warning "WAITING FOR $1 START"
-        sleep 2
-        ps -C $1 > /dev/null 2>&1
-    done
-    echo_success "PROCESS $1 STARTED"
-    return 0
-}
-
-is_process_started () {
-    if  [ -z "$1" ]; then
-        echo_error "WAITING FOR PROCESS START: NO PROCESS"
-        return 1
-    fi
-    ps -C $1 > /dev/null 2>&1
-    if [ $? -ne 0 ]; then
-        echo_success "PROCESS $1 NOT STARTED"
-        return 1
-    fi
-    echo_success "PROCESS $1 STARTED"
-    return 0
-}
-
-assert() {
-    # If condition false
-    # exit from script with error message
-    E_PARAM_ERR=98
-    E_PARAM_FAILED=99
-
-    if [ -z "$2" ] ; then # Not enought parameters passed.
-        return $E_PARAM_ERR
-    fi
-
-    lineno=$2
-    if [ ! $1 ]; then
-        echo_error "Assertion failed:  \"$1\""
-        echo_fatal "File \"$0\", line $lineno"
-    fi
-}
diff --git a/targets/build_oai.bash b/targets/build_oai.bash
deleted file mode 100755
index 05b14a541b10a14dc6c4dfc72a939cbb1f37b8c0..0000000000000000000000000000000000000000
--- a/targets/build_oai.bash
+++ /dev/null
@@ -1,840 +0,0 @@
-#/*
-# * 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
-# * the OAI Public License, Version 1.1  (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.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
-# */
-################################################################################
-# file build_oai.bash
-# brief OAI automated build tool that can be used to install, compile, run OAI.
-# author  Navid Nikaein, Lionel GAUTHIER
-# company Eurecom
-# email:  navid.nikaein@eurecom.fr, lionel.gauthier@eurecom.fr 
-#
-
-#!/bin/bash
-################################
-# include helper functions
-################################
-THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
-. $THIS_SCRIPT_PATH/build_helper.bash
-
-check_for_root_rights
-
-#######################################
-# Default PARAMETERS
-######################################
-declare OAI_DB_ADMIN_USER_NAME="root"
-declare OAI_DB_ADMIN_USER_PASSWORD="linux"
-
-#only one could be set at the time
-declare BUILD_LTE="NONE" # ENB, EPC, HSS
-
-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, NONE
-declare DEBUG=0
-declare CONFIG_FILE=" "
-declare CONFIG_FILE_ACCESS_OK=0
-declare EXE_ARGUMENTS=" "
-declare RUN_GDB=0
-declare RUN=0
-declare DISABLE_CHECK_INSTALLED_SOFTWARE=0
-declare OAI_CLEAN=0
-declare CLEAN_IPTABLES=0
-declare CLEAN_HSS=0
-
-declare OAI_TEST=0
-declare XFORMS=0
-
-# script is not currently handling these params
-declare EPC=0 # flag to build EPC
-
-declare ITTI_ANALYZER=0
-declare VCD_TIMING=0
-declare WIRESHARK=0
-declare TIME_MEAS=0
-declare DOXYGEN=0
-declare DEV=0
-
-#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}'`
-
-############## script params #####################
-
-if [ -f ./.lock_oaibuild ]; then 
-    OAI_CLEAN=0
-else 
-    OAI_CLEAN=1
-fi 
- 
-#for i in "$@"
-#do 
-#    echo "i is : $i"
-#    case $i in
-
-
-  until [ -z "$1" ]
-  do
-  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
-            CLEAN_HSS=1
-            echo "setting clean flag to: $OAI_CLEAN"
-            echo "may check package installation, and recompile OAI"
-            shift;
-            ;;
-       --clean-iptables)
-            CLEAN_IPTABLES=1;
-            shift;
-            ;;
-       -C | --config-file)
-            CONFIG_FILE=$2
-            # 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"
-                CONFIG_FILE_ACCESS_OK=1
-            else
-                # may be absolute path 
-                if [ -f $CONFIG_FILE ]; then
-                    echo "setting config file to: $CONFIG_FILE"
-                    CONFIG_FILE_ACCESS_OK=1
-                else
-                    echo "config file not found"
-                    exit 1
-                fi
-            fi
-            EXE_ARGUMENTS="$EXE_ARGUMENTS -O $CONFIG_FILE"
-            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)
-            RT=$2
-            echo "setting realtime flag to: $RT"
-            shift 2 ;
-            ;;
-       -g | --run-with-gdb)
-            DEBUG=1
-            RUN=1 
-            RUN_GDB=1
-            echo "Running with gdb"
-            shift;
-            ;;
-       -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) 
-            BUILD_LTE=$2
-            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)
-            REL=$2 
-            echo "setting release to: $REL"
-            shift 2 ;
-            ;;
-       -R | --run)
-            RUN=1 
-            echo "setting run to $RUN"
-            shift;
-            ;;
-       -s | --check)
-            OAI_TEST=1
-            echo "setting sanity check to: $OAI_TEST"
-            shift;
-            ;;
-       -t | --enb-build-target)
-            TARGET=$2 
-            echo "setting enb build target to: $TARGET"
-            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
-            EXE_ARGUMENTS="$EXE_ARGUMENTS -d"
-            echo "setting xforms to: $XFORMS"
-            shift;
-            ;;
-       -p | --wireshark)
-	  WIRESHARK=1
-	  echo "enabling Wireshark interface to $WIRESHARK"
-          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 ;
-            # unknown option
-            ;;
-   esac
-done
-
-#####################
-# create a bin dir
-#####################
-echo_info "1. Creating the bin dir ..." 
-mkdir -m 777 bin 
-
-build_date=`date +%Y_%m_%d`
-oai_build_date="oai_built_${build_date}"
-touch bin/${oai_build_date} 
-chmod -f 777 bin/${oai_build_date}
-
-touch bin/install_log.txt
-chmod -f 777 bin/install_log.txt
-################################
-# cleanup first 
-################################
-#echo_info "3. Cleaning ..."
-
-#$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
-
-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
-############################################
-# setting and printing OAI envs, we should check here
-############################################
-    
-echo_info "2. Setting the OAI PATHS ..."
-
-set_openair_env 
-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 "OPENAIR3_DIR   = $OPENAIR3_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 "OPENAIR3_DIR   = $OPENAIR3_DIR"  >>  bin/${oai_build_date}
-echo "OPENAIR_TARGETS = $OPENAIR_TARGETS"  >>  bin/${oai_build_date}
-
-
-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 ..."
-    
-    
-    SOFTMODEM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
-    OAISIM_DIRECTIVES="DEBUG=$DEBUG XFORMS=$XFORMS "
-    
-    if [ $ENB_S1 -eq 1 ]; then 
-        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 "
-    fi 
-    
-    if [ $DEBUG -eq 0 ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES DISABLE_XER_PRINT=1 "
-        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES DISABLE_XER_PRINT=1 "
-    fi 
-
-    if [ $HW = "USRP" ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES USRP=1 "
-    fi
-    
-    if [ $HW = "ADRV9371_ZC706" ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES ADRV9371_ZC706=1 "
-    fi
-    
-    if [ $HW = "EXMIMO" ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES EXMIMO=1 "
-    fi
-    
-    if [ $HW = "ETHERNET" ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES ETHERNET=1 "
-    fi 
-    
-    if [ $ENB_S1 -eq 0 ]; then 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES NAS=1 "
-        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES NAS=1 "
-    fi 
-    
-    if [ $REL = "REL8" ]; then
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel8=1 "
-        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel8=1 "
-    else 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES Rel10=1 "
-        OAISIM_DIRECTIVES="$OAISIM_DIRECTIVES Rel10=1 "
-    fi
-    
-    if [ $RT = "RTAI" ]; then 
-        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
-    else 
-        SOFTMODEM_DIRECTIVES="$SOFTMODEM_DIRECTIVES RTAI=0 "
-        RT="NONE"
-    fi
-    
-    if [ $TARGET != "ALL" ]; then 
-        if [ $TARGET  != "SOFTMODEM" ]; then 
-            HW="NONE"
-        fi
-    fi
-    
-    if [ $UBUNTU_REL = "12.04" ]; then 
-        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
-    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}
-    
-    
-############################################
-# check the installation
-############################################
-    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 ..."
-        touch ./.lock_oaibuild
-    fi
-    
-############################################
-# compile 
-############################################
-
-    echo_info "7. compiling and installing the OAI binaries ..."
-
-    softmodem_compiled=1
-    oaisim_compiled=1
-    unisim_compiled=1
-    
-    if [ $TARGET = "ALL" ]; then
-        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" 
-
-
-    else
-        if [ $TARGET == "SOFTMODEM" ]; then 
-            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"
-            
-            if [ $HW == "EXMIMO" ]; then 
-                output=$(compile_exmimo2_driver   >> bin/install_log.txt  2>&1)
-            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" 
-            
-            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
-        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
-    fi
-
-
-############################################
-# install 
-############################################
-
-    echo_info "8. Installing ..."
-    
-    if [ $softmodem_compiled -eq 0 ]; then 
-        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 )
-    fi
-    if [ $oaisim_compiled -eq 0 ]; then 
-        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 )
-    fi 
-    if [ $unisim_compiled -eq  0 ]; then 
-        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}
-    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"
-    
-
-
-}
-build_epc(){
-
-    epc_compiled=1
-
-    echo_info "Note: this scripts tested only on Ubuntu 14.04x64"
-
-######################################
-# CHECK MISC SOFTWARES AND LIBS      #
-######################################
-    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
-        echo_info "4. Checking the the required softwares/packages for EPC..."
-
-        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"
-    fi
-
-###########################################
-# configure and compile
-##########################################
-
-    echo_info "5. configure and compile epc"
-
-    output=$(compile_epc $OAI_CLEAN  >> $OPENAIR_TARGETS/bin/install_log.txt  2>&1 )
-    epc_compiled=$?
-    if [ $epc_compiled -ne 0 ]; then
-        echo_error "EPC compilation failed : check the installation log file bin/install_log.txt" 
-        exit 1
-    fi
-    check_for_epc_executable
-    echo_info "finished epc target: check the installation log file bin/install_log.txt" 
-
-    if [ $CONFIG_FILE_ACCESS_OK -eq 0 ]; then
-        echo_error "You have to provide a EPC config file"
-        exit 1
-    fi
-    
-    TEMP_FILE=`tempfile`
-    VARIABLES=" S6A_CONF\|\
-           HSS_HOSTNAME\|\
-           REALM"
-
-    VARIABLES=$(echo $VARIABLES | sed -e 's/\\r//g')
-    VARIABLES=$(echo $VARIABLES | tr -d ' ')
-    cat $CONFIG_FILE | grep -w "$VARIABLES"| tr -d " " | tr -d ";" > $TEMP_FILE
-    source $TEMP_FILE
-    rm -f $TEMP_FILE
-
-    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
-
-###########################################
-# install the binary in bin
-##########################################
-
-    echo_info "6. install the binary file"
-
-    if [ $epc_compiled -eq 0 ]; then 
-        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}
-        cp -f $CONFIG_FILE  $OPENAIR_TARGETS/bin
-        cp -f $OPENAIR3_DIR/objs/UTILS/CONF/s6a.conf  $OPENAIR_TARGETS/bin/epc_s6a.conf
-    fi
-}
-
-build_hss(){
-    echo_info "Note: this script tested only for Ubuntu 12.04 x64 -> 14.04 x64"
-
-######################################
-# CHECK MISC SOFTWARES AND LIBS      #
-######################################
-    if [ $DISABLE_CHECK_INSTALLED_SOFTWARE -eq 0 ]; then 
-        echo_info "4. check the required packages for HSS"
-        check_install_hss_software
-        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 packages for HSS"
-    fi
-    
-  
-######################################
-# compile HSS                        #
-######################################
-    echo_info "5. compile HSS"
-
-     # Bad behaviour of $OAI_CLEAN with ./.lock_oaibuild ...
-     compile_hss $CLEAN_HSS
-     hss_compiled=$?
-     check_for_hss_executable
-     echo_info "finished hss target" 
- 
-######################################
-# Check certificates                 #
-######################################
-  
-    TEMP_FILE=`tempfile`
-    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
-    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/.*\.//')
-    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>"
-       sed -ibak "s/$HSS_HOSTNAME/$NEW_HOSTNAME/"  $OPENAIR3_DIR/OPENAIRHSS/conf/hss_fd.conf 
-    fi
-    check_hss_s6a_certificate $HSS_REALM
-    
-######################################
-# fill the HSS DB
-######################################
-     echo_info "6. create HSS database (for EURECOM SIM CARDS)"
-     hss_db_created=1
-     create_hss_database $OAI_DB_ADMIN_USER_NAME $OAI_DB_ADMIN_USER_PASSWORD $MYSQL_user $MYSQL_pass $MYSQL_db
-     if [ $? -eq 1 ]; then
-         echo_fatal "hss DB not created"
-     fi
-}
-
-
- 
-
-echo_info "3. set the top-level build target"
-case "$BUILD_LTE" in
-    'ENB')
-         echo_success "build LTE eNB"
-         build_enb
-         ;;
-    'EPC')
-         echo_success "build EPC(MME and xGW)"
-         build_epc
-         ;;
-    'HSS')
-        echo_success "build HSS"
-        build_hss 
-        ;;
-    'NONE')
-        ;;
-    *)
-        ;;
-esac
-
-# Additional operation 
-
-############################################
-# Generate doxygen documentation
-############################################
-
-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 
-
-
-############################################
-# testing
-############################################
-    
-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 
-    
-############################################
-# run 
-############################################
-
-if [ $RUN -ne 0 ]; then 
-    echo_info "11. Running ..."
-    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
-		if [ $WIRESHARK -eq 1 ]; then 
-		    EXE_ARGUMENTS="$EXE_ARGUMENTS -W"
-		fi 
-                echo "############# running ltesoftmodem #############"
-                if [ $RUN_GDB -eq 0 ]; then 
-                    $SUDO $OPENAIR_TARGETS/bin/lte-softmodem  `echo $EXE_ARGUMENTS`
-                else
-                    $SUDO setenv MALLOC_CHECK_ 2
-                    $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
-                
-            elif [ $TARGET == "OAISIM" ]; then
-            
-                if [ $ENB_S1 -eq 0 ]; then
-		    install_nasmesh
-                else
-                    # prepare NAS for UE
-                    if [ ! -f .ue.nvram0 ]; then
-                        echo_success "generate .ue_emm.nvram0 .ue.nvram0"
-                        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
-                    fi
-
-                    if [ ! -f .usim.nvram0 ]; then
-                        echo_success "generate .usim.nvram0"
-                        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
-                    fi
-                    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
-                    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
-
-                    insmod  $OPENAIR2_DIR/NETWORK_DRIVER/UE_IP/ue_ip.ko
-                    
-                fi
-                if [ $WIRESHARK -eq 1 ]; then 
-		    EXE_ARGUMENTS="$EXE_ARGUMENTS -P wireshark"
-		fi 
-                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
-            fi
-            ;;
-        
-        
-        'EPC')
-            echo "############# running EPC #############"
-            test_is_host_reachable $HSS_HOSTNAME.$REALM HSS
-            if [ $RUN_GDB -eq 0 ]; then
-                $SUDO $OPENAIR_TARGETS/bin/oai_epc  `echo $EXE_ARGUMENTS`
-            else
-                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
-                $SUDO gdb -nh -x ~/.gdb_epc 2>&1 
-            fi
-            ;;
-        
-        
-        'HSS')
-            echo "############# running HSS #############"
-            cd $OPENAIR3_DIR/OPENAIRHSS/objs
-            if [ $RUN_GDB -eq 0 ]; then
-                $SUDO exec ./openair-hss -c ./conf/hss.conf
-            else
-                touch ~/.gdb_hss
-                chmod 777 ~/.gdb_hss
-                echo "file ./openair-hss" > ~/.gdb_hss
-                echo "set args -c ./conf/hss.conf" >> ~/.gdb_hss
-                echo "run" >> ~/.gdb_hss
-                $SUDO gdb -nh -x ~/.gdb_hss 2>&1 
-            fi
-             ;;
-         
-         
-        'NONE')
-             ;;
-         
-         
-        *)
-             echo_error "Unknown option $BUILD_LTE: do not execute"
-             ;;
-    esac
-else
-    echo_info "11. No run requested, end of script"
-    exit 0
-fi
-
-