2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: 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 "oransc.org/usecase/oduclosedloop/internal/restclient"
28 "oransc.org/usecase/oduclosedloop/internal/structures"
29 "oransc.org/usecase/oduclosedloop/messages"
31 log "github.com/sirupsen/logrus"
36 DEFAULT_DEDICATED_RATIO = 40
37 NEW_DEDICATED_RATIO = 50
42 client *restclient.Client
43 metricsPolicies *structures.SliceAssuranceMeas
49 func (a *App) Initialize(dmaapUrl string, sdnrUrl string) {
53 a.client = restclient.New(&http.Client{})
54 a.metricsPolicies = structures.NewSliceAssuranceMeas()
57 func (a *App) Run(topic string, pollTime int) {
59 a.getMessagesFromDmaap(dmaapMRUrl + topic)
61 for key := range a.metricsPolicies.Metrics {
62 a.getRRMInformation(key.Duid)
64 a.updateDedicatedRatio()
66 time.Sleep(time.Second * time.Duration(pollTime))
70 func (a *App) getMessagesFromDmaap(url string) {
71 var stdMessage messages.StdDefinedMessage
72 a.client.Get(url, &stdMessage)
73 log.Infof("Polling new messages from DmaapMR")
74 for _, meas := range stdMessage.GetMeasurements() {
75 //Create sliceMetric and check if metric exist and update existing one or create new one
76 if _, err := a.metricsPolicies.AddOrUpdateMetric(meas); err != nil {
77 log.Error("Metric could not be added ", err)
82 func (a *App) getRRMInformation(duid string) {
83 var duRRMPolicyRatio messages.ORanDuRestConf
84 a.client.Get(getUrlForDistributedUnitFunctions(sDNRUrl, duid), &duRRMPolicyRatio)
86 policies := duRRMPolicyRatio.DistributedUnitFunction.RRMPolicyRatio
87 for _, policy := range policies {
88 a.metricsPolicies.AddNewPolicy(duid, policy)
92 func (a *App) updateDedicatedRatio() {
94 for _, metric := range a.metricsPolicies.Metrics {
95 policy, check := a.metricsPolicies.Policies[metric.RRMPolicyRatioId]
96 //TODO What happened if dedicated ratio is already higher that default and threshold is exceed?
97 if check && policy.PolicyDedicatedRatio <= DEFAULT_DEDICATED_RATIO {
98 log.Infof("Send Post Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId)
99 url := getUrlUpdatePolicyDedicatedRatio(sDNRUrl, metric.DUId, policy.PolicyRatioId)
100 a.client.Post(url, policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO), nil)
105 func getUrlForDistributedUnitFunctions(host string, duid string) string {
106 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
109 func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string) string {
110 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