dc6c852695a733cd9ee5ddc131ec30f1e3bb1666
[sim/e2-interface.git] / e2sim / e2sm_examples / kpm_e2sm / src / kpm / kpm_callbacks.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2020 AT&T Intellectual Property                                  *
4 #                                                                            *
5 # Licensed under the Apache License, Version 2.0 (the "License");            *
6 # you may not use this file except in compliance with the License.           *
7 # You may obtain a copy of the License at                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
11 # Unless required by applicable law or agreed to in writing, software        *
12 # distributed under the License is distributed on an "AS IS" BASIS,          *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
14 # See the License for the specific language governing permissions and        *
15 # limitations under the License.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 #include <iostream>
20 #include <fstream>
21 #include <vector>
22
23
24
25 extern "C" {
26   #include "OCUCP-PF-Container.h"
27   #include "OCTET_STRING.h"
28   #include "asn_application.h"
29   #include "E2SM-KPM-IndicationMessage.h"
30   #include "FQIPERSlicesPerPlmnListItem.h"
31   #include "E2SM-KPM-RANfunction-Description.h"
32   #include "E2SM-KPM-IndicationHeader-Format1.h"
33   #include "E2SM-KPM-IndicationHeader.h"
34   #include "Timestamp.h"
35   #include "E2AP-PDU.h"
36   #include "RICsubscriptionRequest.h"
37   #include "RICsubscriptionResponse.h"
38   #include "RICactionType.h"
39   #include "ProtocolIE-Field.h"
40   #include "ProtocolIE-SingleContainer.h"
41   #include "InitiatingMessage.h"
42 }
43
44 #include "kpm_callbacks.hpp"
45 #include "encode_kpm.hpp"
46
47 #include "encode_e2apv1.hpp"
48
49 #include <nlohmann/json.hpp>
50 #include <thread>
51
52
53 using json = nlohmann::json;
54
55 using namespace std;
56 class E2Sim;
57
58
59 E2Sim e2sim;
60
61 int main(int argc, char* argv[]) {
62
63   fprintf(stderr, "Starting KPM processor sim");
64
65   fprintf(stderr, "JSON Test\n");
66
67   std::ifstream input("/playpen/src/reports.json");
68   bool x = input.good();
69
70   fprintf(stderr, "%s\n", x ? "true" : "false");
71
72   long seqNum = 1;
73
74   std::string str;
75
76   
77   while ( getline(input, str) ) {
78
79     json all_ues_json;
80
81     fprintf(stderr,"De line is %s\n", str.c_str());
82
83     bool valid = false;
84
85     try {
86       all_ues_json = json::parse(str);
87
88       valid = true;
89     } catch (...) {
90       fprintf(stderr, "Exception on reading json\n");
91     }
92
93     if (valid) {
94
95       fprintf(stderr, "key is valid\n");
96
97       std::string first_key = all_ues_json.begin().key();
98       fprintf(stderr, "first key is %s\n", first_key.c_str());
99       
100       if (first_key.compare("ueMeasReport") == 0) {
101         
102         fprintf(stderr, "it is equal to ue meas report\n");
103
104         int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
105         
106       
107         for (int i = 0; i < numMeasReports; i++) {
108           int nextCellId;
109           int nextRsrp;
110           int nextRsrq;
111           int nextRssinr;
112           float tput;
113           int prb_usage;
114           fprintf(stderr,"UE number %d\n", i);
115           
116           json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
117           tput = all_ues_json[p0].get<float>();
118           fprintf(stderr, "Throughput %f\n", tput);
119           
120           json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
121           prb_usage = all_ues_json[p00].get<int>();
122           fprintf(stderr, "Throughput %d\n", prb_usage);        
123           
124           json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
125           nextCellId = all_ues_json[p1].get<int>();
126           fprintf(stderr, "Serving Cell %d\n",nextCellId);
127           
128           json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
129           nextRsrp = all_ues_json[p2].get<int>();
130           fprintf(stderr,"  RSRP %d\n", nextRsrp);
131           
132           json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
133           nextRsrq = all_ues_json[p3].get<int>();
134           fprintf(stderr,"  RSRQ %d\n",nextRsrq);
135           
136           json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
137           nextRssinr = all_ues_json[p4].get<int>();
138           fprintf(stderr,"  RSSINR %d\n", nextRssinr);
139           
140           json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
141           
142           uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
143           
144           uint8_t *buf2 = (uint8_t*)"12";
145           memcpy(crnti_buf, buf2, 2);
146           
147           
148           std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
149             std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
150           const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());   
151           
152           int numNeighborCells = (all_ues_json[p5]).size();
153           
154           std::string neighbor_str = "[";
155           
156           int nextNbCell;
157           int nextNbRsrp;
158           int nextNbRsrq;
159           int nextNbRssinr;
160           
161           for (int j = 0; j < numNeighborCells; j++) {
162             json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
163             nextNbCell = all_ues_json[p8].get<int>();
164             //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
165             json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
166                                   +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
167             nextNbRsrp = all_ues_json[p9].get<int>();
168             //cout << "  RSRP " << nextNbRsrp << endl;
169             
170             json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
171                                    +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
172             nextNbRsrq = all_ues_json[p10].get<int>();
173             //cout << "  RSRQ " << nextNbRsrq << endl;
174             
175             json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
176                                    +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
177             nextNbRssinr = all_ues_json[p11].get<int>();
178             //cout << "  RSSINR " << nextNbRssinr << endl;
179             
180             if (j != 0) {
181               neighbor_str += ",";
182               
183             }
184             
185             neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
186               ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
187             
188           }
189           
190           neighbor_str += "]";
191           
192           fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
193           
194           //Creating UE-level RAN-Container CUCP message
195           
196           fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
197           
198           const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
199           uint8_t *plmnid_buf = (uint8_t*)"747";
200           uint8_t *nrcellid_buf = (uint8_t*)"12340";
201           
202           E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
203             (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
204           
205           encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
206           
207           uint8_t e2sm_message_buf_cucp_ue[8192];
208           size_t e2sm_message_buf_size_cucp_ue = 8192;
209           
210           asn_codec_ctx_t *opt_cod;
211           
212           long requestorId = 9;
213           long instanceId = 8;
214           long ranFunctionId = 2;
215           long actionId = 4;
216           
217           asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
218                                                                    ATS_ALIGNED_BASIC_PER,
219                                                                    &asn_DEF_E2SM_KPM_IndicationMessage,
220                                                                    ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
221           
222           fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
223           fprintf(stderr, "after encoding message\n");
224
225           E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
226             (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
227           encode_e2sm_kpm_indication_header(ind_header_cucp_ue);
228
229           uint8_t e2sm_header_buf_cucp_ue[8192];
230           size_t e2sm_header_buf_size_cucp_ue = 8192;
231           
232           asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
233                                                                   ATS_ALIGNED_BASIC_PER,
234                                                                   &asn_DEF_E2SM_KPM_IndicationHeader,
235                                                                   ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
236           
237           E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
238           
239           encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
240                                                                      instanceId, ranFunctionId,
241                                                                      actionId, seqNum, e2sm_header_buf_cucp_ue,
242                                                                      er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
243                                                                      er_message_cucp_ue.encoded);
244           
245           //    e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
246           
247           //Creating UE-level RAN-Container CUUP message
248           
249           fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");     
250           
251           E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
252             (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
253           
254           long bytes = (long)(tput * 100);
255           
256           encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
257           
258           uint8_t e2sm_message_buf_cuup_ue[8192];
259           size_t e2sm_message_buf_size_cuup_ue = 8192;
260           
261           asn_codec_ctx_t *opt_cod2;
262           
263           long requestorId2 = 9;
264           long instanceId2 = 8;
265           long ranFunctionId2 = 2;
266           long actionId2 = 4;
267           
268           asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
269                                                                ATS_ALIGNED_BASIC_PER,
270                                                                &asn_DEF_E2SM_KPM_IndicationMessage,
271                                                                ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
272           
273           fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
274           fprintf(stderr, "after encoding message\n");
275
276           E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
277             (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
278           encode_e2sm_kpm_indication_header(ind_header_cuup_ue);
279
280           uint8_t e2sm_header_buf_cuup_ue[8192];
281           size_t e2sm_header_buf_size_cuup_ue = 8192;
282           
283           asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
284                                                                   ATS_ALIGNED_BASIC_PER,
285                                                                   &asn_DEF_E2SM_KPM_IndicationHeader,
286                                                                   ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
287           
288           
289           E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));        
290           
291           encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId2,
292                                                                      instanceId2, ranFunctionId2,
293                                                                      actionId2, seqNum, e2sm_header_buf_cuup_ue,
294                                                                      er_header_cuup_ue.encoded,
295                                                                      e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
296           
297           //Creating UE-level RAN-Container DU message
298           
299           fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
300           
301           E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
302             (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
303           
304           encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
305                                                           plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
306           
307           uint8_t e2sm_message_buf_du_ue[8192];
308           size_t e2sm_message_buf_size_du_ue = 8192;
309           
310           asn_codec_ctx_t *opt_cod3;
311           
312           long requestorId3 = 9;
313           long instanceId3 = 8;
314           long ranFunctionId3 = 2;
315           long actionId3 = 4;
316           
317           asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
318                                                                  ATS_ALIGNED_BASIC_PER,
319                                                                  &asn_DEF_E2SM_KPM_IndicationMessage,
320                                                                  ind_message_du_ue,
321                                                                  e2sm_message_buf_du_ue,
322                                                                  e2sm_message_buf_size_du_ue);
323           
324           fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
325           fprintf(stderr, "after encoding message\n");
326
327           E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
328             (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
329           encode_e2sm_kpm_indication_header(ind_header_du_ue);    
330
331           uint8_t e2sm_header_buf_du_ue[8192];
332           size_t e2sm_header_buf_size_du_ue = 8192;
333           
334           asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
335                                                                 ATS_ALIGNED_BASIC_PER,
336                                                                 &asn_DEF_E2SM_KPM_IndicationHeader,
337                                                                 ind_header_du_ue, e2sm_header_buf_du_ue,
338                                                                 e2sm_header_buf_size_du_ue);
339           
340           
341           E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
342           
343           encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId3,
344                                                                      instanceId3, ranFunctionId3,
345                                                                      actionId3, seqNum,
346                                                                      e2sm_header_buf_du_ue, er_header_du_ue.encoded,
347                                                                      e2sm_message_buf_du_ue, er_message_du_ue.encoded);
348           
349           fprintf(stderr, "done with ue meas report\n");
350         }
351         
352       } else if (first_key.compare("cellMeasReport") == 0) {
353
354         fprintf(stderr, "it is equal to cell meas report\n");   
355         
356         int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();  
357       
358         for (int i = 0; i < numMeasReports; i++) {
359           int nextCellId;
360
361           float bytes_dl;
362           float bytes_ul;
363           int prb_dl;
364           int prb_ul;
365           
366           fprintf(stderr,"UE number %d\n", i);
367           
368           json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
369           bytes_dl = all_ues_json[p0].get<float>();
370           fprintf(stderr, "Bytes DL %f\n", bytes_dl);
371
372           json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
373           bytes_ul = all_ues_json[p1].get<float>();
374           fprintf(stderr, "Bytes UL %f\n", bytes_ul);     
375           
376           json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
377           prb_dl = all_ues_json[p2].get<int>();
378           fprintf(stderr, "Avail PRB DL %d\n", prb_dl); 
379
380           json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
381           prb_ul = all_ues_json[p3].get<int>();
382           fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
383
384           uint8_t *buf = (uint8_t*)"GNBCUUP5";    
385
386           uint8_t *sst_buf = (uint8_t*)"1";
387           uint8_t *sd_buf = (uint8_t*)"100";
388           uint8_t *plmnid_buf = (uint8_t*)"747";
389
390
391           //Encoding Style 5 Message Body
392           
393           fprintf(stderr, "Encoding Style 5 Message body\n");
394
395           asn_codec_ctx_t *opt_cod;       
396
397           E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
398             (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
399           E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
400           
401           encode_kpm_report_style5_parameterized(ind_msg_style5 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
402           
403           uint8_t e2sm_message_buf_style5[8192];
404           size_t e2sm_message_buf_size_style5 = 8192;
405           
406           asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
407                                                                   ATS_ALIGNED_BASIC_PER,
408                                                                   &asn_DEF_E2SM_KPM_IndicationMessage,
409                                                                   ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
410           
411           fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
412           fprintf(stderr, "after encoding message\n");
413           
414           //Encode header
415           //    encode_kpm_indication_header();
416           
417           int seqNum0 = 1;
418
419           long requestorId = 9;
420           long instanceId = 8;
421           long ranFunctionId = 2;
422           long actionId = 4;
423
424           E2SM_KPM_IndicationHeader_t* ind_header_style5 =
425             (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
426           encode_e2sm_kpm_indication_header(ind_header_style5);
427
428           uint8_t e2sm_header_buf_style5[8192];
429           size_t e2sm_header_buf_size_style5 = 8192;
430           
431           asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
432                                                                  ATS_ALIGNED_BASIC_PER,
433                                                                  &asn_DEF_E2SM_KPM_IndicationHeader,
434                                                                  ind_header_style5,
435                                                                  e2sm_header_buf_style5, e2sm_header_buf_size_style5);    
436           
437           
438           encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
439                                                                      instanceId, ranFunctionId,
440                                                                      actionId, seqNum0, e2sm_header_buf_style5,
441                                                                      er_header_style5.encoded, e2sm_message_buf_style5,
442                                                                      er_message_style5.encoded);
443           
444           //    e2sim.encode_and_send_sctp_data(pdu2);
445
446           //Encoding Style 1 Message Body
447           
448           fprintf(stderr, "Encoding Style 1 Message body\n");     
449           asn_codec_ctx_t *opt_cod2;
450           
451           
452           E2SM_KPM_IndicationMessage_t *ind_message_style1 =
453             (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
454           E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
455           
456           long fiveqi = 7;
457           
458           uint8_t *nrcellid_buf = (uint8_t*)"12340";
459
460           long l_dl_prbs = prb_dl;
461           long l_ul_prbs = prb_ul;
462           
463           encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
464                                                  prb_dl, prb_ul, sst_buf, sd_buf,
465                                                  plmnid_buf, nrcellid_buf, &l_dl_prbs, &l_ul_prbs);
466           
467           uint8_t e2sm_message_buf_style1[8192];
468           size_t e2sm_message_buf_size_style1 = 8192;
469           
470           asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
471                                                                   ATS_ALIGNED_BASIC_PER,
472                                                                   &asn_DEF_E2SM_KPM_IndicationMessage,
473                                                                   ind_message_style1,
474                                                                   e2sm_message_buf_style1, e2sm_message_buf_size_style1);
475           
476           fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
477           fprintf(stderr, "after encoding message\n");
478
479           
480           uint8_t *cpid_buf2 = (uint8_t*)"CPID";
481           
482           fprintf(stderr, "About to encode Indication\n");
483
484           E2SM_KPM_IndicationHeader_t* ind_header_style1 =
485             (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
486           encode_e2sm_kpm_indication_header(ind_header_style1);
487
488           uint8_t e2sm_header_buf_style1[8192];
489           size_t e2sm_header_buf_size_style1 = 8192;
490           
491           asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
492                                                                  ATS_ALIGNED_BASIC_PER,
493                                                                  &asn_DEF_E2SM_KPM_IndicationHeader,
494                                                                  ind_header_style1,
495                                                                  e2sm_header_buf_style1, e2sm_header_buf_size_style1);            
496           
497           encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
498                                                                      instanceId, ranFunctionId,
499                                                                      actionId, seqNum, e2sm_header_buf_style1,
500                                                                      er_header_style1.encoded,
501                                                                      e2sm_message_buf_style1, er_message_style1.encoded);
502           
503           //      e2sim.encode_and_send_sctp_data(pdu);   
504           
505           
506
507         }
508       }                                            
509     }
510   }
511
512   asn_codec_ctx_t *opt_cod;
513   
514   E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
515     (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
516   encode_kpm_function_description(ranfunc_desc);
517   
518   uint8_t e2smbuffer[8192];
519   size_t e2smbuffer_size = 8192;
520   
521   asn_enc_rval_t er =
522     asn_encode_to_buffer(opt_cod,
523                          ATS_ALIGNED_BASIC_PER,
524                          &asn_DEF_E2SM_KPM_RANfunction_Description,
525                          ranfunc_desc, e2smbuffer, e2smbuffer_size);
526   
527   fprintf(stderr, "er encded is %d\n", er.encoded);
528   fprintf(stderr, "after encoding message\n");
529   fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
530   
531   uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
532   memcpy(ranfuncdesc, e2smbuffer, er.encoded);
533   
534   printf("this is the char array %s\n", (char*)ranfuncdesc);
535   
536   OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
537   ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
538   ranfunc_ostr->size = er.encoded;
539   memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
540
541   printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
542   printf("value of this index is %d\n", ranfuncdesc[0]);
543   printf("value of this index is %d\n", ranfuncdesc[1]);
544   printf("value of this index is %d\n", ranfuncdesc[2]);
545   printf("value of this index is %d\n", ranfuncdesc[3]);
546   printf("value of this index is %d\n", ranfuncdesc[4]);
547   printf("value of this index is %d\n", ranfuncdesc[5]);
548   printf("value of this index is %d\n", ranfuncdesc[6]);
549   printf("value of this index is %d\n", ranfuncdesc[10]);
550   printf("value of this index is %d\n", ranfuncdesc[15]);
551   printf("value of this index is %d\n", ranfuncdesc[100]);
552   printf("value of this index is %d\n", ranfuncdesc[101]);
553   
554   e2sim.register_e2sm(0,ranfunc_ostr);
555   e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
556
557   e2sim.run_loop(argc, argv);
558
559 }
560
561
562
563 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
564
565   //Process simulation file
566
567   ifstream simfile;
568   string line;
569
570   long seqNum = 1;
571   
572   simfile.open("simulation.txt", ios::in);
573
574   //  cout << "step1" << endl;
575
576   std::ifstream ue_stream("/playpen/src/ueMeasReport.txt");
577   std::ifstream cell_stream("/playpen/src/cellMeasReport.txt");
578
579   json all_ues_json;
580
581   ue_stream  >> all_ues_json;
582
583   json all_cells_json;
584
585   cell_stream >> all_cells_json;
586
587   asn_codec_ctx_t *opt_cod;
588
589   //  cout << "UE RF Measurements" << endl;
590   //  cout << "******************" << endl;
591
592   int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
593
594   for (int i = 0; i < numMeasReports; i++) {
595     int nextCellId;
596     int nextRsrp;
597     int nextRsrq;
598     int nextRssinr;
599     //    cout << "UE number " + i << endl;
600     //    cout << "**********" << endl;
601     json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
602     nextCellId = all_ues_json[p1].get<int>();
603     //    cout << "Serving Cell " << nextCellId << endl;
604     
605     json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
606     nextRsrp = all_ues_json[p2].get<int>();
607     //    cout << "  RSRP " << nextRsrp << endl;
608     json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
609     nextRsrq = all_ues_json[p3].get<int>();
610     //    cout << "  RSRQ " << nextRsrq << endl;
611     json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
612     nextRssinr = all_ues_json[p4].get<int>();
613     //    cout << "  RSSINR " << nextRssinr << endl;
614
615     json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
616
617     int numNeighborCells = (all_ues_json[p5]).size();
618
619
620     //REPORT Message 3 -- Encode and send OCUCP user-level report
621     
622     E2SM_KPM_IndicationMessage_t *ind_msg3 =
623       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
624     E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
625     
626     uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
627
628     if (nextCellId == 0) {
629       uint8_t *buf2 = (uint8_t*)"12";
630       memcpy(crnti_buf, buf2, 2);
631     } else if (nextCellId == 1) {
632       uint8_t *buf2 = (uint8_t*)"22";
633       memcpy(crnti_buf, buf2, 2);
634     }
635
636     std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
637       std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
638     const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
639         
640     std::string neighbor_str = "[";
641
642     int nextNbCell;
643     int nextNbRsrp;
644     int nextNbRsrq;
645     int nextNbRssinr;
646
647     for (int j = 0; j < numNeighborCells; j++) {
648       json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
649       nextNbCell = all_ues_json[p8].get<int>();
650       //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
651       json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
652                             +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
653       nextNbRsrp = all_ues_json[p9].get<int>();
654       //cout << "  RSRP " << nextNbRsrp << endl;
655
656       json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
657                             +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
658       nextNbRsrq = all_ues_json[p10].get<int>();
659       //cout << "  RSRQ " << nextNbRsrq << endl;
660
661       json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
662                              +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
663       nextNbRssinr = all_ues_json[p11].get<int>();
664       //cout << "  RSSINR " << nextNbRssinr << endl;
665
666       if (j != 0) {
667         neighbor_str += ",";
668
669       }
670
671       neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
672         ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
673       
674     }
675
676     neighbor_str += "]";
677     
678     const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
679     
680     //    printf("Neighbor string\n%s", neighbor_buf);
681
682     uint8_t *plmnid_buf = (uint8_t*)"747";
683     uint8_t *nrcellid_buf = (uint8_t*)"12340";
684
685     /*
686     encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
687     
688     uint8_t e2smbuffer3[8192];
689     size_t e2smbuffer_size3 = 8192;
690
691     
692     asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
693                                               ATS_ALIGNED_BASIC_PER,
694                                               &asn_DEF_E2SM_KPM_IndicationMessage,
695                                               ind_msg3, e2smbuffer3, e2smbuffer_size3);
696     
697     fprintf(stderr, "er encded is %d\n", er3.encoded);
698     fprintf(stderr, "after encoding message\n");
699     uint8_t *e2smheader_buf3 = (uint8_t*)"";
700     
701     generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
702                                                      instanceId, ranFunctionId,
703                                                      actionId, seqNum, e2smheader_buf3, 0, e2smbuffer3, er3.encoded);
704     
705                                                      e2sim.encode_and_send_sctp_data(pdu3);
706     */
707     
708     seqNum++;
709         
710   }
711
712
713   //  cout << "Cell Measurements" << endl;
714   //  cout << "******************" << endl;
715
716   int numCellMeasReports = (all_cells_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
717
718   uint8_t *sst_buf = (uint8_t*)"1";
719   uint8_t *sd_buf = (uint8_t*)"100";
720   uint8_t *plmnid_buf = (uint8_t*)"747";
721   
722   for (int i = 0; i < numCellMeasReports; i++) {
723
724     int nextCellId;
725
726
727     /*    
728     int nextPdcpBytesDL;
729     int nextPdcpBytesUL;
730     int nextPRBBytesDL;
731     int nextPRBBytesUL;
732
733     json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
734     nextCellId = all_cells_json[p1].get<int>();
735     //    cout << std::string("Cell number ") << nextCellId << endl;
736     
737     //    cout << "**********" << endl;
738     
739     json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
740     nextPdcpBytesDL = all_cells_json[p2].get<int>();
741     //    cout << std::string("  PDCP Bytes DL ") << nextPdcpBytesDL << endl;
742
743     json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
744     nextPdcpBytesUL = all_cells_json[p3].get<int>();    
745     //    cout << std::string("  PDCP Bytes UL ") << nextPdcpBytesUL << endl;
746
747     uint8_t *buf = (uint8_t*)"GNBCUUP5";
748     
749     int bytes_dl = nextPdcpBytesDL;
750     //int bytes_dl = 1250;
751
752     int bytes_ul = nextPdcpBytesUL;
753     //int bytes_ul = 1450;
754
755     //    int bytes_dl = 3905;
756     //    int bytes_ul = 1609321;
757     
758     E2SM_KPM_IndicationMessage_t *ind_msg2 =
759       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
760     E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
761     
762     encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
763     
764     uint8_t e2smbuffer2[8192];
765     size_t e2smbuffer_size2 = 8192;
766     
767     asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
768                                               ATS_ALIGNED_BASIC_PER,
769                                               &asn_DEF_E2SM_KPM_IndicationMessage,
770                                               ind_msg2, e2smbuffer2, e2smbuffer_size2);
771
772     fprintf(stderr, "er encded is %d\n", er2.encoded);
773     fprintf(stderr, "after encoding message\n");
774
775     //Encode header
776     //    encode_kpm_indication_header();
777
778     //    int seqNum0 = 1;
779
780     //    fprintf(stderr, "i is %d\n", i);
781
782     //    encoding::generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
783     //                                                           instanceId, ranFunctionId,
784     //                                                 actionId, seqNum0, e2sm_header_buffer, er4.encoded, e2smbuffer2, er2.encoded);
785     
786     //    e2sim.encode_and_send_sctp_data(pdu2);
787   
788
789     seqNum++;
790
791     
792
793     json::json_pointer p4(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
794     nextPRBBytesDL = all_cells_json[p4].get<int>();    
795     //    cout << std::string("  PRB Bytes DL ") << all_cells_json[p4] << endl;
796
797     json::json_pointer p5(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
798     nextPRBBytesUL = all_cells_json[p5].get<int>();
799     //    cout << std::string("  PRB Bytes UL ") << all_cells_json[p5] << endl;
800
801
802     //REPORT Message 1 -- Encode and send ODU cell-level report
803     
804     E2SM_KPM_IndicationMessage_t *ind_msg1 =
805       (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
806     E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
807     
808     long fiveqi = 7;
809
810     uint8_t *nrcellid_buf = (uint8_t*)"12340";
811     long dl_prbs = nextPRBBytesDL;
812     long ul_prbs = nextPRBBytesUL;
813
814
815     encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
816     
817     uint8_t e2smbuffer[8192];
818     size_t e2smbuffer_size = 8192;
819     
820     asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
821                                              ATS_ALIGNED_BASIC_PER,
822                                              &asn_DEF_E2SM_KPM_IndicationMessage,
823                                              ind_msg1, e2smbuffer, e2smbuffer_size);
824     
825     fprintf(stderr, "er encded is %d\n", er.encoded);
826     fprintf(stderr, "after encoding message\n");
827     uint8_t *e2smheader_buf = (uint8_t*)"";
828     
829     uint8_t *cpid_buf = (uint8_t*)"CPID";
830     
831     fprintf(stderr, "About to encode Indication\n");
832
833 //    generate_e2apv1_indication_request_parameterized(pdu, requestorId,
834 //                                                   instanceId, ranFunctionId,
835 //                                                   actionId, seqNum, e2smheader_buf, 0, e2smbuffer, er.encoded);
836     
837 //                                                   e2sim.encode_and_send_sctp_data(pdu);
838     */
839     seqNum++;
840     
841   }
842
843
844
845   /*
846   if (simfile.is_open()) {
847
848     while (getline(simfile, line)) {
849       cout << line << "\n";
850
851       //REPORT Message 1 -- Encode and send ODU cell-level report
852
853       E2SM_KPM_IndicationMessage_t *ind_msg1 =
854         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
855       E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
856
857       long fiveqi = 7;
858       uint8_t *sst_buf = (uint8_t*)"1";
859       uint8_t *sd_buf = (uint8_t*)"100";
860       uint8_t *plmnid_buf = (uint8_t*)"747";
861       uint8_t *nrcellid_buf = (uint8_t*)"12340";
862       long dl_prbs = 100;
863       long ul_prbs = 50; 
864      
865       encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
866
867       uint8_t e2smbuffer[8192];
868       size_t e2smbuffer_size = 8192;
869       asn_codec_ctx_t *opt_cod;
870
871       asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
872                                                ATS_ALIGNED_BASIC_PER,
873                                                &asn_DEF_E2SM_KPM_IndicationMessage,
874                                                ind_msg1, e2smbuffer, e2smbuffer_size);
875       
876       fprintf(stderr, "er encded is %d\n", er.encoded);
877       fprintf(stderr, "after encoding message\n");
878       uint8_t *e2smheader_buf = (uint8_t*)"header";
879
880       uint8_t *cpid_buf = (uint8_t*)"CPID";
881
882       fprintf(stderr, "About to encode Indication\n");
883       generate_e2apv1_indication_request_parameterized(pdu, requestorId,
884                                                        instanceId, ranFunctionId,
885                                                        actionId, seqNum, e2smheader_buf, 6, e2smbuffer, er.encoded);
886
887       encode_and_send_sctp_data(pdu, socket_fd);
888       
889       seqNum++;
890
891       //REPORT Message 2 -- Encode and send OCUUP cell-level report
892
893       uint8_t *buf = (uint8_t*)"GNBCUUP5";
894
895       int bytes_dl = 40000;
896       int bytes_ul = 50000;
897
898       E2SM_KPM_IndicationMessage_t *ind_msg2 =
899         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
900       E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
901       
902       encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
903
904       uint8_t e2smbuffer2[8192];
905       size_t e2smbuffer_size2 = 8192;
906
907
908       asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
909                                                ATS_ALIGNED_BASIC_PER,
910                                                &asn_DEF_E2SM_KPM_IndicationMessage,
911                                                ind_msg2, e2smbuffer2, e2smbuffer_size2);
912       
913       fprintf(stderr, "er encded is %d\n", er2.encoded);
914       fprintf(stderr, "after encoding message\n");
915       uint8_t *e2smheader_buf2 = (uint8_t*)"header";
916
917       generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
918                                                        instanceId, ranFunctionId,
919                                                        actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
920
921       encode_and_send_sctp_data(pdu2, socket_fd);
922       
923       seqNum++;
924
925       //REPORT Message 3 -- Encode and send OCUCP user-level report
926
927       E2SM_KPM_IndicationMessage_t *ind_msg3 =
928         (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
929       E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
930
931       uint8_t *crnti_buf = (uint8_t*)"12";
932       //      uint8_t *serving_buf = (uint8_t*)"RSRP10";
933       //uint8_t *neighbor_buf = (uint8_t*)"-10,-15";
934       int rsrpServ = 10;
935       int rsrqServ = 0;
936       int rssinrServ = 0;
937
938       std::string serving_str = "{\"rsrp\": " + std::to_string(rsrpServ) + ", \"rsrq\": " +
939         std::to_string(rsrqServ) + ", \"rssinr\": " + std::to_string(rssinrServ) + "}";
940       const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
941
942
943       neighbor_cell_entry n_entries[3];
944       n_entries[0] = {"123", 10, 0, 0};
945       n_entries[1] = {"456", 10, 0, 0};
946       n_entries[2] = {"789", 10, 0, 0};
947
948       std::string neighbor_str = "[";
949
950       for (int i=0; i < sizeof(n_entries)/sizeof(n_entries[0]); i++) {
951
952         if (i != 0) {
953           neighbor_str += ",";
954         }
955         neighbor_str += "{\"CID\" : \"" + std::string(n_entries[i].cellid) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(n_entries[i].rsrp) +
956           ", \"rsrq\": " + std::to_string(n_entries[i].rsrq) + ", \"rssinr\": " + std::to_string(n_entries[i].rsrp) + "}}";
957       }
958
959       neighbor_str += "]";
960
961       const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
962
963       printf("Neighbor string\n%s", neighbor_buf);
964
965       encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
966       
967       uint8_t e2smbuffer3[8192];
968       size_t e2smbuffer_size3 = 8192;
969
970       asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
971                                                 ATS_ALIGNED_BASIC_PER,
972                                                 &asn_DEF_E2SM_KPM_IndicationMessage,
973                                                 ind_msg3, e2smbuffer3, e2smbuffer_size3);
974       
975       fprintf(stderr, "er encded is %d\n", er3.encoded);
976       fprintf(stderr, "after encoding message\n");
977       uint8_t *e2smheader_buf3 = (uint8_t*)"header";
978
979       generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
980                                                        instanceId, ranFunctionId,
981                                                        actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
982
983       encode_and_send_sctp_data(pdu3, socket_fd);
984             
985       seqNum++;
986       
987       //Encode and send OCUUP user-level report
988
989
990       
991       //Encode and send ODU user-level report
992
993       
994
995       
996     }
997
998     simfile.close();
999
1000   }
1001   */
1002
1003 }
1004
1005
1006 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
1007
1008   fprintf(stderr, "Calling callback_kpm_subscription_request\n");
1009
1010   //Record RIC Request ID
1011   //Go through RIC action to be Setup List
1012   //Find first entry with REPORT action Type
1013   //Record ricActionID
1014   //Encode subscription response
1015
1016   RICsubscriptionRequest_t orig_req =
1017     sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1018   
1019   RICsubscriptionResponse_IEs_t *ricreqid =
1020     (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
1021                                            
1022   int count = orig_req.protocolIEs.list.count;
1023   int size = orig_req.protocolIEs.list.size;
1024   
1025   RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
1026
1027   fprintf(stderr, "count%d\n", count);
1028   fprintf(stderr, "size%d\n", size);
1029
1030   RICsubscriptionRequest_IEs__value_PR pres;
1031
1032   long reqRequestorId;
1033   long reqInstanceId;
1034   long reqActionId;
1035
1036   std::vector<long> actionIdsAccept;
1037   std::vector<long> actionIdsReject;
1038
1039   for (int i=0; i < count; i++) {
1040     RICsubscriptionRequest_IEs_t *next_ie = ies[i];
1041     pres = next_ie->value.present;
1042     
1043     fprintf(stderr, "The next present value %d\n", pres);
1044
1045     switch(pres) {
1046     case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
1047       {
1048         fprintf(stderr,"in case request id\n"); 
1049         RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
1050         long requestorId = reqId.ricRequestorID;
1051         long instanceId = reqId.ricInstanceID;
1052         fprintf(stderr, "requestorId %d\n", requestorId);
1053         fprintf(stderr, "instanceId %d\n", instanceId);
1054         reqRequestorId = requestorId;
1055         reqInstanceId = instanceId;
1056
1057         break;
1058       }
1059     case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
1060       {
1061         fprintf(stderr,"in case ran func id\n");        
1062         break;
1063       }
1064     case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
1065       {
1066         fprintf(stderr,"in case subscription details\n");
1067         RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
1068         fprintf(stderr,"in case subscription details 1\n");     
1069         RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
1070         fprintf(stderr,"in case subscription details 2\n");     
1071         RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
1072         fprintf(stderr,"in case subscription details 3\n");
1073         //We are ignoring the trigger definition
1074
1075         //We identify the first action whose type is REPORT
1076         //That is the only one accepted; all others are rejected
1077         
1078         int actionCount = actionList.list.count;
1079         fprintf(stderr, "action count%d\n", actionCount);
1080
1081         auto **item_array = actionList.list.array;
1082
1083         bool foundAction = false;
1084
1085         for (int i=0; i < actionCount; i++) {
1086
1087           auto *next_item = item_array[i];
1088           RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1089           RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
1090
1091           if (!foundAction && actionType == RICactionType_report) {
1092             reqActionId = actionId;
1093             actionIdsAccept.push_back(reqActionId);
1094             printf("adding accept\n");
1095             foundAction = true;
1096           } else {
1097             reqActionId = actionId;
1098             printf("adding reject\n");
1099             actionIdsReject.push_back(reqActionId);
1100           }
1101         }
1102         
1103         break;
1104       }
1105     default:
1106       {
1107         fprintf(stderr,"in case default\n");    
1108         break;
1109       }      
1110     }
1111     
1112   }
1113
1114   fprintf(stderr, "After Processing Subscription Request\n");
1115
1116   fprintf(stderr, "requestorId %d\n", reqRequestorId);
1117   fprintf(stderr, "instanceId %d\n", reqInstanceId);
1118
1119
1120   for (int i=0; i < actionIdsAccept.size(); i++) {
1121     fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
1122     
1123   }
1124
1125   E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
1126
1127   long *accept_array = &actionIdsAccept[0];
1128   long *reject_array = &actionIdsReject[0];
1129   int accept_size = actionIdsAccept.size();
1130   int reject_size = actionIdsReject.size();
1131
1132   encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
1133
1134   e2sim.encode_and_send_sctp_data(e2ap_pdu);
1135
1136   //Start thread for sending REPORT messages
1137
1138   //  std::thread loop_thread;
1139
1140   long funcId = 1;
1141
1142   run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
1143
1144   //  loop_thread = std::thread(&run_report_loop);
1145
1146 }