From b3ded7799a8326434be597d860bc468e958f384d Mon Sep 17 00:00:00 2001
From: Imad ALAWE <imad.Alawe@b-com.com>
Date: Wed, 22 Jun 2016 12:00:29 +0200
Subject: [PATCH] openairinterface5g: Fix multi definition of UE/eNB NB_MAX

In openairinterface5g many definitions in many layers of UE or eNB NB_MAX.
We created a file called openairinterface5g_limits.h
located at openairinterface5g_dir/targets/COMMON/ declaring the number max
of UE and eNB to be used in ALL layers depending on launching conditions
(LARGE_SCALE for example).
---
 cmake_targets/at_commands/CMakeLists.txt   |  3 +++
 openair1/PHY/impl_defs_top.h               | 16 +---------------
 openair2/NETWORK_DRIVER/UE_IP/constant.h   |  3 ++-
 openair2/UTIL/OMV/structures.h             | 11 +++++------
 openair2/UTIL/OTG/otg_defs.h               |  8 ++++----
 openair3/NAS/UE/nas_ue_task.h              |  3 +--
 targets/COMMON/openairinterface5g_limits.h | 20 ++++++++++++++++++++
 7 files changed, 36 insertions(+), 28 deletions(-)
 create mode 100644 targets/COMMON/openairinterface5g_limits.h

diff --git a/cmake_targets/at_commands/CMakeLists.txt b/cmake_targets/at_commands/CMakeLists.txt
index bf964cec465..8993466bc25 100755
--- a/cmake_targets/at_commands/CMakeLists.txt
+++ b/cmake_targets/at_commands/CMakeLists.txt
@@ -452,6 +452,7 @@ set(esm_SRC
 )
 
 set(esm_HDR
+    ${OPENAIR_TARGETS}/COMMON/openairinterface5g_limits.h
     ${OPENAIR_NAS_DIR}/UE/ESM/esm_main.h
     ${OPENAIR_NAS_DIR}/COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextAccept.h
     ${OPENAIR_NAS_DIR}/COMMON/ESM/MSG/ActivateDedicatedEpsBearerContextReject.h
@@ -491,6 +492,7 @@ target_include_directories(esm PRIVATE
                      ${OPENAIR_NAS_DIR}/UE
                      ${OPENAIR_NAS_DIR}/UE/API/USER 
                      ${OPENAIR_NAS_DIR}/UE/ESM
+                     ${OPENAIR_TARGETS}/COMMON
                      ${OPENAIR_NAS_DIR}/COMMON/ESM/MSG
                      ${OPENAIR_NAS_DIR}/UE/ESM/SAP
                      ${OPENAIR_NAS_DIR}/COMMON/IES
@@ -673,6 +675,7 @@ target_include_directories(ies PRIVATE
 # EXECUTABLE at_nas_ue
 ################################################################################
 include_directories( 
+                     ${OPENAIR_TARGETS}/COMMON
                      ${OPENAIR_NAS_DIR}/UE
                      ${OPENAIR_DIR}/common/utils
                      ${OPENAIR_DIR}/common/utils/msc 
diff --git a/openair1/PHY/impl_defs_top.h b/openair1/PHY/impl_defs_top.h
index dd09749fbf1..4ef01315160 100644
--- a/openair1/PHY/impl_defs_top.h
+++ b/openair1/PHY/impl_defs_top.h
@@ -284,21 +284,7 @@ typedef enum {
 #define NUMBER_OF_HARQ_PID_MAX 8
 
 #define MAX_FRAME_NUMBER 0x400
-#if defined(CBMIMO1) || defined(EXMIMO) || defined(OAI_USRP)
-#define NUMBER_OF_eNB_MAX 1
-#define NUMBER_OF_UE_MAX 16
-#define NUMBER_OF_CONNECTED_eNB_MAX 3
-#else
-#ifdef LARGE_SCALE
-#define NUMBER_OF_eNB_MAX 2
-#define NUMBER_OF_UE_MAX 120
-#define NUMBER_OF_CONNECTED_eNB_MAX 1 // to save some memory
-#else
-#define NUMBER_OF_eNB_MAX 7
-#define NUMBER_OF_UE_MAX 16
-#define NUMBER_OF_CONNECTED_eNB_MAX 3
-#endif
-#endif
+#include "openairinterface5g_limits.h"
 
 #define NUMBER_OF_RN_MAX 3
 typedef enum {no_relay=1,unicast_relay_type1,unicast_relay_type2, multicast_relay} relaying_type_t;
diff --git a/openair2/NETWORK_DRIVER/UE_IP/constant.h b/openair2/NETWORK_DRIVER/UE_IP/constant.h
index 9b4017773b0..42fd0b6303c 100644
--- a/openair2/NETWORK_DRIVER/UE_IP/constant.h
+++ b/openair2/NETWORK_DRIVER/UE_IP/constant.h
@@ -19,6 +19,7 @@
  *      contact@openairinterface.org
  */
 
+#include "openairinterface5g_limits.h"
 #ifndef _UE_IP_CST
 #define _UE_IP_CST
 
@@ -51,7 +52,7 @@
 
 
 
-#define UE_IP_NB_INSTANCES_MAX       8
+#define UE_IP_NB_INSTANCES_MAX       NUMBER_OF_UE_MAX
 
 
 #endif
diff --git a/openair2/UTIL/OMV/structures.h b/openair2/UTIL/OMV/structures.h
index c50e7b22973..434fa4c3836 100644
--- a/openair2/UTIL/OMV/structures.h
+++ b/openair2/UTIL/OMV/structures.h
@@ -31,13 +31,12 @@
 #ifndef STRUCTURES_H
 #define STRUCTURES_H
 
+#include "openairinterface5g_limits.h"
 #ifndef __PHY_IMPLEMENTATION_DEFS_H__
-#define Maxneighbor 64
-#define NUMBER_OF_UE_MAX 64
-#define NUMBER_OF_eNB_MAX 3
-#ifndef NB_ANTENNAS_RX
-#  define NB_ANTENNAS_RX  4
-#endif
+	#define Maxneighbor NUMBER_OF_UE_MAX
+	#ifndef NB_ANTENNAS_RX
+		#define NB_ANTENNAS_RX  4
+	#endif
 #endif
 //
 
diff --git a/openair2/UTIL/OTG/otg_defs.h b/openair2/UTIL/OTG/otg_defs.h
index 0cef777b8f0..ebb3f299897 100644
--- a/openair2/UTIL/OTG/otg_defs.h
+++ b/openair2/UTIL/OTG/otg_defs.h
@@ -33,12 +33,12 @@
 #ifndef __OTG_DEFS_H__
 # define __OTG_DEFS_H__
 
-
+/* \brief To define the NUMBER_OF_eNB_MAX and NUMBER_OF_UE_MAX */
 #if STANDALONE==1
-# define NUMBER_OF_eNB_MAX 3
-# define NUMBER_OF_UE_MAX 3
+	#include "openairinterface5g_limits.h"
 #else
-#include "PHY/impl_defs_top.h" /* \brief To define the NUMBER_OF_eNB_MAX and NUMBER_OF_UE_MAX */
+	// impl_defs_top.h includes openairinterface5g_limits.h
+	#include "PHY/impl_defs_top.h"
 #endif
 
 #include "otg_config.h"
diff --git a/openair3/NAS/UE/nas_ue_task.h b/openair3/NAS/UE/nas_ue_task.h
index 4c7cd142494..90ef26bd80f 100644
--- a/openair3/NAS/UE/nas_ue_task.h
+++ b/openair3/NAS/UE/nas_ue_task.h
@@ -22,8 +22,7 @@
 #ifndef NAS_UE_TASK_H_
 #define NAS_UE_TASK_H_
 
-// FIXME There is multiple definition of NUMBER_OF_UE_MAX
-#include "defs.h"
+#include "openairinterface5g_limits.h"
 #include "user_defs.h"
 
 // XXX simple array container for multiple users
diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h
new file mode 100644
index 00000000000..6185dd8bbe5
--- /dev/null
+++ b/targets/COMMON/openairinterface5g_limits.h
@@ -0,0 +1,20 @@
+#if defined(CBMIMO1) || defined(EXMIMO) || defined(OAI_USRP)
+	#define NUMBER_OF_eNB_MAX 1
+	#define NUMBER_OF_UE_MAX 16
+	#define NUMBER_OF_CONNECTED_eNB_MAX 3
+#else
+	#define NUMBER_OF_eNB_MAX 7
+	#define NUMBER_OF_UE_MAX 20
+	#define NUMBER_OF_CONNECTED_eNB_MAX 3
+
+	#if STANDALONE==1
+		#define NUMBER_OF_eNB_MAX 3
+		#define NUMBER_OF_UE_MAX 3
+	#endif
+
+	#if LARGE_SCALE
+		#define NUMBER_OF_eNB_MAX 2
+		#define NUMBER_OF_UE_MAX 120
+		#define NUMBER_OF_CONNECTED_eNB_MAX 1 // to save some memory
+	#endif
+#endif
-- 
GitLab