e759125503a97ea8095e8a4fca94ac49f7a8b4c1
[nonrtric.git] / test / usecases / odusliceassurance / goversion / stub / mrproducer / mrstub.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2021: Nordix Foundation
6 //   %%
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
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
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===================================
19 //
20
21 package main
22
23 import (
24         "encoding/json"
25         "flag"
26         "fmt"
27         "math/rand"
28         "net/http"
29         "time"
30
31         "github.com/gorilla/mux"
32         "oransc.org/usecase/oduclosedloop/messages"
33 )
34
35 func main() {
36         rand.Seed(time.Now().UnixNano())
37         port := flag.Int("port", 3905, "The port this message router will listen on")
38         flag.Parse()
39
40         r := mux.NewRouter()
41         r.HandleFunc("/events/unauthenticated.PERFORMANCE_MEASUREMENTS", sendStdMessage).Methods(http.MethodGet)
42
43         fmt.Println("Starting mr on port: ", *port)
44
45         http.ListenAndServe(fmt.Sprintf(":%v", *port), r)
46
47 }
48
49 // Variables ::
50 // DU-ID: ERICSSON-O-DU-11220
51 // Cell-ID: cell1
52 // Slice-Diff: 2
53 // Value: 300
54 func sendStdMessage(w http.ResponseWriter, r *http.Request) {
55         message := fetchMessage()
56         fmt.Println("-----------------------------------------------------------------------------")
57         fmt.Println("Sending message: ", message)
58         fmt.Println("-----------------------------------------------------------------------------")
59         response, _ := json.Marshal(message)
60         time.Sleep(time.Duration(rand.Intn(3)) * time.Second)
61         w.Header().Set("Content-Type", "application/json")
62         w.WriteHeader(http.StatusOK)
63         w.Write(response)
64 }
65
66 func fetchMessage() messages.StdDefinedMessage {
67
68         index := rand.Intn(5)
69         fmt.Println(index)
70
71         measurements := [5][]messages.Measurement{meas1, meas2, meas3, meas4, meas5}
72
73         message := messages.StdDefinedMessage{
74                 Event: messages.Event{
75                         CommonEventHeader: messages.CommonEventHeader{
76                                 Domain:               "stndDefined",
77                                 StndDefinedNamespace: "o-ran-sc-du-hello-world-pm-streaming-oas3",
78                         },
79                         StndDefinedFields: messages.StndDefinedFields{
80                                 StndDefinedFieldsVersion: "1.0",
81                                 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",
82                                 Data: messages.Data{
83                                         DataId:       "id",
84                                         Measurements: measurements[index],
85                                 },
86                         },
87                 },
88         }
89         return message
90 }
91
92 var meas1 = []messages.Measurement{
93         {
94                 MeasurementTypeInstanceReference: "/network-function/distributed-unit-functions[id='ERICSSON-O-DU-11220']/cell[id='cell1']/supported-measurements/performance-measurement-type[.='user-equipment-average-throughput-downlink']/supported-snssai-subcounter-instances/slice-differentiator[.=2][slice-service-type=1]",
95                 Value:                            300,
96                 Unit:                             "kbit/s",
97         },
98 }
99
100 var meas2 = []messages.Measurement{
101         {
102                 MeasurementTypeInstanceReference: "/network-function/distributed-unit-functions[id='ERICSSON-O-DU-11220']/cell[id='cell1']/supported-measurements/performance-measurement-type[.='user-equipment-average-throughput-downlink']/supported-snssai-subcounter-instances/slice-differentiator[.=1]",
103                 Value:                            400,
104                 Unit:                             "kbit/s",
105         },
106 }
107
108 var meas3 = []messages.Measurement{
109         {
110                 MeasurementTypeInstanceReference: "/network-function/distributed-unit-functions[id='ERICSSON-O-DU-11220']/cell[id='cell1']/supported-measurements/performance-measurement-type[.='user-equipment-average-throughput-uplink']/supported-snssai-subcounter-instances/slice-differentiator[.=2][slice-service-type=2]",
111                 Value:                            800,
112                 Unit:                             "kbit/s",
113         },
114 }
115
116 var meas4 = []messages.Measurement{
117         {
118                 MeasurementTypeInstanceReference: "/network-function/distributed-unit-functions[id='ERICSSON-O-DU-11220']/cell[id='cell1']/supported-measurements/performance-measurement-type[.='user-equipment-average-throughput-downlink']/supported-snssai-subcounter-instances/slice-differentiator[.=1]",
119                 Value:                            750,
120                 Unit:                             "kbit/s",
121         },
122 }
123
124 var meas5 = []messages.Measurement{
125         {
126                 MeasurementTypeInstanceReference: "/network-function/distributed-unit-functions[id='ERICSSON-O-DU-11220']/cell[id='cell1']/supported-measurements/performance-measurement-type[.='user-equipment-average-throughput-downlink']/supported-snssai-subcounter-instances/[slice-differentiator[.=2]][slice-service-type=1]",
127                 Value:                            900,
128                 Unit:                             "kbit/s",
129         },
130 }