Incorporating A1 HealthCheck functionality
[ric-app/hw.git] / src / xapp-formats / e2ap / subscription_response.cc
1 /*
2 ==================================================================================
3         Copyright (c) 2018-2019 AT&T Intellectual Property.
4
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
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
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 ==================================================================================
17 */
18
19
20 #include "subscription_response.hpp"
21
22 /* The xAPP need only worry about the get_fields from a response, since it does
23 not generate a response. Generating response however is included to support testing. 
24 */
25
26
27 // Primarly for generation
28 subscription_response::subscription_response(void){
29
30   e2ap_pdu_obj = 0;
31   e2ap_pdu_obj = (E2N_E2AP_PDU_t *)calloc(1, sizeof(E2N_E2AP_PDU_t));
32   assert(e2ap_pdu_obj != 0);
33
34   successMsg = 0;
35   successMsg = (E2N_SuccessfulOutcome_t *)calloc(1, sizeof(E2N_SuccessfulOutcome_t));
36   assert(successMsg != 0);
37
38   unsuccessMsg = 0;
39   unsuccessMsg = (E2N_UnsuccessfulOutcome_t *)calloc(1, sizeof(E2N_UnsuccessfulOutcome_t));
40   assert(unsuccessMsg != 0);
41
42   IE_array = 0;
43   IE_array = (E2N_RICsubscriptionResponse_IEs_t *)calloc(NUM_SUBSCRIPTION_RESPONSE_IES, sizeof(E2N_RICsubscriptionResponse_IEs_t));
44   assert(IE_array != 0);
45
46   IE_Failure_array = 0;
47   IE_Failure_array = (E2N_RICsubscriptionFailure_IEs_t *)calloc(NUM_SUBSCRIPTION_FAILURE_IES, sizeof(E2N_RICsubscriptionFailure_IEs_t));
48   assert(IE_Failure_array != 0);
49
50   ie_admitted_list = 0;
51   ie_admitted_list = (E2N_RICaction_Admitted_ItemIEs_t *)calloc(INITIAL_RESPONSE_LIST_SIZE, sizeof(E2N_RICaction_Admitted_ItemIEs_t));
52   assert(ie_admitted_list != 0);
53   ie_admitted_list_size = INITIAL_RESPONSE_LIST_SIZE;
54   
55   ie_not_admitted_list = 0;
56   ie_not_admitted_list = (E2N_RICaction_NotAdmitted_ItemIEs_t *)calloc(INITIAL_RESPONSE_LIST_SIZE, sizeof(E2N_RICaction_NotAdmitted_ItemIEs_t));
57   assert(ie_not_admitted_list != 0);
58   ie_not_admitted_list_size = INITIAL_RESPONSE_LIST_SIZE;
59
60
61
62
63   
64 };
65
66   
67
68 // Clear assigned protocolIE list from RIC indication IE container
69 subscription_response::~subscription_response(void){
70
71   mdclog_write(MDCLOG_DEBUG, "Freeing subscription response memory");
72   E2N_RICaction_Admitted_List_t * response_admitted_list = (E2N_RICaction_Admitted_List_t *) &(IE_array[2].value.choice.RICaction_Admitted_List);
73   
74   for(int i = 0; i < response_admitted_list->list.size; i++){
75     response_admitted_list->list.array[i] = 0;
76   }
77
78   
79   if (response_admitted_list->list.size > 0){
80     free(response_admitted_list->list.array);
81     response_admitted_list->list.array = 0;
82     response_admitted_list->list.size = 0;
83     response_admitted_list->list.count = 0;
84   }
85
86   
87   E2N_RICaction_NotAdmitted_List_t * response_not_admitted_list = &(IE_array[3].value.choice.RICaction_NotAdmitted_List);
88   for(int i = 0; i < response_not_admitted_list->list.size; i++){
89     response_not_admitted_list->list.array[i] = 0;
90   }
91   
92   if (response_not_admitted_list->list.size > 0){
93     free(response_not_admitted_list->list.array);
94     response_not_admitted_list->list.array = 0;
95     response_not_admitted_list->list.size = 0;
96     response_not_admitted_list->list.count = 0;
97   }
98      
99   E2N_RICsubscriptionResponse_t * ric_subscription_response = &(successMsg->value.choice.RICsubscriptionResponse);
100   for(int i = 0; i < ric_subscription_response->protocolIEs.list.size ; i++){
101     ric_subscription_response->protocolIEs.list.array[i] = 0;
102   }
103   
104   if (ric_subscription_response->protocolIEs.list.size > 0){
105     free(ric_subscription_response->protocolIEs.list.array);
106     ric_subscription_response->protocolIEs.list.array = 0;
107     ric_subscription_response->protocolIEs.list.size = 0;
108     ric_subscription_response->protocolIEs.list.count = 0;
109   }
110   
111   
112   E2N_RICaction_NotAdmitted_List_t * failure_not_admitted_list = &(IE_Failure_array[2].value.choice.RICaction_NotAdmitted_List);
113   for(int i = 0; i < failure_not_admitted_list->list.size; i++){
114     failure_not_admitted_list->list.array[i] = 0;
115   }
116
117   if ( failure_not_admitted_list->list.size > 0){
118     free( failure_not_admitted_list->list.array);
119     failure_not_admitted_list->list.array = 0;
120     failure_not_admitted_list->list.size = 0;
121     failure_not_admitted_list->list.count = 0;
122   }
123   
124      
125   E2N_RICsubscriptionFailure_t * ric_subscription_failure = &(unsuccessMsg->value.choice.RICsubscriptionFailure);
126   for(int i = 0; i < ric_subscription_failure->protocolIEs.list.size; i++){
127     ric_subscription_failure->protocolIEs.list.array[i] = 0;
128   }
129   
130   if (  ric_subscription_failure->protocolIEs.list.size > 0){
131     free(ric_subscription_failure->protocolIEs.list.array);
132     ric_subscription_failure->protocolIEs.list.array = 0;
133     ric_subscription_failure->protocolIEs.list.size = 0;
134     ric_subscription_failure->protocolIEs.list.count = 0;
135   }
136
137
138   free(ie_admitted_list);  
139   free(ie_not_admitted_list);
140   free(IE_Failure_array);
141   free(IE_array);
142
143   
144   ASN_STRUCT_FREE(asn_DEF_E2N_SuccessfulOutcome, successMsg);
145   ASN_STRUCT_FREE(asn_DEF_E2N_UnsuccessfulOutcome, unsuccessMsg);
146
147   
148   e2ap_pdu_obj->choice.initiatingMessage = NULL;
149   e2ap_pdu_obj->present = E2N_E2AP_PDU_PR_NOTHING;
150   ASN_STRUCT_FREE(asn_DEF_E2N_E2AP_PDU, e2ap_pdu_obj);
151
152   mdclog_write(MDCLOG_DEBUG, "Freed subscription response memory ");
153
154   
155 };
156
157
158 bool subscription_response::encode_e2ap_subscription_response(unsigned char *buf, size_t *size, subscription_response_helper &dinput, bool is_success){
159   
160
161   if(is_success){
162     set_fields_success(dinput);
163     e2ap_pdu_obj->present =  E2N_E2AP_PDU_PR_successfulOutcome;
164     e2ap_pdu_obj->choice.successfulOutcome = successMsg;
165
166     successMsg->procedureCode = E2N_ProcedureCode_id_ricSubscription;
167     successMsg->criticality = E2N_Criticality_reject;
168     successMsg->value.present = E2N_SuccessfulOutcome__value_PR_RICsubscriptionResponse;   
169  
170   }
171   else{
172     set_fields_unsuccess(dinput);
173     e2ap_pdu_obj->present = E2N_E2AP_PDU_PR_unsuccessfulOutcome;
174     e2ap_pdu_obj->choice.unsuccessfulOutcome = unsuccessMsg;
175
176     unsuccessMsg->procedureCode = E2N_ProcedureCode_id_ricSubscription;
177     unsuccessMsg->criticality = E2N_Criticality_reject;
178     unsuccessMsg->value.present = E2N_UnsuccessfulOutcome__value_PR_RICsubscriptionFailure;
179
180   }
181     
182   //xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu_obj);
183
184   int ret_constr = asn_check_constraints(&asn_DEF_E2N_E2AP_PDU, (void *) e2ap_pdu_obj, errbuf, &errbuf_len);
185   if(ret_constr){
186     error_string.assign(errbuf, errbuf_len);
187     error_string = "Constraints failed for encoding subscription response. Reason = " + error_string;
188     return false;
189   }
190     
191   asn_enc_rval_t res = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2N_E2AP_PDU, e2ap_pdu_obj, buf, *size);
192     
193   if(res.encoded == -1){
194     std::cout <<"Error encoding PDU. Reason =" << strerror(errno) << std::endl;
195     return false;
196   }
197   else {
198     if(*size < res.encoded){
199       fprintf(stderr,  "Buffer assigned too small to encode: %s",(char *)(asn_DEF_E2N_E2AP_PDU.name));
200       res.encoded = -1;
201       return false;
202     }
203   }
204     
205   *size = res.encoded;
206   return true;
207     
208 }
209   
210 void subscription_response::set_fields_success(subscription_response_helper &helper){
211
212   int ie_index;
213
214   E2N_RICsubscriptionResponse_t * subscription_response = &(successMsg->value.choice.RICsubscriptionResponse);
215   //reset list count ..
216   subscription_response->protocolIEs.list.count = 0;
217     
218   ie_index = 0;
219   E2N_RICsubscriptionResponse_IEs_t *ies_ricreq = &IE_array[ie_index];
220   
221   ies_ricreq->criticality = E2N_Criticality_reject;
222   ies_ricreq->id = E2N_ProtocolIE_ID_id_RICrequestID;
223   ies_ricreq->value.present = E2N_RICsubscriptionResponse_IEs__value_PR_RICrequestID;
224   E2N_RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID;
225   ricrequest_ie->ricRequestorID = helper.get_request_id();
226   ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq();
227   ASN_SEQUENCE_ADD(&subscription_response->protocolIEs, &(IE_array[ie_index]));  
228
229   
230   ie_index = 1;
231   E2N_RICsubscriptionResponse_IEs_t *ies_ranfunc = &IE_array[ie_index];
232   ies_ranfunc->criticality = E2N_Criticality_reject;
233   ies_ranfunc->id = E2N_ProtocolIE_ID_id_RANfunctionID;
234   ies_ranfunc->value.present = E2N_RICsubscriptionResponse_IEs__value_PR_RANfunctionID;
235   E2N_RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
236   *ranfunction_ie = helper.get_function_id();
237   ASN_SEQUENCE_ADD(&subscription_response->protocolIEs, &(IE_array[ie_index]));
238
239   
240   ie_index = 2;
241   E2N_RICsubscriptionResponse_IEs_t *ies_admitted_actid = &IE_array[ie_index];
242   ies_admitted_actid->criticality = E2N_Criticality_reject;
243   ies_admitted_actid->id = E2N_ProtocolIE_ID_id_RICactions_Admitted;
244   E2N_RICaction_Admitted_List_t *ric_admitted_actions_ie = &ies_admitted_actid->value.choice.RICaction_Admitted_List;
245   ric_admitted_actions_ie->list.count = 0;
246   std::vector<ActionResponse> * ref_admitted_action_array = helper.get_admitted_list();  
247
248   if(ref_admitted_action_array->size() ==  0){
249     ies_admitted_actid->value.present =  E2N_RICsubscriptionResponse_IEs__value_PR_NOTHING;
250   }
251   else{  
252     ies_admitted_actid->value.present =  E2N_RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
253
254     // resize memory ?
255     if (ref_admitted_action_array->size() >= ie_admitted_list_size){
256       ie_admitted_list_size = 2 * ref_admitted_action_array->size();
257       free(ie_admitted_list);
258       ie_admitted_list = (E2N_RICaction_Admitted_ItemIEs_t *)calloc(ie_admitted_list_size, sizeof(E2N_RICaction_Admitted_ItemIEs_t));
259       assert(ie_admitted_list != 0);
260     };
261   
262
263     for(unsigned int i = 0; i < ref_admitted_action_array->size(); i ++){
264       ie_admitted_list[i].criticality = E2N_Criticality_ignore;
265       ie_admitted_list[i].id = E2N_ProtocolIE_ID_id_RICaction_Admitted_Item ;
266       ie_admitted_list[i].value.present = E2N_RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
267       ie_admitted_list[i].value.choice.RICaction_Admitted_Item.ricActionID = (*ref_admitted_action_array)[i].get_id();
268       ASN_SEQUENCE_ADD(ric_admitted_actions_ie, &(ie_admitted_list[i]));
269     }
270   }  
271   ASN_SEQUENCE_ADD(&subscription_response->protocolIEs, &(IE_array[ie_index]));
272
273   // optional IE : add only if non-zero list 
274   ie_index = 3;
275   std::vector<ActionResponse> * ref_notadmitted_action_array = helper.get_not_admitted_list();
276   if (ref_notadmitted_action_array->size() > 0){
277     
278     E2N_RICsubscriptionResponse_IEs_t *ies_notadmitted_actid = &IE_array[ie_index];
279     ies_notadmitted_actid->criticality = E2N_Criticality_reject;
280     ies_notadmitted_actid->id = E2N_ProtocolIE_ID_id_RICactions_NotAdmitted;
281
282     E2N_RICaction_NotAdmitted_List_t *ric_not_admitted_actions_ie = &ies_notadmitted_actid->value.choice.RICaction_NotAdmitted_List;
283     ric_not_admitted_actions_ie->list.count = 0;
284   
285   
286     ies_notadmitted_actid->value.present =  E2N_RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
287   
288     // resize memory ?
289     if (ref_notadmitted_action_array->size() >= ie_not_admitted_list_size){
290       ie_not_admitted_list_size = 2 * ref_notadmitted_action_array->size();
291       free(ie_not_admitted_list);
292       ie_not_admitted_list = (E2N_RICaction_NotAdmitted_ItemIEs_t *)calloc(ie_not_admitted_list_size, sizeof(E2N_RICaction_NotAdmitted_ItemIEs_t));
293       assert(ie_not_admitted_list != 0);
294     
295     };
296   
297   
298     for(unsigned int i = 0; i < ref_notadmitted_action_array->size(); i ++){
299       ie_not_admitted_list[i].criticality = E2N_Criticality_ignore;
300       ie_not_admitted_list[i].id = E2N_ProtocolIE_ID_id_RICaction_NotAdmitted_Item ;
301       ie_not_admitted_list[i].value.present = E2N_RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;;
302       ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricActionID = (*ref_notadmitted_action_array)[i].get_id();
303
304       int cause = (*ref_notadmitted_action_array)[i].get_cause();
305       switch(cause){
306       case E2N_RICcause_PR_radioNetwork:
307         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork = (*ref_notadmitted_action_array)[i].get_sub_cause();
308         break;
309       case E2N_RICcause_PR_transport:
310         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport = (*ref_notadmitted_action_array)[i].get_sub_cause();
311         break;
312       case E2N_RICcause_PR_protocol:
313         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol= (*ref_notadmitted_action_array)[i].get_sub_cause();
314         break;
315       case E2N_RICcause_PR_misc:
316         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc = (*ref_notadmitted_action_array)[i].get_sub_cause();
317         break;
318       case E2N_RICcause_PR_ric:
319         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric = (*ref_notadmitted_action_array)[i].get_sub_cause();
320         break;
321       default:
322         mdclog_write(MDCLOG_ERR, "Error :: %s, %d : Unknown RIC cause %d\n", __FILE__, __LINE__, cause);
323         return;
324       }
325
326       ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.present = (E2N_RICcause_PR)cause;      
327       ASN_SEQUENCE_ADD(ric_not_admitted_actions_ie, &(ie_not_admitted_list[i]));
328     }
329
330     ASN_SEQUENCE_ADD(&subscription_response->protocolIEs, &(IE_array[ie_index]));
331   }
332   
333 }
334
335 void subscription_response:: get_fields(E2N_SuccessfulOutcome_t * success_msg,  subscription_response_helper & dout)
336 {
337
338   assert(success_msg != NULL);
339   
340   E2N_RICrequestID_t *requestid;
341   E2N_RANfunctionID_t * ranfunctionid;
342   E2N_RICaction_Admitted_List_t  * ric_admitted_action_list;
343   E2N_RICaction_NotAdmitted_List_t * ric_not_admitted_action_list;
344     
345   for(int edx = 0; edx < success_msg->value.choice.RICsubscriptionResponse.protocolIEs.list.count; edx++) {
346     E2N_RICsubscriptionResponse_IEs_t *memb_ptr = success_msg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx];
347     
348     switch(memb_ptr->id)
349       {
350       case (E2N_ProtocolIE_ID_id_RICrequestID):
351         requestid = &memb_ptr->value.choice.RICrequestID;
352         dout.set_request(requestid->ricRequestorID, requestid->ricRequestSequenceNumber);
353         break;
354           
355       case (E2N_ProtocolIE_ID_id_RANfunctionID):
356         ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
357         dout.set_function_id(*ranfunctionid);
358         break;
359           
360       case (E2N_ProtocolIE_ID_id_RICactions_Admitted):
361         ric_admitted_action_list = &memb_ptr->value.choice.RICaction_Admitted_List;
362           
363         // admitted actions
364         for(int index = 0; index < ric_admitted_action_list->list.count; index ++){
365           E2N_RICaction_Admitted_ItemIEs_t * item = (E2N_RICaction_Admitted_ItemIEs_t *)ric_admitted_action_list->list.array[index];
366           long int id = item->value.choice.RICaction_Admitted_Item.ricActionID;
367           dout.get_admitted_list()->push_back(ActionResponse(id));
368         };
369
370         break;
371
372       case (E2N_ProtocolIE_ID_id_RICactions_NotAdmitted):
373         ric_not_admitted_action_list = &memb_ptr->value.choice.RICaction_NotAdmitted_List;
374           
375         for(int index = 0; index < ric_not_admitted_action_list->list.count; index ++){
376           E2N_RICaction_NotAdmitted_ItemIEs_t * item = (E2N_RICaction_NotAdmitted_ItemIEs_t *)ric_not_admitted_action_list->list.array[index];
377           long int id = item->value.choice.RICaction_NotAdmitted_Item.ricActionID;
378           int cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.present;
379           int sub_cause;
380           switch(cause){
381               
382           case  E2N_RICcause_PR_radioNetwork :
383             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork;
384             break;
385               
386           case E2N_RICcause_PR_transport :
387             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport;
388             break;
389               
390           case  E2N_RICcause_PR_protocol :
391             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol;
392             break;
393               
394           case E2N_RICcause_PR_misc :
395             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc;
396             break;
397               
398           case E2N_RICcause_PR_ric :
399             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric;
400             break;
401               
402           default:
403             std::cout <<"Error ! Illegal cause enum" << cause << std::endl;
404             return;
405           }  
406           dout.get_not_admitted_list()->push_back(ActionResponse(id, cause, sub_cause));
407         }
408         break;
409       }
410       
411   }
412     
413   //asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
414 }
415
416
417 void subscription_response::set_fields_unsuccess( subscription_response_helper &helper){
418
419   int ie_index;
420   E2N_RICsubscriptionFailure_t * ric_subscription_failure = &(unsuccessMsg->value.choice.RICsubscriptionFailure);
421   // reset list count
422   ric_subscription_failure->protocolIEs.list.count = 0;
423   
424   ie_index = 0;
425   E2N_RICsubscriptionFailure_IEs_t *ies_ricreq = &IE_Failure_array[ie_index];
426   ies_ricreq->criticality = E2N_Criticality_reject;
427   ies_ricreq->id = E2N_ProtocolIE_ID_id_RICrequestID;
428   ies_ricreq->value.present = E2N_RICsubscriptionFailure_IEs__value_PR_RICrequestID;
429   E2N_RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID;
430   ricrequest_ie->ricRequestorID = helper.get_request_id();
431   ricrequest_ie->ricRequestSequenceNumber = helper.get_req_seq();
432   ASN_SEQUENCE_ADD(&ric_subscription_failure->protocolIEs, &(IE_Failure_array[ie_index]));  
433   
434   ie_index = 1;
435   E2N_RICsubscriptionFailure_IEs_t *ies_ranfunc = &IE_Failure_array[ie_index];
436   ies_ranfunc->criticality = E2N_Criticality_reject;
437   ies_ranfunc->id = E2N_ProtocolIE_ID_id_RANfunctionID;
438   ies_ranfunc->value.present = E2N_RICsubscriptionFailure_IEs__value_PR_RANfunctionID;
439   E2N_RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID;
440   *ranfunction_ie = helper.get_function_id();
441   ASN_SEQUENCE_ADD(&ric_subscription_failure->protocolIEs, &(IE_Failure_array[ie_index]));  
442
443   ie_index = 2;
444   E2N_RICsubscriptionFailure_IEs_t *ies_notadmitted_actid = &IE_Failure_array[ie_index];
445   ies_notadmitted_actid->criticality = E2N_Criticality_reject;
446   ies_notadmitted_actid->id = E2N_ProtocolIE_ID_id_RICactions_NotAdmitted;
447   E2N_RICaction_NotAdmitted_List_t *ric_not_admitted_actions_ie = &ies_notadmitted_actid->value.choice.RICaction_NotAdmitted_List;
448   ric_not_admitted_actions_ie->list.count = 0;   
449   std::vector<ActionResponse> * ref_notadmitted_action_array = helper.get_not_admitted_list();  
450   if(ref_notadmitted_action_array->size() == 0){
451     ies_notadmitted_actid->value.present =  E2N_RICsubscriptionFailure_IEs__value_PR_NOTHING;
452   }
453   else{
454     ies_notadmitted_actid->value.present =  E2N_RICsubscriptionFailure_IEs__value_PR_RICaction_NotAdmitted_List;
455
456     // resize memory  ?
457     if (ref_notadmitted_action_array->size() >= ie_not_admitted_list_size){
458       ie_not_admitted_list_size = 2 * ref_notadmitted_action_array->size();
459       free(ie_not_admitted_list);
460       ie_not_admitted_list = (E2N_RICaction_NotAdmitted_ItemIEs_t *)calloc(ie_not_admitted_list_size, sizeof(E2N_RICaction_NotAdmitted_ItemIEs_t));
461       assert(ie_not_admitted_list != 0);
462     };
463       
464   
465     // reset the list count on ricAction_ToBeSetup_List;
466     for(unsigned int i = 0; i < ref_notadmitted_action_array->size(); i ++){
467       ie_not_admitted_list[i].criticality = E2N_Criticality_ignore;
468       ie_not_admitted_list[i].id = E2N_ProtocolIE_ID_id_RICaction_NotAdmitted_Item ;
469       ie_not_admitted_list[i].value.present = E2N_RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;;
470       ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricActionID = (*ref_notadmitted_action_array)[i].get_id();
471
472       int cause = (*ref_notadmitted_action_array)[i].get_cause();
473       switch(cause){
474       case E2N_RICcause_PR_radioNetwork:
475         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork = (*ref_notadmitted_action_array)[i].get_sub_cause();
476         break;
477       case E2N_RICcause_PR_transport:
478         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport = (*ref_notadmitted_action_array)[i].get_sub_cause();
479         break;
480       case E2N_RICcause_PR_protocol:
481         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol= (*ref_notadmitted_action_array)[i].get_sub_cause();
482         break;
483       case E2N_RICcause_PR_misc:
484         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc = (*ref_notadmitted_action_array)[i].get_sub_cause();
485         break;
486       case E2N_RICcause_PR_ric:
487         ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric = (*ref_notadmitted_action_array)[i].get_sub_cause();
488         break;
489       default:
490         mdclog_write(MDCLOG_ERR, "Error :: %s, %d : Unknown RIC cause %d\n", __FILE__, __LINE__, cause);
491         return ;
492       }
493
494       ie_not_admitted_list[i].value.choice.RICaction_NotAdmitted_Item.ricCause.present = (E2N_RICcause_PR)cause;
495       
496       ASN_SEQUENCE_ADD(ric_not_admitted_actions_ie, &(ie_not_admitted_list[i]));
497     }
498
499   }
500   ASN_SEQUENCE_ADD(&ric_subscription_failure->protocolIEs, &(IE_Failure_array[ie_index]));  
501
502
503   // // criticality diagnostics is not generated/parsed currently since optional
504   // i = 3;
505   // E2N_RICsubscriptionFailure_IEs_t *ies_criticality_diagnostics= &IE_Failure_array[i];
506   // ies_criticality_diagnostics->criticality = E2N_Criticality_ignore;
507   // ies_criticality_diagnostics->id = E2N_ProtocolIE_ID_id_CriticalityDiagnostics ;
508   // ies_criticality_diagnostics->value.present = E2N_RICsubscriptionFailure_IEs__value_PR_NOTHING;
509
510     
511 }
512
513 void subscription_response:: get_fields(E2N_UnsuccessfulOutcome_t * unsuccess_msg,  subscription_response_helper & dout)
514 {
515
516   assert(unsuccess_msg != NULL);
517   
518   E2N_RICrequestID_t *requestid;
519   E2N_RANfunctionID_t * ranfunctionid;
520   E2N_RICaction_NotAdmitted_List_t * ric_not_admitted_action_list;
521     
522   for(int edx = 0; edx < unsuccess_msg->value.choice.RICsubscriptionFailure.protocolIEs.list.count; edx++) {
523     E2N_RICsubscriptionFailure_IEs_t *memb_ptr = unsuccess_msg->value.choice.RICsubscriptionFailure.protocolIEs.list.array[edx];
524     
525     switch(memb_ptr->id)
526       {
527       case (E2N_ProtocolIE_ID_id_RICrequestID):
528         requestid = &memb_ptr->value.choice.RICrequestID;
529         dout.set_request(requestid->ricRequestorID, requestid->ricRequestSequenceNumber);
530         break;
531           
532       case (E2N_ProtocolIE_ID_id_RANfunctionID):
533         ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
534         dout.set_function_id(*ranfunctionid);
535         break;
536           
537
538       case (E2N_ProtocolIE_ID_id_RICactions_NotAdmitted):
539         ric_not_admitted_action_list = &memb_ptr->value.choice.RICaction_NotAdmitted_List;
540           
541         for(int index = 0; index < ric_not_admitted_action_list->list.count; index ++){
542           E2N_RICaction_NotAdmitted_ItemIEs_t * item = (E2N_RICaction_NotAdmitted_ItemIEs_t *)ric_not_admitted_action_list->list.array[index];
543           long int id = item->value.choice.RICaction_NotAdmitted_Item.ricActionID;
544           int cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.present;
545           int sub_cause;
546           switch(cause){
547               
548           case  E2N_RICcause_PR_radioNetwork :
549             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork;
550             break;
551               
552           case E2N_RICcause_PR_transport :
553             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport;
554             break;
555               
556           case  E2N_RICcause_PR_protocol :
557             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol;
558             break;
559               
560           case E2N_RICcause_PR_misc :
561             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc;
562             break;
563               
564           case E2N_RICcause_PR_ric :
565             sub_cause = item->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric;
566             break;
567               
568           default:
569             mdclog_write(MDCLOG_ERR, "Error :: %s, %d : Unknown RIC cause %d\n", __FILE__, __LINE__, cause);
570             return;
571           }  
572           dout.get_not_admitted_list()->push_back(ActionResponse(id, cause, sub_cause));
573         }
574         break;
575       }
576       
577   }
578     
579   //asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
580 }
581
582
583