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===================================
29 "github.com/gorilla/mux"
30 "oransc.org/usecase/oduclosedloop/messages"
34 port := flag.Int("port", 3904, "The port this SDNR stub will listen on")
38 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}", getDistributedUnitFunctions).Methods(http.MethodGet)
39 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)
41 fmt.Println("Starting SDNR on port: ", *port)
42 http.ListenAndServe(fmt.Sprintf(":%v", *port), r)
46 func getDistributedUnitFunctions(w http.ResponseWriter, r *http.Request) {
49 message := messages.ORanDuRestConf{
50 DistributedUnitFunction: messages.DistributedUnitFunction{
52 RRMPolicyRatio: []messages.RRMPolicyRatio{
56 UserLabel: "rrm-pol-1",
57 RRMPolicyMaxRatio: 100,
58 RRMPolicyMinRatio: "0",
59 RRMPolicyDedicatedRatio: "0",
61 RRMPolicyMembers: []messages.RRMPolicyMember{
63 MobileCountryCode: "046",
64 MobileNetworkCode: "651",
65 SliceDifferentiator: 1,
73 UserLabel: "rrm-pol-2",
74 RRMPolicyMaxRatio: 20,
75 RRMPolicyMinRatio: "10",
76 RRMPolicyDedicatedRatio: "15",
78 RRMPolicyMembers: []messages.RRMPolicyMember{
80 MobileCountryCode: "046",
81 MobileNetworkCode: "651",
82 SliceDifferentiator: 2,
90 UserLabel: "rrm-pol-3",
91 RRMPolicyMaxRatio: 30,
92 RRMPolicyMinRatio: "10",
93 RRMPolicyDedicatedRatio: "5",
95 RRMPolicyMembers: []messages.RRMPolicyMember{
97 MobileCountryCode: "310",
98 MobileNetworkCode: "150",
99 SliceDifferentiator: 2,
108 respondWithJSON(w, http.StatusOK, message)
111 func updateRRMPolicyDedicatedRatio(w http.ResponseWriter, r *http.Request) {
112 //vars := mux.Vars(r)
113 fmt.Println("::updateRRMPolicyDedicatedRatio::")
114 var prMessage messages.DistributedUnitFunction
115 decoder := json.NewDecoder(r.Body)
117 if err := decoder.Decode(&prMessage); err != nil {
118 respondWithError(w, http.StatusBadRequest, "Invalid request payload")
123 fmt.Println("prMessage: ", prMessage)
124 //prMessage.Id = vars["POLICY-ID"]
126 respondWithJSON(w, http.StatusOK, map[string]string{"status": "200"})
129 func respondWithError(w http.ResponseWriter, code int, message string) {
130 fmt.Println("-----------------------------------------------------------------------------")
131 fmt.Println("Sending error message: ", message)
132 fmt.Println("-----------------------------------------------------------------------------")
133 respondWithJSON(w, code, map[string]string{"error": message})
136 func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
137 fmt.Println("-----------------------------------------------------------------------------")
138 fmt.Println("Sending message: ", payload)
139 fmt.Println("-----------------------------------------------------------------------------")
140 response, _ := json.Marshal(payload)
142 w.Header().Set("Content-Type", "application/json")