c46094148844ceb99f54d7b5ee2d184eee57b4ae
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / endc_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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20
21 package rmrmsghandlers
22
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>
26 // #include <configuration_update_wrapper.h>
27 import "C"
28 import (
29         "e2mgr/converters"
30         "e2mgr/e2pdus"
31         "e2mgr/logger"
32         "e2mgr/models"
33         "e2mgr/rmrCgo"
34         "e2mgr/services/rmrsender"
35         "e2mgr/utils"
36 )
37
38 type EndcConfigurationUpdateHandler struct {
39         logger *logger.Logger
40         rmrSender *rmrsender.RmrSender
41 }
42
43 func NewEndcConfigurationUpdateHandler(logger *logger.Logger, rmrSender *rmrsender.RmrSender) EndcConfigurationUpdateHandler {
44         return EndcConfigurationUpdateHandler{
45                 logger: logger,
46                 rmrSender: rmrSender,
47         }
48 }
49
50 func (h EndcConfigurationUpdateHandler) Handle(request *models.NotificationRequest) {
51
52         refinedMessage, err := converters.UnpackX2apPduAndRefine(h.logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
53
54         if err != nil {
55                 h.logger.Errorf("#endc_configuration_update_handler.Handle - unpack failed. Error: %v", err)
56
57                 msg := models.NewRmrMessage(rmrCgo.RIC_ENDC_CONF_UPDATE_FAILURE, request.RanName, e2pdus.PackedEndcConfigurationUpdateFailure, request.TransactionId)
58                 _ = h.rmrSender.Send(msg)
59
60                 h.logger.Infof("#EndcConfigurationUpdateHandler.Handle - Summary: elapsed time for receiving and handling endc configuration update initiating message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
61                 return
62         }
63
64         h.logger.Infof("#endc_configuration_update_handler.Handle - Endc configuration update initiating message received")
65         h.logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update initiating message payload: %s", refinedMessage.PduPrint)
66         msg := models.NewRmrMessage(rmrCgo.RIC_ENDC_CONF_UPDATE_ACK, request.RanName, e2pdus.PackedEndcConfigurationUpdateAck, request.TransactionId)
67         _ = h.rmrSender.Send(msg)
68
69         h.logger.Infof("#EndcConfigurationUpdateHandler.Handle - Summary: elapsed time for receiving and handling endc configuration update initiating message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
70 }