From: HariomGupta Date: Thu, 4 Feb 2021 16:19:51 +0000 (+0530) Subject: O1 IP PORT configuration for CM .[Issue-Id: ODUHIGH-196] X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=c5c8d87cedf8b51e40989c21c0dd8cd1dab1b073;p=o-du%2Fl2.git O1 IP PORT configuration for CM .[Issue-Id: ODUHIGH-196] Signed-off-by: HariomGupta Change-Id: Idc2539f20ab7d238fc5f7156bc29d473a9120638 --- diff --git a/build/common/cu_stub.mak b/build/common/cu_stub.mak index b95ec585a..1e9add2ee 100755 --- a/build/common/cu_stub.mak +++ b/build/common/cu_stub.mak @@ -39,6 +39,10 @@ I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/common I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/F1AP I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/RRC +ifeq ($(O1_ENABLE),YES) +I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client +endif + #-------------------------------------------------------------# #Linker macros #-------------------------------------------------------------# diff --git a/build/common/du_app.mak b/build/common/du_app.mak index ca0a07d86..f7175d1b1 100644 --- a/build/common/du_app.mak +++ b/build/common/du_app.mak @@ -40,7 +40,10 @@ I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/common I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/F1AP I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/RRC I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/E2AP + +ifeq ($(O1_ENABLE),YES) I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client +endif #-------------------------------------------------------------# #Linker macros diff --git a/build/common/ric_stub.mak b/build/common/ric_stub.mak index bf2f94fea..f7c5175c6 100644 --- a/build/common/ric_stub.mak +++ b/build/common/ric_stub.mak @@ -38,6 +38,9 @@ I_OPTS+=-I$(ROOT_DIR)/src/mt I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/common I_OPTS+=-I$(ROOT_DIR)/src/codec_utils/E2AP +ifeq ($(O1_ENABLE),YES) +I_OPTS+=-I$(ROOT_DIR)/src/o1/o1_client +endif #-------------------------------------------------------------# #Linker macros #-------------------------------------------------------------# diff --git a/build/o1/yang/o-ran-sc-odu-interface-v1.yang b/build/o1/yang/o-ran-sc-odu-interface-v1.yang new file mode 100644 index 000000000..ee19b93a1 --- /dev/null +++ b/build/o1/yang/o-ran-sc-odu-interface-v1.yang @@ -0,0 +1,80 @@ +module o-ran-sc-odu-interface-v1 { + yang-version 1; + namespace "urn:o-ran:odu:interface:1.0"; + prefix rxad; + + import ietf-inet-types { prefix inet; } + + organization + "O-RAN Software Community"; + contact + "www.o-ran.org"; + description + "This module defines active interface information visible to operators + + Copyright 2020 the O-RAN Alliance. + + Licensed under the Apache License, Version 2.0 (the 'License'); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an 'AS IS' BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License."; + + revision 2020-01-29 { + description + "initial revision"; + reference + "O-RAN-OAM-Interface-Specification (O1)"; + } + + grouping interface-info { + leaf interface-name { + type string; + description + "The unique interface ID"; + } + leaf interface-address { + type inet:ip-address; + mandatory true; + description + "The local IP address to listen on for incoming + client connections. INADDR_ANY (0.0.0.0) or + INADDR6_ANY (0:0:0:0:0:0:0:0 a.k.a. ::) MUST be + used when the server is to listen on all IPv4 or + IPv6 addresses, respectively."; + } + leaf port { + type inet:port-number; + default "0"; + description + "The local port number to listen on for incoming + client connections. An invalid default value (0) + is used (instead of 'mandatory true') so that an + application level data model may 'refine' it with + an application specific default port number value."; + } + description + "interface information"; + } + + container odu { + container interfaces { + list interface { + key "interface-name"; + uses interface-info; + description + "The list of active interfaces in RIC"; + } + description + "State data container of the interfaces"; + } + description + "Root object for RIC interfaces"; + } +} diff --git a/build/odu/makefile b/build/odu/makefile index 1874e6c3e..13adc41ef 100644 --- a/build/odu/makefile +++ b/build/odu/makefile @@ -204,7 +204,9 @@ du: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/rl.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/phy_stub.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' +endif link_du: du $(Q)$(CC1) -g -o $(OBJ_ROOT)/odu/odu -Wl,-R../lib/:. $(OBJ_ROOT)/odu/*.o\ @@ -223,7 +225,9 @@ clean_odu: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/rl.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/phy_stub.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak clean OBJ_DIR=$(OBJ_ROOT)/odu LIB_DIR=$(LIB_ROOT)/odu LOG_DIR=$(LOG_ROOT)/odu CC='$(CC1)' +endif $(Q)rm -rf $(OBJ_ROOT)/odu/* $(Q)rm -rf $(LIB_ROOT)/odu/* $(Q)rm -rf $(BIN_DIR)/odu/* @@ -245,6 +249,9 @@ cu: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_rrc.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cm.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' +endif clean_cu: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cu_stub.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' @@ -253,6 +260,9 @@ clean_cu: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_rrc.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cm.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak clean OBJ_DIR=$(OBJ_ROOT)/cu_stub LIB_DIR=$(LIB_ROOT)/cu_stub LOG_DIR=$(LOG_ROOT)/cu_stub CC='$(CC1)' +endif $(Q)rm -rf $(OBJ_ROOT)/cu_stub/* $(Q)rm -rf $(LIB_ROOT)/cu_stub/* $(Q)rm -rf $(BIN_DIR)/cu_stub/* @@ -273,6 +283,9 @@ ric: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_e2ap.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cm.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' +endif clean_ric: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/ric_stub.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' @@ -281,6 +294,9 @@ clean_ric: $(Q)$(MAKE) -f $(COM_BUILD_DIR)/asn_rrc.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/cm.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' $(Q)$(MAKE) -f $(COM_BUILD_DIR)/mt.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' +ifeq ($(O1_ENABLE),YES) + $(Q)$(MAKE) -f $(COM_BUILD_DIR)/o1_client.mak clean OBJ_DIR=$(OBJ_ROOT)/ric_stub LIB_DIR=$(LIB_ROOT)/ric_stub LOG_DIR=$(LOG_ROOT)/ric_stub CC='$(CC1)' +endif $(Q)rm -rf $(OBJ_ROOT)/ric_stub/* $(Q)rm -rf $(LIB_ROOT)/ric_stub/* $(Q)rm -rf $(BIN_DIR)/ric_stub/* diff --git a/src/cu_stub/cu_stub.c b/src/cu_stub/cu_stub.c index f3ca64a1f..d1c1b1dff 100644 --- a/src/cu_stub/cu_stub.c +++ b/src/cu_stub/cu_stub.c @@ -23,14 +23,27 @@ #include "cu_stub_egtp.h" #include "du_log.h" +#ifdef O1_ENABLE + +#include "Config.h" + +#endif + #define CU_ID 1 #define CU_NAME "ORAN_OAM_CU" -#define DU_IP_V4_ADDR "192.168.130.81" -#define CU_IP_V4_ADDR "192.168.130.82" + #define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001" #define CU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011" + +#ifndef O1_ENABLE + +#define DU_IP_V4_ADDR "192.168.130.81" +#define CU_IP_V4_ADDR "192.168.130.82" #define DU_PORT 38472 #define CU_PORT 38472 + +#endif + #define DU_EGTP_PORT 39001 #define CU_EGTP_PORT 39002 #define RRC_VER 0 @@ -42,6 +55,13 @@ #define PLMN_MNC1 8 #define PLMN_MNC2 0 +#ifdef O1_ENABLE + +extern StartupConfig g_cfg; + +#endif + + /******************************************************************* * * @brief Handles SCTP notification @@ -146,21 +166,36 @@ void readCuCfg() DU_LOG("\nReading CU configurations"); +#ifdef O1_ENABLE + if( getStartupConfig(&g_cfg) != ROK ) + { + RETVALUE(RFAILED); + } + DU_LOG("\nReading CU configurations---"); + DU_LOG("\nReading CU configurations g_cfg.DU_IPV4_Addr=%s", g_cfg.DU_IPV4_Addr); + DU_LOG("\nReading CU configurations g_cfg.CU_IPV4_Addr=%s", g_cfg.CU_IPV4_Addr); + cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du); + cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu); + + cuCfgParams.sctpParams.duPort = g_cfg.DU_Port; + cuCfgParams.sctpParams.cuPort = g_cfg.CU_Port; +#else cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du); cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu); - + cuCfgParams.sctpParams.duPort = DU_PORT; + cuCfgParams.sctpParams.cuPort = CU_PORT; +#endif + cuCfgParams.cuId = CU_ID; strcpy(cuCfgParams.cuName, CU_NAME); /* DU IP Address and Port*/ cuCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du; cuCfgParams.sctpParams.duIpAddr.ipV6Pres = false; - cuCfgParams.sctpParams.duPort = DU_PORT; /* CU IP Address and Port*/ cuCfgParams.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu; cuCfgParams.sctpParams.cuIpAddr.ipV6Pres = false; - cuCfgParams.sctpParams.cuPort = CU_PORT; /*PLMN*/ cuCfgParams.plmn.mcc[0] = PLMN_MCC0; diff --git a/src/du_app/du_cfg.c b/src/du_app/du_cfg.c index 17b0fb6a4..52abb121c 100644 --- a/src/du_app/du_cfg.c +++ b/src/du_app/du_cfg.c @@ -52,6 +52,13 @@ #include "BWP-DownlinkCommon.h" #include "BWP-UplinkCommon.h" +#ifdef O1_ENABLE + +#include "Config.h" +extern StartupConfig g_cfg; + +#endif + DuCfgParams duCfgParam; char encBuf[ENC_BUF_MAX_LEN]; @@ -335,9 +342,14 @@ uint8_t readMacCfg() * ****************************************************************/ uint8_t fillDuPort(uint16_t *duPort) { + +#ifdef O1_ENABLE + duPort[F1_INTERFACE] = g_cfg.DU_Port; + duPort[E2_INTERFACE] = g_cfg.RIC_Port; +#else duPort[F1_INTERFACE] = DU_PORT; /* DU Port idx 0 38472 */ duPort[E2_INTERFACE] = RIC_PORT; /* RIC Port idx 1 38482 */ - +#endif return ROK; } @@ -537,9 +549,26 @@ uint8_t readCfg() MibParams mib; Sib1Params sib1; +#ifdef O1_ENABLE + if( getStartupConfig(&g_cfg) != ROK ) + { + RETVALUE(RFAILED); + } + cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du); + cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu); + cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric); + + duCfgParam.sctpParams.cuPort = g_cfg.CU_Port; + duCfgParam.sctpParams.ricPort = g_cfg.RIC_Port; +#else cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du); cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu); cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric); + + duCfgParam.sctpParams.cuPort = CU_PORT; + duCfgParam.sctpParams.ricPort = RIC_PORT; +#endif + fillDuPort(duCfgParam.sctpParams.duPort); /* F1 DU IP Address and Port*/ @@ -547,11 +576,10 @@ uint8_t readCfg() /* F1 CU IP Address and Port*/ duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu; - duCfgParam.sctpParams.cuPort = CU_PORT; /* Fill RIC Params */ duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric; - duCfgParam.sctpParams.ricPort = RIC_PORT; + /* EGTP Parameters */ duCfgParam.egtpParams.localIp.ipV4Pres = TRUE; duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du; diff --git a/src/du_app/du_cfg.h b/src/du_app/du_cfg.h index 668074f0e..c0c0b2eb0 100644 --- a/src/du_app/du_cfg.h +++ b/src/du_app/du_cfg.h @@ -22,12 +22,18 @@ /* MACROS */ #define DU_INST 0 #define DU_ID 1 + +#ifndef O1_ENABLE + #define DU_IP_V4_ADDR "192.168.130.81" #define CU_IP_V4_ADDR "192.168.130.82" #define RIC_IP_V4_ADDR "192.168.130.80" #define DU_PORT 38472 #define CU_PORT 38472 #define RIC_PORT 36422 /* using X2 port since E2 port not defined */ + +#endif + #define DU_EGTP_PORT 39001 #define CU_EGTP_PORT 39002 #define NR_PCI 1 diff --git a/src/o1/InitConfig.cpp b/src/o1/InitConfig.cpp new file mode 100644 index 000000000..4edc8c2a6 --- /dev/null +++ b/src/o1/InitConfig.cpp @@ -0,0 +1,331 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains methods of InitConfig and Interfaces to + YANG modules */ + +#include "InitConfig.hpp" +#include +#include +using namespace std; + + +/* Default constructor */ +InitConfig::InitConfig() +{ +} + + +/* Destructor */ +InitConfig::~InitConfig() +{ +} + +/******************************************************************* + * + * @brief Initialize Configuration + * + * @details + * + * Function : init + * + * Functionality: + * - Initialize Configuration + * + * @params[in] Reference to S_Session + * @return bool + * + ******************************************************************/ + +bool InitConfig::init(sysrepo::S_Session sess) +{ + O1_LOG("\nInitConfig::init started "); + mSess = sess; + getInterfaceConfig(sess); + return true; +} + +/******************************************************************* + * + * @brief Get running Interface Configuration + * + * @details + * + * Function : getCurrInterfaceConfig + * + * Functionality: + * - Get running Interface Configuration + * + * @params[in] Reference of StartupConfig + * @return bool + * + ******************************************************************/ + +bool InitConfig::getCurrInterfaceConfig(StartupConfig & cfg) +{ + //O1_LOG("\n InitConfig::getCurrInterfaceConfig entry"); + InitConfig::InterfaceMap::iterator it; + for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++) + { + //O1_LOG("\n InitConfig::getCurrInterfaceConfig iterator"); + switch (it->first) + { + case Interface::ODU : + if(it->second.first != "0") + strcpy(cfg.DU_IPV4_Addr, it->second.first.c_str()); + else + strcpy(cfg.DU_IPV4_Addr, DEFAULT_DU_IPV4_ADDR); + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.DU_IPV4_Addr = \ + %s", cfg.DU_IPV4_Addr); + + if(it->second.second != 0) + cfg.DU_Port = (uint16_t)it->second.second; + else + cfg.DU_Port = (uint16_t) DEFAULT_DU_PORT; + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.DU_Port = %d", \ + cfg.DU_Port); + break; + + case Interface::OCU : + + if(it->second.first != "0") + strcpy(cfg.CU_IPV4_Addr, it->second.first.c_str()); + else + strcpy(cfg.CU_IPV4_Addr, DEFAULT_CU_IPV4_ADDR); + + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.CU_IPV4_Addr = \ + %s", cfg.CU_IPV4_Addr); + + if(it->second.second != 0) + cfg.CU_Port = (uint16_t) it->second.second; + else + cfg.CU_Port = (uint16_t) DEFAULT_CU_PORT; + + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.CU_Port = %d", \ + cfg.CU_Port); + break; + + case Interface::RIC : + + if(it->second.first != "0") + strcpy(cfg.RIC_IPV4_Addr, it->second.first.c_str()); + else + strcpy(cfg.RIC_IPV4_Addr, DEFAULT_RIC_IPV4_ADDR); + + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.RIC_IPV4_Addr = \ + %s", cfg.RIC_IPV4_Addr); + + if(it->second.second != 0) + cfg.RIC_Port = (uint16_t) it->second.second; + else + cfg.RIC_Port = (uint16_t) DEFAULT_RIC_PORT; + + //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.RIC_Port = %d", \ + cfg.RIC_Port); + break; + + default : + O1_LOG("\nno matching interface"); + break; + } + } + return true; +} + +/******************************************************************* + * + * @brief Get Interface Configuration + * + * @details + * + * Function : getInterfaceConfig + * + * Functionality: + * - Get running Interface Configuration + * + * @params[in] Reference of S_Session + * @return reference of InterfaceMap + * + ******************************************************************/ +InitConfig::InterfaceMap InitConfig::getInterfaceConfig(sysrepo::S_Session sess) +{ + O1_LOG("\nInitConfig::getInterfaceConfig started"); + mInterfaceList.insert(std::make_pair(Interface::ODU, \ + getInterfaceData(sess,Interface::ODU))); + mInterfaceList.insert(std::make_pair(Interface::OCU, \ + getInterfaceData(sess,Interface::OCU))); + mInterfaceList.insert(std::make_pair(Interface::RIC, \ + getInterfaceData(sess,Interface::RIC))); + return mInterfaceList; +} + +/******************************************************************* + * + * @brief Get Interface Data + * + * @details + * + * Function : getInterfaceData + * + * Functionality: + * - Get running Interface Data + * + * @params[in] Reference of S_Session and Interface + * @return reference of Address + * + ******************************************************************/ +InitConfig::Address InitConfig::getInterfaceData(sysrepo::S_Session sess, \ + Interface inf) +{ + O1_LOG("\nInitConfig::getInterfaceData started"); + string sInf = interfaceToString(inf); + return std::make_pair(getData(sess, getInterfaceXpath(sInf, IP_ADDRESS)), \ + atoi(getData(sess, getInterfaceXpath(sInf, PORT)).c_str())); +} + +/******************************************************************* + * + * @brief create xpath for interfaces + * + * @details + * + * Function : getInterfaceXpath + * + * Functionality: + * - create xpath for interfaces + * + * @params[in] String of sInf and String of param + * @return pointer to xpath + * + ******************************************************************/ +char * InitConfig::getInterfaceXpath( string sInf, string param) +{ + sprintf(xpath, "%s/interfaces/interface[interface-name='%s']/%s", \ + INTERFACE_MODULE_NAME_ORAN, sInf.c_str(),param.c_str()); + return xpath; +} + +/******************************************************************* + * + * @brief Get data of the xpath + * + * @details + * + * Function : getData + * + * Functionality: + * - get data of the xpath + * + * @params[in] reference of S_Session and pointer to xpath + * @return value against the xpath + * + ******************************************************************/ + +string InitConfig::getData(sysrepo::S_Session sess,char* xpath) +{ + //O1_LOG("\nInitConfig::getData of xpath = %s", \ + xpath); //enable for debugging only + try + { + auto value = sess->get_item(xpath); + if (value == nullptr) + { + //O1_LOG("\nget_item value are null for xpath = %s", \ + xpath); //enable for debugging only + return "0"; + } + string mVal = value->val_to_string(); + return mVal; + + } + catch (...) + { + //O1_LOG("\nInitConfig::getData exception occured for block xpath= %s", \ + xpath); //enable for debugging only + return "0"; + } +} + +/******************************************************************* + * + * @brief Convert interface value to string + * + * @details + * + * Function : interfaceToString + * + * Functionality: + * - Convert interface value to string + * + * @params[in] reference to Interface + * @return string value of Interface + * + ******************************************************************/ +string InitConfig::interfaceToString(Interface inf) +{ + string interface; + switch (inf) + { + case Interface::ODU : + interface = "odu"; + break; + case Interface::OCU : + interface = "ocu"; + break; + case Interface::RIC : + interface = "ric"; + break; + default : + O1_LOG("\n\n no matching interface "); + break; + } + return interface; + +} + + +/******************************************************************* + * + * @brief Print Interface configuration + * + * @details + * + * Function : printInterfaceConfig + * + * Functionality: + * - Print Interface configuration + * + * @params[in] void + * @return bool + * + ******************************************************************/ +bool InitConfig::printInterfaceConfig() +{ + InitConfig::InterfaceMap::iterator it; + for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++) + { + O1_LOG("\ninterface [%s] : \n \t IP = %s \n \t Port = %d", \ + interfaceToString(it->first).c_str(), it->second.first.c_str(), \ + it->second.second); + } + return true; +} + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/InitConfig.hpp b/src/o1/InitConfig.hpp new file mode 100644 index 000000000..e8c2584df --- /dev/null +++ b/src/o1/InitConfig.hpp @@ -0,0 +1,92 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains InitConfig class header*/ + +#ifndef __INIT_CONFIG_HPP__ +#define __INIT_CONFIG_HPP__ + +#include +#include +#include +#include "sysrepo-cpp/Session.hpp" +#include +#include "Singleton.hpp" +#include "Config.h" + +#include "GlobalDefs.hpp" +#define IP_ADDRESS "interface-address" +#define PORT "port" +#define INTERFACE_MODULE_NAME_ORAN "/o-ran-sc-odu-interface-v1:odu" +#define MAX_XPATH 100 +#define NETCONF_STARTUP_CFG "/etc/netconf_startup.cfg" + +#define DEFAULT_DU_IPV4_ADDR "192.168.130.81" +#define DEFAULT_DU_PORT 38472 + +#define DEFAULT_CU_IPV4_ADDR "192.168.130.82" +#define DEFAULT_CU_PORT 38472 + +#define DEFAULT_RIC_IPV4_ADDR "192.168.130.80" +#define DEFAULT_RIC_PORT 36422 + +enum class Interface +{ ODU, + OCU, + RIC +}; + + +class InitConfig : public Singleton +{ + + friend Singleton; + + public: + + //member variable + typedef std::pair Address; + typedef std::map InterfaceMap; + + InitConfig(); + ~InitConfig(); + bool init(sysrepo::S_Session sess); + bool getCurrInterfaceConfig(StartupConfig & cfg); + + private: + + InterfaceMap mInterfaceList; + char xpath[MAX_XPATH]; + sysrepo::S_Session mSess; + //string mVal; + /* function to get the data of Interfaces param*/ + InterfaceMap getInterfaceConfig(sysrepo::S_Session sess); + Address getInterfaceData(sysrepo::S_Session sess, Interface inf); + char * getInterfaceXpath( std::string sInf, std::string param); + std::string getData(sysrepo::S_Session sess,char* xpath); + std::string interfaceToString(Interface inf); + bool printInterfaceConfig(); + bool writeInterfaceConfig(); + +}; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/SessionHandler.cpp b/src/o1/SessionHandler.cpp index f4108c003..bc6ec9f98 100644 --- a/src/o1/SessionHandler.cpp +++ b/src/o1/SessionHandler.cpp @@ -19,9 +19,14 @@ /* This file contains methods of Session/Connection creation and Subscription to YANG modules */ +#include +#include +#include "sysrepo.h" #include "SessionHandler.hpp" +#include "InitConfig.hpp" +#include - +using namespace std; /* Default constructor */ SessionHandler::SessionHandler() { @@ -45,10 +50,14 @@ bool SessionHandler::init() { try { + O1_LOG("\nO1 SessionHandler : Initialization done"); mConn = createConnection(); + O1_LOG("\nO1 SessionHandler : Initialization done"); mSess = createSession(mConn); mSub = createSubscribe(mSess); O1_LOG("\nO1 SessionHandler : Initialization done"); + //InitConfig initConf; + InitConfig::instance().init(mSess); return true; } catch( const std::exception& e ) diff --git a/src/o1/TcpServer.cpp b/src/o1/TcpServer.cpp index 47ce09475..337387d09 100644 --- a/src/o1/TcpServer.cpp +++ b/src/o1/TcpServer.cpp @@ -24,6 +24,7 @@ #include "TcpServer.hpp" #include "Alarm.hpp" #include "AlarmManager.hpp" +#include "Config.h" #include "GlobalDefs.hpp" #include #include @@ -35,6 +36,7 @@ #include #include #include +#include "InitConfig.hpp" using std::map; using std::pair; @@ -46,62 +48,100 @@ TcpServer::~TcpServer() } -/********************************************************************** - Description : Read the data from the connected client application - Params[In] : fd - File descriptor - Return : int - No of bytes read -**********************************************************************/ +/******************************************************************* + * + * @brief Read the data from the connected client application + * + * @details + * + * Function : readMessage + * + * Functionality: + * - Reads the data from the connected client application + * + * @params[in] File descriptor + * @return No. of bytes read + * + ******************************************************************/ int TcpServer::readMessage(int fd) { - AlarmRecord alrmRec; - bzero(&alrmRec,sizeof(alrmRec)); - int nbytes = read (fd, &alrmRec, sizeof(alrmRec)); + AlarmRecord *alrmRec = NULL; + char recvBuf[BUFLEN]; + Alarm alrm; + bzero(&recvBuf,sizeof(recvBuf)); + + int nbytes = read (fd, &recvBuf, sizeof(recvBuf)); + if (nbytes > 0) { - Alarm alrm; - uint16_t alrmId; - O1_LOG("\nO1 TcpServer :\nAction %d\nalarm ID %s\n%d\n%s\n%d\n%s\n%s\nbytes %d", - alrmRec.msgHeader.action, - alrmRec.alarmId, - alrmRec.perceivedSeverity, - alrmRec.additionalText, - alrmRec.eventType, - alrmRec.specificProblem, - alrmRec.additionalInfo, + MsgHeader *msgHdr = (MsgHeader*)recvBuf; + + O1_LOG("\nO1 TcpServer :\nBuf size %ld", sizeof(recvBuf)); + O1_LOG("\nO1 TcpServer :\nMsgType %d",msgHdr->msgType); + O1_LOG("\nO1 TcpServer :\nAction %d",msgHdr->action); + + if ( msgHdr->msgType == ALARM ){ + uint16_t alrmId; + alrmRec = (AlarmRecord*) recvBuf; + O1_LOG("\nO1 TcpServer :\nAction %d\nalarm ID %s\n%d\n%s\n%d\n%s\n%s\nbytes %d", + alrmRec->msgHeader.action, + alrmRec->alarmId, + alrmRec->perceivedSeverity, + alrmRec->additionalText, + alrmRec->eventType, + alrmRec->specificProblem, + alrmRec->additionalInfo, nbytes ); - /*Fill the alarm structure */ - sscanf(alrmRec.alarmId,"%hu",&alrmId); - alrm.setAlarmId(alrmId); - alrm.setPerceivedSeverity(alrmRec.perceivedSeverity); - alrm.setAdditionalText(alrmRec.additionalText); - alrm.setEventType(alrmRec.eventType); - alrm.setSpecificProblem(alrmRec.specificProblem); - alrm.setAdditionalInfo(alrmRec.additionalInfo); + /*Fill the alarm structure */ + sscanf(alrmRec->alarmId,"%hu",&alrmId); + alrm.setAlarmId(alrmId); + alrm.setPerceivedSeverity(alrmRec->perceivedSeverity); + alrm.setAdditionalText(alrmRec->additionalText); + alrm.setEventType(alrmRec->eventType); + alrm.setSpecificProblem(alrmRec->specificProblem); + alrm.setAdditionalInfo(alrmRec->additionalInfo); + } - switch(alrmRec.msgHeader.action) + switch(msgHdr->action) { - case RAISE: + case RAISE_ALARM: if(AlarmManager::instance().raiseAlarm(alrm)) { - O1_LOG("\nO1 TcpServer : Alarm raised for alarm Id %s", alrmRec.alarmId); + O1_LOG("\nO1 TcpServer : Alarm raised for alarm Id %s", alrmRec->alarmId); } else { - O1_LOG("\nO1 TcpServer : Error in raising alarm for alrm Id %s", alrmRec.alarmId); + O1_LOG("\nO1 TcpServer : Error in raising alarm for alrm Id %s", alrmRec->alarmId); } break; - case CLEAR: + case CLEAR_ALARM: if(AlarmManager::instance().clearAlarm(alrm)) { - O1_LOG("\nO1 TcpServer : Alarm cleared for alarm Id %s", alrmRec.alarmId); + O1_LOG("\nO1 TcpServer : Alarm cleared for alarm Id %s", alrmRec->alarmId); } else { - O1_LOG("\nO1 TcpServer : Error in clearing alarm for alarm Id %s", alrmRec.alarmId); + O1_LOG("\nO1 TcpServer : Error in clearing alarm for alarm Id %s", alrmRec->alarmId); } break; + case GET_STARTUP_CONFIG: + { + StartupConfig cfg; + InitConfig::instance().getCurrInterfaceConfig(cfg); + O1_LOG("\nO1 TcpServer : cfg.DU_IPV4_Addr [%s]", cfg.DU_IPV4_Addr); + O1_LOG("\nO1 TcpServer : cfg.DU_Port [%d]", cfg.DU_Port); + O1_LOG("\nO1 TcpServer : cfg.CU_IPV4_Addr [%s]", cfg.CU_IPV4_Addr); + O1_LOG("\nO1 TcpServer : cfg.CU_Port [%d]", cfg.CU_Port); + O1_LOG("\nO1 TcpServer : cfg.RIC_IPV4_Addr [%s]", cfg.RIC_IPV4_Addr); + O1_LOG("\nO1 TcpServer : cfg.RIC_Port [%d]", cfg.RIC_Port); + if (write (fd, &cfg, sizeof(cfg)) < 0) + { + O1_LOG("\nO1 TcpServer : Error sending startup configuration \n"); + } + break; + } default: O1_LOG("\nO1 TcpServer : No action performed"); break; @@ -112,12 +152,21 @@ int TcpServer::readMessage(int fd) } -/********************************************************************** - Description : Open a TCP socket and bind on the port - Params[In] : None - Return : O1::SUCCESS - socket open and bind successful - O1::FAILURE - socket open and bind failed -**********************************************************************/ +/******************************************************************* + * + * @brief Open a TCP socket and bind on the port + * + * @details + * + * Function : makeSocket + * + * Functionality: + * - Opens a TCP socket and bind on the port + * + * @params[in] void + * @return O1:SUCCESS - success + * O1:FAILURE - failure + ******************************************************************/ int TcpServer::makeSocket() { struct sockaddr_in name; @@ -143,24 +192,42 @@ int TcpServer::makeSocket() } -/********************************************************************** - Description : Start TCP server in thread - Params[In] : None - Return : true - task launched in pthread successfully - false - task failed to launch -**********************************************************************/ +/******************************************************************* + * + * @brief Start TCP server in thread + * + * @details + * + * Function : start + * + * Functionality: + * - Start TCP server in thread + * + * @params[in] void + * @return true - success + * false - failure + ******************************************************************/ bool TcpServer::start() { return (pthread_create(&mThreadId, NULL, task, this) == 0); } -/********************************************************************** - Description : A TCP server to handle multiple connection using - select multiplexing - Params[In] : None - Return : true - task launched in pthread successfully - false - task failed to launch -**********************************************************************/ +/******************************************************************* + * + * @brief A TCP server to handle multiple connection + * + * @details + * + * Function : run + * + * Functionality: + * - A TCP server to handle multiple connection + * Uses select multiplexing + * + * @params[in] void + * @return true - success + * false - failure + ******************************************************************/ bool TcpServer::run() { @@ -243,12 +310,22 @@ bool TcpServer::run() } -/********************************************************************** - Description : Static function for launching a TCP server instance - in a thread - Params[In] : TcpServer instance - Return : NULL -**********************************************************************/ +/******************************************************************* + * + * @brief Static function for launching a TCP server instance + * in a thread + * + * @details + * + * Function : task + * + * Functionality: + * - Static function for launching a TCP server instance + * in a thread + * + * @params[in] TcpServer instance + * @return void + ******************************************************************/ void* TcpServer::task(void *args) { TcpServer *tcpServer = (TcpServer*)args; @@ -257,12 +334,21 @@ void* TcpServer::task(void *args) } -/********************************************************************** - Description : Wait for the thread to complete in the parent process - Params[In] : None - Return : true - pthread join success - false - pthread join failed -**********************************************************************/ +/******************************************************************* + * + * @brief Wait for the thread to complete in the parent process + * + * @details + * + * Function : wait + * + * Functionality: + * - Waits for the thread to complete in the parent process + * + * @params[in] void + * @return true : success + * false : failure + ******************************************************************/ bool TcpServer::wait() { return (pthread_join(mThreadId,NULL) == 0); diff --git a/src/o1/TcpServer.hpp b/src/o1/TcpServer.hpp index 19f0eba81..862b57eab 100644 --- a/src/o1/TcpServer.hpp +++ b/src/o1/TcpServer.hpp @@ -27,6 +27,7 @@ #include using std::string; +#define BUFLEN 512 class TcpServer { diff --git a/src/o1/o1_client/Alarm.h b/src/o1/o1_client/Alarm.h index 3506f4bfb..f88ed2eb2 100644 --- a/src/o1/o1_client/Alarm.h +++ b/src/o1/o1_client/Alarm.h @@ -22,6 +22,7 @@ #define __ALARM_H__ #include +#include "CommonMessages.h" #define ALRM_ID_SIZE 10 #define OBJ_INST_SIZE 15 #define TEXT_SIZE 50 @@ -51,16 +52,6 @@ typedef enum TIME_DOMAIN_VIOLATION = 11 }EventType; -typedef enum -{ - CLEAR = 0, - RAISE = 1 -}AlarmAction; - -typedef struct -{ - AlarmAction action; -}MsgHeader; typedef struct { diff --git a/src/o1/o1_client/AlarmInterface.c b/src/o1/o1_client/AlarmInterface.c index 1f5bc3b60..dcb9447d2 100644 --- a/src/o1/o1_client/AlarmInterface.c +++ b/src/o1/o1_client/AlarmInterface.c @@ -22,20 +22,30 @@ #include "TcpClient.h" -/********************************************************************** - Description : Raise an alarm by sending alarm info to O1 module over - TCP socket with action set to RAISE - Params[In] : Alarm information - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Raise an alarm + * + * @details + * + * Function : raiseAlarm + * + * Functionality: + * - Raise an alarm by sending alarm info to O1 module over + * TCP socket with action set to RAISE + * + * @params[in] alarm information + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t raiseAlarm(AlarmRecord* alrm) { if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED) { return RFAILED; } - alrm->msgHeader.action = RAISE; + alrm->msgHeader.msgType = ALARM; + alrm->msgHeader.action = RAISE_ALARM; if (sendData(alrm,sizeof(AlarmRecord)) < 0 ) { closeSocket(); @@ -45,21 +55,31 @@ uint8_t raiseAlarm(AlarmRecord* alrm) return ROK; } -/********************************************************************** - Description : Clears an alarm raised earlier by sending the alrm - information to O1 module over TCP socket with action - set to CLEAR - Params[In] : Alarm information - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Clear an alarm + * + * @details + * + * Function : clearAlarm + * + * Functionality: + * - Clears an alarm raised earlier by sending the alrm + * information to O1 module over TCP socket with action + * set to CLEAR + * + * @params[in] alarm information + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t clearAlarm(AlarmRecord* alrm) { if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED) { return RFAILED; } - alrm->msgHeader.action = CLEAR; + alrm->msgHeader.msgType = ALARM; + alrm->msgHeader.action = CLEAR_ALARM; if (sendData(alrm,sizeof(AlarmRecord)) < 0) { closeSocket(); @@ -70,13 +90,22 @@ uint8_t clearAlarm(AlarmRecord* alrm) } -/********************************************************************** - Description : Fill the cell specific alarm parmeters and generate - the alarm - Params[In] : alarm Id, cell Id - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Raise a cell specific alarm + * + * @details + * + * Function : raiseCellAlrm + * + * Functionality: + * - Fills the cell specific alarm parmeters and generate + * the alarm + * + * @params[in] alarm Id, cell Id + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId) { char buff[BUFF_SIZE]; @@ -112,12 +141,21 @@ uint8_t raiseCellAlrm(uint16_t alrmId, uint16_t cellId) return raiseAlarm(&alrm); } -/********************************************************************** - Description : Clear the cell alarm - Params[In] : alarm Id - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Clear the cell alarm + * + * @details + * + * Function : clearCellAlrm + * + * Functionality: + * - Clears the cell specific alarm using alarm id + * + * @params[in] alarm Id + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t clearCellAlrm(uint16_t alrmId) { AlarmRecord alrm; diff --git a/src/o1/o1_client/CommonMessages.h b/src/o1/o1_client/CommonMessages.h new file mode 100644 index 000000000..35ab96539 --- /dev/null +++ b/src/o1/o1_client/CommonMessages.h @@ -0,0 +1,48 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains definitions of common message structures */ + +#ifndef __COMMON_MESSAGES_H__ +#define __COMMON_MESSAGES_H__ + + +typedef enum +{ + RAISE_ALARM, + CLEAR_ALARM, + GET_STARTUP_CONFIG +}MsgAction; + +typedef enum +{ + ALARM, + CONFIGURATION +}MsgType; + +typedef struct +{ + MsgType msgType; + MsgAction action; +}MsgHeader; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/Config.c b/src/o1/o1_client/Config.c new file mode 100644 index 000000000..0f766cab4 --- /dev/null +++ b/src/o1/o1_client/Config.c @@ -0,0 +1,77 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains definitions of startup configuration structure */ + +#include "Config.h" +#include "ssi.h" +#include "GlobalDefs.h" +#include "TcpClient.h" + +StartupConfig g_cfg; + +/******************************************************************* + * + * @brief Get the startup config from Netconf + * + * @details + * + * Function : getStartupConfig + * + * Functionality: + * - Get the start up IP and port for DU,CU and RIC + * + * @params[in] pointer to StartupConfig + * @return ROK - success + * RFAILED - failure + ******************************************************************/ +uint8_t getStartupConfig(StartupConfig *cfg) +{ + O1_LOG("\nCONFIG : getStartupConfig ------ \n"); + MsgHeader msg; + msg.msgType = CONFIGURATION; + msg.action = GET_STARTUP_CONFIG; + if (openSocket(TCP_SERVER_IP,TCP_PORT) == RFAILED) + { + return RFAILED; + } + if (sendData(&msg,sizeof(msg)) < 0 ) + { + closeSocket(); + return RFAILED; + } + if (receiveData(cfg, sizeof(StartupConfig)) < 0) + { + closeSocket(); + return RFAILED; + } + O1_LOG("\nCONFIG : ip du %s\n",cfg->DU_IPV4_Addr ); + O1_LOG("\nCONFIG : ip cu %s\n",cfg->CU_IPV4_Addr ); + O1_LOG("\nCONFIG : ip ric %s\n",cfg->RIC_IPV4_Addr ); + O1_LOG("\nCONFIG : port cu %hu\n",cfg->CU_Port); + O1_LOG("\nCONFIG : port du %hu\n",cfg->DU_Port); + O1_LOG("\nCONFIG : port ric %hu\n",cfg->RIC_Port); + + closeSocket(); + return ROK; +} + + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/Config.h b/src/o1/o1_client/Config.h new file mode 100644 index 000000000..fb7250ca4 --- /dev/null +++ b/src/o1/o1_client/Config.h @@ -0,0 +1,46 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains definitions of startup configuration structure */ + +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#include +#include + +#define IPV4_LEN 16 +#define PORT_LEN 10 + +typedef struct +{ + char DU_IPV4_Addr[IPV4_LEN]; + char CU_IPV4_Addr[IPV4_LEN]; + char RIC_IPV4_Addr[IPV4_LEN]; + uint16_t CU_Port; + uint16_t DU_Port; + uint16_t RIC_Port; +}StartupConfig; + +uint8_t getStartupConfig(); + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/Message.h b/src/o1/o1_client/Message.h new file mode 100644 index 000000000..80fdc5804 --- /dev/null +++ b/src/o1/o1_client/Message.h @@ -0,0 +1,49 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2020] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains definitions of common message structures */ + +#ifndef __MESSAGE_H__ +#define __MESSAGE_H__ + +#include + +typedef enum +{ + RAISE_ALARM, + CLEAR_ALARM, + GET_STARTUP_CONFIG +}MsgAction; + +typedef enum +{ + ALARM, + CONFIGURATION +}MsgType; + +typedef struct +{ + MsgType msgType; + MsgAction action; +}MsgHeader; + +#endif + +/********************************************************************** + End of file +**********************************************************************/ diff --git a/src/o1/o1_client/TcpClient.c b/src/o1/o1_client/TcpClient.c index a7187e387..0049962b5 100644 --- a/src/o1/o1_client/TcpClient.c +++ b/src/o1/o1_client/TcpClient.c @@ -38,12 +38,21 @@ static uint16_t s_port; static const char* s_hostName = NULL; -/********************************************************************** - Description : Initilize the sockadd_in structure - Params[In] : None - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Initilize the sockadd_in structure + * + * @details + * + * Function : initSockaddr + * + * Functionality: + * - Initilizes the sockadd_in structure + * + * @params[in] void + * @return ROK - success + * RFAILED - failure + ******************************************************************/ static uint8_t initSockaddr() { @@ -63,12 +72,21 @@ static uint8_t initSockaddr() } -/********************************************************************** - Description : Open a TCP socket - Params[In] : hostName, port - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Open a TCP socket + * + * @details + * + * Function : openSocket + * + * Functionality: + * - Opens a TCP socket + * + * @params[in] hostname, port + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t openSocket(const char* hostName, const uint16_t port) { /* Create the socket. */ @@ -99,11 +117,21 @@ uint8_t openSocket(const char* hostName, const uint16_t port) } -/********************************************************************** - Description : Send the message on TCP socket - Params[In] : message, size of the message - Return : Number of bytes sent -**********************************************************************/ +/******************************************************************* + * + * @brief Send message over TCP socket + * + * @details + * + * Function : sendData + * + * Functionality: + * - Sends message over TCP socket + * + * @params[in] message, size of the message + * @return Number of bytes sent + * + ******************************************************************/ int sendData(void* data, const int size) { int nbytes = write (s_sock, data, size); @@ -114,12 +142,46 @@ int sendData(void* data, const int size) return nbytes; } -/********************************************************************** - Description : Close the TCP socket - Params[In] : None - Return : ROK - success - RFAILED - failure -**********************************************************************/ +/******************************************************************* + * + * @brief Recieve message over TCP socket + * + * @details + * + * Function : receiveData + * + * Functionality: + * - Recieves message over TCP socket + * + * @params[in] message, size of the message + * @return Number of bytes received + * + ******************************************************************/ +int receiveData(void* data, const int size) +{ + int nbytes = read (s_sock, data, size); + if (nbytes < 0) + { + O1_LOG("\nO1 TcpClient : Error reading. %d bytes sent", nbytes); + } + return nbytes; +} + +/******************************************************************* + * + * @brief Close the TCP socket + * + * @details + * + * Function : closeSocket + * + * Functionality: + * - Closes the TCP socket + * + * @params[in] message, size of the message + * @return ROK - success + * RFAILED - failure + ******************************************************************/ uint8_t closeSocket() { if( close(s_sock) != 0 ) diff --git a/src/o1/o1_client/TcpClient.h b/src/o1/o1_client/TcpClient.h index 13d6b3f9b..8349e580f 100644 --- a/src/o1/o1_client/TcpClient.h +++ b/src/o1/o1_client/TcpClient.h @@ -25,6 +25,7 @@ uint8_t openSocket(const char*, const uint16_t); int sendData(void*, const int); +int receiveData(void* data, const int size); uint8_t closeSocket(); #endif diff --git a/src/ric_stub/ric_stub.c b/src/ric_stub/ric_stub.c index aebf42c55..3f8947ad1 100644 --- a/src/ric_stub/ric_stub.c +++ b/src/ric_stub/ric_stub.c @@ -22,14 +22,25 @@ #include "ric_stub_sctp.h" #include "du_log.h" +#ifdef O1_ENABLE +#include "Config.h" +#endif + #define RIC_ID 1 #define RIC_NAME "ORAN_OAM_RIC" -#define DU_IP_V4_ADDR "192.168.130.81" -#define RIC_IP_V4_ADDR "192.168.130.80" + #define DU_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0001" #define RIC_IP_V6_ADDR "0000:0000:0000:0000:0000:0000:0000:0011" + +#ifndef O1_ENABLE + +#define DU_IP_V4_ADDR "192.168.130.81" +#define RIC_IP_V4_ADDR "192.168.130.80" #define DU_PORT 36422 #define RIC_PORT 36422 + +#endif + #define RRC_VER 0 #define EXT_RRC_VER 5 #define PLMN_MCC0 3 @@ -39,6 +50,12 @@ #define PLMN_MNC1 8 #define PLMN_MNC2 0 +#ifdef O1_ENABLE + +extern StartupConfig g_cfg; + +#endif + /******************************************************************* * * @brief Handles SCTP notification @@ -119,21 +136,34 @@ void readRicCfg() DU_LOG("\nReading RIC configurations"); +#ifdef O1_ENABLE + if( getStartupConfig(&g_cfg) != ROK ) + { + RETVALUE(RFAILED); + } + cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du); + cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric); + + ricCfgParams.sctpParams.duPort = g_cfg.RIC_Port; + ricCfgParams.sctpParams.ricPort = g_cfg.RIC_Port; +#else cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du); cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric); - + + ricCfgParams.sctpParams.duPort = DU_PORT; + ricCfgParams.sctpParams.ricPort = RIC_PORT; +#endif + ricCfgParams.ricId = RIC_ID; strcpy(ricCfgParams.ricName, RIC_NAME); /* DU IP Address and Port*/ ricCfgParams.sctpParams.duIpAddr.ipV4Addr = ipv4_du; ricCfgParams.sctpParams.duIpAddr.ipV6Pres = false; - ricCfgParams.sctpParams.duPort = DU_PORT; /* RIC IP Address and Port*/ ricCfgParams.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric; ricCfgParams.sctpParams.ricIpAddr.ipV6Pres = false; - ricCfgParams.sctpParams.ricPort = RIC_PORT; /*PLMN*/ ricCfgParams.plmn.mcc[0] = PLMN_MCC0;