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===================================
27 log "github.com/sirupsen/logrus"
29 "oransc.org/usecase/oruclosedloop/internal/repository"
30 "oransc.org/usecase/oruclosedloop/internal/restclient"
31 "oransc.org/usecase/oruclosedloop/internal/ves"
34 type Configuration struct {
40 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]"
41 const unlockMessage = `{"o-ran-sc-du-hello-world:du-to-ru-connection": [{"name":"[O-RU-ID]","administrative-state":"UNLOCKED"}]}`
43 type LinkFailureHandler struct {
44 lookupService repository.LookupService
46 client restclient.HTTPClient
49 func NewLinkFailureHandler(ls repository.LookupService, conf Configuration, client restclient.HTTPClient) *LinkFailureHandler {
50 return &LinkFailureHandler{
57 func (lfh LinkFailureHandler) MessagesHandler(w http.ResponseWriter, r *http.Request) {
58 log.Debug("Handling messages")
59 if messages := ves.GetVesMessages(r.Body); messages != nil {
60 faultMessages := ves.GetFaultMessages(messages)
62 for _, message := range faultMessages {
63 if message.IsLinkFailure() {
64 lfh.sendUnlockMessage(message.GetORuId())
65 } else if message.IsClearLinkFailure() {
66 log.Debugf("Cleared Link failure for O-RU ID: %v", message.GetORuId())
72 func (lfh LinkFailureHandler) sendUnlockMessage(oRuId string) {
73 if oDuId, err := lfh.lookupService.GetODuID(oRuId); err == nil {
74 sdnrPath := getSdnrPath(oRuId, oDuId)
75 unlockMessage := lfh.getUnlockMessage(oRuId)
76 if error := restclient.Put(lfh.config.SDNRAddress+sdnrPath, unlockMessage, lfh.client, lfh.config.SDNRUser, lfh.config.SDNRPassword); error == nil {
77 log.Debugf("Sent unlock message for O-RU: %v to O-DU: %v.", oRuId, oDuId)
79 log.Warn("Send of unlock message failed due to ", error)
82 log.Warn("Send of unlock message failed due to ", err)
87 func getSdnrPath(oRuId string, oDuId string) string {
88 sdnrPath := strings.Replace(rawSdnrPath, "[O-DU-ID]", oDuId, 1)
89 sdnrPath = strings.Replace(sdnrPath, "[O-RU-ID]", oRuId, 1)
93 func (lfh LinkFailureHandler) getUnlockMessage(oRuId string) string {
94 return strings.Replace(unlockMessage, "[O-RU-ID]", oRuId, 1)