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 #include "viavi_connector.hpp"
55 using json = nlohmann::json;
63 int main(int argc, char* argv[]) {
65 fprintf(stderr, "Starting KPM processor sim");
67 fprintf(stderr, "JSON Test\n");
69 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
70 nrcellid_buf[0] = 0x22;
71 nrcellid_buf[1] = 0x5B;
72 nrcellid_buf[2] = 0xD6;
73 nrcellid_buf[3] = 0x00;
74 nrcellid_buf[4] = 0x70;
78 asn_codec_ctx_t *opt_cod;
80 E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
81 (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
82 encode_kpm_function_description(ranfunc_desc);
84 uint8_t e2smbuffer[8192] = {0, };
85 size_t e2smbuffer_size = 8192;
88 asn_encode_to_buffer(opt_cod,
89 ATS_ALIGNED_BASIC_PER,
90 &asn_DEF_E2SM_KPM_RANfunction_Description,
91 ranfunc_desc, e2smbuffer, e2smbuffer_size);
93 fprintf(stderr, "er encded is %d\n", er.encoded);
94 fprintf(stderr, "after encoding message\n");
95 fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
97 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
98 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
100 printf("this is the char array %s\n", (char*)ranfuncdesc);
102 OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
103 ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
104 ranfunc_ostr->size = er.encoded;
105 memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
107 printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
108 printf("value of this index is %d\n", ranfuncdesc[0]);
109 printf("value of this index is %d\n", ranfuncdesc[1]);
110 printf("value of this index is %d\n", ranfuncdesc[2]);
111 printf("value of this index is %d\n", ranfuncdesc[3]);
112 printf("value of this index is %d\n", ranfuncdesc[4]);
113 printf("value of this index is %d\n", ranfuncdesc[5]);
114 printf("value of this index is %d\n", ranfuncdesc[6]);
115 printf("value of this index is %d\n", ranfuncdesc[10]);
116 printf("value of this index is %d\n", ranfuncdesc[15]);
117 printf("value of this index is %d\n", ranfuncdesc[100]);
118 printf("value of this index is %d\n", ranfuncdesc[101]);
120 e2sim.register_e2sm(0,ranfunc_ostr);
121 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
123 e2sim.run_loop(argc, argv);
127 void get_cell_id(uint8_t *nrcellid_buf, char *cid_return_buf) {
129 uint8_t nr0 = nrcellid_buf[0] >> 4;
130 uint8_t nr1 = nrcellid_buf[0] << 4;
133 uint8_t nr2 = nrcellid_buf[1] >> 4;
134 uint8_t nr3 = nrcellid_buf[1] << 4;
137 uint8_t nr4 = nrcellid_buf[2] >> 4;
138 uint8_t nr5 = nrcellid_buf[2] << 4;
141 uint8_t nr6 = nrcellid_buf[3] >> 4;
142 uint8_t nr7 = nrcellid_buf[3] << 4;
145 uint8_t nr8 = nrcellid_buf[4] >> 4;
147 sprintf(cid_return_buf, "373437%d%d%d%d%d%d%d%d%d", nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8);
151 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId)
153 std::filebuf reports_json;
154 std::streambuf *input_filebuf = &reports_json;
156 std::unique_ptr<viavi::RICTesterReceiver> viavi_connector;
157 if (!reports_json.open("/playpen/src/reports.json", std::ios::in)) {
158 std::cerr << "Can't open reports.json, enabling VIAVI connector instead..." << endl;
159 viavi_connector.reset(new viavi::RICTesterReceiver {3001, nullptr});
160 input_filebuf = viavi_connector->get_data_filebuf();
163 std::istream input {input_filebuf};
169 while ( getline(input, str) ) {
176 uint8_t *plmnid_buf = (uint8_t*)"747";
177 uint8_t *sst_buf = (uint8_t*)"1";
178 uint8_t *sd_buf = (uint8_t*)"100";
181 fprintf(stderr,"De line is %s\n", str.c_str());
186 all_ues_json = json::parse(str);
190 fprintf(stderr, "Exception on reading json\n");
195 fprintf(stderr, "key is valid\n");
197 std::string first_key = all_ues_json.begin().key();
198 fprintf(stderr, "first key is %s\n", first_key.c_str());
200 if (first_key.compare("ueMeasReport") == 0) {
202 fprintf(stderr, "it is equal to ue meas report\n");
204 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
207 for (int i = 0; i < numMeasReports; i++) {
216 fprintf(stderr,"UE number %d\n", i);
218 json::json_pointer p001(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/ue-id");
219 ueId = all_ues_json[p001].get<std::string>();
220 fprintf(stderr, "UEID %s\n", ueId.c_str());
222 json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
223 tput = all_ues_json[p0].get<float>();
224 fprintf(stderr, "Throughput %f\n", tput);
226 json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
227 prb_usage = all_ues_json[p00].get<int>();
228 fprintf(stderr, "Throughput %d\n", prb_usage);
230 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
231 nextCellId = all_ues_json[p1].get<int>();
232 fprintf(stderr, "Serving Cell %d\n",nextCellId);
234 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
235 nextRsrp = all_ues_json[p2].get<int>();
236 fprintf(stderr," RSRP %d\n", nextRsrp);
238 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
239 nextRsrq = all_ues_json[p3].get<int>();
240 fprintf(stderr," RSRQ %d\n",nextRsrq);
242 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
243 nextRssinr = all_ues_json[p4].get<int>();
244 fprintf(stderr," RSSINR %d\n", nextRssinr);
246 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
248 uint8_t crnti_buf[3] = {0, };
250 if (ueId.find("Pedestrian") != string::npos) {
251 std::string ind = ueId.substr(11);
252 fprintf(stderr, "ind is %s\n", ind.c_str());
254 int indval = std::stoi(ind);
257 crnti_buf[1] = indval;
260 crnti_buf[0] = indval/10;
261 crnti_buf[1] = indval % 10;
264 } else if (ueId.find("Car") != string::npos) {
269 // uint8_t *buf2 = (uint8_t*)"12";
271 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
272 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
273 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
275 int numNeighborCells = (all_ues_json[p5]).size();
277 std::string neighbor_str = "[";
284 for (int j = 0; j < numNeighborCells; j++) {
285 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
286 nextNbCell = all_ues_json[p8].get<int>();
287 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
288 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
289 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
290 nextNbRsrp = all_ues_json[p9].get<int>();
291 //cout << " RSRP " << nextNbRsrp << endl;
293 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
294 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
295 nextNbRsrq = all_ues_json[p10].get<int>();
296 //cout << " RSRQ " << nextNbRsrq << endl;
298 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
299 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
300 nextNbRssinr = all_ues_json[p11].get<int>();
301 //cout << " RSSINR " << nextNbRssinr << endl;
309 uint8_t neighbor_cellid_buf[6] = {0, };
310 neighbor_cellid_buf[0] = 0x22;
311 neighbor_cellid_buf[1] = 0x5B;
312 neighbor_cellid_buf[2] = 0xD6;
313 neighbor_cellid_buf[3] = nextNbCell;
314 neighbor_cellid_buf[4] = 0x70;
316 char cid_buf[25] = {0, };
317 get_cell_id(neighbor_cellid_buf,cid_buf);
320 neighbor_str += "{\"CID\" : \"" + std::string(cid_buf) + "\", \"Cell-RF\" : {\"rsrp\": " + std::to_string(nextNbRsrp) +
321 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
327 fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
329 //Creating UE-level RAN-Container CUCP message
331 fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
333 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
336 uint8_t nrcellid_buf[6] = {0, };
337 nrcellid_buf[0] = 0x22;
338 nrcellid_buf[1] = 0x5B;
339 nrcellid_buf[2] = 0xD6;
340 nrcellid_buf[3] = nextCellId;
341 nrcellid_buf[4] = 0x70;
343 uint8_t gnbid_buf[4] = {0, };
348 uint8_t cuupid_buf[2] = {0, };
349 cuupid_buf[0] = 20000;
351 uint8_t duid_buf[2] = {0, };
354 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
357 E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
358 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
360 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
362 uint8_t e2sm_message_buf_cucp_ue[8192] = {0, };
363 size_t e2sm_message_buf_size_cucp_ue = 8192;
365 asn_codec_ctx_t *opt_cod;
368 asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
369 ATS_ALIGNED_BASIC_PER,
370 &asn_DEF_E2SM_KPM_IndicationMessage,
371 ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
372 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cucp_ue);
374 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
375 fprintf(stderr, "after encoding message\n");
377 E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
378 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
379 encode_e2sm_kpm_indication_header(ind_header_cucp_ue, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
380 fprintf(stderr, "Now printing xer outside of function call\n");
381 xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
383 uint8_t e2sm_header_buf_cucp_ue[8192] = {0, };
384 size_t e2sm_header_buf_size_cucp_ue = 8192;
386 asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
387 ATS_ALIGNED_BASIC_PER,
388 &asn_DEF_E2SM_KPM_IndicationHeader,
389 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
390 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
392 fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
393 fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
394 fprintf(stderr, "after encoding header\n");
396 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
398 encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
399 instanceId, ranFunctionId,
400 actionId, seqNum, e2sm_header_buf_cucp_ue,
401 er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
402 er_message_cucp_ue.encoded);
405 e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
409 std::this_thread::sleep_for (std::chrono::milliseconds(50));
411 //Creating UE-level RAN-Container CUUP message
413 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
415 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
416 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
418 long bytes = (long)(tput * 100);
420 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
422 uint8_t e2sm_message_buf_cuup_ue[8192] = {0, };
423 size_t e2sm_message_buf_size_cuup_ue = 8192;
425 asn_codec_ctx_t *opt_cod2;
428 asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
429 ATS_ALIGNED_BASIC_PER,
430 &asn_DEF_E2SM_KPM_IndicationMessage,
431 ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
432 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cuup_ue);
434 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
435 fprintf(stderr, "after encoding message\n");
437 E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
438 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
439 encode_e2sm_kpm_indication_header(ind_header_cuup_ue, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
441 uint8_t e2sm_header_buf_cuup_ue[8192] = {0, };
442 size_t e2sm_header_buf_size_cuup_ue = 8192;
444 asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
445 ATS_ALIGNED_BASIC_PER,
446 &asn_DEF_E2SM_KPM_IndicationHeader,
447 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
448 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cuup_ue);
451 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
453 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
454 instanceId, ranFunctionId,
455 actionId, seqNum, e2sm_header_buf_cuup_ue,
456 er_header_cuup_ue.encoded,
457 e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
459 e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
463 std::this_thread::sleep_for (std::chrono::milliseconds(50));
465 //Creating UE-level RAN-Container DU message
467 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
469 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
470 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
472 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
473 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
475 uint8_t e2sm_message_buf_du_ue[8192] = {0, };
476 size_t e2sm_message_buf_size_du_ue = 8192;
478 asn_codec_ctx_t *opt_cod3;
481 asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
482 ATS_ALIGNED_BASIC_PER,
483 &asn_DEF_E2SM_KPM_IndicationMessage,
485 e2sm_message_buf_du_ue,
486 e2sm_message_buf_size_du_ue);
487 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_du_ue);
489 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
490 fprintf(stderr, "after encoding message\n");
492 E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
493 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
494 encode_e2sm_kpm_indication_header(ind_header_du_ue, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
496 uint8_t e2sm_header_buf_du_ue[8192] = {0, };
497 size_t e2sm_header_buf_size_du_ue = 8192;
499 asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
500 ATS_ALIGNED_BASIC_PER,
501 &asn_DEF_E2SM_KPM_IndicationHeader,
502 ind_header_du_ue, e2sm_header_buf_du_ue,
503 e2sm_header_buf_size_du_ue);
504 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_du_ue);
507 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
509 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
510 instanceId, ranFunctionId,
512 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
513 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
515 e2sim.encode_and_send_sctp_data(pdu_du_ue);
519 std::this_thread::sleep_for (std::chrono::milliseconds(50));
521 fprintf(stderr, "done with ue meas report\n");
524 } else if (first_key.compare("cellMeasReport") == 0) {
526 fprintf(stderr, "it is equal to cell meas report\n");
528 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
530 for (int i = 0; i < numMeasReports; i++) {
539 fprintf(stderr,"UE number %d\n", i);
541 json::json_pointer p00(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
542 cellid = all_ues_json[p00].get<int>();
543 fprintf(stderr, "Cell ID %d\n", cellid);
545 json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
546 bytes_dl = all_ues_json[p0].get<float>();
547 fprintf(stderr, "Bytes DL %f\n", bytes_dl);
549 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
550 bytes_ul = all_ues_json[p1].get<float>();
551 fprintf(stderr, "Bytes UL %f\n", bytes_ul);
553 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
554 prb_dl = all_ues_json[p2].get<int>();
555 fprintf(stderr, "Avail PRB DL %d\n", prb_dl);
557 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
558 prb_ul = all_ues_json[p3].get<int>();
559 fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
562 uint8_t *sst_buf = (uint8_t*)"1";
563 uint8_t *sd_buf = (uint8_t*)"100";
564 uint8_t *plmnid_buf = (uint8_t*)"747";
566 uint8_t nrcellid_buf[6] = {0, };
567 nrcellid_buf[0] = 0x22;
568 nrcellid_buf[1] = 0x5B;
569 nrcellid_buf[2] = 0xD6;
570 nrcellid_buf[3] = cellid;
571 nrcellid_buf[4] = 0x70;
573 uint8_t gnbid_buf[4] = {0, };
578 uint8_t cuupid_buf[2] = {0, };
579 cuupid_buf[0] = 20000;
581 uint8_t duid_buf[2] = {0, };
584 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
587 //Encoding Style 5 Message Body
589 fprintf(stderr, "Encoding Style 5 Message body\n");
591 asn_codec_ctx_t *opt_cod;
593 E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
594 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
595 E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
597 encode_kpm_report_style5_parameterized(ind_msg_style5 , cuupname_buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
599 uint8_t e2sm_message_buf_style5[8192] = {0, };
600 size_t e2sm_message_buf_size_style5 = 8192;
602 asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
603 ATS_ALIGNED_BASIC_PER,
604 &asn_DEF_E2SM_KPM_IndicationMessage,
605 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
606 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_style5);
608 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
609 fprintf(stderr, "after encoding message\n");
614 E2SM_KPM_IndicationHeader_t* ind_header_style5 =
615 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
616 encode_e2sm_kpm_indication_header(ind_header_style5, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
618 uint8_t e2sm_header_buf_style5[8192] = {0, };
619 size_t e2sm_header_buf_size_style5 = 8192;
621 asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
622 ATS_ALIGNED_BASIC_PER,
623 &asn_DEF_E2SM_KPM_IndicationHeader,
625 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
626 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style5);
629 encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
630 instanceId, ranFunctionId,
631 actionId, seqNum0, e2sm_header_buf_style5,
632 er_header_style5.encoded, e2sm_message_buf_style5,
633 er_message_style5.encoded);
635 e2sim.encode_and_send_sctp_data(pdu_style5);
639 std::this_thread::sleep_for (std::chrono::milliseconds(50));
642 //Encoding Style 1 Message Body
644 fprintf(stderr, "Encoding Style 1 Message body\n");
645 asn_codec_ctx_t *opt_cod2;
648 E2SM_KPM_IndicationMessage_t *ind_message_style1 =
649 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
650 E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
656 long *l_dl_prbs = (long*)calloc(1, sizeof(long));
657 long *l_ul_prbs = (long*)calloc(1, sizeof(long));
658 *l_dl_prbs = (long)prb_dl;
659 *l_ul_prbs = (long)prb_ul;
661 encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
662 prb_dl, prb_ul, sst_buf, sd_buf,
663 plmnid_buf, nrcellid_buf, l_dl_prbs, l_ul_prbs);
665 uint8_t e2sm_message_buf_style1[8192] = {0, };
666 size_t e2sm_message_buf_size_style1 = 8192;
668 asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
669 ATS_ALIGNED_BASIC_PER,
670 &asn_DEF_E2SM_KPM_IndicationMessage,
672 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
673 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_style1);
675 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
676 fprintf(stderr, "after encoding message\n");
679 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
681 fprintf(stderr, "About to encode Indication\n");
683 E2SM_KPM_IndicationHeader_t* ind_header_style1 =
684 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
685 encode_e2sm_kpm_indication_header(ind_header_style1, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
687 uint8_t e2sm_header_buf_style1[8192] = {0, };
688 size_t e2sm_header_buf_size_style1 = 8192;
690 asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
691 ATS_ALIGNED_BASIC_PER,
692 &asn_DEF_E2SM_KPM_IndicationHeader,
694 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
695 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style1);
697 encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
698 instanceId, ranFunctionId,
699 actionId, seqNum, e2sm_header_buf_style1,
700 er_header_style1.encoded,
701 e2sm_message_buf_style1, er_message_style1.encoded);
703 e2sim.encode_and_send_sctp_data(pdu_style1);
705 std::this_thread::sleep_for (std::chrono::milliseconds(50));
714 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
716 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
718 //Record RIC Request ID
719 //Go through RIC action to be Setup List
720 //Find first entry with REPORT action Type
722 //Encode subscription response
724 RICsubscriptionRequest_t orig_req =
725 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
727 RICsubscriptionResponse_IEs_t *ricreqid =
728 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
730 int count = orig_req.protocolIEs.list.count;
731 int size = orig_req.protocolIEs.list.size;
733 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
735 fprintf(stderr, "count%d\n", count);
736 fprintf(stderr, "size%d\n", size);
738 RICsubscriptionRequest_IEs__value_PR pres;
744 std::vector<long> actionIdsAccept;
745 std::vector<long> actionIdsReject;
747 for (int i=0; i < count; i++) {
748 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
749 pres = next_ie->value.present;
751 fprintf(stderr, "The next present value %d\n", pres);
754 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
756 fprintf(stderr,"in case request id\n");
757 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
758 long requestorId = reqId.ricRequestorID;
759 long instanceId = reqId.ricInstanceID;
760 fprintf(stderr, "requestorId %d\n", requestorId);
761 fprintf(stderr, "instanceId %d\n", instanceId);
762 reqRequestorId = requestorId;
763 reqInstanceId = instanceId;
767 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
769 fprintf(stderr,"in case ran func id\n");
772 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
774 fprintf(stderr,"in case subscription details\n");
775 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
776 fprintf(stderr,"in case subscription details 1\n");
777 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
778 fprintf(stderr,"in case subscription details 2\n");
779 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
780 fprintf(stderr,"in case subscription details 3\n");
781 //We are ignoring the trigger definition
783 //We identify the first action whose type is REPORT
784 //That is the only one accepted; all others are rejected
786 int actionCount = actionList.list.count;
787 fprintf(stderr, "action count%d\n", actionCount);
789 auto **item_array = actionList.list.array;
791 bool foundAction = false;
793 for (int i=0; i < actionCount; i++) {
795 auto *next_item = item_array[i];
796 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
797 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
799 if (!foundAction && actionType == RICactionType_report) {
800 reqActionId = actionId;
801 actionIdsAccept.push_back(reqActionId);
802 printf("adding accept\n");
805 reqActionId = actionId;
806 printf("adding reject\n");
807 actionIdsReject.push_back(reqActionId);
815 fprintf(stderr,"in case default\n");
822 fprintf(stderr, "After Processing Subscription Request\n");
824 fprintf(stderr, "requestorId %d\n", reqRequestorId);
825 fprintf(stderr, "instanceId %d\n", reqInstanceId);
828 for (int i=0; i < actionIdsAccept.size(); i++) {
829 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
833 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
835 long *accept_array = &actionIdsAccept[0];
836 long *reject_array = &actionIdsReject[0];
837 int accept_size = actionIdsAccept.size();
838 int reject_size = actionIdsReject.size();
840 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
842 e2sim.encode_and_send_sctp_data(e2ap_pdu);
844 //Start thread for sending REPORT messages
846 // std::thread loop_thread;
850 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
852 // loop_thread = std::thread(&run_report_loop);