2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
21 package sliceassurance
27 log "github.com/sirupsen/logrus"
28 "oransc.org/usecase/oduclosedloop/icsversion/internal/restclient"
29 "oransc.org/usecase/oduclosedloop/icsversion/internal/structures"
30 "oransc.org/usecase/oduclosedloop/icsversion/messages"
33 type SdnrConfiguration struct {
39 type SdnrHandler struct {
40 config SdnrConfiguration
41 client *restclient.Client
42 data *structures.SliceAssuranceMeas
45 func NewSdnrHandler(conf SdnrConfiguration, client *restclient.Client, data *structures.SliceAssuranceMeas) *SdnrHandler {
53 func (handler SdnrHandler) getRRMInformation(duid string) {
54 var duRRMPolicyRatio messages.ORanDuRestConf
56 log.Infof("Get RRM Information from SDNR url: %v", handler.config.SDNRAddress)
57 if error := handler.client.Get(getUrlForDistributedUnitFunctions(handler.config.SDNRAddress, duid), &duRRMPolicyRatio, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
58 prettyPrint(duRRMPolicyRatio.DistributedUnitFunction)
60 log.Warn("Send of Get RRM Information failed! ", error)
63 for _, odu := range duRRMPolicyRatio.DistributedUnitFunction {
64 for _, policy := range odu.RRMPolicyRatio {
65 log.Infof("Add or Update policy: %+v from DU id: %v", policy.Id, duid)
66 handler.data.AddNewPolicy(duid, policy)
71 func (handler SdnrHandler) updateDedicatedRatio() {
72 for _, metric := range handler.data.Metrics {
73 policy, check := handler.data.Policies[metric.RRMPolicyRatioId]
74 //TODO What happened if dedicated ratio is already higher that default and threshold is exceed?
75 if check && policy.PolicyDedicatedRatio <= DEFAULT_DEDICATED_RATIO {
76 log.Infof("Send Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId)
77 path := getUrlUpdatePolicyDedicatedRatio(handler.config.SDNRAddress, metric.DUId, policy.PolicyRatioId)
78 updatePolicyMessage := policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO)
79 prettyPrint(updatePolicyMessage)
80 if error := handler.client.Put(path, updatePolicyMessage, nil, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
81 log.Infof("Policy Dedicated Ratio for PolicyId: %v was updated to %v", policy.PolicyRatioId, NEW_DEDICATED_RATIO)
83 log.Warn("Send of Put Request to update DedicatedRatio failed! ", error)
89 func getUrlForDistributedUnitFunctions(host string, duid string) string {
90 return host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + NODE_ID + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid
93 func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string) string {
94 return host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + NODE_ID + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid + "/radio-resource-management-policy-ratio=" + policyid
97 func prettyPrint(jsonStruct interface{}) {
98 b, err := json.MarshalIndent(jsonStruct, "", " ")
100 fmt.Println("error:", err)