Name alignment, agent to a1pms, in test env
[nonrtric.git] / test / usecases / odusliceassurance / goversion / stub / simulator.go
index dcf450c..aef85d8 100644 (file)
@@ -38,7 +38,7 @@ import (
        log "github.com/sirupsen/logrus"
 )
 
-const THRESHOLD_TPUT int = 700
+const THRESHOLD_TPUT int = 7000
 
 type SliceAssuranceInformation struct {
        duId                 string
@@ -117,8 +117,7 @@ func main() {
 
                r := mux.NewRouter()
                r.HandleFunc("/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={O-DU-ID}", getSdnrResponseMessage).Methods(http.MethodGet)
-               r.HandleFunc("/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={O-DU-ID}/radio-resource-management-policy-ratio={POLICY-ID}", updateRRMPolicyDedicatedRatio).Methods(http.MethodPost)
-               r.HandleFunc("/events/unauthenticated.PERFORMANCE_MEASUREMENTS", sendDmaapMRMessages).Methods(http.MethodGet)
+               r.HandleFunc("/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={O-DU-ID}/radio-resource-management-policy-ratio={POLICY-ID}", updateRRMPolicyDedicatedRatio).Methods(http.MethodPut)
 
                fmt.Println("Starting SDNR stub on port: ", *portSdnr)
 
@@ -129,7 +128,7 @@ func main() {
        go func() {
 
                r := mux.NewRouter()
-               r.HandleFunc("/events/unauthenticated.PERFORMANCE_MEASUREMENTS", sendDmaapMRMessages).Methods(http.MethodGet)
+               r.HandleFunc("/events/unauthenticated.VES_O_RAN_SC_HELLO_WORLD_PM_STREAMING_OUTPUT/myG/C1", sendDmaapMRMessages).Methods(http.MethodGet)
 
                fmt.Println("Starting DmaapMR stub on port: ", *portDmaapMR)
 
@@ -144,54 +143,133 @@ func getSdnrResponseMessage(w http.ResponseWriter, r *http.Request) {
        vars := mux.Vars(r)
        log.Info("Get messages for RRM Policy Ratio information for O-Du ID ", vars["O-DU-ID"])
 
-       message := messages.ORanDuRestConf{
-               DistributedUnitFunction: messages.DistributedUnitFunction{
-                       Id:             vars["O-DU-ID"],
-                       RRMPolicyRatio: getPolicyRatioMessage(),
-               },
-       }
-       respondWithJSON(w, http.StatusOK, message)
+       distUnitFunctions := getDistributedUnitFunctionMessage(vars["O-DU-ID"])
+
+       respondWithJSON(w, http.StatusOK, distUnitFunctions)
 }
 
-func getPolicyRatioMessage() []messages.RRMPolicyRatio {
+func getDistributedUnitFunctionMessage(oduId string) messages.ORanDuRestConf {
+
        var policies []messages.RRMPolicyRatio
+       keys := make(map[string]bool)
+       for _, entry := range data {
+               if _, value := keys[entry.policyRatioId]; !value {
+                       keys[entry.policyRatioId] = true
+                       message := messages.RRMPolicyRatio{
+
+                               Id:                      entry.policyRatioId,
+                               AdmState:                "locked",
+                               UserLabel:               entry.policyRatioId,
+                               RRMPolicyMaxRatio:       entry.policyMaxRatio,
+                               RRMPolicyMinRatio:       entry.policyMinRatio,
+                               RRMPolicyDedicatedRatio: entry.policyDedicatedRatio,
+                               ResourceType:            "prb",
+                               RRMPolicyMembers: []messages.RRMPolicyMember{
+                                       {
+                                               MobileCountryCode:   "310",
+                                               MobileNetworkCode:   "150",
+                                               SliceDifferentiator: entry.sd,
+                                               SliceServiceType:    entry.sst,
+                                       },
+                               },
+                       }
+                       policies = append(policies, message)
+               }
+       }
 
+       var publicLandMobileNetworks []messages.PublicLandMobileNetworks
        for _, entry := range data {
+               publicLandMobileNetwork := messages.PublicLandMobileNetworks{
+                       MobileCountryCode:   "310",
+                       MobileNetworkCode:   "150",
+                       SliceDifferentiator: entry.sd,
+                       SliceServiceType:    entry.sst,
+               }
+               publicLandMobileNetworks = append(publicLandMobileNetworks, publicLandMobileNetwork)
+       }
 
-               message := messages.RRMPolicyRatio{
-                       Id:                      entry.policyRatioId,
-                       AdmState:                "locked",
-                       UserLabel:               entry.policyRatioId,
-                       RRMPolicyMaxRatio:       entry.policyMaxRatio,
-                       RRMPolicyMinRatio:       entry.policyMinRatio,
-                       RRMPolicyDedicatedRatio: entry.policyDedicatedRatio,
-                       ResourceType:            "prb",
-                       RRMPolicyMembers: []messages.RRMPolicyMember{
-                               {
-                                       MobileCountryCode:   "046",
-                                       MobileNetworkCode:   "651",
-                                       SliceDifferentiator: entry.sd,
-                                       SliceServiceType:    entry.sst,
-                               },
-                       },
+       var supportedSnssaiSubcounterInstances []messages.SupportedSnssaiSubcounterInstances
+       for _, entry := range data {
+               supportedSnssaiSubcounterInstance := messages.SupportedSnssaiSubcounterInstances{
+                       SliceDifferentiator: entry.sd,
+                       SliceServiceType:    entry.sst,
                }
-               policies = append(policies, message)
+               supportedSnssaiSubcounterInstances = append(supportedSnssaiSubcounterInstances, supportedSnssaiSubcounterInstance)
+       }
+
+       cell := messages.Cell{
+               Id:             "cell-1",
+               LocalId:        1,
+               PhysicalCellId: 1,
+               BaseStationChannelBandwidth: messages.BaseStationChannelBandwidth{
+                       Uplink:              83000,
+                       Downlink:            80000,
+                       SupplementaryUplink: 84000,
+               },
+               OperationalState:         "enabled",
+               TrackingAreaCode:         10,
+               AdmState:                 "unlocked",
+               PublicLandMobileNetworks: publicLandMobileNetworks,
+               SupportedMeasurements: []messages.SupportedMeasurements{
+                       {
+                               PerformanceMeasurementType:         "o-ran-sc-du-hello-world:user-equipment-average-throughput-uplink",
+                               SupportedSnssaiSubcounterInstances: supportedSnssaiSubcounterInstances,
+                       },
+                       {
+                               PerformanceMeasurementType:         "o-ran-sc-du-hello-world:user-equipment-average-throughput-downlink",
+                               SupportedSnssaiSubcounterInstances: supportedSnssaiSubcounterInstances,
+                       },
+               },
+               TrafficState: "active",
+               AbsoluteRadioFrequencyChannelNumber: messages.AbsoluteRadioFrequencyChannelNumber{
+                       Uplink:              14000,
+                       Downlink:            15000,
+                       SupplementaryUplink: 14500,
+               },
+               UserLabel: "cell-1",
+               SynchronizationSignalBlock: messages.SynchronizationSignalBlock{
+                       Duration:               2,
+                       FrequencyChannelNumber: 12,
+                       Periodicity:            10,
+                       SubcarrierSpacing:      30,
+                       Offset:                 3,
+               },
        }
-       return policies
+
+       distUnitFunction := messages.DistributedUnitFunction{
+               Id:               oduId,
+               OperationalState: "enabled",
+               AdmState:         "unlocked",
+               UserLabel:        oduId,
+               Cell: []messages.Cell{
+                       cell,
+               },
+               RRMPolicyRatio: policies,
+       }
+
+       duRRMPolicyRatio := messages.ORanDuRestConf{
+               DistributedUnitFunction: []messages.DistributedUnitFunction{
+                       distUnitFunction,
+               },
+       }
+
+       return duRRMPolicyRatio
 }
 
 func updateRRMPolicyDedicatedRatio(w http.ResponseWriter, r *http.Request) {
-       log.Info("Post request to update RRMPolicyDedicatedRatio")
-
-       var prMessages []messages.RRMPolicyRatio
+       var policies struct {
+               RRMPolicies []messages.RRMPolicyRatio `json:"radio-resource-management-policy-ratio"`
+       }
        decoder := json.NewDecoder(r.Body)
 
-       if err := decoder.Decode(&prMessages); err != nil {
+       if err := decoder.Decode(&policies); err != nil {
                respondWithError(w, http.StatusBadRequest, "Invalid request payload")
                return
        }
        defer r.Body.Close()
 
+       prMessages := policies.RRMPolicies
+       log.Infof("Post request to update RRMPolicyDedicatedRatio %+v", prMessages)
        findAndUpdatePolicy(prMessages)
        respondWithJSON(w, http.StatusOK, map[string]string{"status": "200"})
 }
@@ -200,8 +278,8 @@ func findAndUpdatePolicy(rRMPolicyRatio []messages.RRMPolicyRatio) {
        for _, policy := range rRMPolicyRatio {
                for _, entry := range data {
                        if entry.policyRatioId == policy.Id {
+                               log.Infof("update Policy Dedicated Ratio: value for policy %+v\n Old value: %v New value: %v ", policy, entry.policyDedicatedRatio, policy.RRMPolicyDedicatedRatio)
                                entry.policyDedicatedRatio = policy.RRMPolicyDedicatedRatio
-                               log.Info("New value for Policy dedicated ratio: ", entry.policyDedicatedRatio)
                                if entry.metricValue > THRESHOLD_TPUT {
                                        entry.metricValue = rand.Intn(THRESHOLD_TPUT)
                                }
@@ -233,35 +311,62 @@ func sendDmaapMRMessages(w http.ResponseWriter, r *http.Request) {
                log.Info("Using tput value higher than THRESHOLD_TPUT ", randomTput)
                entry.metricValue = randomTput
        }
-
+       randomEventId := rand.Intn(10000)
        messagesToSend = append(messagesToSend, generateMeasurementEntry(entry))
 
        message := messages.StdDefinedMessage{
                Event: messages.Event{
                        CommonEventHeader: messages.CommonEventHeader{
-                               Domain:               "stndDefined",
-                               StndDefinedNamespace: "o-ran-sc-du-hello-world-pm-streaming-oas3",
+                               Domain:                  "stndDefined",
+                               EventId:                 "pm-1_16442" + strconv.Itoa(randomEventId),
+                               EventName:               "stndDefined_performanceMeasurementStreaming",
+                               EventType:               "performanceMeasurementStreaming",
+                               Sequence:                825,
+                               Priority:                "Low",
+                               ReportingEntityId:       "",
+                               ReportingEntityName:     "O-DU-1122",
+                               SourceId:                "",
+                               SourceName:              "O-DU-1122",
+                               StartEpochMicrosec:      1644252450000000,
+                               LastEpochMicrosec:       1644252480000000,
+                               NfNamingCode:            "SIM-O-DU",
+                               NfVendorName:            "O-RAN-SC SIM Project",
+                               StndDefinedNamespace:    "o-ran-sc-du-hello-world-pm-streaming-oas3",
+                               TimeZoneOffset:          "+00:00",
+                               Version:                 "4.1",
+                               VesEventListenerVersion: "7.2.1",
                        },
                        StndDefinedFields: messages.StndDefinedFields{
                                StndDefinedFieldsVersion: "1.0",
                                SchemaReference:          "https://gerrit.o-ran-sc.org/r/gitweb?p=scp/oam/modeling.git;a=blob_plain;f=data-model/oas3/experimental/o-ran-sc-du-hello-world-oas3.json;hb=refs/heads/master",
                                Data: messages.Data{
-                                       DataId:       "id",
-                                       Measurements: messagesToSend,
+                                       DataId:              "pm-1_1644252450",
+                                       StartTime:           "2022-02-07T16:47:30.0Z",
+                                       AdministrativeState: "unlocked",
+                                       OperationalState:    "enabled",
+                                       UserLabel:           "pm",
+                                       JobTag:              "my-job-tag",
+                                       GranularityPeriod:   30,
+                                       Measurements:        messagesToSend,
                                },
                        },
                },
        }
 
+       fmt.Printf("Sending Dmaap message:\n %+v\n", message)
+
+       messageAsByteArray, _ := json.Marshal(message)
+       response := [1]string{string(messageAsByteArray)}
+
        time.Sleep(time.Duration(rand.Intn(3)) * time.Second)
-       respondWithJSON(w, http.StatusOK, message)
+       respondWithJSON(w, http.StatusOK, response)
 
        messagesToSend = nil
 }
 
 func generateMeasurementEntry(entry *SliceAssuranceInformation) messages.Measurement {
 
-       measurementTypeInstanceReference := "/network-function/distributed-unit-functions[id='" + entry.duId + "']/cell[id='" + entry.cellId + "']/supported-measurements/performance-measurement-type[.='" + entry.metricName + "']/supported-snssai-subcounter-instances/slice-differentiator[.=" + strconv.Itoa(entry.sd) + "][slice-service-type=" + strconv.Itoa(entry.sst) + "]"
+       measurementTypeInstanceReference := "/o-ran-sc-du-hello-world:network-function/distributed-unit-functions[id='" + entry.duId + "']/cell[id='" + entry.cellId + "']/supported-measurements[performance-measurement-type='(urn:o-ran-sc:yang:o-ran-sc-du-hello-world?revision=2021-11-23)" + entry.metricName + "']/supported-snssai-subcounter-instances[slice-differentiator='" + strconv.Itoa(entry.sd) + "'][slice-service-type='" + strconv.Itoa(entry.sst) + "']"
        meas := messages.Measurement{
 
                MeasurementTypeInstanceReference: measurementTypeInstanceReference,