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>
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
32 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
36 type X2ResetRequestNotificationHandler struct {
37 rnibReaderProvider func() reader.RNibReader
40 func NewX2ResetRequestNotificationHandler(rnibReaderProvider func() reader.RNibReader) X2ResetRequestNotificationHandler {
41 return X2ResetRequestNotificationHandler{
42 rnibReaderProvider: rnibReaderProvider,
46 func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
48 logger.Debugf("#X2ResetRequestNotificationHandler.Handle - Ran name: %s", request.RanName)
50 nb, rNibErr := src.rnibReaderProvider().GetNodeb(request.RanName)
52 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error())
53 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
57 logger.Debugf("#X2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
59 if nb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
60 logger.Warnf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
61 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
66 if nb.ConnectionStatus != entities.ConnectionStatus_CONNECTED {
67 logger.Errorf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus)
68 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
72 src.createAndAddToChannel(logger, request, messageChannel)
74 //TODO change name of printHandlingSetupResponseElapsedTimeInMs (remove setup response) and move to utils?
75 printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
78 func (src X2ResetRequestNotificationHandler) createAndAddToChannel(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
80 packedBuffer := make([]C.uchar, e2pdus.MaxAsn1PackedBufferSize)
81 errorBuffer := make([]C.char, e2pdus.MaxAsn1CodecMessageBufferSize)
82 var payloadSize = C.ulong(e2pdus.MaxAsn1PackedBufferSize)
84 if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(e2pdus.MaxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
85 logger.Errorf("#X2ResetRequestNotificationHandler.createAndAddToChannel - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0]))
88 payload := C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
89 response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_X2_RESET_RESP}
91 messageChannel <- &response