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"
25 /* Default constructor */
26 InitConfig::InitConfig()
32 InitConfig::~InitConfig()
36 /*******************************************************************
38 * @brief Initialize Configuration
45 * - Initialize Configuration
47 * @params[in] Reference to S_Session
50 ******************************************************************/
52 bool InitConfig::init(sysrepo::S_Session sess)
55 InitConfig::InterfaceMap map;
56 if(!getInterfaceConfig(sess, map))
58 O1_LOG("\nInitConfig::getInterfaceConfig InitConfig data error ");
64 /*******************************************************************
66 * @brief Get running Interface Configuration
70 * Function : getCurrInterfaceConfig
73 * - Get running Interface Configuration
75 * @params[in] Reference of StartupConfig
78 ******************************************************************/
80 bool InitConfig::getCurrInterfaceConfig(StartupConfig & cfg)
82 //O1_LOG("\n InitConfig::getCurrInterfaceConfig entry");
83 InitConfig::InterfaceMap::iterator it;
84 for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++)
86 //O1_LOG("\n InitConfig::getCurrInterfaceConfig iterator");
90 if(it->second.first != "")
91 strcpy(cfg.DU_IPV4_Addr, it->second.first.c_str());
95 if(it->second.second != 0)
96 cfg.DU_Port = (uint16_t)it->second.second;
101 case Interface::OCU :
103 if(it->second.first != "")
104 strcpy(cfg.CU_IPV4_Addr, it->second.first.c_str());
109 if(it->second.second != 0)
110 cfg.CU_Port = (uint16_t) it->second.second;
116 case Interface::RIC :
118 if(it->second.first != "")
119 strcpy(cfg.RIC_IPV4_Addr, it->second.first.c_str());
124 if(it->second.second != 0)
125 cfg.RIC_Port = (uint16_t) it->second.second;
132 O1_LOG("\nno matching interface");
139 /*******************************************************************
141 * @brief Get Interface Configuration
145 * Function : getInterfaceConfig
148 * - Get running Interface Configuration
150 * @params[in] Reference of S_Session
151 * @return reference of InterfaceMap
153 ******************************************************************/
154 bool InitConfig::getInterfaceConfig(sysrepo::S_Session sess , InitConfig::InterfaceMap &map)
156 InitConfig::Address oduAddr;
157 InitConfig::Address ocuAddr;
158 InitConfig::Address ricAddr;
159 if(getInterfaceData(sess,Interface::ODU, oduAddr) && \
160 getInterfaceData(sess,Interface::OCU, ocuAddr) && \
161 getInterfaceData(sess,Interface::RIC, ricAddr))
163 mInterfaceList.insert(std::make_pair(Interface::ODU, oduAddr));
164 mInterfaceList.insert(std::make_pair(Interface::OCU, ocuAddr));
165 mInterfaceList.insert(std::make_pair(Interface::RIC, ricAddr));
166 map = mInterfaceList;
175 /*******************************************************************
177 * @brief Get Interface Data
181 * Function : getInterfaceData
184 * - Get running Interface Data
186 * @params[in] Reference of S_Session and Interface
187 * @return reference of Address
189 ******************************************************************/
190 bool InitConfig::getInterfaceData(sysrepo::S_Session sess, \
191 Interface inf, InitConfig::Address & addr)
193 //O1_LOG("\nInitConfig::getInterfaceData started");
194 string sInf = interfaceToString(inf);
198 if(getData(sess, getInterfaceXpath(sInf, IP_ADDRESS), ip))
200 if(getData(sess, getInterfaceXpath(sInf, PORT), port))
202 addr = std::make_pair(ip, atoi(port.c_str()));
212 /*******************************************************************
214 * @brief create xpath for interfaces
218 * Function : getInterfaceXpath
221 * - create xpath for interfaces
223 * @params[in] String of sInf and String of param
224 * @return pointer to xpath
226 ******************************************************************/
227 char * InitConfig::getInterfaceXpath( string sInf, string param)
229 sprintf(xpath, "%s/interfaces/interface[interface-name='%s']/%s", \
230 INTERFACE_MODULE_NAME_ORAN, sInf.c_str(),param.c_str());
234 /*******************************************************************
236 * @brief Get data of the xpath
243 * - get data of the xpath
245 * @params[in] reference of S_Session and pointer to xpath
246 * @return value against the xpath
248 ******************************************************************/
250 bool InitConfig::getData(sysrepo::S_Session sess,char* xpath, string &val)
252 //O1_LOG("\nInitConfig::getData of xpath = %s", \
253 xpath); //enable for debugging only
256 auto value = sess->get_item(xpath);
257 if (value == nullptr)
259 O1_LOG("\nInitConfig::getData no data available at xpath= %s", \
261 //O1_LOG("\nget_item value are null for xpath = %s", \
262 xpath); //enable for debugging only
265 val = value->val_to_string();
271 O1_LOG("\nInitConfig::getData exception occured for xpath= %s", \
277 /*******************************************************************
279 * @brief Convert interface value to string
283 * Function : interfaceToString
286 * - Convert interface value to string
288 * @params[in] reference to Interface
289 * @return string value of Interface
291 ******************************************************************/
292 string InitConfig::interfaceToString(Interface inf)
297 case Interface::ODU :
300 case Interface::OCU :
303 case Interface::RIC :
307 O1_LOG("\n\n no matching interface ");
315 /*******************************************************************
317 * @brief Print Interface configuration
321 * Function : printInterfaceConfig
324 * - Print Interface configuration
329 ******************************************************************/
330 bool InitConfig::printInterfaceConfig()
332 InitConfig::InterfaceMap::iterator it;
333 for (it=mInterfaceList.begin(); it != mInterfaceList.end(); it++)
335 O1_LOG("\ninterface [%s] : \n \t IP = %s \n \t Port = %d", \
336 interfaceToString(it->first).c_str(), it->second.first.c_str(), \
342 /**********************************************************************
344 **********************************************************************/