77a09b32311396495c49e3123adafcdd950ed833
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / x2enb_configuration_update_handler.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 package rmrmsghandlers
19
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 <configuration_update_wrapper.h>
24 import "C"
25 import (
26         "e2mgr/converters"
27         "e2mgr/e2pdus"
28         "e2mgr/logger"
29         "e2mgr/models"
30         "e2mgr/rmrCgo"
31         "e2mgr/services/rmrsender"
32         "unsafe"
33 )
34
35 type X2EnbConfigurationUpdateHandler struct {
36         logger    *logger.Logger
37         rmrSender *rmrsender.RmrSender
38 }
39
40 func NewX2EnbConfigurationUpdateHandler(logger *logger.Logger, rmrSender *rmrsender.RmrSender) X2EnbConfigurationUpdateHandler {
41         return X2EnbConfigurationUpdateHandler{
42                 logger:    logger,
43                 rmrSender: rmrSender,
44         }
45 }
46
47 func (h X2EnbConfigurationUpdateHandler) Handle(request *models.NotificationRequest) {
48
49         var payloadSize C.ulong
50         payloadSize = e2pdus.MaxAsn1PackedBufferSize
51         packedBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.uchar{}
52         errorBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.char{}
53
54         refinedMessage, err := converters.UnpackX2apPduAndRefine(h.logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize)
55
56         if err != nil {
57                 status := C.build_pack_x2enb_configuration_update_failure(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0])
58                 if status {
59                         payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize]
60                         h.logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update negative ack message payload: (%d) %02x", len(payload), payload)
61                         msg := models.NewRmrMessage(rmrCgo.RIC_ENB_CONFIGURATION_UPDATE_FAILURE, request.RanName, payload)
62                         _ = h.rmrSender.Send(msg)
63                 } else {
64                         h.logger.Errorf("#x2enb_configuration_update_handler.Handle - failed to build and pack Enb configuration update unsuccessful outcome message. Error: %v", errorBuffer)
65                 }
66                 h.logger.Errorf("#x2enb_configuration_update_handler.Handle - unpack failed. Error: %v", err)
67
68                 printHandlingSetupResponseElapsedTimeInMs(h.logger, "#x2enb_configuration_update_handler.Handle - Summary: Elapsed time for receiving and handling enb configuration update initiating message from E2 terminator", request.StartTime)
69                 return
70         }
71
72         h.logger.Infof("#x2enb_configuration_update_handler.Handle - Enb configuration update initiating message received")
73         h.logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update initiating message payload: %s", refinedMessage.PduPrint)
74
75         status := C.build_pack_x2enb_configuration_update_ack(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0])
76         if status {
77                 payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize]
78                 h.logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update positive ack message payload: (%d) %02x", len(payload), payload)
79                 msg := models.NewRmrMessage(rmrCgo.RIC_ENB_CONFIGURATION_UPDATE_ACK, request.RanName, payload)
80                 _ = h.rmrSender.Send(msg)
81         } else {
82                 h.logger.Errorf("#x2enb_configuration_update_handler.Handle - failed to build and pack enb configuration update successful outcome message. Error: %v", errorBuffer)
83         }
84         printHandlingSetupResponseElapsedTimeInMs(h.logger, "#x2enb_configuration_update_handler.Handle - Summary: Elapsed time for receiving and handling enb configuration update initiating message from E2 terminator", request.StartTime)
85 }