7484a45b363ed0d5d69edea922f01beab75208b4
[sim/e2-interface.git] / e2sim / previous / e2apv1sim / encode_e2apv1.cpp
1 #include <stdio.h>
2 #include <string.h>
3 #include <iostream>
4 #include <unistd.h>
5
6 #include <iterator>
7 #include <vector>
8
9
10 #include "encode_e2apv1.hpp"
11
12 extern "C" {
13 #include "E2SM-KPM-RANfunction-Description.h"
14
15 #include "e2ap_asn1c_codec.h"
16 #include "GlobalE2node-ID.h"
17 #include "GlobalE2node-gNB-ID.h"
18 #include "GlobalgNB-ID.h"
19 #include "OCTET_STRING.h"
20 #include "asn_application.h"
21 #include "GNB-ID-Choice.h"
22 #include "ProtocolIE-Field.h"
23 #include "E2setupRequest.h"
24 #include "RICaction-ToBeSetup-Item.h"
25 #include "RICactions-ToBeSetup-List.h"
26 #include "RICeventTriggerDefinition.h"
27 #include "RICsubscriptionRequest.h"
28 #include "RICsubscriptionResponse.h"
29 #include "ProtocolIE-SingleContainer.h"
30 #include "RANfunctions-List.h"
31 #include "RICindication.h"
32 #include "RICsubsequentActionType.h"
33 #include "RICsubsequentAction.h"  
34 #include "RICtimeToWait.h"
35   
36 }
37
38 void generate_e2apv1_setup_request(E2AP_PDU_t *e2ap_pdu) {
39   
40   //  uint8_t *buf = (uint8_t *)"gnb1"
41
42   BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
43   gnb_bstring->buf = (uint8_t*)calloc(1,4);
44   gnb_bstring->size = 4;
45   gnb_bstring->buf[0] = 0xB5;
46   gnb_bstring->buf[1] = 0xC6;
47   gnb_bstring->buf[2] = 0x77;
48   gnb_bstring->buf[3] = 0x88;
49
50   gnb_bstring->bits_unused = 3;
51
52   uint8_t *buf2 = (uint8_t *)"747";
53   OCTET_STRING_t *plmn = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
54   plmn->buf = (uint8_t*)calloc(1,3);
55   memcpy(plmn->buf, buf2, 3);
56   plmn->size = 3;
57
58   GNB_ID_Choice_t *gnbchoice = (GNB_ID_Choice_t*)calloc(1,sizeof(GNB_ID_Choice_t));
59   GNB_ID_Choice_PR pres2 = GNB_ID_Choice_PR_gnb_ID;
60   gnbchoice->present = pres2;
61   gnbchoice->choice.gnb_ID = *gnb_bstring;
62
63   GlobalgNB_ID_t *gnb = (GlobalgNB_ID_t*)calloc(1, sizeof(GlobalgNB_ID_t));
64   gnb->plmn_id = *plmn;
65   gnb->gnb_id = *gnbchoice;
66
67   GlobalE2node_gNB_ID_t *e2gnb = (GlobalE2node_gNB_ID_t*)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
68   e2gnb->global_gNB_ID = *gnb;
69
70   GlobalE2node_ID_t *globale2nodeid = (GlobalE2node_ID_t*)calloc(1, sizeof(GlobalE2node_ID_t));
71   GlobalE2node_ID_PR pres;
72   pres = GlobalE2node_ID_PR_gNB;
73   globale2nodeid->present = pres;
74   globale2nodeid->choice.gNB = e2gnb;
75   
76   E2setupRequestIEs_t *e2setuprid = (E2setupRequestIEs_t*)calloc(1, sizeof(E2setupRequestIEs_t));
77   E2setupRequestIEs__value_PR pres3;
78   pres3 = E2setupRequestIEs__value_PR_GlobalE2node_ID;
79   e2setuprid->id = 3;
80   e2setuprid->criticality = 0;
81   e2setuprid->value.choice.GlobalE2node_ID = *globale2nodeid;
82   e2setuprid->value.present = pres3;
83
84
85   auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
86   ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, ranFlistIEs);
87   ranFlistIEs->criticality = 0;
88   ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded;
89   ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
90
91   auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
92   itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
93   itemIes->criticality = Criticality_reject;
94   itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
95   itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
96
97   E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
98     (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
99   encode_kpm_function_description(ranfunc_desc);
100
101   uint8_t e2smbuffer[8192];
102   size_t e2smbuffer_size = 8192;
103
104   asn_codec_ctx_t *opt_cod;  
105
106   asn_enc_rval_t er =
107     asn_encode_to_buffer(opt_cod,
108                          ATS_ALIGNED_BASIC_PER,
109                          &asn_DEF_E2SM_KPM_RANfunction_Description,
110                          ranfunc_desc, e2smbuffer, e2smbuffer_size);
111   
112   fprintf(stderr, "er encded is %d\n", er.encoded);
113   fprintf(stderr, "after encoding message\n");
114
115   OCTET_STRING_t *ranfuncdesc_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
116   ranfuncdesc_str->buf = (uint8_t*)calloc(1,er.encoded);
117   ranfuncdesc_str->size = er.encoded;
118   memcpy(ranfuncdesc_str->buf, e2smbuffer, er.encoded);
119   
120
121   itemIes->value.choice.RANfunction_Item.ranFunctionDefinition = *ranfuncdesc_str;
122   itemIes->value.choice.RANfunction_Item.ranFunctionRevision = (long)2;
123
124   ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes);
125
126   E2setupRequest_t *e2setupreq = (E2setupRequest_t*)calloc(1, sizeof(E2setupRequest_t));
127   ASN_SEQUENCE_ADD(&e2setupreq->protocolIEs.list, e2setuprid);
128   ASN_SEQUENCE_ADD(&e2setupreq->protocolIEs.list, ranFlistIEs);
129
130   InitiatingMessage__value_PR pres4;
131   pres4 = InitiatingMessage__value_PR_E2setupRequest;
132   InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
133
134   initmsg->procedureCode = ProcedureCode_id_E2setup;
135   initmsg->criticality = Criticality_reject;
136   initmsg->value.present = pres4;
137   initmsg->value.choice.E2setupRequest = *e2setupreq;
138
139   E2AP_PDU_PR pres5;
140   pres5 = E2AP_PDU_PR_initiatingMessage;
141   
142
143   e2ap_pdu->present = pres5;
144   e2ap_pdu->choice.initiatingMessage = initmsg;
145
146 }
147
148
149 void generate_e2apv1_setup_response(E2AP_PDU_t *e2ap_pdu) {
150
151   E2setupResponseIEs *resp_ies1 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
152   E2setupResponseIEs *resp_ies2 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
153   E2setupResponseIEs *resp_ies3 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
154
155   uint8_t *buf = (uint8_t *)"gnb1";
156
157   BIT_STRING_t *ricid_bstring = (BIT_STRING_t*)calloc(1,sizeof(BIT_STRING_t));
158   ricid_bstring->buf = buf;
159   ricid_bstring->size = 4;
160   ricid_bstring->bits_unused = 0;
161
162   uint8_t *buf2 = (uint8_t *)"plmn3";
163   OCTET_STRING_t *plmn = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
164   plmn->buf = buf2;
165   plmn->size = 5;
166
167   GlobalRIC_ID_t *globalricid = (GlobalRIC_ID_t*)calloc(1,sizeof(GlobalRIC_ID_t));
168   globalricid->pLMN_Identity = *plmn;
169   globalricid->ric_ID = *ricid_bstring;
170
171   E2setupResponseIEs__value_PR pres1;
172   pres1 = E2setupResponseIEs__value_PR_GlobalRIC_ID;
173   
174   resp_ies1->id = ProtocolIE_ID_id_GlobalRIC_ID;
175   resp_ies1->criticality = 0;
176   resp_ies1->value.present = pres1;
177   resp_ies1->value.choice.GlobalRIC_ID = *globalricid;
178
179   E2setupResponse_t *e2setupresp = (E2setupResponse_t*)calloc(1,sizeof(E2setupResponse_t));
180   int ret = ASN_SEQUENCE_ADD(&e2setupresp->protocolIEs.list, resp_ies1);
181
182
183   SuccessfulOutcome__value_PR pres;
184   pres = SuccessfulOutcome__value_PR_E2setupResponse;
185   SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
186   successoutcome->procedureCode = 1;
187   successoutcome->criticality = 0;
188   successoutcome->value.present = pres;
189   successoutcome->value.choice.E2setupResponse = *e2setupresp;
190
191   E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
192   
193   e2ap_pdu->present = pres5;
194   e2ap_pdu->choice.successfulOutcome = successoutcome;
195   
196 }
197
198
199 void generate_e2apv1_subscription_request(E2AP_PDU *e2ap_pdu) {
200
201   fprintf(stderr, "in sub 1\n");
202   RICsubscriptionRequest_IEs_t *ricreqid = (RICsubscriptionRequest_IEs_t*)calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
203   fprintf(stderr, "in sub 2\n");  
204   ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, ricreqid);
205   fprintf(stderr, "in sub 3\n");  
206   auto *ricsubrid = (RICsubscriptionRequest_IEs_t*)calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
207   fprintf(stderr, "in sub 4\n");  
208   ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, ricsubrid);
209   
210   fprintf(stderr, "in generate sub\n");
211   uint8_t *buf2 = (uint8_t *)"SubscriptionTriggers";
212   fprintf(stderr, "in gen sub 1\n");
213   OCTET_STRING_t *triggerdef = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
214   triggerdef->buf = (uint8_t *)calloc(1,20);
215   triggerdef->size = 20;  
216   memcpy(triggerdef->buf, buf2, triggerdef->size);
217
218
219   fprintf(stderr, "sub1\n");
220   ProtocolIE_ID_t proto_id= ProtocolIE_ID_id_RICaction_ToBeSetup_Item;
221
222   RICaction_ToBeSetup_ItemIEs__value_PR pres6;
223   pres6 = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
224
225   printf("sub2\n");
226
227   uint8_t *buf5 = (uint8_t *)"ActionDef";
228
229   OCTET_STRING_t *actdef = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
230   actdef->buf = (uint8_t *)calloc(1,9);
231   actdef->size = 9;  
232   memcpy(triggerdef->buf, buf5, 9);
233
234   auto *sa = (RICsubsequentAction_t *) calloc(1, sizeof(RICsubsequentAction_t));
235   ASN_STRUCT_RESET(asn_DEF_RICsubsequentAction, sa);
236   
237   sa->ricTimeToWait = RICtimeToWait_w500ms;
238   sa->ricSubsequentActionType = RICsubsequentActionType_continue;
239     
240   /*
241   RICaction_ToBeSetup_Item_t *action_item = (RICaction_ToBeSetup_Item_t*)calloc(1, sizeof(RICaction_ToBeSetup_Item_t));
242   action_item->ricActionID = 5;
243   action_item->ricActionType = 9;
244   action_item->ricActionDefinition = actdef;
245   action_item->ricSubsequentAction = sa;
246   */
247   printf("sub3\n");
248
249   RICaction_ToBeSetup_ItemIEs_t *action_item_ies = (RICaction_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(RICaction_ToBeSetup_Item_t));
250   action_item_ies->id = proto_id;
251   action_item_ies->criticality = 0;
252
253   action_item_ies->value.present = pres6;
254   action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionID = 5;
255   action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report;
256   action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = actdef;
257   action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction = sa;
258
259
260   printf("sub5\n");
261   /*
262   RICsubscriptionDetails_t *ricsubdetails = (RICsubscriptionDetails_t*)calloc(1, sizeof(RICsubscriptionDetails_t));
263   printf("sub5.5\n");
264
265   ASN_SEQUENCE_ADD(&ricsubdetails->ricAction_ToBeSetup_List.list, action_item_ies);
266   ricsubdetails->ricEventTriggerDefinition = *triggerdef;
267
268   printf("sub6\n");
269   */
270   
271
272   RICsubscriptionRequest_IEs__value_PR pres3;
273   printf("sub6.1\n");
274   pres3 = RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
275   ricsubrid->id = ProtocolIE_ID_id_RICsubscriptionDetails;
276   printf("sub6.2\n");
277   
278   ricsubrid->criticality = 0;
279   ricsubrid->value.present = pres3;
280   printf("sub6.3\n");
281
282   ricsubrid->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition = *triggerdef;
283   printf("sub6.4\n");
284   
285   ASN_SEQUENCE_ADD(&ricsubrid->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list, action_item_ies);
286
287   printf("sub7\n");
288
289
290   ricreqid->id = ProtocolIE_ID_id_RICrequestID;
291   ricreqid->criticality = 0;
292   ricreqid->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
293   ricreqid->value.choice.RICrequestID.ricRequestorID = 22;
294   ricreqid->value.choice.RICrequestID.ricInstanceID = 6;
295
296   RICsubscriptionRequest_t *ricsubreq = (RICsubscriptionRequest_t*)calloc(1, sizeof(RICsubscriptionRequest_t));
297
298   ASN_SEQUENCE_ADD(&ricsubreq->protocolIEs.list,ricreqid);
299   ASN_SEQUENCE_ADD(&ricsubreq->protocolIEs.list,ricsubrid);
300
301
302
303   InitiatingMessage__value_PR pres4;
304   pres4 = InitiatingMessage__value_PR_RICsubscriptionRequest;
305   InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
306   initmsg->procedureCode = ProcedureCode_id_RICsubscription;
307   initmsg->criticality = Criticality_reject;
308   initmsg->value.present = pres4;
309   initmsg->value.choice.RICsubscriptionRequest = *ricsubreq;
310
311   E2AP_PDU_PR pres5;
312   pres5 = E2AP_PDU_PR_initiatingMessage;
313   
314
315   e2ap_pdu->present = pres5;
316   e2ap_pdu->choice.initiatingMessage = initmsg;
317
318   char *error_buf = (char*)calloc(300, sizeof(char));;
319   size_t errlen;
320                                                                           
321   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
322   printf("error length %d\n", errlen);
323   printf("error buf %s\n", error_buf);
324
325   //  xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu);  
326
327 }
328
329 void generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, long reqActionIdsAccepted[],
330                                                    long reqActionIdsRejected[], int accept_size, int reject_size,
331                                                    long reqRequestorId, long reqInstanceId) {
332
333   RICsubscriptionResponse_IEs_t *respricreqid =
334     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
335   
336   respricreqid->id = ProtocolIE_ID_id_RICrequestID;
337   respricreqid->criticality = 0;
338   respricreqid->value.present = RICsubscriptionResponse_IEs__value_PR_RICrequestID;
339   respricreqid->value.choice.RICrequestID.ricRequestorID = reqRequestorId;
340   
341   respricreqid->value.choice.RICrequestID.ricInstanceID = reqInstanceId;
342
343
344   RICsubscriptionResponse_IEs_t *ricactionadmitted =
345     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
346   ricactionadmitted->id = ProtocolIE_ID_id_RICactions_Admitted;
347   ricactionadmitted->criticality = 0;
348   ricactionadmitted->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
349
350   RICaction_Admitted_List_t* admlist = 
351     (RICaction_Admitted_List_t*)calloc(1,sizeof(RICaction_Admitted_List_t));
352   ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist;
353
354   //  int numAccept = sizeof(reqActionIdsAccepted);
355   int numAccept = accept_size;
356   int numReject = reject_size;
357   //  int numReject = sizeof(reqActionIdsRejected);
358
359   
360   for (int i=0; i < numAccept ; i++) {
361     fprintf(stderr, "in for loop i = %d\n", i);
362
363     long aid = reqActionIdsAccepted[i];
364
365     RICaction_Admitted_ItemIEs_t *admitie = (RICaction_Admitted_ItemIEs_t*)calloc(1,sizeof(RICaction_Admitted_ItemIEs_t));
366     admitie->id = ProtocolIE_ID_id_RICaction_Admitted_Item;
367     admitie->criticality = 0;
368     admitie->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
369     admitie->value.choice.RICaction_Admitted_Item.ricActionID = aid;
370     
371     ASN_SEQUENCE_ADD(&ricactionadmitted->value.choice.RICaction_Admitted_List.list, admitie);
372
373   }
374
375   RICsubscriptionResponse_t *ricsubresp = (RICsubscriptionResponse_t*)calloc(1,sizeof(RICsubscriptionResponse_t));
376   ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respricreqid);
377   ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionadmitted);
378   
379
380   if (numReject > 0) {
381
382     RICsubscriptionResponse_IEs_t *ricactionrejected =
383       (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
384     ricactionrejected->id = ProtocolIE_ID_id_RICactions_NotAdmitted;
385     ricactionrejected->criticality = 0;
386     ricactionrejected->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
387     
388     RICaction_NotAdmitted_List_t* rejectlist = 
389       (RICaction_NotAdmitted_List_t*)calloc(1,sizeof(RICaction_NotAdmitted_List_t));
390     ricactionadmitted->value.choice.RICaction_NotAdmitted_List = *rejectlist;
391     
392     for (int i=0; i < numReject; i++) {
393       fprintf(stderr, "in for loop i = %d\n", i);
394       
395       long aid = reqActionIdsRejected[i];
396       
397       RICaction_NotAdmitted_ItemIEs_t *noadmitie = (RICaction_NotAdmitted_ItemIEs_t*)calloc(1,sizeof(RICaction_NotAdmitted_ItemIEs_t));
398       noadmitie->id = ProtocolIE_ID_id_RICaction_NotAdmitted_Item;
399       noadmitie->criticality = 0;
400       noadmitie->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
401       noadmitie->value.choice.RICaction_NotAdmitted_Item.ricActionID = aid;
402       
403       ASN_SEQUENCE_ADD(&ricactionrejected->value.choice.RICaction_NotAdmitted_List.list, noadmitie);
404       ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionrejected);      
405     }
406   }
407
408
409   SuccessfulOutcome__value_PR pres2;
410   pres2 = SuccessfulOutcome__value_PR_RICsubscriptionResponse;
411   SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
412   successoutcome->procedureCode = ProcedureCode_id_RICsubscription;
413   successoutcome->criticality = 0;
414   successoutcome->value.present = pres2;
415   successoutcome->value.choice.RICsubscriptionResponse = *ricsubresp;
416
417   E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
418   
419   e2ap_pdu->present = pres5;
420   e2ap_pdu->choice.successfulOutcome = successoutcome;
421
422   char *error_buf = (char*)calloc(300, sizeof(char));
423   size_t errlen;
424
425   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
426   printf("error length %d\n", errlen);
427   printf("error buf %s\n", error_buf);
428
429   
430 }
431
432 void generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PDU *sub_req_pdu) {
433
434   //Gather details of the request
435
436   RICsubscriptionRequest_t orig_req =
437     sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
438   
439   RICsubscriptionResponse_IEs_t *ricreqid =
440     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
441                                            
442   int count = orig_req.protocolIEs.list.count;
443   int size = orig_req.protocolIEs.list.size;
444   
445   RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
446
447   fprintf(stderr, "count%d\n", count);
448   fprintf(stderr, "size%d\n", size);
449
450   RICsubscriptionRequest_IEs__value_PR pres;
451
452   long responseRequestorId;
453   long responseInstanceId;
454   long responseActionId;
455
456   std::vector<long> actionIds;
457
458   for (int i=0; i < count; i++) {
459     RICsubscriptionRequest_IEs_t *next_ie = ies[i];
460     pres = next_ie->value.present;
461     
462     fprintf(stderr, "next present value %d\n", pres);
463
464     switch(pres) {
465     case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
466       {
467         RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
468         long requestorId = reqId.ricRequestorID;
469         long instanceId = reqId.ricInstanceID;
470         fprintf(stderr, "requestorId %d\n", requestorId);
471         fprintf(stderr, "instanceId %d\n", instanceId);
472         responseRequestorId = requestorId;
473         responseInstanceId = instanceId;
474                 
475         break;
476       }
477     case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
478       break;
479     case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
480       {
481         RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; 
482         RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
483         RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
484         
485         int actionCount = actionList.list.count;
486         fprintf(stderr, "action count%d\n", actionCount);
487
488         auto **item_array = actionList.list.array;
489
490         for (int i=0; i < actionCount; i++) {
491           //RICaction_ToBeSetup_Item_t
492           auto *next_item = item_array[i];
493           RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
494           fprintf(stderr, "Next Action ID %ld\n", actionId);
495           responseActionId = actionId;
496           actionIds.push_back(responseActionId);
497         }
498         
499         break;
500       }
501     }
502     
503   }
504
505   fprintf(stderr, "After Processing Subscription Request\n");
506
507   fprintf(stderr, "requestorId %d\n", responseRequestorId);
508   fprintf(stderr, "instanceId %d\n", responseInstanceId);
509
510
511   for (int i=0; i < actionIds.size(); i++) {
512     fprintf(stderr, "Action ID %d %ld\n", i, actionIds.at(i));
513     
514   }
515
516
517   RICsubscriptionResponse_IEs_t *respricreqid =
518     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
519   
520   respricreqid->id = ProtocolIE_ID_id_RICrequestID;
521   respricreqid->criticality = 0;
522   respricreqid->value.present = RICsubscriptionResponse_IEs__value_PR_RICrequestID;
523   respricreqid->value.choice.RICrequestID.ricRequestorID = responseRequestorId;
524   
525   respricreqid->value.choice.RICrequestID.ricInstanceID = responseInstanceId;
526
527
528   RICsubscriptionResponse_IEs_t *ricactionadmitted =
529     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
530   ricactionadmitted->id = ProtocolIE_ID_id_RICactions_Admitted;
531   ricactionadmitted->criticality = 0;
532   ricactionadmitted->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
533
534   RICaction_Admitted_List_t* admlist = 
535     (RICaction_Admitted_List_t*)calloc(1,sizeof(RICaction_Admitted_List_t));
536   ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist;
537
538   for (int i=0; i < actionIds.size(); i++) {
539     fprintf(stderr, "in for loop i = %d\n", i);
540
541     long aid = actionIds.at(i);
542
543     RICaction_Admitted_ItemIEs_t *admitie = (RICaction_Admitted_ItemIEs_t*)calloc(1,sizeof(RICaction_Admitted_ItemIEs_t));
544     admitie->id = ProtocolIE_ID_id_RICaction_Admitted_Item;
545     admitie->criticality = 0;
546     admitie->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
547     admitie->value.choice.RICaction_Admitted_Item.ricActionID = aid;
548     
549     ASN_SEQUENCE_ADD(&ricactionadmitted->value.choice.RICaction_Admitted_List.list, admitie);
550
551   }
552
553
554   RICsubscriptionResponse_t *ricsubresp = (RICsubscriptionResponse_t*)calloc(1,sizeof(RICsubscriptionResponse_t));
555   
556   ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respricreqid);
557   ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionadmitted);
558
559
560   SuccessfulOutcome__value_PR pres2;
561   pres2 = SuccessfulOutcome__value_PR_RICsubscriptionResponse;
562   SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
563   successoutcome->procedureCode = ProcedureCode_id_RICsubscription;
564   successoutcome->criticality = 0;
565   successoutcome->value.present = pres2;
566   successoutcome->value.choice.RICsubscriptionResponse = *ricsubresp;
567
568   E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
569   
570   e2ap_pdu->present = pres5;
571   e2ap_pdu->choice.successfulOutcome = successoutcome;
572
573   char *error_buf = (char*)calloc(300, sizeof(char));
574   size_t errlen;
575
576   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
577   printf("error length %d\n", errlen);
578   printf("error buf %s\n", error_buf);
579   
580 }
581
582 void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu,
583                                                       long requestorId,
584                                                       long instanceId,
585                                                       long ranFunctionId,
586                                                       long actionId,
587                                                       long seqNum,
588                                                       uint8_t *ind_header_buf,
589                                                       int header_length,
590                                                       uint8_t *ind_message_buf,
591                                                       int message_length) {
592
593   fprintf(stderr, "ind1\n");
594   RICindication_IEs_t *ricind_ies = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
595   RICindication_IEs_t *ricind_ies2 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
596   RICindication_IEs_t *ricind_ies3 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
597   RICindication_IEs_t *ricind_ies4 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
598   RICindication_IEs_t *ricind_ies5 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
599   RICindication_IEs_t *ricind_ies6 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
600   RICindication_IEs_t *ricind_ies7 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
601   RICindication_IEs_t *ricind_ies8 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
602
603   RICindication_IEs__value_PR pres3;
604
605   pres3 = RICindication_IEs__value_PR_RICrequestID;
606   ricind_ies->id = ProtocolIE_ID_id_RICrequestID;
607   ricind_ies->criticality = 0;
608   ricind_ies->value.present = pres3;
609   ricind_ies->value.choice.RICrequestID.ricRequestorID = requestorId;
610   ricind_ies->value.choice.RICrequestID.ricInstanceID = instanceId;
611
612   fprintf(stderr, "ind2\n");
613
614   pres3 = RICindication_IEs__value_PR_RANfunctionID;
615   ricind_ies2->id = ProtocolIE_ID_id_RANfunctionID;
616   ricind_ies2->criticality = 0;
617   ricind_ies2->value.present = pres3;
618   ricind_ies2->value.choice.RANfunctionID = ranFunctionId;
619
620   
621   ricind_ies3->id = ProtocolIE_ID_id_RICactionID;
622   ricind_ies3->criticality = 0;
623   pres3 =  RICindication_IEs__value_PR_RICactionID;
624   ricind_ies3->value.present = pres3;
625   ricind_ies3->value.choice.RICactionID = actionId;
626
627
628   pres3 = RICindication_IEs__value_PR_RICindicationSN;
629   ricind_ies4->id = ProtocolIE_ID_id_RICindicationSN;
630   ricind_ies4->criticality = 0;
631   ricind_ies4->value.present = pres3;
632   ricind_ies4->value.choice.RICindicationSN = seqNum;
633
634   //Indication type is REPORT
635   pres3 = RICindication_IEs__value_PR_RICindicationType;
636   ricind_ies5->id = ProtocolIE_ID_id_RICindicationType;
637   ricind_ies5->criticality = 0;
638   ricind_ies5->value.present = pres3;
639   ricind_ies5->value.choice.RICindicationType = 0;
640
641
642   uint8_t *buf2 = (uint8_t *)"reportheader";
643   OCTET_STRING_t *hdr_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
644
645   hdr_str->buf = (uint8_t*)calloc(1,header_length);
646   hdr_str->size = header_length;
647   memcpy(hdr_str->buf, ind_header_buf, header_length);
648
649   fprintf(stderr, "ind3\n");
650
651   ricind_ies6->value.choice.RICindicationHeader.buf = (uint8_t*)calloc(1,header_length);
652
653   pres3 = RICindication_IEs__value_PR_RICindicationHeader;
654   ricind_ies6->id = ProtocolIE_ID_id_RICindicationHeader;
655   ricind_ies6->criticality = 0;
656   ricind_ies6->value.present = pres3;
657   ricind_ies6->value.choice.RICindicationHeader.size = header_length;
658   memcpy(ricind_ies6->value.choice.RICindicationHeader.buf, ind_header_buf, header_length);
659   
660   ricind_ies7->value.choice.RICindicationMessage.buf = (uint8_t*)calloc(1,8192);
661
662
663   
664
665   pres3 = RICindication_IEs__value_PR_RICindicationMessage;
666   ricind_ies7->id = ProtocolIE_ID_id_RICindicationMessage;
667   fprintf(stderr, "after encoding message 1\n");
668
669   ricind_ies7->criticality = 0;
670   ricind_ies7->value.present = pres3;
671
672   fprintf(stderr, "after encoding message 2\n");
673
674   fprintf(stderr, "after encoding message 3\n");      
675   ricind_ies7->value.choice.RICindicationMessage.size = message_length;
676
677   fprintf(stderr, "after encoding message 4\n");
678   memcpy(ricind_ies7->value.choice.RICindicationMessage.buf, ind_message_buf, message_length);
679
680   fprintf(stderr, "after encoding message 5\n");      
681
682   uint8_t *cpid_buf = (uint8_t *)"cpid";
683   OCTET_STRING_t cpid_str;
684
685   printf("5.1\n");
686
687   int cpid_buf_len = strlen((char*)cpid_buf);
688   pres3 = RICindication_IEs__value_PR_RICcallProcessID;
689   ricind_ies8->id = ProtocolIE_ID_id_RICcallProcessID;
690
691   ricind_ies8->criticality = 0;
692   ricind_ies8->value.present = pres3;
693
694   ricind_ies8->value.choice.RICcallProcessID.buf = (uint8_t*)calloc(1,cpid_buf_len);
695   ricind_ies8->value.choice.RICcallProcessID.size = cpid_buf_len;
696
697   memcpy(ricind_ies8->value.choice.RICcallProcessID.buf, cpid_buf, cpid_buf_len);
698
699   printf("5.2\n");
700
701   RICindication_t *ricindication = (RICindication_t*)calloc(1, sizeof(RICindication_t));
702
703   
704   int ret;
705
706   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies);
707   
708   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies2);
709
710   printf("5.3\n");
711
712   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies3);
713
714   printf("5.35\n");
715   
716   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies4);
717
718   printf("5.36\n");
719   
720   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies5);
721
722   printf("5.4\n");
723   
724   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies6);
725
726   printf("5.5\n");
727
728   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies7);  
729   
730   //  ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies8);    
731
732
733   InitiatingMessage__value_PR pres4;
734   pres4 = InitiatingMessage__value_PR_RICindication;
735   InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
736   initmsg->procedureCode = 5;
737   initmsg->criticality = 1;
738   initmsg->value.present = pres4;
739   initmsg->value.choice.RICindication = *ricindication;
740
741   E2AP_PDU_PR pres5;
742   pres5 = E2AP_PDU_PR_initiatingMessage;
743   
744   e2ap_pdu->present = pres5;
745   e2ap_pdu->choice.initiatingMessage = initmsg;
746
747   char *error_buf = (char*)calloc(300, sizeof(char));
748   size_t errlen;
749
750   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
751   printf("error length %d\n", errlen);
752   printf("error buf %s\n", error_buf);
753
754   xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu);  
755
756 }
757
758 void generate_e2apv1_indication_request(E2AP_PDU *e2ap_pdu) {
759   fprintf(stderr, "ind1\n");
760   RICindication_IEs_t *ricind_ies = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
761   RICindication_IEs_t *ricind_ies2 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
762   RICindication_IEs_t *ricind_ies3 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
763   RICindication_IEs_t *ricind_ies4 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
764   RICindication_IEs_t *ricind_ies5 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
765   RICindication_IEs_t *ricind_ies6 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
766   RICindication_IEs_t *ricind_ies7 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
767   RICindication_IEs_t *ricind_ies8 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
768
769   RICindication_IEs__value_PR pres3;
770
771   pres3 = RICindication_IEs__value_PR_RICrequestID;
772   ricind_ies->id = ProtocolIE_ID_id_RICrequestID;
773   ricind_ies->criticality = 0;
774   ricind_ies->value.present = pres3;
775   ricind_ies->value.choice.RICrequestID.ricRequestorID = 25;
776   ricind_ies->value.choice.RICrequestID.ricInstanceID = 3;
777
778   fprintf(stderr, "ind2\n");  
779
780   pres3 = RICindication_IEs__value_PR_RANfunctionID;
781   ricind_ies2->id = ProtocolIE_ID_id_RANfunctionID;
782   ricind_ies2->criticality = 0;
783   ricind_ies2->value.present = pres3;
784   ricind_ies2->value.choice.RANfunctionID = 70;
785
786   
787   ricind_ies3->id = ProtocolIE_ID_id_RICactionID;
788   ricind_ies3->criticality = 0;
789   pres3 =  RICindication_IEs__value_PR_RICactionID;
790   ricind_ies3->value.present = pres3;
791   ricind_ies3->value.choice.RICactionID = 80;
792
793
794   pres3 = RICindication_IEs__value_PR_RICindicationSN;
795   ricind_ies4->id = ProtocolIE_ID_id_RICindicationSN;
796   ricind_ies4->criticality = 0;
797   ricind_ies4->value.present = pres3;
798   ricind_ies4->value.choice.RICindicationSN = 45;
799
800   pres3 = RICindication_IEs__value_PR_RICindicationType;
801   ricind_ies5->id = ProtocolIE_ID_id_RICindicationType;
802   ricind_ies5->criticality = 0;
803   ricind_ies5->value.present = pres3;
804   ricind_ies5->value.choice.RICindicationType = 0;
805
806
807   uint8_t *buf2 = (uint8_t *)"reportheader";
808   OCTET_STRING_t *hdr_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
809   hdr_str->buf = (uint8_t*)calloc(1,12);
810   hdr_str->size = 12;
811   memcpy(hdr_str->buf, buf2, 12);
812
813   fprintf(stderr, "ind3\n");
814
815   ricind_ies6->value.choice.RICindicationHeader.buf = (uint8_t*)calloc(1,12);
816
817   pres3 = RICindication_IEs__value_PR_RICindicationHeader;
818   ricind_ies6->id = ProtocolIE_ID_id_RICindicationHeader;
819   ricind_ies6->criticality = 0;
820   ricind_ies6->value.present = pres3;
821   ricind_ies6->value.choice.RICindicationHeader.size = 12;
822   memcpy(ricind_ies6->value.choice.RICindicationHeader.buf, buf2, 12);
823   
824   ricind_ies7->value.choice.RICindicationMessage.buf = (uint8_t*)calloc(1,8192);
825   //  uint8_t *buf9 = (uint8_t *)"reportmsg";
826
827   /*
828   E2SM_KPM_IndicationMessage_t *e2sm_ind_msg =
829     (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
830
831   encode_kpm(e2sm_ind_msg);
832   */
833
834   E2SM_KPM_RANfunction_Description_t *e2sm_desc =
835     (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
836
837   encode_kpm_function_description(e2sm_desc);
838   
839   
840   uint8_t e2smbuffer[8192];
841   size_t e2smbuffer_size = 8192;
842
843   asn_codec_ctx_t *opt_cod;
844
845   
846   asn_enc_rval_t er =
847     asn_encode_to_buffer(opt_cod,
848                          ATS_ALIGNED_BASIC_PER,
849                          &asn_DEF_E2SM_KPM_RANfunction_Description,
850                          e2sm_desc, e2smbuffer, e2smbuffer_size);
851     
852     /*
853     asn_encode_to_buffer(opt_cod,
854                          ATS_ALIGNED_BASIC_PER,
855                          &asn_DEF_E2SM_KPM_IndicationMessage,
856                          e2sm_ind_msg, e2smbuffer, e2smbuffer_size);    
857     */
858
859
860   
861   fprintf(stderr, "er encded is %d\n", er.encoded);
862   fprintf(stderr, "after encoding message\n");
863   
864   OCTET_STRING_t *msg_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
865   msg_str->buf = (uint8_t*)calloc(1,er.encoded);
866   msg_str->size = er.encoded;
867   memcpy(msg_str->buf, e2smbuffer, er.encoded);
868   
869
870   pres3 = RICindication_IEs__value_PR_RICindicationMessage;
871   ricind_ies7->id = ProtocolIE_ID_id_RICindicationMessage;
872   fprintf(stderr, "after encoding message 1\n");
873
874   ricind_ies7->criticality = 0;
875   ricind_ies7->value.present = pres3;
876
877   fprintf(stderr, "after encoding message 2\n");
878
879   fprintf(stderr, "after encoding message 3\n");      
880   ricind_ies7->value.choice.RICindicationMessage.size = er.encoded;
881
882   fprintf(stderr, "after encoding message 4\n");      
883   memcpy(ricind_ies7->value.choice.RICindicationMessage.buf, e2smbuffer, er.encoded);
884
885   fprintf(stderr, "after encoding message 5\n");      
886
887   uint8_t *buf4 = (uint8_t *)"cpid";
888   OCTET_STRING_t cpid_str;
889   cpid_str.buf = buf4;
890   cpid_str.size = 4;      
891
892
893   pres3 = RICindication_IEs__value_PR_RICcallProcessID;
894   ricind_ies8->id = ProtocolIE_ID_id_RICcallProcessID;
895
896   ricind_ies8->criticality = 0;
897   ricind_ies8->value.present = pres3;
898
899   ricind_ies8->value.choice.RICcallProcessID = cpid_str;
900
901
902   RICindication_t *ricindication = (RICindication_t*)calloc(1, sizeof(RICindication_t));
903
904   
905   int ret;
906   /*
907     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies);
908
909     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies2);
910
911     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies3);  
912     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies4);
913     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies5);  
914
915     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies6);
916   */
917     ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies7);  
918
919   ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies8);    
920
921
922   InitiatingMessage__value_PR pres4;
923   pres4 = InitiatingMessage__value_PR_RICindication;
924   InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
925   initmsg->procedureCode = 5;
926   initmsg->criticality = 1;
927   initmsg->value.present = pres4;
928   initmsg->value.choice.RICindication = *ricindication;
929
930   E2AP_PDU_PR pres5;
931   pres5 = E2AP_PDU_PR_initiatingMessage;
932   
933   e2ap_pdu->present = pres5;
934   e2ap_pdu->choice.initiatingMessage = initmsg;
935
936   char *error_buf = (char*)calloc(300, sizeof(char));;
937   size_t errlen;  
938
939   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
940   printf("error length %d\n", errlen);
941   printf("error buf %s\n", error_buf);
942
943   xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu);
944 }
945
946
947 void generate_e2apv1_indication_response(E2AP_PDU *e2ap_pdu) {
948
949
950 }