1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020] [HCL Technologies Ltd.] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /* This file contains methods of InitConfig and Interfaces to
22 #include "InitConfig.hpp"
28 /* Default constructor */
29 InitConfig::InitConfig()
35 InitConfig::~InitConfig()
39 /*******************************************************************
41 * @brief Initialize Configuration
48 * - Initialize Configuration
50 * @params[in] Reference to S_Session
53 ******************************************************************/
55 bool InitConfig::init(sysrepo::S_Session sess)
57 O1_LOG("\nInitConfig::init started ");
59 getInterfaceConfig(sess);
63 /*******************************************************************
65 * @brief Get running Interface Configuration
69 * Function : getCurrInterfaceConfig
72 * - Get running Interface Configuration
74 * @params[in] Reference of StartupConfig
77 ******************************************************************/
79 bool InitConfig::getCurrInterfaceConfig(StartupConfig & cfg)
81 //O1_LOG("\n InitConfig::getCurrInterfaceConfig entry");
82 InitConfig::InterfaceMap::iterator it;
83 for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++)
85 //O1_LOG("\n InitConfig::getCurrInterfaceConfig iterator");
89 if(it->second.first != "0")
90 strcpy(cfg.DU_IPV4_Addr, it->second.first.c_str());
92 strcpy(cfg.DU_IPV4_Addr, DEFAULT_DU_IPV4_ADDR);
93 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.DU_IPV4_Addr = \
94 %s", cfg.DU_IPV4_Addr);
96 if(it->second.second != 0)
97 cfg.DU_Port = (uint16_t)it->second.second;
99 cfg.DU_Port = (uint16_t) DEFAULT_DU_PORT;
100 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.DU_Port = %d", \
104 case Interface::OCU :
106 if(it->second.first != "0")
107 strcpy(cfg.CU_IPV4_Addr, it->second.first.c_str());
109 strcpy(cfg.CU_IPV4_Addr, DEFAULT_CU_IPV4_ADDR);
111 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.CU_IPV4_Addr = \
112 %s", cfg.CU_IPV4_Addr);
114 if(it->second.second != 0)
115 cfg.CU_Port = (uint16_t) it->second.second;
117 cfg.CU_Port = (uint16_t) DEFAULT_CU_PORT;
119 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.CU_Port = %d", \
123 case Interface::RIC :
125 if(it->second.first != "0")
126 strcpy(cfg.RIC_IPV4_Addr, it->second.first.c_str());
128 strcpy(cfg.RIC_IPV4_Addr, DEFAULT_RIC_IPV4_ADDR);
130 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.RIC_IPV4_Addr = \
131 %s", cfg.RIC_IPV4_Addr);
133 if(it->second.second != 0)
134 cfg.RIC_Port = (uint16_t) it->second.second;
136 cfg.RIC_Port = (uint16_t) DEFAULT_RIC_PORT;
138 //O1_LOG("\n InitConfig::getCurrInterfaceConfig cfg.RIC_Port = %d", \
143 O1_LOG("\nno matching interface");
150 /*******************************************************************
152 * @brief Get Interface Configuration
156 * Function : getInterfaceConfig
159 * - Get running Interface Configuration
161 * @params[in] Reference of S_Session
162 * @return reference of InterfaceMap
164 ******************************************************************/
165 InitConfig::InterfaceMap InitConfig::getInterfaceConfig(sysrepo::S_Session sess)
167 O1_LOG("\nInitConfig::getInterfaceConfig started");
168 mInterfaceList.insert(std::make_pair(Interface::ODU, \
169 getInterfaceData(sess,Interface::ODU)));
170 mInterfaceList.insert(std::make_pair(Interface::OCU, \
171 getInterfaceData(sess,Interface::OCU)));
172 mInterfaceList.insert(std::make_pair(Interface::RIC, \
173 getInterfaceData(sess,Interface::RIC)));
174 return mInterfaceList;
177 /*******************************************************************
179 * @brief Get Interface Data
183 * Function : getInterfaceData
186 * - Get running Interface Data
188 * @params[in] Reference of S_Session and Interface
189 * @return reference of Address
191 ******************************************************************/
192 InitConfig::Address InitConfig::getInterfaceData(sysrepo::S_Session sess, \
195 O1_LOG("\nInitConfig::getInterfaceData started");
196 string sInf = interfaceToString(inf);
197 return std::make_pair(getData(sess, getInterfaceXpath(sInf, IP_ADDRESS)), \
198 atoi(getData(sess, getInterfaceXpath(sInf, PORT)).c_str()));
201 /*******************************************************************
203 * @brief create xpath for interfaces
207 * Function : getInterfaceXpath
210 * - create xpath for interfaces
212 * @params[in] String of sInf and String of param
213 * @return pointer to xpath
215 ******************************************************************/
216 char * InitConfig::getInterfaceXpath( string sInf, string param)
218 sprintf(xpath, "%s/interfaces/interface[interface-name='%s']/%s", \
219 INTERFACE_MODULE_NAME_ORAN, sInf.c_str(),param.c_str());
223 /*******************************************************************
225 * @brief Get data of the xpath
232 * - get data of the xpath
234 * @params[in] reference of S_Session and pointer to xpath
235 * @return value against the xpath
237 ******************************************************************/
239 string InitConfig::getData(sysrepo::S_Session sess,char* xpath)
241 //O1_LOG("\nInitConfig::getData of xpath = %s", \
242 xpath); //enable for debugging only
245 auto value = sess->get_item(xpath);
246 if (value == nullptr)
248 //O1_LOG("\nget_item value are null for xpath = %s", \
249 xpath); //enable for debugging only
252 string mVal = value->val_to_string();
258 //O1_LOG("\nInitConfig::getData exception occured for block xpath= %s", \
259 xpath); //enable for debugging only
264 /*******************************************************************
266 * @brief Convert interface value to string
270 * Function : interfaceToString
273 * - Convert interface value to string
275 * @params[in] reference to Interface
276 * @return string value of Interface
278 ******************************************************************/
279 string InitConfig::interfaceToString(Interface inf)
284 case Interface::ODU :
287 case Interface::OCU :
290 case Interface::RIC :
294 O1_LOG("\n\n no matching interface ");
302 /*******************************************************************
304 * @brief Print Interface configuration
308 * Function : printInterfaceConfig
311 * - Print Interface configuration
316 ******************************************************************/
317 bool InitConfig::printInterfaceConfig()
319 InitConfig::InterfaceMap::iterator it;
320 for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++)
322 O1_LOG("\ninterface [%s] : \n \t IP = %s \n \t Port = %d", \
323 interfaceToString(it->first).c_str(), it->second.first.c_str(), \
329 /**********************************************************************
331 **********************************************************************/