Issue-ID: SIM-18
[sim/e2-interface.git] / e2sim / e2apv1sim / e2sim / kpm_callbacks.cpp
1
2
3 #include <iostream>
4 #include <fstream>
5 #include <vector>
6
7
8
9 extern "C" {
10   #include "OCUCP-PF-Container.h"
11   #include "OCTET_STRING.h"
12   #include "asn_application.h"
13   #include "E2SM-KPM-IndicationMessage.h"
14   #include "FQIPERSlicesPerPlmnListItem.h"
15   #include "E2SM-KPM-RANfunction-Description.h"
16   #include "Timestamp.h"
17   #include "E2AP-PDU.h"
18   #include "RICsubscriptionRequest.h"
19   #include "RICsubscriptionResponse.h"
20   #include "RICactionType.h"
21   #include "ProtocolIE-Field.h"
22   #include "ProtocolIE-SingleContainer.h"
23   #include "InitiatingMessage.h"
24 }
25
26 #include "kpm_callbacks.hpp"
27 #include "encode_kpm.hpp"
28
29 #include "encode_e2apv1.hpp"
30
31 #include <nlohmann/json.hpp>
32 #include <thread>
33
34
35 using json = nlohmann::json;
36
37 using namespace std;
38 class E2Sim;
39
40
41 E2Sim e2sim;
42
43 int main(int argc, char* argv[]) {
44
45   asn_codec_ctx_t *opt_cod;
46
47   E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
48     (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
49   encode_kpm_function_description(ranfunc_desc);
50
51   uint8_t e2smbuffer[8192];
52   size_t e2smbuffer_size = 8192;
53
54   asn_enc_rval_t er =
55     asn_encode_to_buffer(opt_cod,
56                          ATS_ALIGNED_BASIC_PER,
57                          &asn_DEF_E2SM_KPM_RANfunction_Description,
58                          ranfunc_desc, e2smbuffer, e2smbuffer_size);
59   
60   fprintf(stderr, "er encded is %d\n", er.encoded);
61   fprintf(stderr, "after encoding message\n");
62   fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
63
64   uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
65   memcpy(ranfuncdesc, e2smbuffer, er.encoded);
66
67   printf("this is the char array %s\n", (char*)ranfuncdesc);
68
69   OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
70   ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
71   ranfunc_ostr->size = er.encoded;
72   memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
73
74   printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
75   printf("value of this index is %d\n", ranfuncdesc[0]);
76   printf("value of this index is %d\n", ranfuncdesc[1]);
77   printf("value of this index is %d\n", ranfuncdesc[2]);
78   printf("value of this index is %d\n", ranfuncdesc[3]);
79   printf("value of this index is %d\n", ranfuncdesc[4]);
80   printf("value of this index is %d\n", ranfuncdesc[5]);
81   printf("value of this index is %d\n", ranfuncdesc[6]);
82   printf("value of this index is %d\n", ranfuncdesc[10]);
83   printf("value of this index is %d\n", ranfuncdesc[15]);
84   printf("value of this index is %d\n", ranfuncdesc[100]);
85   printf("value of this index is %d\n", ranfuncdesc[101]);
86   
87   e2sim.register_e2sm(1,ranfunc_ostr);
88   e2sim.register_subscription_callback(1,&callback_kpm_subscription_request);
89
90   e2sim.run_loop(argc, argv);
91
92 }
93
94 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
95
96   //Process simulation file
97
98   ifstream simfile;
99   string line;
100
101   long seqNum = 1;
102   
103   simfile.open("simulation.txt", ios::in);
104
105   cout << "step1" << endl;
106     
107   std::ifstream ue_stream("ueMeasReport.txt");
108   std::ifstream cell_stream("cellMeasReport.txt");
109
110   json all_ues_json;
111
112   ue_stream  >> all_ues_json;
113
114   json all_cells_json;
115
116   cell_stream >> all_cells_json;
117
118   asn_codec_ctx_t *opt_cod;
119
120   cout << "UE RF Measurements" << endl;
121   cout << "******************" << endl;
122
123   int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
124
125   for (int i = 0; i < numMeasReports; i++) {
126     int nextCellId;
127     int nextRsrp;
128     int nextRsrq;
129     int nextRssinr;
130     cout << "UE number " + i << endl;
131     cout << "**********" << endl;
132     json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
133     nextCellId = all_ues_json[p1].get<int>();
134     cout << "Serving Cell " << nextCellId << endl;
135     
136     json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
137     nextRsrp = all_ues_json[p2].get<int>();
138     cout << "  RSRP " << nextRsrp << endl;
139     json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
140     nextRsrq = all_ues_json[p3].get<int>();
141     cout << "  RSRQ " << nextRsrq << endl;
142     json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
143     nextRssinr = all_ues_json[p4].get<int>();
144     cout << "  RSSINR " << nextRssinr << endl;
145
146     json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
147
148     int numNeighborCells = (all_ues_json[p5]).size();
149
150
151     //REPORT Message 3 -- Encode and send OCUCP user-level report
152     
153     E2SM_KPM_IndicationMessage_t *ind_msg3 =
154       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
155     E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
156     
157     uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
158
159     if (nextCellId == 0) {
160       uint8_t *buf2 = (uint8_t*)"12";
161       memcpy(crnti_buf, buf2, 2);
162     } else if (nextCellId == 1) {
163       uint8_t *buf2 = (uint8_t*)"22";
164       memcpy(crnti_buf, buf2, 2);
165     }
166
167     std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
168       std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
169     const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
170         
171     std::string neighbor_str = "[";
172
173     int nextNbCell;
174     int nextNbRsrp;
175     int nextNbRsrq;
176     int nextNbRssinr;
177
178     for (int j = 0; j < numNeighborCells; j++) {
179       json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
180       nextNbCell = all_ues_json[p8].get<int>();
181       cout << "Neighbor Cell " << all_ues_json[p8] << endl;
182       json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
183                             +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
184       nextNbRsrp = all_ues_json[p9].get<int>();
185       cout << "  RSRP " << nextNbRsrp << endl;
186
187       json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
188                             +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
189       nextNbRsrq = all_ues_json[p10].get<int>();
190       cout << "  RSRQ " << nextNbRsrq << endl;
191
192       json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
193                              +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
194       nextNbRssinr = all_ues_json[p11].get<int>();
195       cout << "  RSSINR " << nextNbRssinr << endl;
196
197       if (j != 0) {
198         neighbor_str += ",";
199
200       }
201
202       neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
203         ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
204       
205     }
206
207     neighbor_str += "]";
208     
209     const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
210     
211     printf("Neighbor string\n%s", neighbor_buf);
212
213     uint8_t *plmnid_buf = (uint8_t*)"747";
214     uint8_t *nrcellid_buf = (uint8_t*)"12340";
215     
216     encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
217     
218     uint8_t e2smbuffer3[8192];
219     size_t e2smbuffer_size3 = 8192;
220
221     
222     asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
223                                               ATS_ALIGNED_BASIC_PER,
224                                               &asn_DEF_E2SM_KPM_IndicationMessage,
225                                               ind_msg3, e2smbuffer3, e2smbuffer_size3);
226     
227     fprintf(stderr, "er encded is %d\n", er3.encoded);
228     fprintf(stderr, "after encoding message\n");
229     uint8_t *e2smheader_buf3 = (uint8_t*)"header";
230     
231     generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
232                                                      instanceId, ranFunctionId,
233                                                      actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
234     
235     e2sim.encode_and_send_sctp_data(pdu3);
236     
237     seqNum++;
238         
239   }
240
241
242   cout << "Cell Measurements" << endl;
243   cout << "******************" << endl;
244
245   int numCellMeasReports = (all_cells_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
246
247   uint8_t *sst_buf = (uint8_t*)"1";
248   uint8_t *sd_buf = (uint8_t*)"100";
249   uint8_t *plmnid_buf = (uint8_t*)"747";
250   
251   for (int i = 0; i < numCellMeasReports; i++) {
252
253     int nextCellId;
254     int nextPdcpBytesDL;
255     int nextPdcpBytesUL;
256     int nextPRBBytesDL;
257     int nextPRBBytesUL;
258
259     json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
260     nextCellId = all_cells_json[p1].get<int>();
261     cout << std::string("Cell number ") << nextCellId << endl;
262     
263     cout << "**********" << endl;
264     
265     json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
266     nextPdcpBytesDL = all_cells_json[p2].get<int>();
267     cout << std::string("  PDCP Bytes DL ") << nextPdcpBytesDL << endl;
268
269     json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
270     nextPdcpBytesUL = all_cells_json[p3].get<int>();    
271     cout << std::string("  PDCP Bytes UL ") << nextPdcpBytesUL << endl;
272
273     uint8_t *buf = (uint8_t*)"GNBCUUP5";
274     
275     int bytes_dl = nextPdcpBytesDL;
276
277     int bytes_ul = nextPdcpBytesUL;
278
279     //    int bytes_dl = 3905;
280     //    int bytes_ul = 1609321;    
281     
282     E2SM_KPM_IndicationMessage_t *ind_msg2 =
283       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
284     E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
285     
286     encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
287     
288     uint8_t e2smbuffer2[8192];
289     size_t e2smbuffer_size2 = 8192;
290     
291     asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
292                                               ATS_ALIGNED_BASIC_PER,
293                                               &asn_DEF_E2SM_KPM_IndicationMessage,
294                                               ind_msg2, e2smbuffer2, e2smbuffer_size2);
295     
296     fprintf(stderr, "er encded is %d\n", er2.encoded);
297     fprintf(stderr, "after encoding message\n");
298     uint8_t *e2smheader_buf2 = (uint8_t*)"header";
299     
300     generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
301                                                      instanceId, ranFunctionId,
302                                                      actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
303     
304     e2sim.encode_and_send_sctp_data(pdu2);
305     
306     seqNum++;
307
308     
309
310     json::json_pointer p4(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
311     nextPRBBytesDL = all_cells_json[p4].get<int>();    
312     cout << std::string("  PRB Bytes DL ") << all_cells_json[p4] << endl;
313
314     json::json_pointer p5(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
315     nextPRBBytesUL = all_cells_json[p5].get<int>();
316     cout << std::string("  PRB Bytes UL ") << all_cells_json[p5] << endl;
317
318
319     //REPORT Message 1 -- Encode and send ODU cell-level report
320     
321     E2SM_KPM_IndicationMessage_t *ind_msg1 =
322       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
323     E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
324     
325     long fiveqi = 7;
326
327     uint8_t *nrcellid_buf = (uint8_t*)"12340";
328     long dl_prbs = nextPRBBytesDL;
329     long ul_prbs = nextPRBBytesUL;
330     
331     encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
332     
333     uint8_t e2smbuffer[8192];
334     size_t e2smbuffer_size = 8192;
335     
336     asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
337                                              ATS_ALIGNED_BASIC_PER,
338                                              &asn_DEF_E2SM_KPM_IndicationMessage,
339                                              ind_msg1, e2smbuffer, e2smbuffer_size);
340     
341     fprintf(stderr, "er encded is %d\n", er.encoded);
342     fprintf(stderr, "after encoding message\n");
343     uint8_t *e2smheader_buf = (uint8_t*)"header";
344     
345     uint8_t *cpid_buf = (uint8_t*)"CPID";
346     
347     fprintf(stderr, "About to encode Indication\n");
348     generate_e2apv1_indication_request_parameterized(pdu, requestorId,
349                                                      instanceId, ranFunctionId,
350                                                      actionId, seqNum, e2smheader_buf, 6, e2smbuffer, er.encoded);
351     
352     e2sim.encode_and_send_sctp_data(pdu);
353     
354     seqNum++;
355     
356   }
357
358
359   /*
360   if (simfile.is_open()) {
361
362     while (getline(simfile, line)) {
363       cout << line << "\n";
364
365       //REPORT Message 1 -- Encode and send ODU cell-level report
366
367       E2SM_KPM_IndicationMessage_t *ind_msg1 =
368         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
369       E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
370
371       long fiveqi = 7;
372       uint8_t *sst_buf = (uint8_t*)"1";
373       uint8_t *sd_buf = (uint8_t*)"100";
374       uint8_t *plmnid_buf = (uint8_t*)"747";
375       uint8_t *nrcellid_buf = (uint8_t*)"12340";
376       long dl_prbs = 100;
377       long ul_prbs = 50; 
378      
379       encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
380
381       uint8_t e2smbuffer[8192];
382       size_t e2smbuffer_size = 8192;
383       asn_codec_ctx_t *opt_cod;
384
385       asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
386                                                ATS_ALIGNED_BASIC_PER,
387                                                &asn_DEF_E2SM_KPM_IndicationMessage,
388                                                ind_msg1, e2smbuffer, e2smbuffer_size);
389       
390       fprintf(stderr, "er encded is %d\n", er.encoded);
391       fprintf(stderr, "after encoding message\n");
392       uint8_t *e2smheader_buf = (uint8_t*)"header";
393
394       uint8_t *cpid_buf = (uint8_t*)"CPID";
395
396       fprintf(stderr, "About to encode Indication\n");
397       generate_e2apv1_indication_request_parameterized(pdu, requestorId,
398                                                        instanceId, ranFunctionId,
399                                                        actionId, seqNum, e2smheader_buf, 6, e2smbuffer, er.encoded);
400
401       encode_and_send_sctp_data(pdu, socket_fd);
402       
403       seqNum++;
404
405       //REPORT Message 2 -- Encode and send OCUUP cell-level report
406
407       uint8_t *buf = (uint8_t*)"GNBCUUP5";
408
409       int bytes_dl = 40000;
410       int bytes_ul = 50000;
411
412       E2SM_KPM_IndicationMessage_t *ind_msg2 =
413         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
414       E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
415       
416       encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
417
418       uint8_t e2smbuffer2[8192];
419       size_t e2smbuffer_size2 = 8192;
420
421
422       asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
423                                                ATS_ALIGNED_BASIC_PER,
424                                                &asn_DEF_E2SM_KPM_IndicationMessage,
425                                                ind_msg2, e2smbuffer2, e2smbuffer_size2);
426       
427       fprintf(stderr, "er encded is %d\n", er2.encoded);
428       fprintf(stderr, "after encoding message\n");
429       uint8_t *e2smheader_buf2 = (uint8_t*)"header";
430
431       generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
432                                                        instanceId, ranFunctionId,
433                                                        actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
434
435       encode_and_send_sctp_data(pdu2, socket_fd);
436       
437       seqNum++;
438
439       //REPORT Message 3 -- Encode and send OCUCP user-level report
440
441       E2SM_KPM_IndicationMessage_t *ind_msg3 =
442         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
443       E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
444
445       uint8_t *crnti_buf = (uint8_t*)"12";
446       //      uint8_t *serving_buf = (uint8_t*)"RSRP10";
447       //uint8_t *neighbor_buf = (uint8_t*)"-10,-15";
448       int rsrpServ = 10;
449       int rsrqServ = 0;
450       int rssinrServ = 0;
451
452       std::string serving_str = "{\"rsrp\": " + std::to_string(rsrpServ) + ", \"rsrq\": " +
453         std::to_string(rsrqServ) + ", \"rssinr\": " + std::to_string(rssinrServ) + "}";
454       const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
455
456
457       neighbor_cell_entry n_entries[3];
458       n_entries[0] = {"123", 10, 0, 0};
459       n_entries[1] = {"456", 10, 0, 0};
460       n_entries[2] = {"789", 10, 0, 0};
461
462       std::string neighbor_str = "[";
463
464       for (int i=0; i < sizeof(n_entries)/sizeof(n_entries[0]); i++) {
465
466         if (i != 0) {
467           neighbor_str += ",";
468         }
469         neighbor_str += "{\"CID\" : \"" + std::string(n_entries[i].cellid) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(n_entries[i].rsrp) +
470           ", \"rsrq\": " + std::to_string(n_entries[i].rsrq) + ", \"rssinr\": " + std::to_string(n_entries[i].rsrp) + "}}";
471       }
472
473       neighbor_str += "]";
474
475       const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
476
477       printf("Neighbor string\n%s", neighbor_buf);
478
479       encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
480       
481       uint8_t e2smbuffer3[8192];
482       size_t e2smbuffer_size3 = 8192;
483
484       asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
485                                                 ATS_ALIGNED_BASIC_PER,
486                                                 &asn_DEF_E2SM_KPM_IndicationMessage,
487                                                 ind_msg3, e2smbuffer3, e2smbuffer_size3);
488       
489       fprintf(stderr, "er encded is %d\n", er3.encoded);
490       fprintf(stderr, "after encoding message\n");
491       uint8_t *e2smheader_buf3 = (uint8_t*)"header";
492
493       generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
494                                                        instanceId, ranFunctionId,
495                                                        actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
496
497       encode_and_send_sctp_data(pdu3, socket_fd);
498             
499       seqNum++;
500       
501       //Encode and send OCUUP user-level report
502
503
504       
505       //Encode and send ODU user-level report
506
507       
508
509       
510     }
511
512     simfile.close();
513
514   }
515   */
516
517 }
518
519 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
520
521
522   //Record RIC Request ID
523   //Go through RIC action to be Setup List
524   //Find first entry with REPORT action Type
525   //Record ricActionID
526   //Encode subscription response
527
528   RICsubscriptionRequest_t orig_req =
529     sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
530   
531   RICsubscriptionResponse_IEs_t *ricreqid =
532     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
533                                            
534   int count = orig_req.protocolIEs.list.count;
535   int size = orig_req.protocolIEs.list.size;
536   
537   RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
538
539   fprintf(stderr, "count%d\n", count);
540   fprintf(stderr, "size%d\n", size);
541
542   RICsubscriptionRequest_IEs__value_PR pres;
543
544   long reqRequestorId;
545   long reqInstanceId;
546   long reqActionId;
547
548   std::vector<long> actionIdsAccept;
549   std::vector<long> actionIdsReject;
550
551   for (int i=0; i < count; i++) {
552     RICsubscriptionRequest_IEs_t *next_ie = ies[i];
553     pres = next_ie->value.present;
554     
555     fprintf(stderr, "next present value %d\n", pres);
556
557     switch(pres) {
558     case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
559       {
560         RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
561         long requestorId = reqId.ricRequestorID;
562         long instanceId = reqId.ricInstanceID;
563         fprintf(stderr, "requestorId %d\n", requestorId);
564         fprintf(stderr, "instanceId %d\n", instanceId);
565         reqRequestorId = requestorId;
566         reqInstanceId = instanceId;
567
568         break;
569       }
570     case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
571       break;
572     case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
573       {
574         RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails; 
575         RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
576         RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
577
578         //We are ignoring the trigger definition
579
580         //We identify the first action whose type is REPORT
581         //That is the only one accepted; all others are rejected
582         
583         int actionCount = actionList.list.count;
584         fprintf(stderr, "action count%d\n", actionCount);
585
586         auto **item_array = actionList.list.array;
587
588         bool foundAction = false;
589
590         for (int i=0; i < actionCount; i++) {
591
592           auto *next_item = item_array[i];
593           RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
594           RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
595
596           if (!foundAction && actionType == RICactionType_report) {
597             reqActionId = actionId;
598             actionIdsAccept.push_back(reqActionId);
599             printf("adding accept\n");
600             foundAction = true;
601           } else {
602             reqActionId = actionId;
603             printf("adding reject\n");
604             actionIdsReject.push_back(reqActionId);
605           }
606         }
607         
608         break;
609       }
610     }
611     
612   }
613
614   fprintf(stderr, "After Processing Subscription Request\n");
615
616   fprintf(stderr, "requestorId %d\n", reqRequestorId);
617   fprintf(stderr, "instanceId %d\n", reqInstanceId);
618
619
620   for (int i=0; i < actionIdsAccept.size(); i++) {
621     fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
622     
623   }
624
625   E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
626
627   long *accept_array = &actionIdsAccept[0];
628   long *reject_array = &actionIdsReject[0];
629   int accept_size = actionIdsAccept.size();
630   int reject_size = actionIdsReject.size();
631
632   generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
633
634   e2sim.encode_and_send_sctp_data(e2ap_pdu);
635
636   //Start thread for sending REPORT messages
637
638   //  std::thread loop_thread;
639
640   long funcId = 1;
641
642   run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
643
644   //  loop_thread = std::thread(&run_report_loop);
645
646 }