2 ==================================================================================
3 Copyright (c) 2019-2020 AT&T Intellectual Property.
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 ==================================================================================
19 * e2ap_subsdel_response.cc
21 * Author: SJana, Ashwin Sridharan
25 #include "e2ap_subsdel_response.hpp"
27 E2APSubscriptionDeleteResponse::E2APSubscriptionDeleteResponse(SubscriptionDeleteResponseIEs& ieObj){
31 _responseIEs = std::make_unique<SubscriptionDeleteResponseIEs>();
32 *_responseIEs = ieObj;
34 _e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t));
35 assert(_e2ap_pdu_obj != 0);
37 _successMsg = (SuccessfulOutcome_t * )calloc(1, sizeof(SuccessfulOutcome_t));
38 assert(_successMsg != 0);
40 IE_array = (RICsubscriptionDeleteResponse_IEs_t *)calloc(RIC_SUBDEL_RESPONSE_IES_COUNT, sizeof(RICsubscriptionDeleteResponse_IEs_t));
41 assert(IE_array != 0);
43 RICsubscriptionDeleteResponse_t * subDelresponse = &(_successMsg->value.choice.RICsubscriptionDeleteResponse);
44 for(int i = 0; i < RIC_SUBDEL_RESPONSE_IES_COUNT; i++){
45 ASN_SEQUENCE_ADD(&subDelresponse->protocolIEs, &(IE_array[i]));
50 E2APSubscriptionDeleteResponse::E2APSubscriptionDeleteResponse(unsigned char *buf, size_t *size){
55 _responseIEs = std::make_unique<SubscriptionDeleteResponseIEs>();
56 bool status = this->decode(buf, size);
58 throw "E2AP Subscription Delete Response Decode Failed: "+this->get_error();
61 bool E2APSubscriptionDeleteResponse::decode(unsigned char *buf, size_t *size)
64 asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void**)&(_e2ap_pdu_obj), buf, *size);
65 if(dec_res.code != RC_OK){
66 mdclog_write(MDCLOG_ERR, "Failed to decode: %s","RIC Subscription Delete Response");
69 mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","RIC Subscription Delete Response");
72 _successMsg = _e2ap_pdu_obj->choice.successfulOutcome;
73 //write the decoding code.
75 if (_successMsg == 0){
76 _error_string = "Invalid reference to success message in get fields subscription delete response";
81 for(int edx = 0; edx < _successMsg->value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.count; edx++) {
82 RICsubscriptionDeleteResponse_IEs_t *memb_ptr = _successMsg->value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.array[edx];
86 case (ProtocolIE_ID_id_RICrequestID):
87 _responseIEs->set_ricRequestorID(memb_ptr->value.choice.RICrequestID.ricRequestorID);
88 _responseIEs->set_ricInstanceID(memb_ptr->value.choice.RICrequestID.ricInstanceID);
92 case (ProtocolIE_ID_id_RANfunctionID):
93 _responseIEs->set_ranFunctionID(memb_ptr->value.choice.RANfunctionID);
99 // xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj);
104 // Clear assigned protocolIE list from RIC indication IE container
105 E2APSubscriptionDeleteResponse::~E2APSubscriptionDeleteResponse(void){
107 mdclog_write(MDCLOG_DEBUG, "Freeing subscription delete request object memory");
108 RICsubscriptionDeleteResponse_t * E2APSubscriptionDeleteResponse = &(_successMsg->value.choice.RICsubscriptionDeleteResponse);
110 for(int i = 0; i < E2APSubscriptionDeleteResponse->protocolIEs.list.size; i++){
111 E2APSubscriptionDeleteResponse->protocolIEs.list.array[i] = 0;
114 if (E2APSubscriptionDeleteResponse->protocolIEs.list.size > 0){
115 free(E2APSubscriptionDeleteResponse->protocolIEs.list.array);
116 E2APSubscriptionDeleteResponse->protocolIEs.list.count = 0;
117 E2APSubscriptionDeleteResponse->protocolIEs.list.size = 0;
118 E2APSubscriptionDeleteResponse->protocolIEs.list.array = 0;
123 _e2ap_pdu_obj->choice.successfulOutcome = 0;
125 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, _e2ap_pdu_obj);
126 mdclog_write(MDCLOG_DEBUG, "Freed subscription delete request object memory");
132 bool E2APSubscriptionDeleteResponse::encode(unsigned char *buf, size_t *size){
134 _e2ap_pdu_obj->choice.successfulOutcome = _successMsg;
135 _e2ap_pdu_obj->present = E2AP_PDU_PR_successfulOutcome;
136 bool eres = setfields( _successMsg);
140 _successMsg->procedureCode = ProcedureCode_id_RICsubscriptionDelete;
141 _successMsg->criticality = Criticality_reject;
142 _successMsg->value.present = SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse;
144 int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) _e2ap_pdu_obj, _errbuf, &_errbuf_len);
146 _error_string.assign(_errbuf, _errbuf_len);
147 _error_string = "Constraints failed for encoding subscription delete request. Reason = " + _error_string;
151 asn_enc_rval_t res = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj, buf, *size);
153 if(res.encoded == -1){
154 _error_string.assign(strerror(errno));
155 _error_string = "Error encoding Subscription Delete Request. Reason = " + _error_string;
159 if(*size < res.encoded){
160 std::stringstream ss;
161 ss <<"Error encoding Subscription Delete Request . Reason = encoded pdu size " << res.encoded << " exceeds buffer size " << *size << std::endl;
162 _error_string = ss.str();
169 xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj);
176 bool E2APSubscriptionDeleteResponse::setfields( SuccessfulOutcome_t *_successMsg){
177 unsigned int ie_index;
180 RICsubscriptionDeleteResponse_IEs_t *ies_ricresp = &IE_array[ie_index];
181 ies_ricresp->criticality = Criticality_reject;
182 ies_ricresp->id = ProtocolIE_ID_id_RICrequestID;
183 ies_ricresp->value.present = RICsubscriptionDeleteResponse_IEs__value_PR_RICrequestID;
184 RICrequestID_t *ricrequest_ie = &ies_ricresp->value.choice.RICrequestID;
185 ricrequest_ie->ricRequestorID = this->getIEs().get_ricRequestorID();
186 ricrequest_ie->ricInstanceID = this->getIEs().get_ricInstanceID();
190 RICsubscriptionDeleteResponse_IEs_t *ies_ranfunc = &IE_array[ie_index];
191 ies_ranfunc->criticality = Criticality_reject;
192 ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID;
193 ies_ranfunc->value.present = RICsubscriptionDeleteResponse_IEs__value_PR_RANfunctionID;
194 RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
195 *ranfunction_ie = this->getIEs().get_ranFunctionID();