1 /*****************************************************************************
3 # Copyright 2020 AT&T Intellectual Property *
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 *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
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. *
17 ******************************************************************************/
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"
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"
44 #include "kpm_callbacks.hpp"
45 #include "encode_kpm.hpp"
47 #include "encode_e2apv1.hpp"
49 #include <nlohmann/json.hpp>
53 using json = nlohmann::json;
61 int main(int argc, char* argv[]) {
63 fprintf(stderr, "Starting KPM processor sim");
65 fprintf(stderr, "JSON Test\n");
67 std::ifstream input("/playpen/src/reports.json");
68 bool x = input.good();
70 fprintf(stderr, "%s\n", x ? "true" : "false");
77 while ( getline(input, str) ) {
81 fprintf(stderr,"De line is %s\n", str.c_str());
86 all_ues_json = json::parse(str);
90 fprintf(stderr, "Exception on reading json\n");
95 fprintf(stderr, "key is valid\n");
97 std::string first_key = all_ues_json.begin().key();
98 fprintf(stderr, "first key is %s\n", first_key.c_str());
100 if (first_key.compare("ueMeasReport") == 0) {
102 fprintf(stderr, "it is equal to ue meas report\n");
104 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
107 for (int i = 0; i < numMeasReports; i++) {
114 fprintf(stderr,"UE number %d\n", i);
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);
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);
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);
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);
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);
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);
140 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
142 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
144 uint8_t *buf2 = (uint8_t*)"12";
145 memcpy(crnti_buf, buf2, 2);
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());
152 int numNeighborCells = (all_ues_json[p5]).size();
154 std::string neighbor_str = "[";
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;
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;
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;
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) + "}}";
192 fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
194 //Creating UE-level RAN-Container CUCP message
196 fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
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";
202 E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
203 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
205 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
207 uint8_t e2sm_message_buf_cucp_ue[8192];
208 size_t e2sm_message_buf_size_cucp_ue = 8192;
210 asn_codec_ctx_t *opt_cod;
212 long requestorId = 9;
214 long ranFunctionId = 2;
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);
222 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
223 fprintf(stderr, "after encoding message\n");
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);
229 uint8_t e2sm_header_buf_cucp_ue[8192];
230 size_t e2sm_header_buf_size_cucp_ue = 8192;
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);
237 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
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);
245 // e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
247 //Creating UE-level RAN-Container CUUP message
249 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
251 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
252 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
254 long bytes = (long)(tput * 100);
256 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
258 uint8_t e2sm_message_buf_cuup_ue[8192];
259 size_t e2sm_message_buf_size_cuup_ue = 8192;
261 asn_codec_ctx_t *opt_cod2;
263 long requestorId2 = 9;
264 long instanceId2 = 8;
265 long ranFunctionId2 = 2;
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);
273 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
274 fprintf(stderr, "after encoding message\n");
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);
280 uint8_t e2sm_header_buf_cuup_ue[8192];
281 size_t e2sm_header_buf_size_cuup_ue = 8192;
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);
289 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
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);
297 //Creating UE-level RAN-Container DU message
299 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
301 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
302 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
304 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
305 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
307 uint8_t e2sm_message_buf_du_ue[8192];
308 size_t e2sm_message_buf_size_du_ue = 8192;
310 asn_codec_ctx_t *opt_cod3;
312 long requestorId3 = 9;
313 long instanceId3 = 8;
314 long ranFunctionId3 = 2;
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,
321 e2sm_message_buf_du_ue,
322 e2sm_message_buf_size_du_ue);
324 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
325 fprintf(stderr, "after encoding message\n");
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);
331 uint8_t e2sm_header_buf_du_ue[8192];
332 size_t e2sm_header_buf_size_du_ue = 8192;
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);
341 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
343 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId3,
344 instanceId3, ranFunctionId3,
346 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
347 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
349 fprintf(stderr, "done with ue meas report\n");
352 } else if (first_key.compare("cellMeasReport") == 0) {
354 fprintf(stderr, "it is equal to cell meas report\n");
356 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
358 for (int i = 0; i < numMeasReports; i++) {
366 fprintf(stderr,"UE number %d\n", i);
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);
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);
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);
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);
384 uint8_t *buf = (uint8_t*)"GNBCUUP5";
386 uint8_t *sst_buf = (uint8_t*)"1";
387 uint8_t *sd_buf = (uint8_t*)"100";
388 uint8_t *plmnid_buf = (uint8_t*)"747";
391 //Encoding Style 5 Message Body
393 fprintf(stderr, "Encoding Style 5 Message body\n");
395 asn_codec_ctx_t *opt_cod;
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));
401 encode_kpm_report_style5_parameterized(ind_msg_style5 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
403 uint8_t e2sm_message_buf_style5[8192];
404 size_t e2sm_message_buf_size_style5 = 8192;
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);
411 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
412 fprintf(stderr, "after encoding message\n");
415 // encode_kpm_indication_header();
419 long requestorId = 9;
421 long ranFunctionId = 2;
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);
428 uint8_t e2sm_header_buf_style5[8192];
429 size_t e2sm_header_buf_size_style5 = 8192;
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,
435 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
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);
444 // e2sim.encode_and_send_sctp_data(pdu2);
446 //Encoding Style 1 Message Body
448 fprintf(stderr, "Encoding Style 1 Message body\n");
449 asn_codec_ctx_t *opt_cod2;
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));
458 uint8_t *nrcellid_buf = (uint8_t*)"12340";
460 long l_dl_prbs = prb_dl;
461 long l_ul_prbs = prb_ul;
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);
467 uint8_t e2sm_message_buf_style1[8192];
468 size_t e2sm_message_buf_size_style1 = 8192;
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,
474 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
476 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
477 fprintf(stderr, "after encoding message\n");
480 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
482 fprintf(stderr, "About to encode Indication\n");
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);
488 uint8_t e2sm_header_buf_style1[8192];
489 size_t e2sm_header_buf_size_style1 = 8192;
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,
495 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
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);
503 // e2sim.encode_and_send_sctp_data(pdu);
512 asn_codec_ctx_t *opt_cod;
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);
518 uint8_t e2smbuffer[8192];
519 size_t e2smbuffer_size = 8192;
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);
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);
531 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
532 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
534 printf("this is the char array %s\n", (char*)ranfuncdesc);
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);
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]);
554 e2sim.register_e2sm(0,ranfunc_ostr);
555 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
557 e2sim.run_loop(argc, argv);
563 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
565 //Process simulation file
572 simfile.open("simulation.txt", ios::in);
574 // cout << "step1" << endl;
576 std::ifstream ue_stream("/playpen/src/ueMeasReport.txt");
577 std::ifstream cell_stream("/playpen/src/cellMeasReport.txt");
581 ue_stream >> all_ues_json;
585 cell_stream >> all_cells_json;
587 asn_codec_ctx_t *opt_cod;
589 // cout << "UE RF Measurements" << endl;
590 // cout << "******************" << endl;
592 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
594 for (int i = 0; i < numMeasReports; i++) {
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;
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;
615 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
617 int numNeighborCells = (all_ues_json[p5]).size();
620 //REPORT Message 3 -- Encode and send OCUCP user-level report
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));
626 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
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);
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());
640 std::string neighbor_str = "[";
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;
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;
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;
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) + "}}";
678 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
680 // printf("Neighbor string\n%s", neighbor_buf);
682 uint8_t *plmnid_buf = (uint8_t*)"747";
683 uint8_t *nrcellid_buf = (uint8_t*)"12340";
686 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
688 uint8_t e2smbuffer3[8192];
689 size_t e2smbuffer_size3 = 8192;
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);
697 fprintf(stderr, "er encded is %d\n", er3.encoded);
698 fprintf(stderr, "after encoding message\n");
699 uint8_t *e2smheader_buf3 = (uint8_t*)"";
701 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
702 instanceId, ranFunctionId,
703 actionId, seqNum, e2smheader_buf3, 0, e2smbuffer3, er3.encoded);
705 e2sim.encode_and_send_sctp_data(pdu3);
713 // cout << "Cell Measurements" << endl;
714 // cout << "******************" << endl;
716 int numCellMeasReports = (all_cells_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
718 uint8_t *sst_buf = (uint8_t*)"1";
719 uint8_t *sd_buf = (uint8_t*)"100";
720 uint8_t *plmnid_buf = (uint8_t*)"747";
722 for (int i = 0; i < numCellMeasReports; i++) {
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;
737 // cout << "**********" << endl;
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;
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;
747 uint8_t *buf = (uint8_t*)"GNBCUUP5";
749 int bytes_dl = nextPdcpBytesDL;
750 //int bytes_dl = 1250;
752 int bytes_ul = nextPdcpBytesUL;
753 //int bytes_ul = 1450;
755 // int bytes_dl = 3905;
756 // int bytes_ul = 1609321;
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));
762 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
764 uint8_t e2smbuffer2[8192];
765 size_t e2smbuffer_size2 = 8192;
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);
772 fprintf(stderr, "er encded is %d\n", er2.encoded);
773 fprintf(stderr, "after encoding message\n");
776 // encode_kpm_indication_header();
780 // fprintf(stderr, "i is %d\n", i);
782 // encoding::generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
783 // instanceId, ranFunctionId,
784 // actionId, seqNum0, e2sm_header_buffer, er4.encoded, e2smbuffer2, er2.encoded);
786 // e2sim.encode_and_send_sctp_data(pdu2);
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;
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;
802 //REPORT Message 1 -- Encode and send ODU cell-level report
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));
810 uint8_t *nrcellid_buf = (uint8_t*)"12340";
811 long dl_prbs = nextPRBBytesDL;
812 long ul_prbs = nextPRBBytesUL;
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);
817 uint8_t e2smbuffer[8192];
818 size_t e2smbuffer_size = 8192;
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);
825 fprintf(stderr, "er encded is %d\n", er.encoded);
826 fprintf(stderr, "after encoding message\n");
827 uint8_t *e2smheader_buf = (uint8_t*)"";
829 uint8_t *cpid_buf = (uint8_t*)"CPID";
831 fprintf(stderr, "About to encode Indication\n");
833 // generate_e2apv1_indication_request_parameterized(pdu, requestorId,
834 // instanceId, ranFunctionId,
835 // actionId, seqNum, e2smheader_buf, 0, e2smbuffer, er.encoded);
837 // e2sim.encode_and_send_sctp_data(pdu);
846 if (simfile.is_open()) {
848 while (getline(simfile, line)) {
849 cout << line << "\n";
851 //REPORT Message 1 -- Encode and send ODU cell-level report
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));
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";
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);
867 uint8_t e2smbuffer[8192];
868 size_t e2smbuffer_size = 8192;
869 asn_codec_ctx_t *opt_cod;
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);
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";
880 uint8_t *cpid_buf = (uint8_t*)"CPID";
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);
887 encode_and_send_sctp_data(pdu, socket_fd);
891 //REPORT Message 2 -- Encode and send OCUUP cell-level report
893 uint8_t *buf = (uint8_t*)"GNBCUUP5";
895 int bytes_dl = 40000;
896 int bytes_ul = 50000;
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));
902 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
904 uint8_t e2smbuffer2[8192];
905 size_t e2smbuffer_size2 = 8192;
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);
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";
917 generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
918 instanceId, ranFunctionId,
919 actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
921 encode_and_send_sctp_data(pdu2, socket_fd);
925 //REPORT Message 3 -- Encode and send OCUCP user-level report
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));
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";
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());
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};
948 std::string neighbor_str = "[";
950 for (int i=0; i < sizeof(n_entries)/sizeof(n_entries[0]); i++) {
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) + "}}";
961 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
963 printf("Neighbor string\n%s", neighbor_buf);
965 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
967 uint8_t e2smbuffer3[8192];
968 size_t e2smbuffer_size3 = 8192;
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);
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";
979 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
980 instanceId, ranFunctionId,
981 actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
983 encode_and_send_sctp_data(pdu3, socket_fd);
987 //Encode and send OCUUP user-level report
991 //Encode and send ODU user-level report
1006 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
1008 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
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
1016 RICsubscriptionRequest_t orig_req =
1017 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1019 RICsubscriptionResponse_IEs_t *ricreqid =
1020 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
1022 int count = orig_req.protocolIEs.list.count;
1023 int size = orig_req.protocolIEs.list.size;
1025 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
1027 fprintf(stderr, "count%d\n", count);
1028 fprintf(stderr, "size%d\n", size);
1030 RICsubscriptionRequest_IEs__value_PR pres;
1032 long reqRequestorId;
1036 std::vector<long> actionIdsAccept;
1037 std::vector<long> actionIdsReject;
1039 for (int i=0; i < count; i++) {
1040 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
1041 pres = next_ie->value.present;
1043 fprintf(stderr, "The next present value %d\n", pres);
1046 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
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;
1059 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
1061 fprintf(stderr,"in case ran func id\n");
1064 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
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
1075 //We identify the first action whose type is REPORT
1076 //That is the only one accepted; all others are rejected
1078 int actionCount = actionList.list.count;
1079 fprintf(stderr, "action count%d\n", actionCount);
1081 auto **item_array = actionList.list.array;
1083 bool foundAction = false;
1085 for (int i=0; i < actionCount; i++) {
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;
1091 if (!foundAction && actionType == RICactionType_report) {
1092 reqActionId = actionId;
1093 actionIdsAccept.push_back(reqActionId);
1094 printf("adding accept\n");
1097 reqActionId = actionId;
1098 printf("adding reject\n");
1099 actionIdsReject.push_back(reqActionId);
1107 fprintf(stderr,"in case default\n");
1114 fprintf(stderr, "After Processing Subscription Request\n");
1116 fprintf(stderr, "requestorId %d\n", reqRequestorId);
1117 fprintf(stderr, "instanceId %d\n", reqInstanceId);
1120 for (int i=0; i < actionIdsAccept.size(); i++) {
1121 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
1125 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
1127 long *accept_array = &actionIdsAccept[0];
1128 long *reject_array = &actionIdsReject[0];
1129 int accept_size = actionIdsAccept.size();
1130 int reject_size = actionIdsReject.size();
1132 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
1134 e2sim.encode_and_send_sctp_data(e2ap_pdu);
1136 //Start thread for sending REPORT messages
1138 // std::thread loop_thread;
1142 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
1144 // loop_thread = std::thread(&run_report_loop);