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.
18 package rmrmsghandlers
20 // #cgo CFLAGS: -I../../asn1codec/inc/ -I../../asn1codec/e2ap_engine/
21 // #cgo LDFLAGS: -L ../../asn1codec/lib/ -L../../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
22 // #include <asn1codec_utils.h>
23 // #include <x2reset_response_wrapper.h>
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
35 type X2ResetRequestNotificationHandler struct {
36 rnibReaderProvider func() reader.RNibReader
39 func NewX2ResetRequestNotificationHandler(rnibReaderProvider func() reader.RNibReader) X2ResetRequestNotificationHandler {
40 return X2ResetRequestNotificationHandler{
41 rnibReaderProvider: rnibReaderProvider,
45 func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
47 logger.Debugf("#X2ResetRequestNotificationHandler.Handle - Ran name: %s", request.RanName)
49 nb, rNibErr := src.rnibReaderProvider().GetNodeb(request.RanName)
51 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error())
52 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
56 logger.Debugf("#X2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
58 if nb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
59 logger.Warnf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
60 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
65 if nb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
66 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
67 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
71 src.createAndAddToChannel(logger, request, messageChannel)
73 //TODO change name of printHandlingSetupResponseElapsedTimeInMs (remove setup response) and move to utils?
74 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
77 func (src X2ResetRequestNotificationHandler) createAndAddToChannel(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
79 packedBuffer := make([]C.uchar, e2pdus.MaxAsn1PackedBufferSize)
80 errorBuffer := make([]C.char, e2pdus.MaxAsn1CodecMessageBufferSize)
81 var payloadSize = C.ulong(e2pdus.MaxAsn1PackedBufferSize)
83 if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(e2pdus.MaxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
84 logger.Errorf("#X2ResetRequestNotificationHandler.createAndAddToChannel - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0]))
87 payload := C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
88 response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_X2_RESET_RESP}
90 messageChannel <- &response