1 // Copyright 2023 Nokia
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
16 // platform project (RICP)
18 package rmrmsghandlers
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
33 var e2ErrorIndicationMessage = models.ErrorIndicationMessage{}
35 var E2SETUP_PROCEDURE string = "1"
36 var RICSERVICEUPDATE_PROCEDURE string = "7"
38 type ErrorIndicationHandler struct {
40 ranDisconnectionManager managers.IRanDisconnectionManager
41 RicServiceUpdateManager managers.IRicServiceUpdateManager
42 procedureMapMutex sync.RWMutex
46 func ErrorIndicationNotificationHandler(logger *logger.Logger, ranDisconnectionManager managers.IRanDisconnectionManager, RicServiceUpdateManager managers.IRicServiceUpdateManager) *ErrorIndicationHandler {
47 return &ErrorIndicationHandler{
49 ranDisconnectionManager: ranDisconnectionManager,
50 RicServiceUpdateManager: RicServiceUpdateManager,
53 func (errorIndicationHandler *ErrorIndicationHandler) Handle (request *models.NotificationRequest) {
54 ranName := request.RanName
55 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-Received Error Indication from E2Node - %s", ranName)
57 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-Received ErrorIndication payload at E2M is - %x", request.Payload)
58 errorIndicationMessage, err := errorIndicationHandler.parseErrorIndication(request.Payload)
60 errorIndicationHandler.logger.Errorf("#ErrorIndicationHandler.Handle- Parsing is not successful")
63 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle ERROR INDICATION from E2Node has been parsed successfully- %+v", errorIndicationMessage)
64 errorIndicationIE := errorIndicationMessage.E2APPDU.InitiatingMessage.Value.ErrorIndication.ProtocolIEs.ErrorIndicationIEs
65 fmt.Printf("errorIndicationIE value is %+v", errorIndicationIE)
67 for i := 0 ; i < len(errorIndicationIE) ; i++ {
68 if errorIndicationIE[i].ID == 2 {
69 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-CD is: %+v", errorIndicationIE[i].Value.CriticalityDiagnostics)
70 if errorIndicationIE[i].Value.CriticalityDiagnostics.ProcedureCode != "" && errorIndicationIE[i].Value.CriticalityDiagnostics.TriggeringMessage.SuccessfulOutcome != nil {
71 procedureCode := errorIndicationIE[i].Value.CriticalityDiagnostics.ProcedureCode
72 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-procedureCode present is: %+v", procedureCode)
73 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle- before triggeringMessage present is: %+v", errorIndicationIE[i].Value.CriticalityDiagnostics.TriggeringMessage)
74 triggeringMessageValue := &errorIndicationIE[i].Value.CriticalityDiagnostics.TriggeringMessage.SuccessfulOutcome
75 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-triggeringMessage present is: %+v", *triggeringMessageValue)
76 if procedureCode != "" && triggeringMessageValue != nil {
77 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.handleErrorIndicationBasedOnProcedureCode for all scenarios")
78 switch procedureCode {
79 case E2SETUP_PROCEDURE:
80 if triggeringMessageValue != nil {
81 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication happened at E2Setup procedure")
82 err = errorIndicationHandler.ranDisconnectionManager.DisconnectRan(ranName)
83 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-Cleanup Completed !!")
86 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication recieved for unsuccessful-outcome, no action taken")
88 case RICSERVICEUPDATE_PROCEDURE:
89 if triggeringMessageValue != nil {
90 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication happened at Ric Service Update procedure")
91 err = errorIndicationHandler.RicServiceUpdateManager.RevertRanFunctions(ranName)
93 errorIndicationHandler.logger.Errorf("#ErrorIndicationHandler.Handle-reverting RanFunctions and updating the nodebInfo failed due to error %+v", err)
97 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication recieved for unsuccessful-outcome, no action taken")
100 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-problem in handling of error indication")
107 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-CriticalityDiagnostics IEs unsuccessful hence Retrieving based on procedureMap")
108 errorIndicationHandler.HandleBasedOnProcedureType(ranName)
109 errorIndicationHandler.logger.Debugf("#ErrorIndicationHandler.Handle-Cleanup Completed !!")
114 func (errorIndicationHandler *ErrorIndicationHandler) HandleBasedOnProcedureType(ranName string) error {
115 errorIndicationHandler.procedureMapMutex.RLock()
116 procedureType, ok := models.ProcedureMap[ranName]
117 errorIndicationHandler.procedureMapMutex.RUnlock()
119 errorIndicationHandler.logger.Errorf("#ErrorIndicationHandler.Handle-Error ProcedureType not found for ranName %s", ranName)
121 switch procedureType {
122 case models.E2SetupProcedureCompleted:
123 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication happened at E2Setup procedure")
124 err := errorIndicationHandler.ranDisconnectionManager.DisconnectRan(ranName)
126 errorIndicationHandler.logger.Errorf("#ErrorIndicationHandler.Handle-Disconnect RAN and updating the nodebInfo failed due to error %+v", err)
128 case models.RicServiceUpdateCompleted:
129 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication happened at Ric Service Update procedure")
130 err := errorIndicationHandler.RicServiceUpdateManager.RevertRanFunctions(ranName)
132 errorIndicationHandler.logger.Errorf("#ErrorIndicationHandler.Handle-reverting RanFunctions and updating the nodebInfo failed due to error %+v", err)
134 case models.E2SetupProcedureFailure, models.RicServiceUpdateFailure:
135 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-ErrorIndication occcured before successful outcome hence ignoring")
137 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.Handle-Error in handling the ErrorIndication based on enum")
143 func (errorIndicationHandler *ErrorIndicationHandler) parseErrorIndication(payload []byte) (*models.ErrorIndicationMessage, error) {
144 pipInd := bytes.IndexByte(payload, '|')
146 return nil, common.NewInternalError(fmt.Errorf("#ErrorIndicationHandler.parseErrorIndication - Error parsing ERROR INDICATION failed extract Payload: no | separator found"))
148 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.parseErrorIndication - payload: %s", payload)
149 errorIndicationHandler.logger.Infof("#ErrorIndicationHandler.parseErrorIndication - payload: %s", payload[pipInd+1:])
150 errorIndicationMessage := &models.ErrorIndicationMessage{}
151 err := xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &errorIndicationMessage.E2APPDU)
153 return nil, common.NewInternalError(fmt.Errorf("#ErrorIndicationHandler.parseErrorIndication - Error unmarshalling ERROR INDICATION payload: %x", payload))
155 return errorIndicationMessage, nil