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 ==================================================================================
20 * HWIndicationMessage.cc
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));
41 HWIndicationMessage::HWIndicationMessage(unsigned char *buf, size_t *size, bool &status){
47 status = this->decode(buf, size);
52 HWIndicationHeader::HWIndicationHeader(void){
54 memset(&_header_fmt1, 0, sizeof(E2SM_HelloWorld_IndicationHeader_Format1_t));
57 _header = ( E2SM_HelloWorld_IndicationHeader_t *)calloc(1, sizeof( E2SM_HelloWorld_IndicationHeader_t));
64 HWIndicationHeader::HWIndicationHeader(unsigned char *buf, size_t *size, bool &status){
69 status = this->decode(buf, size);
74 HWIndicationMessage::~HWIndicationMessage(void){
76 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
77 _message->choice.indicationMessage_Format1 = 0;
78 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationMessage, _message);
82 HWIndicationHeader::~HWIndicationHeader(void){
84 mdclog_write(MDCLOG_DEBUG, "Freeing event trigger object memory");
85 _header->choice.indicationHeader_Format1 = 0;
86 ASN_STRUCT_FREE(asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
89 bool HWIndicationHeader::encode(unsigned char *buf, size_t *size){
91 ASN_STRUCT_RESET(asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
94 res = setfields(_header);
100 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationHeader, _header, _errbuf, &_errbuf_len);
102 _error_string.assign(&_errbuf[0], _errbuf_len);
106 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationHeader, _header);
108 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, _header, buf, *size);
110 if(retval.encoded == -1){
111 _error_string.assign(strerror(errno));
114 else if (retval.encoded > *size){
115 std::stringstream ss;
116 ss <<"Error encoding event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
117 _error_string = ss.str();
121 *size = retval.encoded;
127 bool HWIndicationMessage::encode(unsigned char *buf, size_t *size){
130 res = setfields(_message);
135 int ret_constr = asn_check_constraints(&asn_DEF_E2SM_HelloWorld_IndicationMessage, _message, _errbuf, &_errbuf_len);
137 _error_string.assign(&_errbuf[0], _errbuf_len);
141 xer_fprint(stdout, &asn_DEF_E2SM_HelloWorld_IndicationMessage, _message);
143 asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, _message, buf, *size);
145 if(retval.encoded == -1){
146 _error_string.assign(strerror(errno));
149 else if (retval.encoded > *size){
150 std::stringstream ss;
151 ss <<"Error encoding action definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
152 _error_string = ss.str();
156 *size = retval.encoded;
162 bool HWIndicationHeader::setfields(E2SM_HelloWorld_IndicationHeader_t * _header){
165 _error_string = "Invalid reference for Event Trigger Definition set fields";
169 _header->present = E2SM_HelloWorld_IndicationHeader_PR_indicationHeader_Format1;
170 _header_fmt1.indicationHeaderParam = this->get_hw_header();
171 _header->choice.indicationHeader_Format1 = &_header_fmt1;
176 bool HWIndicationMessage::setfields(E2SM_HelloWorld_IndicationMessage_t * _message){
179 _error_string = "Invalid reference for Event Action Definition set fields";
182 _message->present = E2SM_HelloWorld_IndicationMessage_PR_indicationMessage_Format1;
184 _message_fmt1.indicationMsgParam.buf = this->get_hw_message();
185 _message_fmt1.indicationMsgParam.size = this->get_hw_message_size();
186 _message->choice.indicationMessage_Format1 = &_message_fmt1;
191 bool HWIndicationHeader::decode(unsigned char *buf, size_t *size){
192 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, (void**)&(_header), buf, *size);
193 if(dec_res.code != RC_OK){
194 mdclog_write(MDCLOG_ERR, "Failed to decode: %s","HW-E2SM RIC Indication Header");
197 mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","HW-E2SM RIC Indication Header");
201 _error_string = "Invalid reference for Indication Header get fields";
205 this->set_ricIndicationHeader(_header->choice.indicationHeader_Format1->indicationHeaderParam);
209 bool HWIndicationMessage::decode(unsigned char *buf, size_t *size){
211 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, (void**)&(_message), buf, *size);
212 if(dec_res.code != RC_OK){
213 mdclog_write(MDCLOG_ERR, "Failed to decode: %s","HW-E2SM RIC Indication Message");
216 mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","HW-E2SM RIC Indication Message");
220 _error_string = "Invalid reference for Indication Message get fields";
223 // this->set_ricIndicationMessage(_message->choice.indicationMessage_Format1->indicationMsgParam.buf, _message->choice.indicationMessage_Format1->indicationMsgParam.size);