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 {
40 type SdnrHandler struct {
41 config SdnrConfiguration
42 client *restclient.Client
43 data *structures.SliceAssuranceMeas
46 func NewSdnrHandler(conf SdnrConfiguration, client *restclient.Client, data *structures.SliceAssuranceMeas) *SdnrHandler {
54 func (handler SdnrHandler) getRRMInformation(duid string) {
55 var duRRMPolicyRatio messages.ORanDuRestConf
57 log.Infof("Get RRM Information from SDNR url: %v", handler.config.SDNRAddress)
58 if error := handler.client.Get(getUrlForDistributedUnitFunctions(handler.config.SDNRAddress, duid, handler.config.NodeId), &duRRMPolicyRatio, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
59 prettyPrint(duRRMPolicyRatio.DistributedUnitFunction)
61 log.Warn("Send of Get RRM Information failed! ", error)
64 for _, odu := range duRRMPolicyRatio.DistributedUnitFunction {
65 for _, policy := range odu.RRMPolicyRatio {
66 log.Infof("Add or Update policy: %+v from DU id: %v", policy.Id, duid)
67 handler.data.AddNewPolicy(duid, policy)
72 func (handler SdnrHandler) updateDedicatedRatio() {
73 for _, metric := range handler.data.Metrics {
74 policy, check := handler.data.Policies[metric.RRMPolicyRatioId]
75 //TODO What happened if dedicated ratio is already higher that default and threshold is exceed?
76 if check && policy.PolicyDedicatedRatio <= DEFAULT_DEDICATED_RATIO {
77 log.Infof("Send Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId)
78 path := getUrlUpdatePolicyDedicatedRatio(handler.config.SDNRAddress, metric.DUId, policy.PolicyRatioId, handler.config.NodeId)
79 updatePolicyMessage := policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO)
80 prettyPrint(updatePolicyMessage)
81 if error := handler.client.Put(path, updatePolicyMessage, nil, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
82 log.Infof("Policy Dedicated Ratio for PolicyId: %v was updated to %v", policy.PolicyRatioId, NEW_DEDICATED_RATIO)
84 log.Warn("Send of Put Request to update DedicatedRatio failed! ", error)
90 func getUrlForDistributedUnitFunctions(host string, duid string, nodeid string) string {
91 fmt.Print(host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + nodeid + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid)
92 return host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + nodeid + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid
95 func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string, nodeid string) string {
96 fmt.Print(host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + nodeid + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid + "/radio-resource-management-policy-ratio=" + policyid)
97 return host + "/rests/data/network-topology:network-topology/topology=topology-netconf/node=" + nodeid + "/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=" + duid + "/radio-resource-management-policy-ratio=" + policyid
100 func prettyPrint(jsonStruct interface{}) {
101 b, err := json.MarshalIndent(jsonStruct, "", " ")
103 fmt.Println("error:", err)