Add NodeId and JobId as configuration in ICS Version 96/9396/2
authoraravind.est <aravindhan.a@est.tech>
Tue, 25 Oct 2022 18:51:43 +0000 (19:51 +0100)
committeraravind.est <aravindhan.a@est.tech>
Wed, 26 Oct 2022 13:45:05 +0000 (14:45 +0100)
Issue-ID: NONRTRIC-807
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: Ie52a19d7a4d1d7a50b841ae2411929a52d666415

icsversion/internal/config/config.go
icsversion/internal/config/config_test.go
icsversion/internal/odusliceassurance/app.go
icsversion/internal/odusliceassurance/sdnrHandler.go
icsversion/main.go

index fcf2721..8fb8383 100644 (file)
@@ -36,6 +36,8 @@ type Configuration struct {
        SDNPassword            string
        InfoCoordinatorAddress string
        LogLevel               log.Level
+       NodeId                 string
+       JobId                  string
 }
 
 func New() *Configuration {
@@ -47,11 +49,13 @@ func New() *Configuration {
                SDNPassword:            getEnv("SDNR_PASSWORD", "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"),
                InfoCoordinatorAddress: getEnv("INFO_COORD_ADDR", "http://enrichmentservice:8083"),
                LogLevel:               getLogLevel(),
+               NodeId:                 getEnv("NODE_ID", ""),
+               JobId:                  getEnv("JOB_ID", "14e7bb84-a44d-44c1-90b7-6995a92ad83d"),
        }
 }
 
 func (c Configuration) String() string {
-       return fmt.Sprintf("[ConsumerHost: %v, ConsumerPort: %v, SDNRAddress: %v, SDNRUser: %v, SDNRPassword: %v, InfoCoordinatorAddress: %v, LogLevel: %v]", c.ConsumerHost, c.ConsumerPort, c.SDNRAddress, c.SDNRUser, c.SDNPassword, c.InfoCoordinatorAddress, c.LogLevel)
+       return fmt.Sprintf("[ConsumerHost: %v, ConsumerPort: %v, SDNRAddress: %v, SDNRUser: %v, SDNRPassword: %v, InfoCoordinatorAddress: %v, LogLevel: %v, NodeId: %v, JobId: %v]", c.ConsumerHost, c.ConsumerPort, c.SDNRAddress, c.SDNRUser, c.SDNPassword, c.InfoCoordinatorAddress, c.LogLevel, c.NodeId, c.JobId)
 }
 
 func getEnv(key string, defaultVal string) string {
index fffc60b..3eea2af 100644 (file)
@@ -52,6 +52,8 @@ func TestConfigurationValuesSetProperly(t *testing.T) {
                                        SDNPassword:            "pass",
                                        InfoCoordinatorAddress: "infoCoordAddr",
                                        LogLevel:               log.InfoLevel,
+                                       NodeId:                 "O-DU-1122",
+                                       JobId:                  "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
                                },
                        },
                },
@@ -65,6 +67,8 @@ func TestConfigurationValuesSetProperly(t *testing.T) {
                                        SDNPassword:            "pass",
                                        InfoCoordinatorAddress: "infoCoordAddr",
                                        LogLevel:               log.InfoLevel,
+                                       NodeId:                 "O-DU-1122",
+                                       JobId:                  "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
                                },
                                envVar: map[string]string{"CONSUMER_PORT": "wrong"},
                        },
@@ -80,6 +84,8 @@ func TestConfigurationValuesSetProperly(t *testing.T) {
                                        SDNPassword:            "pass",
                                        InfoCoordinatorAddress: "infoCoordAddr",
                                        LogLevel:               log.InfoLevel,
+                                       NodeId:                 "O-DU-1122",
+                                       JobId:                  "14e7bb84-a44d-44c1-90b7-6995a92ad83d",
                                },
                                envVar: map[string]string{"LOG_LEVEL": "wrong"},
                        },
@@ -94,6 +100,8 @@ func TestConfigurationValuesSetProperly(t *testing.T) {
                        os.Setenv("SDNR_USER", "admin")
                        os.Setenv("SDNR_PASSWORD", "pass")
                        os.Setenv("INFO_COORD_ADDR", "infoCoordAddr")
+                       os.Setenv("NODE_ID", "O-DU-1122")
+                       os.Setenv("JOB_ID", "14e7bb84-a44d-44c1-90b7-6995a92ad83d")
 
                        for key, element := range tt.args.envVar {
                                os.Setenv(key, element)
index 852e0f3..d09fa71 100644 (file)
@@ -34,13 +34,12 @@ import (
 var started bool
 var icsAddr string
 var consumerPort string
+var jobId string
 
 const (
        THRESHOLD_TPUT          = 7000
        DEFAULT_DEDICATED_RATIO = 15
        NEW_DEDICATED_RATIO     = 25
-       NODE_ID                 = "O-DU-1122"
-       jobId                   = "14e7bb84-a44d-44c1-90b7-6995a92ad83d"
 )
 
 var jobRegistrationInfo = struct {
@@ -73,8 +72,10 @@ func (a *App) Initialize(config *config.Configuration) {
                SDNRAddress:  config.SDNRAddress,
                SDNRUser:     config.SDNRUser,
                SDNRPassword: config.SDNPassword,
+               NodeId:       config.NodeId,
        }
        icsAddr = config.InfoCoordinatorAddress
+       jobId = config.JobId
 
        a.client = restclient.New(&http.Client{}, false)
        a.data = structures.NewSliceAssuranceMeas()
index d2e2d87..32fef89 100644 (file)
@@ -34,6 +34,7 @@ type SdnrConfiguration struct {
        SDNRAddress  string
        SDNRUser     string
        SDNRPassword string
+       NodeId       string
 }
 
 type SdnrHandler struct {
@@ -54,7 +55,7 @@ func (handler SdnrHandler) getRRMInformation(duid string) {
        var duRRMPolicyRatio messages.ORanDuRestConf
 
        log.Infof("Get RRM Information from SDNR url: %v", handler.config.SDNRAddress)
-       if error := handler.client.Get(getUrlForDistributedUnitFunctions(handler.config.SDNRAddress, duid), &duRRMPolicyRatio, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
+       if error := handler.client.Get(getUrlForDistributedUnitFunctions(handler.config.SDNRAddress, duid, handler.config.NodeId), &duRRMPolicyRatio, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
                prettyPrint(duRRMPolicyRatio.DistributedUnitFunction)
        } else {
                log.Warn("Send of Get RRM Information failed! ", error)
@@ -74,7 +75,7 @@ func (handler SdnrHandler) updateDedicatedRatio() {
                //TODO What happened if dedicated ratio is already higher that default and threshold is exceed?
                if check && policy.PolicyDedicatedRatio <= DEFAULT_DEDICATED_RATIO {
                        log.Infof("Send Request to update DedicatedRatio for DU id: %v Policy id: %v", metric.DUId, policy.PolicyRatioId)
-                       path := getUrlUpdatePolicyDedicatedRatio(handler.config.SDNRAddress, metric.DUId, policy.PolicyRatioId)
+                       path := getUrlUpdatePolicyDedicatedRatio(handler.config.SDNRAddress, metric.DUId, policy.PolicyRatioId, handler.config.NodeId)
                        updatePolicyMessage := policy.GetUpdateDedicatedRatioMessage(metric.SliceDiff, metric.SliceServiceType, NEW_DEDICATED_RATIO)
                        prettyPrint(updatePolicyMessage)
                        if error := handler.client.Put(path, updatePolicyMessage, nil, handler.config.SDNRUser, handler.config.SDNRPassword); error == nil {
@@ -86,12 +87,14 @@ func (handler SdnrHandler) updateDedicatedRatio() {
        }
 }
 
-func getUrlForDistributedUnitFunctions(host string, duid string) string {
-       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
+func getUrlForDistributedUnitFunctions(host string, duid string, nodeid string) string {
+       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)
+       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
 }
 
-func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string) string {
-       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
+func getUrlUpdatePolicyDedicatedRatio(host string, duid string, policyid string, nodeid string) string {
+       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)
+       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
 }
 
 func prettyPrint(jsonStruct interface{}) {
index dcf37ff..eeff5b4 100644 (file)
@@ -59,6 +59,8 @@ func main() {
 func validateConfiguration(configuration *config.Configuration) error {
        if configuration.ConsumerHost == "" || configuration.ConsumerPort == 0 {
                return fmt.Errorf("consumer host and port must be provided")
+       } else if configuration.NodeId == "" {
+               return fmt.Errorf("NodeId must be provided")
        }
        return nil
 }