2 ==================================================================================
4 Copyright (c) 2019-2020 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
22 * Created on: Apr, 2020
23 * Author: Shraboni Jana
25 /* Classes to handle E2 service model based on e2sm-HelloWorld-v001.asn */
26 #include "e2sm_indication.hpp"
29 HWIndicationMessage::HWIndicationMessage(void){
31 memset(&_message_fmt1, 0, sizeof(E2SM_HelloWorld_IndicationMessage_Format1_t));
34 _message = (E2SM_HelloWorld_IndicationMessage_t*)calloc(1, sizeof(E2SM_HelloWorld_IndicationMessage_t));
40 HWIndicationMessage::HWIndicationMessage(unsigned char *buf, size_t *size){
45 bool status = this->decode(buf, size);
47 throw "HWIndicationMessage: "+this->get_error();
53 HWIndicationHeader::HWIndicationHeader(void){
55 memset(&_header_fmt1, 0, sizeof(E2SM_HelloWorld_IndicationHeader_Format1_t));
58 _header = ( E2SM_HelloWorld_IndicationHeader_t *)calloc(1, sizeof( E2SM_HelloWorld_IndicationHeader_t));
65 HWIndicationHeader::HWIndicationHeader(unsigned char *buf, size_t *size){
70 bool status = this->decode(buf, size);
72 // throw "HWIndicationHeader: "+this->get_error();
77 HWIndicationMessage::~HWIndicationMessage(void){
79 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
80 _message->choice.indicationMessage_Format1 = 0;
82 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationMessage, _message);
86 HWIndicationHeader::~HWIndicationHeader(void){
88 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
89 _header->choice.indicationHeader_Format1 = 0;
90 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
93 bool HWIndicationHeader::encode(unsigned char *buf, size_t *size){
95 ASN_STRUCT_RESET(asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
98 res = setfields(_header);
104 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationHeader, _header, _errbuf, &_errbuf_len);
106 _error_string.assign(&_errbuf[0], _errbuf_len);
110 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
112 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, _header, 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 event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
121 _error_string = ss.str();
125 *size = retval.encoded;
131 bool HWIndicationMessage::encode(unsigned char *buf, size_t *size){
133 ASN_STRUCT_RESET(asn_DEF_E2SM_HelloWorld_IndicationMessage, _message);
136 res = setfields(_message);
141 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationMessage, _message, _errbuf, &_errbuf_len);
143 _error_string.assign(&_errbuf[0], _errbuf_len);
147 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationMessage, _message);
149 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, _message, buf, *size);
151 if(retval.encoded == -1){
152 _error_string.assign(strerror(errno));
155 else if (retval.encoded > *size){
156 std::stringstream ss;
157 ss <<"Error encoding action definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
158 _error_string = ss.str();
162 *size = retval.encoded;
168 bool HWIndicationHeader::setfields(E2SM_HelloWorld_IndicationHeader_t * _header){
171 _error_string = "Invalid reference for Event Trigger Definition set fields";
175 _header->present = E2SM_HelloWorld_IndicationHeader_PR_indicationHeader_Format1;
176 _header_fmt1.indicationHeaderParam = this->get_hw_header();
177 _header->choice.indicationHeader_Format1 = &_header_fmt1;
182 bool HWIndicationMessage::setfields(E2SM_HelloWorld_IndicationMessage_t * _message){
185 _error_string = "Invalid reference for Event Action Definition set fields";
188 _message->present = E2SM_HelloWorld_IndicationMessage_PR_indicationMessage_Format1;
189 _message_fmt1.indicationMsgParam.buf = this->get_hw_message();
190 _message_fmt1.indicationMsgParam.size = this->get_hw_message_size();
191 _message->choice.indicationMessage_Format1 = &_message_fmt1;
196 bool HWIndicationHeader::decode(unsigned char *buf, size_t *size){
199 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, (void**)&(_header), buf, *size);
201 if(dec_res.code != RC_OK){
202 mdclog_write(MDCLOG_ERR, "Failed to decode: %s","HW-E2SM RIC Indication Header");
203 _error_string = "Failed to decode HW-E2SM RIC Indication Header";
206 mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","HW-E2SM RIC Indication Header");
210 _error_string = "Invalid reference for Indication Header get fields";
214 this->set_ricIndicationHeader(_header->choice.indicationHeader_Format1->indicationHeaderParam);
218 bool HWIndicationMessage::decode(unsigned char *buf, size_t *size){
220 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, (void**)&(_message), buf, *size);
221 if(dec_res.code != RC_OK){
222 mdclog_write(MDCLOG_ERR, "Failed to decode: %s","HW-E2SM RIC Indication Message");
225 mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","HW-E2SM RIC Indication Message");
229 _error_string = "Invalid reference for Indication Message get fields";
232 // this->set_ricIndicationMessage(_message->choice.indicationMessage_Format1->indicationMsgParam.buf, _message->choice.indicationMessage_Format1->indicationMsgParam.size);