1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2021] [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 implementation of RRM Policy get and update handler along
20 * with some supporting funtion. It handles get and change callback for
21 * rrmpolicy yang module */
24 #include "RrmPolicyCb.hpp"
26 RrmPolicyList rrmPolicy[MAX_POLICY];
28 uint8_t policyNum = 0;
29 uint8_t policyIndex = 0;
30 uint8_t policyMemberListNum =0;
32 /*******************************************************************
34 * @brief override oper_get_items to handle callback
38 * Function : oper_get_items
41 * - override oper_get_items to handle callback of get of
42 * o-ran-sc-du-hello-world yang module
45 * @params[in] sysrepo::S_Session session, const char *module_name,
46 * const char *path, const char *request_xpath,
47 * uint32_t request_id, libyang::S_Data_Node &parent,
49 * @return SR_ERR_OK - success
51 ******************************************************************/
53 int RrmPolicyCb::oper_get_items(sysrepo::S_Session session, \
54 const char *module_name, \
56 const char *request_xpath, \
57 uint32_t request_id, \
58 libyang::S_Data_Node &parent, \
61 O1_LOG("\nO1 RrmPolicyCb : Callback called for path=%s on get request", \
66 /*******************************************************************
68 * @brief convert string resouce type to enum
72 * Function : resourceTypeToEnum
75 * - convert string resouce type to enum
78 * @params[in] string resouceType
79 * @return Enum resouceType
80 ******************************************************************/
81 RrmResourceType RrmPolicyCb::resourceTypeToEnum(string &val)
89 else if(val == "PRB_UL")
93 else if(val == "PRB_DL")
101 else if(val == "DRB")
107 O1_LOG("\nO1 RrmPolicyCb::updateParams non handeled value of "
108 "ResourceType = %s", val.c_str());
110 O1_LOG("\nO1 rrmPolicy resourceTypeToEnum : val [%d]", ret);
114 /*******************************************************************
116 * @brief fill the parameters value into the structure instance
120 * Function : updateParams
123 * - fill the parameters value into the structure instance
126 * @params[in] string leafNode, string val
128 ******************************************************************/
130 bool RrmPolicyCb::updateParams(string &parent, string &leafNode, string &val)
133 O1_LOG("\nO1 RrmPolicyCb::updateParams parameter name=%s val = %s", \
134 leafNode.c_str(), val.c_str());
139 if (leafNode == "id")
142 policyNum = policyIndex -1 ;
143 memset(rrmPolicy[policyNum].id, '\0', ID_MAX_LEN);
144 strncpy(rrmPolicy[policyNum].id, val.c_str(), ID_MAX_LEN-1);
145 O1_LOG("\nO1 RrmPolicyCb::updateParams id = %s", rrmPolicy[policyNum].id);
146 rrmPolicy[policyNum].rRMMemberNum = 0;
148 else if(leafNode == "resourceType")
150 rrmPolicy[policyNum].resourceType = resourceTypeToEnum(val);
151 O1_LOG("\nO1 RrmPolicyCb::updateParams ResourceType = %d", \
152 rrmPolicy[policyNum].resourceType);
154 else if(leafNode == "rRMPolicyMaxRatio")
156 rrmPolicy[policyNum].rRMPolicyMaxRatio = atoi(val.c_str());
157 O1_LOG("\nO1 RrmPolicyCb::updateParams rRMPolicyMaxRatio = %d", \
158 rrmPolicy[policyNum].rRMPolicyMaxRatio);
160 else if(leafNode == "rRMPolicyMinRatio")
162 rrmPolicy[policyNum].rRMPolicyMinRatio = atoi(val.c_str());
163 O1_LOG("\nO1 RrmPolicyCb::updateParams rRMPolicyMinRatio = %d", \
164 rrmPolicy[policyNum].rRMPolicyMinRatio);
166 else if(leafNode == "rRMPolicyDedicatedRatio")
168 rrmPolicy[policyNum].rRMPolicyDedicatedRatio = atoi(val.c_str());
169 O1_LOG("\nO1 RrmPolicyCb::updateParams rRMPolicyDedicatedRatio = %d", \
170 rrmPolicy[policyNum].rRMPolicyDedicatedRatio);
172 else if((leafNode == "mcc") || (leafNode == "mnc")
173 || leafNode == "sst" || leafNode == "sd")
175 int memberNum = policyMemberListNum/MAX_POLICY_LIST;
176 rrmPolicy[policyNum].rRMMemberNum = memberNum+1;
177 if(leafNode == "mcc")
179 memset(rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc, \
181 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc[0] = std::stoi(val.substr(0,1).c_str(),0,10);
182 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc[1] = std::stoi(val.substr(1,1).c_str(),0,10);
183 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc[2] = std::stoi(val.substr(2,1).c_str(),0,10);
184 //strncpy((char *)rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc, \
185 val.c_str(), MCC_LEN);
186 O1_LOG("\nO1 RrmPolicyCb::updateParams rrmPolicy[%d]."
187 "rRMPolicyMemberList[%d].mcc[2] = %c", policyNum, memberNum, \
188 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mcc[2]);
190 else if(leafNode == "mnc")
192 memset(rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc, \
194 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc[0] = std::stoi(val.substr(0,1).c_str(),0,10);
195 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc[1] = std::stoi(val.substr(1,1).c_str(),0,10);
196 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc[2] = std::stoi(val.substr(2,1).c_str(),0,10);
197 //strncpy((char *) rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc, \
198 val.c_str(), MNC_LEN);
199 O1_LOG("\nO1 RrmPolicyCb::updateParams rrmPolicy[%d]."
200 "rRMPolicyMemberList[%d].mnc[1] = %c", policyNum, memberNum, \
201 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].mnc[1]);
203 else if(leafNode == "sst")
205 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sst = \
207 O1_LOG("\nO1 RrmPolicyCb::updateParams sst val = %d",
208 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sst);
210 else if(leafNode == "sd")
212 memset(rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sd, \
215 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sd[0] = \
216 std::stoi(val.substr(0,2).c_str(),0,16);
217 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sd[1] = \
218 std::stoi(val.substr(2,2).c_str(),0,16);
219 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sd[2] = \
220 std::stoi(val.substr(4,2).c_str(),0,16);
221 O1_LOG("\nO1 RrmPolicyCb::updateParams rrmPolicy[%d]."
222 "rRMPolicyMemberList[%d].sd[2] = %c", policyNum, memberNum, \
223 rrmPolicy[policyNum].rRMPolicyMemberList[memberNum].sd[SD_LEN-1]);
225 policyMemberListNum++;
229 O1_LOG("\nO1 RrmPolicyCb::updateParams some parameter not handled name=%s "
230 "val = %s", leafNode.c_str(), val.c_str());
236 O1_LOG("\nO1 RrmPolicyCb::updateParams without value node name=%s val = %s",
237 leafNode.c_str(), val.c_str());
242 /*******************************************************************
244 * @brief override module_change to handle callback
248 * Function : module_change
251 * - override module_change to handle callback of modification of
252 * o-ran-sc-du-hello-world yang module
255 * @params[in] sysrepo::S_Session session, const char *module_name,
256 * const char *xpath, sr_event_t event, uint32_t request_id,
258 * @return SR_ERR_OK - success
259 * SR_ERR_OK - failure
260 ******************************************************************/
262 int RrmPolicyCb::module_change(sysrepo::S_Session sess, \
263 const char *module_name, \
266 uint32_t request_id, \
269 char change_path[MAX_LEN];
272 O1_LOG("\nO1 RrmPolicyCb : Notification %s", NetconfUtils::evToStr(event));
273 if (SR_EV_CHANGE == event)
275 snprintf(change_path, MAX_LEN, "/%s:*//.", module_name);
276 auto it = sess->get_changes_iter(change_path);
277 while (auto change = sess->get_change_next(it)) {
278 //NetconfUtils::printChange(change); //enable only for debugging
279 if(nullptr != change->new_val())
281 O1_LOG("\n\nO1 RrmPolicyCb : Parameter value has been \
282 changed val=%s", change->new_val()->val_to_string().c_str());
283 string val = change->new_val()->val_to_string();
284 string parent, leafNode;
285 NetconfUtils::getLeafInfo(change->new_val()->to_string(), parent, leafNode);
286 O1_LOG("\nO1 RrmPolicy : LeafNode name = [%s]", leafNode.c_str());
287 if(!updateParams(parent, leafNode, val)){
288 O1_LOG("\nO1 RrmPolicy : LeafNode [%s] not handled", leafNode.c_str());
289 //later error handling can be done
293 #ifndef ODU_TEST_STUB
294 if(ROK != setRrmPolicy(rrmPolicy, policyIndex))
296 O1_LOG("\nO1 RrmPolicy : updateRrmPolicy failed");
297 return SR_ERR_INTERNAL;
298 //later error handling can be done
303 catch( const std::exception& e ) {
304 O1_LOG("\nO1 RrmPolicyCb exception : %s\n", e.what());
309 /**********************************************************************
311 **********************************************************************/