From 92ef60d07fcc9ab76d7f7b55958854506fc02cc6 Mon Sep 17 00:00:00 2001
From: Melissa Elkadi <melissa@episci.com>
Date: Tue, 23 Nov 2021 15:49:47 -0800
Subject: [PATCH] This commit does the following:

1. Reverts GTPU_need_ITTI back to develop
2. Removed gdb helper and co files
3. Reverts changes to logging mechanism
4. Reverts changes to assert that were unnecessary
5. Reverts changes to VNF that occured from a bad merge
6. Removes unnecessary else() in gNB softmodem
---
 cmake_targets/CMakeLists.txt                  |   2 -
 cmake_targets/gdb-helper                      |  13 --
 cmake_targets/gdb.txt                         | 195 ------------------
 cmake_targets/sudo-gdb                        |   6 -
 common/utils/LOG/log.c                        |  21 +-
 common/utils/LOG/log.h                        |  10 -
 common/utils/ocp_itti/intertask_interface.cpp |   2 +-
 executables/nr-gnb.c                          |  30 +--
 executables/nr-softmodem.c                    |   5 +-
 9 files changed, 12 insertions(+), 272 deletions(-)
 delete mode 100755 cmake_targets/gdb-helper
 delete mode 100644 cmake_targets/gdb.txt
 delete mode 100755 cmake_targets/sudo-gdb

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 8580857b0b..8d7acaf18f 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -2846,7 +2846,6 @@ add_executable(lte-softmodem
   ${OPENAIR_DIR}/common/utils/utils.c
   ${OPENAIR_DIR}/common/utils/system.c
   ${PHY_INTERFACE_DIR}/queue_t.c
-  ${GTPU_need_ITTI}
   ${OPENAIR_DIR}/common/utils/lte/ue_power.c
   ${OPENAIR_DIR}/common/utils/lte/prach_utils.c
   ${XFORMSINTERFACE_SOURCE}
@@ -3034,7 +3033,6 @@ add_executable(nr-softmodem
   ${OPENAIR_DIR}/common/utils/lte/prach_utils.c
   ${OPENAIR_DIR}/common/utils/nr/nr_common.c
   ${PHY_INTERFACE_DIR}/queue_t.c
-  ${GTPU_need_ITTI}
   ${XFORMSINTERFACE_SOURCE}
   ${T_SOURCE}
   ${CONFIG_SOURCES}
diff --git a/cmake_targets/gdb-helper b/cmake_targets/gdb-helper
deleted file mode 100755
index fe85809c10..0000000000
--- a/cmake_targets/gdb-helper
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-cd "$(dirname "$0")/.." || exit
-source oaienv
-cd cmake_targets || exit
-
-cmd=(
-    ./ran_build/build/lte-softmodem
-    -O ../ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
-    --noS1
-    "$@"
-)
-
-exec sudo -E gdb "$@" --args "${cmd[@]}"
diff --git a/cmake_targets/gdb.txt b/cmake_targets/gdb.txt
deleted file mode 100644
index 8c59d9a06d..0000000000
--- a/cmake_targets/gdb.txt
+++ /dev/null
@@ -1,195 +0,0 @@
--------------------------------------------------------------------------------
-Build.
-
-Make sure you've built with debug info:
-
-  cd ~/openairinterface5g # or wherever
-  source oaienv
-  cd cmake_targets
-  ./build_oai --UE --eNB --verbose-compile --run-with-gdb RelWithDebInfo
-  make -C ran_build/build -j4 lte-softmodem lte-uesoftmodem
-
--------------------------------------------------------------------------------
-Verify.
-
-Verify the build was done correctly:
-
-$ ./gdb-helper
-...
-Reading symbols from ./ran_build/build/lte-softmodem...done.
-(gdb) b main
-Breakpoint 1 at 0x59f110: file /local/episys/openairinterface5g/targets/RT/USER/lte-softmodem.c, line 516.
-(gdb) run
-Starting program: /local/episys/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem -O ../ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf --noS1
-[Thread debugging using libthread_db enabled]
-Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
-
-Breakpoint 1, main (argc=4, argv=0x7fffffffe058) at /local/episys/openairinterface5g/targets/RT/USER/lte-softmodem.c:516
-516     {
-(gdb) list
-511       pthread_mutex_unlock(&nfapi_sync_mutex);
-512       printf( "NFAPI: got sync (%s)\n", thread_name);
-513     }
-514
-515     int main ( int argc, char **argv )
-516     {
-517       struct sched_param param =
-518       {
-519         .sched_priority = 79
-520       };
-(gdb) n
-521       if (sched_setscheduler( 0, SCHED_RR, &param ) == -1 )
-(gdb) quit
-A debugging session is active.
-
-        Inferior 1 [process 19964] will be killed.
-
-Quit anyway? (y or n) y
-$
-
-If gdb says "no debugging symbols found" then clean your workspace and re-do
-the build as above.
-
-(gdb) b main
-
--------------------------------------------------------------------------------
-Password-less sudo.
-
-Vscode launches lte-softmodem via sudo.  Make sure sudo does not prompt you
-for a password:
-
-  sudo -n id
-
-If that command fails, do the following:
-
-  echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
-
-Then verify:
-
-  sudo -n id
-
--------------------------------------------------------------------------------
-Vscode.
-
-Launch Vscode:
-
-  cd ~/openairinterface5g # or wherever
-  code . targets/RT/USER/lte-softmodem.c .vscode/launch.json
-
-See launch.json for details about how vscode launches lte-softmodem for debugging.
-
-For example, in lte-softmodem.c, scroll to main() and click the line number to
-the left of main to add a breakpoint.  then do Run => Start debugging (F5) to
-run lte-softmodem in the debugger
-
--------------------------------------------------------------------------------
-Running Vscode remotely.
-
-Currently, running Vscode remotely (via an X-Windows connection) does not work
--- the Vscode window appears but remains blank.  Presumably the Vscode
-developers will fix this problem eventually.  Meanwhile, you can use `sshfs`
-to make the remote filesystem appear locally and then run Vscode locally.
-
-On the local machine:
-
-  $ remote=surfer      # or whatever the remote machine's name is
-  $ mkdir ~/openairinterface5g
-  $ sshfs $remote:openairinterface5g ~/openairinterface5g
-  $ ls ~/openairinterface5g
-   CHANGELOG.md    CONTRIBUTING.md   nfapi       openair3            targets
-  ...
-  $ code ~/openairinterface5g
-  $
-
-The remote and local pathnames of your openairinterface5g workspace should be
-the same.  If they're different, use a symlink on the local machine to make
-the remote pathnames work locally.  This part is important because executables
-built on $remote contain references to the source files and vscode & gdb will
-use those pathnames to find the source files.
-
-You may want to locally mount the remote logs directory, too:
-
-  $ mkdir ~/logs
-  $ sshfs $remote:logs ~/logs
-  $ ls -l ~/logs
-  total 40
-  lrwxrwxrwx 1 1002 1002   22 Jan 17 11:54 latest -> logs-2021-01-17-085419
-  drwxr-xr-x 1 1002 1002 4096 Jan 17 11:54 logs-2021-01-17-085419
-  $
-
-That will give you access to core files collected by lte_testscript.py, for
-example.
-
-  $ file ~/logs/latest/0001/coredump-6699
-  /home/michael/logs/latest/0001/coredump-6699: ELF 64-bit LSB core file,
-  x86-64, version 1 (SYSV), SVR4-style, from './ran_build/build/lte-softmodem
-  -O ../ci-scripts/conf_files/rcc.band7.tm1.nfapi', real uid: 0, effective
-  uid: 0, real gid: 0, effective gid: 0, execfn:
-  './ran_build/build/lte-softmodem', platform: 'x86_64'
-  $
-  $ file ~/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem
-  /home/michael/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem:
-  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked,
-  interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,
-  BuildID[sha1]=831400d4aae5d43b94ef3b22ebbd635107de48ae, with debug_info, not
-  stripped
-  $
-
-Verify gdb can access these remote files:
-
-  $ gdb ~/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem \
-  ~/logs/latest/0001/coredump-6699
-  ...
-  Program terminated with signal SIGABRT, Aborted.
-  #0  0x00007f7fd7d11438 in ?? ()
-  [Current thread is 1 (LWP 39)]
-  (gdb)
-
-If this step is too slow, you may want to copy the executable and coredump
-files to the local machine first.
-
-  $ scp -C $remote:openairinterface5g/cmake_targets/ran_build/build/lte-softmodem .
-  $ scp -C $remote:logs/latest/0001/coredump-6699 .
-  $ gdb lte-softmodem coredump-6699
-
-Note, the local and remote machines should be the same version of Linux (e.g.,
-both Ubuntu 16.04).  Otherwise, gdb will likely have trouble understanding the
-coredump.
-
-To load the coredump into Vscode, modify launch.json to add "coreDumpPath".
-You may also need to modify the "program" path and delete "miDebuggerPath".
-
---- .vscode/launch.json
-+++ .vscode/launch.json
-@@ -9,7 +9,7 @@
-             "name": "(gdb) Launch",
-             "type": "cppdbg",
-             "request": "launch",
--            "program": "${workspaceFolder}/cmake_targets/ran_build/build/lte-so
-+            "program": "/home/michael/tmp/lte-softmodem",
-             "args": [
-                 "-O", "../ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf",
-                 "--noS1"
-@@ -19,14 +19,14 @@
-             "environment": [],
-             "externalConsole": false,
-             "MIMode": "gdb",
--            "miDebuggerPath": "${workspaceFolder}/cmake_targets/sudo-gdb",
-             "setupCommands": [
-                 {
-                     "description": "Enable pretty-printing for gdb",
-                     "text": "-enable-pretty-printing",
-                     "ignoreFailures": true
-                 }
--            ]
-+            ],
-+            "coreDumpPath": "/home/michael/tmp/coredump-6699"
-         }
-     ]
- }
-
-Then, in Vscode click the debug icon on the left navigation bar, then click
-the green "play" triangle near the upper left corner of the window.  See the
-"CALL STACK" near the lower left of the window.
-
--------------------------------------------------------------------------------
diff --git a/cmake_targets/sudo-gdb b/cmake_targets/sudo-gdb
deleted file mode 100755
index 7c4005e19b..0000000000
--- a/cmake_targets/sudo-gdb
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-# Helper script for Vscode. See .vscode/launch.json "miDebuggerPath"
-cd "$(dirname "$0")/.." || exit
-source oaienv
-cd cmake_targets || exit
-exec sudo -nE gdb "$@"
diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c
index da009d9ba0..f733bc7ec5 100644
--- a/common/utils/LOG/log.c
+++ b/common/utils/LOG/log.c
@@ -562,19 +562,14 @@ static int log_header(char *log_buffer,
 					  const char *format)
 {
   char threadname[PR_SET_NAME];
-    struct timespec ts;
-    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
-        abort();
-    return snprintf(log_buffer, buffsize, "%lu.%06lu %s%s[%s]%c %s %s%s",
-                    ts.tv_sec,
-                    ts.tv_nsec / 1000,
-                    log_level_highlight_end[level],
-                    ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]),
-                    g_log->log_component[comp].name,
-                    ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '),
-                    ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""),
-                    format,
-                    log_level_highlight_end[level]);
+  return  snprintf(log_buffer, buffsize, "%s%s[%s]%c %s %s%s",
+                   log_level_highlight_end[level],
+                   ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]),
+                   g_log->log_component[comp].name,
+                   ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '),
+                   ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""),
+                   format,
+                   log_level_highlight_end[level]);
 }
 
 void logRecord_mt(const char *file,
diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index 6083d23580..e64a6183d3 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -106,22 +106,12 @@ extern "C" {
 /* .log_format = 0x13 uncolored standard messages
  * .log_format = 0x93 colored standard messages */
 /* keep white space in first position; switching it to 0 allows colors to be disabled*/
-#define LOG_WITH_COLORS 1
-#if LOG_WITH_COLORS
 #define LOG_RED "\033[1;31m"  /*!< \brief VT100 sequence for bold red foreground */
 #define LOG_GREEN "\033[32m"  /*!< \brief VT100 sequence for green foreground */
 #define LOG_ORANGE "\033[93m"   /*!< \brief VT100 sequence for orange foreground */
 #define LOG_BLUE "\033[34m" /*!< \brief VT100 sequence for blue foreground */
 #define LOG_CYBL "\033[40;36m"  /*!< \brief VT100 sequence for cyan foreground on black background */
 #define LOG_RESET "\033[0m" /*!< \brief VT100 sequence for reset (black) foreground */
-#else
-#  define LOG_RED    ""
-#  define LOG_GREEN  ""
-#  define LOG_ORANGE ""
-#  define LOG_BLUE   ""
-#  define LOG_CYBL   ""
-#  define LOG_RESET  ""
-#endif // LOG_WITH_COLORS
 /* @}*/
 
 
diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp
index 4239d1f42e..7254dfec93 100644
--- a/common/utils/ocp_itti/intertask_interface.cpp
+++ b/common/utils/ocp_itti/intertask_interface.cpp
@@ -82,7 +82,7 @@ extern "C" {
 
   void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size) {
     void *ptr = NULL;
-    AssertFatal ((ptr=calloc (1, size)) != NULL, "Memory allocation of %zu bytes failed (%d -> %d)!\n",
+    AssertFatal ((ptr=calloc (size, 1)) != NULL, "Memory allocation of %zu bytes failed (%d -> %d)!\n",
                  size, origin_task_id, destination_task_id);
     return ptr;
   }
diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c
index 2d43669f17..8e9bc34f98 100644
--- a/executables/nr-gnb.c
+++ b/executables/nr-gnb.c
@@ -238,34 +238,8 @@ void rx_func(void *param) {
   if (pthread_mutex_unlock(&rnti_to_remove_mutex)) exit(1);
 
   // RX processing
-  int tx_slot_type; int rx_slot_type;
-  if(NFAPI_MODE != NFAPI_MONOLITHIC) { //slot selection routines not working properly in nfapi, so temporarily hardcoding
-    if ((slot_tx==8) || (slot_tx==9) || (slot_tx==18) ||  (slot_tx==19)) { //tx slot config
-      tx_slot_type         = NR_UPLINK_SLOT;
-    }
-    else if ((slot_tx==7) || (slot_tx==17)) {
-      tx_slot_type         = NR_MIXED_SLOT;
-    }
-    else {
-      tx_slot_type         = NR_DOWNLINK_SLOT;;
-    }
-
-    if ((slot_rx==8) || (slot_rx==9) || (slot_rx==18) ||  (slot_rx==19)) { // rx slot config
-      rx_slot_type         = NR_UPLINK_SLOT; 
-    }
-    else if ((slot_rx==7) || (slot_rx==17)) {
-      rx_slot_type         = NR_MIXED_SLOT;
-    }
-    else {
-      rx_slot_type         = NR_DOWNLINK_SLOT;;
-    }
-
-
-  }
-  else {
-  tx_slot_type         = nr_slot_select(cfg,frame_tx,slot_tx);
-  rx_slot_type         = nr_slot_select(cfg,frame_rx,slot_rx);
-  }
+  int tx_slot_type         = nr_slot_select(cfg,frame_tx,slot_tx);
+  int rx_slot_type         = nr_slot_select(cfg,frame_rx,slot_rx);
   if (rx_slot_type == NR_UPLINK_SLOT || rx_slot_type == NR_MIXED_SLOT) {
     // UE-specific RX processing for subframe n
     // TODO: check if this is correct for PARALLEL_RU_L1_TRX_SPLIT
diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 57e375d9f0..5abf1851b7 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -633,7 +633,7 @@ void init_pdcp(void) {
       LOG_I(PDCP, "node is DU, rlc send pdcp_data_ind by proto_agent \n");
       pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
     }
-  } else if (get_softmodem_params()->nsa) {
+  } else {
     pdcp_layer_init();
     uint32_t pdcp_initmask = (IS_SOFTMODEM_NOS1) ?
                              (PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT) : LINK_ENB_PDCP_TO_GTPV1U_BIT;
@@ -646,9 +646,6 @@ void init_pdcp(void) {
     nr_pdcp_module_init(pdcp_initmask, 0);
     pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
     pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
-  } else {
-    LOG_I(PDCP, "node is DU, rlc send pdcp_data_ind by proto_agent \n");
-    pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
   }
 }
 
-- 
2.26.2