2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
21 package rmrmsghandlers
23 // #cgo CFLAGS: -I../../3rdparty/asn1codec/inc/ -I../../3rdparty/asn1codec/e2ap_engine/
24 // #cgo LDFLAGS: -L ../../3rdparty/asn1codec/lib/ -L../../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
25 // #include <asn1codec_utils.h>
36 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
39 const ResetResponseLogInfoElapsedTime = "#X2ResetResponseHandler.Handle - Summary: elapsed time for receiving and handling reset request message from E2 terminator: %f ms"
41 type X2ResetResponseHandler struct {
43 rnibDataService services.RNibDataService
44 ranStatusChangeManager managers.IRanStatusChangeManager
45 extractor converters.IX2ResetResponseExtractor
48 func NewX2ResetResponseHandler(logger *logger.Logger, rnibDataService services.RNibDataService, ranStatusChangeManager managers.IRanStatusChangeManager, x2ResetResponseExtractor converters.IX2ResetResponseExtractor) X2ResetResponseHandler {
49 return X2ResetResponseHandler{
51 rnibDataService: rnibDataService,
52 ranStatusChangeManager: ranStatusChangeManager,
53 extractor: x2ResetResponseExtractor,
57 func (h X2ResetResponseHandler) Handle(request *models.NotificationRequest) {
58 ranName := request.RanName
59 h.logger.Infof("#X2ResetResponseHandler.Handle - RAN name: %s - received reset response. Payload: %x", ranName, request.Payload)
61 nodebInfo, err := h.rnibDataService.GetNodeb(ranName)
63 h.logger.Errorf("#x2ResetResponseHandler.Handle - RAN name: %s - failed to retrieve nodebInfo entity. Error: %s", ranName, err)
67 if nodebInfo.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
68 h.logger.Warnf("#X2ResetResponseHandler.Handle - RAN name: %s, connection status: %s - nodeB entity in incorrect state", nodebInfo.RanName, nodebInfo.ConnectionStatus)
69 h.logger.Infof(ResetResponseLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))
73 if nodebInfo.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
74 h.logger.Errorf("#X2ResetResponseHandler.Handle - RAN name: %s, connection status: %s - nodeB entity in incorrect state", nodebInfo.RanName, nodebInfo.ConnectionStatus)
75 h.logger.Infof(ResetResponseLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))
79 isSuccessfulResetResponse, err := h.isSuccessfulResetResponse(ranName, request.Payload)
81 h.logger.Infof(ResetResponseLogInfoElapsedTime, utils.ElapsedTime(request.StartTime))
83 if err != nil || !isSuccessfulResetResponse {
87 _ = h.ranStatusChangeManager.Execute(rmrCgo.RAN_RESTARTED, enums.RIC_TO_RAN, nodebInfo)
90 func (h X2ResetResponseHandler) isSuccessfulResetResponse(ranName string, packedBuffer []byte) (bool, error) {
92 criticalityDiagnostics, err := h.extractor.ExtractCriticalityDiagnosticsFromPdu(packedBuffer)
95 h.logger.Errorf("#X2ResetResponseHandler.isSuccessfulResetResponse - RAN name: %s - Failed extracting pdu: %s", ranName, err)
99 if criticalityDiagnostics != nil {
100 h.logger.Errorf("#X2ResetResponseHandler.isSuccessfulResetResponse - RAN name: %s - Unsuccessful RESET response message. Criticality diagnostics: %s", ranName, criticalityDiagnostics)
104 h.logger.Infof("#X2ResetResponseHandler.isSuccessfulResetResponse - RAN name: %s - Successful RESET response message", ranName)