1c3736fd9bcd8847eb862496134bdbda0d6b9069
[ric-plt/e2mgr.git] / E2Manager / handlers / 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
18 package handlers
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/logger"
27         "e2mgr/models"
28         "e2mgr/rmrCgo"
29         "e2mgr/sessions"
30         "unsafe"
31 )
32
33 type EndcConfigurationUpdateHandler struct{}
34
35 func (src EndcConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest,
36         messageChannel chan<- *models.NotificationResponse) {
37
38         var payloadSize C.ulong
39         payloadSize = MaxAsn1PackedBufferSize
40         packedBuffer := [MaxAsn1PackedBufferSize]C.uchar{}
41         errorBuffer := [MaxAsn1PackedBufferSize]C.char{}
42         refinedMessage, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/)
43         if err != nil {
44                 status := C.build_pack_endc_configuration_update_failure(&payloadSize, &packedBuffer[0], MaxAsn1PackedBufferSize, &errorBuffer[0])
45                 if status {
46                         payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize]
47                         logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update negative ack message payload: (%d) %02x", len(payload), payload)
48                         response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_ENDC_CONF_UPDATE_FAILURE}
49                         messageChannel <- &response
50                 } else {
51                         logger.Errorf("#endc_configuration_update_handler.Handle - failed to build and pack Endc configuration update unsuccessful outcome message. Error: %v", errorBuffer)
52                 }
53                 logger.Errorf("#endc_configuration_update_handler.Handle - unpack failed. Error: %v", err)
54         } else {
55                 logger.Infof("#endc_configuration_update_handler.Handle - Endc configuration update initiating message received")
56                 logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update initiating message payload: %s", refinedMessage.pduPrint)
57                 status := C.build_pack_endc_configuration_update_ack(&payloadSize, &packedBuffer[0], MaxAsn1PackedBufferSize, &errorBuffer[0])
58                 if status {
59                         payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize]
60                         logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update positive ack message payload: (%d) %02x", len(payload), payload)
61                         response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_ENDC_CONF_UPDATE_ACK}
62                         messageChannel <- &response
63                 } else {
64                         logger.Errorf("#endc_configuration_update_handler.Handle - failed to build and pack endc configuration update successful outcome message. Error: %v", errorBuffer)
65                 }
66         }
67         printHandlingSetupResponseElapsedTimeInMs(logger, "#endc_configuration_update_handler.Handle - Summary: Elapsed time for receiving and handling endc configuration update initiating message from E2 terminator", request.StartTime)
68 }