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