ISSUE ID:- (RICAPP-176).
[ric-app/bouncer.git] / Bouncer / src / xapp-asn / e2ap / subscription_delete_request.cc
1
2
3 /*
4 ==================================================================================
5         Copyright (c) 2019-2020 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21
22 #include "subscription_delete_request.hpp"
23   
24 subscription_delete::subscription_delete(void){
25
26   _name = "default";
27   
28   e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t));
29   assert(e2ap_pdu_obj != 0);
30
31   initMsg = (InitiatingMessage_t * )calloc(1, sizeof(InitiatingMessage_t));
32   assert(initMsg != 0);
33   
34   IE_array = (RICsubscriptionDeleteRequest_IEs_t *)calloc(NUM_SUBSCRIPTION_DELETE_IES, sizeof(RICsubscriptionDeleteRequest_IEs_t));
35   assert(IE_array != 0);
36   
37   RICsubscriptionDeleteRequest_t * subscription_delete = &(initMsg->value.choice.RICsubscriptionDeleteRequest);
38   for(int i = 0; i < NUM_SUBSCRIPTION_DELETE_IES; i++){
39     ASN_SEQUENCE_ADD(&subscription_delete->protocolIEs, &(IE_array[i]));
40   }
41   
42 };
43
44
45
46 // Clear assigned protocolIE list from RIC indication IE container
47 subscription_delete::~subscription_delete(void){
48     
49   mdclog_write(MDCLOG_DEBUG, "Freeing subscription delete request object memory");
50   RICsubscriptionDeleteRequest_t * subscription_delete = &(initMsg->value.choice.RICsubscriptionDeleteRequest);
51   
52   for(int i = 0; i < subscription_delete->protocolIEs.list.size; i++){
53     subscription_delete->protocolIEs.list.array[i] = 0;
54   }
55
56   if (subscription_delete->protocolIEs.list.size > 0){
57     free(subscription_delete->protocolIEs.list.array);
58     subscription_delete->protocolIEs.list.count = 0;
59     subscription_delete->protocolIEs.list.size = 0;
60     subscription_delete->protocolIEs.list.array = 0;
61   }
62   
63   free(IE_array);
64   free(initMsg);
65   e2ap_pdu_obj->choice.initiatingMessage = 0;
66
67   ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2ap_pdu_obj);
68   mdclog_write(MDCLOG_DEBUG, "Freed subscription delete request object memory");
69   
70
71 };
72
73
74 bool subscription_delete::encode_e2ap_subscription(unsigned char *buf, size_t *size,  subscription_helper &dinput){
75
76   e2ap_pdu_obj->choice.initiatingMessage = initMsg;
77   e2ap_pdu_obj->present = E2AP_PDU_PR_initiatingMessage;
78   set_fields( dinput);
79
80   initMsg->procedureCode = ProcedureCode_id_RICsubscriptionDelete;
81   initMsg->criticality = Criticality_reject;
82   initMsg->value.present = InitiatingMessage__value_PR_RICsubscriptionDeleteRequest;
83
84   //xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu_obj);
85   
86   int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) e2ap_pdu_obj, errbuf, &errbuf_len);
87   if(ret_constr){
88     error_string.assign(errbuf, errbuf_len);
89     error_string = "Constraints failed for encoding subscription delete request. Reason = " + error_string;
90     return false;
91   }
92   
93   asn_enc_rval_t res = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, e2ap_pdu_obj, buf, *size);
94     
95   if(res.encoded == -1){
96     error_string.assign(strerror(errno));
97     error_string = "Error encoding Subscription Delete Request. Reason = " + error_string;
98     return false;
99   }
100   else {
101     if(*size < res.encoded){
102       std::stringstream ss;
103       ss  <<"Error encoding Subscription Delete Request . Reason =  encoded pdu size " << res.encoded << " exceeds buffer size " << *size << std::endl;
104       error_string = ss.str();
105       res.encoded = -1;
106       return false;
107     }
108   }
109     
110   *size = res.encoded;
111   return true;
112     
113 }
114
115
116 bool  subscription_delete::set_fields( subscription_helper &helper)
117 {
118         static long update_instance=0;//static variable to update ricInstaceID for sending delete req
119         unsigned int ie_index;
120         ie_index = 0;
121         RICsubscriptionDeleteRequest_IEs_t *ies_ricreq = &IE_array[ie_index];
122         ies_ricreq->criticality = Criticality_reject;
123         ies_ricreq->id = ProtocolIE_ID_id_RICrequestID;
124         ies_ricreq->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID;
125         RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID;
126         ricrequest_ie->ricRequestorID = helper.get_request_id();
127         update_instance++;//incrementing ricInstanceID by one, each time the bouncer send delete req
128         ricrequest_ie->ricInstanceID = update_instance;
129         mdclog_write(MDCLOG_INFO,"instance id for subsdelreq  = %d", update_instance);
130         //ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq();
131
132
133   
134         ie_index = 1;
135         RICsubscriptionDeleteRequest_IEs_t *ies_ranfunc = &IE_array[ie_index];
136         ies_ranfunc->criticality = Criticality_reject;
137         ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID;
138         ies_ranfunc->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID;
139         RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
140         *ranfunction_ie = helper.get_function_id();
141         mdclog_write(MDCLOG_INFO,"ran function  id for subsdelreq  = %d", helper.get_function_id());
142         //*ranfunction_ie =1;
143   
144         return true;
145 };
146
147
148    
149
150 bool  subscription_delete:: get_fields(InitiatingMessage_t * init_msg,  subscription_helper & dout)
151 {
152
153   if (init_msg == 0){
154     error_string = "Invalid reference for initiating message for get string";
155     return false;
156   }
157   
158   RICrequestID_t *requestid;
159   RANfunctionID_t * ranfunctionid;
160     
161   for(int edx = 0; edx < init_msg->value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.count; edx++) {
162     RICsubscriptionDeleteRequest_IEs_t *memb_ptr = init_msg->value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.array[edx];
163     
164     switch(memb_ptr->id)
165       {
166       case (ProtocolIE_ID_id_RICrequestID):
167         requestid = &memb_ptr->value.choice.RICrequestID;
168         //dout.set_request(requestid->ricRequestorID, requestid->ricRequestSequenceNumber);
169         break;
170           
171       case (ProtocolIE_ID_id_RANfunctionID):
172         ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
173         dout.set_function_id(*ranfunctionid);
174         break;
175         
176       }
177     
178   //asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
179   }
180
181   return true;
182 }
183
184
185