2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
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.
16 # ==================================================================================
20 /* Classes to handle E2 service model based on e2sm-Bouncer-v001.asn */
21 #include "e2sm_control.hpp"
24 e2sm_control::e2sm_control(void){
26 memset(&head_fmt1, 0, sizeof(E2SM_Bouncer_ControlHeader_Format1_t));
28 memset(&msg_fmt1, 0, sizeof(E2SM_Bouncer_ControlMessage_Format1_t));
33 control_head = ( E2SM_Bouncer_ControlHeader_t *)calloc(1, sizeof( E2SM_Bouncer_ControlHeader_t));
34 assert(control_head != 0);
37 control_msg = (E2SM_Bouncer_ControlMessage_t*)calloc(1, sizeof(E2SM_Bouncer_ControlMessage_t));
38 assert(control_msg !=0);
43 e2sm_control::~e2sm_control(void){
45 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
47 control_head->choice.controlHeader_Format1 = 0;
49 control_msg->choice.controlMessage_Format1 = 0;
51 ASN_STRUCT_FREE(asn_DEF_E2SM_Bouncer_ControlHeader, control_head);
52 ASN_STRUCT_FREE(asn_DEF_E2SM_Bouncer_ControlMessage, control_msg);
57 bool e2sm_control::encode_control_header(unsigned char *buf, size_t *size, e2sm_control_helper &helper){
59 ASN_STRUCT_RESET(asn_DEF_E2SM_Bouncer_ControlHeader, control_head);
62 res = set_fields(control_head, helper);
68 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_Bouncer_ControlHeader, control_head, errbuf, &errbuf_len);
70 error_string.assign(&errbuf[0], errbuf_len);
74 xer_fprint(stdout, &asn_DEF_E2SM_Bouncer_ControlHeader, control_head);
76 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_Bouncer_ControlHeader, control_head, buf, *size);
78 if(retval.encoded == -1){
79 error_string.assign(strerror(errno));
82 else if (retval.encoded > *size){
84 ss <<"Error encoding event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
85 error_string = ss.str();
89 *size = retval.encoded;
95 bool e2sm_control::encode_control_message(unsigned char *buf, size_t *size, e2sm_control_helper &helper){
98 res = set_fields(control_msg, helper);
104 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_Bouncer_ControlMessage, control_msg, errbuf, &errbuf_len);
106 error_string.assign(&errbuf[0], errbuf_len);
110 xer_fprint(stdout, &asn_DEF_E2SM_Bouncer_ControlMessage, control_msg);
112 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_Bouncer_ControlMessage, control_msg, buf, *size);
114 if(retval.encoded == -1){
115 error_string.assign(strerror(errno));
118 else if (retval.encoded > *size){
119 std::stringstream ss;
120 ss <<"Error encoding action definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
121 error_string = ss.str();
125 *size = retval.encoded;
131 bool e2sm_control::set_fields(E2SM_Bouncer_ControlHeader_t * ref_control_head, e2sm_control_helper & helper){
133 if(ref_control_head == 0){
134 error_string = "Invalid reference for Event Trigger Definition set fields";
138 ref_control_head->present = E2SM_Bouncer_ControlHeader_PR_controlHeader_Format1;
140 head_fmt1.controlHeaderParam = helper.header;
142 ref_control_head->choice.controlHeader_Format1 = &head_fmt1;
147 bool e2sm_control::set_fields(E2SM_Bouncer_ControlMessage_t * ref_control_msg, e2sm_control_helper & helper){
149 if(ref_control_msg == 0){
150 error_string = "Invalid reference for Event Action Definition set fields";
153 ref_control_msg->present = E2SM_Bouncer_ControlMessage_PR_controlMessage_Format1;
155 msg_fmt1.controlMsgParam.buf = helper.message;
156 msg_fmt1.controlMsgParam.size = helper.message_len;
159 ref_control_msg->choice.controlMessage_Format1 = &msg_fmt1;
165 bool e2sm_control::get_fields(E2SM_Bouncer_ControlHeader_t * ref_indictaion_header, e2sm_control_helper & helper){
167 if (ref_indictaion_header == 0){
168 error_string = "Invalid reference for Control Header get fields";
172 helper.header = ref_indictaion_header->choice.controlHeader_Format1->controlHeaderParam;
176 bool e2sm_control::get_fields(E2SM_Bouncer_ControlMessage_t * ref_control_message, e2sm_control_helper & helper){
178 if (ref_control_message == 0){
179 error_string = "Invalid reference for Control Message get fields";
182 helper.message = ref_control_message->choice.controlMessage_Format1->controlMsgParam.buf;
183 helper.message_len = ref_control_message->choice.controlMessage_Format1->controlMsgParam.size;