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 log "github.com/sirupsen/logrus"
31 "oransc.org/usecase/oruclosedloop/internal/repository"
32 "oransc.org/usecase/oruclosedloop/internal/restclient"
33 "oransc.org/usecase/oruclosedloop/internal/ves"
36 type Configuration struct {
37 ConsumerAddress string
38 InfoCoordAddress string
44 const rawSdnrPath = "/rests/data/network-topology:network-topology/topology=topology-netconf/node=[O-DU-ID]/yang-ext:mount/o-ran-sc-du-hello-world:network-function/du-to-ru-connection=[O-RU-ID]"
46 const unlockMessage = `{"o-ran-sc-du-hello-world:du-to-ru-connection": [{"name":"[O-RU-ID]","administrative-state":"UNLOCKED"}]}`
48 type LinkFailureHandler struct {
49 lookupService repository.LookupService
53 func NewLinkFailureHandler(ls repository.LookupService, conf Configuration) *LinkFailureHandler {
54 return &LinkFailureHandler{
60 func (lfh LinkFailureHandler) MessagesHandler(w http.ResponseWriter, r *http.Request) {
61 log.Debug("Handling messages")
62 if messages := lfh.getVesMessages(r); messages != nil {
63 faultMessages := ves.GetFaultMessages(messages)
65 for _, message := range faultMessages {
66 if message.IsLinkFailure() {
67 lfh.sendUnlockMessage(message.GetORuId())
68 } else if message.IsClearLinkFailure() {
69 log.Debugf("Cleared Link failure for O-RU ID: %v", message.GetORuId())
75 func (lfh LinkFailureHandler) sendUnlockMessage(oRuId string) {
76 if oDuId, err := lfh.lookupService.GetODuID(oRuId); err == nil {
77 sdnrPath := getSdnrPath(oRuId, oDuId)
78 unlockMessage := lfh.getUnlockMessage(oRuId)
79 if error := restclient.Put(lfh.config.SDNRAddress+sdnrPath, unlockMessage, lfh.config.SDNRUser, lfh.config.SDNRPassword); error == nil {
80 log.Debugf("Sent unlock message for O-RU: %v to O-DU: %v.", oRuId, oDuId)
90 func getSdnrPath(oRuId string, oDuId string) string {
91 sdnrPath := strings.Replace(rawSdnrPath, "[O-DU-ID]", oDuId, 1)
92 sdnrPath = strings.Replace(sdnrPath, "[O-RU-ID]", oRuId, 1)
96 func (lfh LinkFailureHandler) getUnlockMessage(oRuId string) string {
97 return strings.Replace(unlockMessage, "[O-RU-ID]", oRuId, 1)
100 func (lfh LinkFailureHandler) getVesMessages(r *http.Request) *[]string {
101 var messages []string
102 body, err := ioutil.ReadAll(r.Body)
107 err = json.Unmarshal(body, &messages)