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 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
68 nrcellid_buf[0] = 0x22;
69 nrcellid_buf[1] = 0x5B;
70 nrcellid_buf[2] = 0xD6;
71 nrcellid_buf[3] = 0x00;
72 nrcellid_buf[4] = 0x70;
76 asn_codec_ctx_t *opt_cod;
78 E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
79 (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
80 encode_kpm_function_description(ranfunc_desc);
82 uint8_t e2smbuffer[8192];
83 size_t e2smbuffer_size = 8192;
86 asn_encode_to_buffer(opt_cod,
87 ATS_ALIGNED_BASIC_PER,
88 &asn_DEF_E2SM_KPM_RANfunction_Description,
89 ranfunc_desc, e2smbuffer, e2smbuffer_size);
91 fprintf(stderr, "er encded is %d\n", er.encoded);
92 fprintf(stderr, "after encoding message\n");
93 fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
95 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
96 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
98 printf("this is the char array %s\n", (char*)ranfuncdesc);
100 OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
101 ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
102 ranfunc_ostr->size = er.encoded;
103 memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
105 printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
106 printf("value of this index is %d\n", ranfuncdesc[0]);
107 printf("value of this index is %d\n", ranfuncdesc[1]);
108 printf("value of this index is %d\n", ranfuncdesc[2]);
109 printf("value of this index is %d\n", ranfuncdesc[3]);
110 printf("value of this index is %d\n", ranfuncdesc[4]);
111 printf("value of this index is %d\n", ranfuncdesc[5]);
112 printf("value of this index is %d\n", ranfuncdesc[6]);
113 printf("value of this index is %d\n", ranfuncdesc[10]);
114 printf("value of this index is %d\n", ranfuncdesc[15]);
115 printf("value of this index is %d\n", ranfuncdesc[100]);
116 printf("value of this index is %d\n", ranfuncdesc[101]);
118 e2sim.register_e2sm(0,ranfunc_ostr);
119 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
121 e2sim.run_loop(argc, argv);
125 void get_cell_id(uint8_t *nrcellid_buf, char *cid_return_buf) {
127 uint8_t nr0 = nrcellid_buf[0] >> 4;
128 uint8_t nr1 = nrcellid_buf[0] << 4;
131 uint8_t nr2 = nrcellid_buf[1] >> 4;
132 uint8_t nr3 = nrcellid_buf[1] << 4;
135 uint8_t nr4 = nrcellid_buf[2] >> 4;
136 uint8_t nr5 = nrcellid_buf[2] << 4;
139 uint8_t nr6 = nrcellid_buf[3] >> 4;
140 uint8_t nr7 = nrcellid_buf[3] << 4;
143 uint8_t nr8 = nrcellid_buf[4] >> 4;
145 sprintf(cid_return_buf, "373437%d%d%d%d%d%d%d%d%d", nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8);
149 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
151 std::ifstream input("/playpen/src/reports.json");
152 bool x = input.good();
154 fprintf(stderr, "%s\n", x ? "true" : "false");
160 while ( getline(input, str) ) {
167 uint8_t *plmnid_buf = (uint8_t*)"747";
168 uint8_t *sst_buf = (uint8_t*)"1";
169 uint8_t *sd_buf = (uint8_t*)"100";
172 fprintf(stderr,"De line is %s\n", str.c_str());
177 all_ues_json = json::parse(str);
181 fprintf(stderr, "Exception on reading json\n");
186 fprintf(stderr, "key is valid\n");
188 std::string first_key = all_ues_json.begin().key();
189 fprintf(stderr, "first key is %s\n", first_key.c_str());
191 if (first_key.compare("ueMeasReport") == 0) {
193 fprintf(stderr, "it is equal to ue meas report\n");
195 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
198 for (int i = 0; i < numMeasReports; i++) {
207 fprintf(stderr,"UE number %d\n", i);
209 json::json_pointer p001(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/ue-id");
210 ueId = all_ues_json[p001].get<std::string>();
211 fprintf(stderr, "UEID %s\n", ueId.c_str());
213 json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
214 tput = all_ues_json[p0].get<float>();
215 fprintf(stderr, "Throughput %f\n", tput);
217 json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
218 prb_usage = all_ues_json[p00].get<int>();
219 fprintf(stderr, "Throughput %d\n", prb_usage);
221 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
222 nextCellId = all_ues_json[p1].get<int>();
223 fprintf(stderr, "Serving Cell %d\n",nextCellId);
225 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
226 nextRsrp = all_ues_json[p2].get<int>();
227 fprintf(stderr," RSRP %d\n", nextRsrp);
229 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
230 nextRsrq = all_ues_json[p3].get<int>();
231 fprintf(stderr," RSRQ %d\n",nextRsrq);
233 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
234 nextRssinr = all_ues_json[p4].get<int>();
235 fprintf(stderr," RSSINR %d\n", nextRssinr);
237 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
239 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
241 if (ueId.find("Pedestrian") != string::npos) {
242 std::string ind = ueId.substr(11);
243 fprintf(stderr, "ind is %s\n", ind.c_str());
245 int indval = std::stoi(ind);
248 crnti_buf[1] = indval;
251 crnti_buf[0] = indval/10;
252 crnti_buf[1] = indval % 10;
255 } else if (ueId.find("Car") != string::npos) {
260 // uint8_t *buf2 = (uint8_t*)"12";
262 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
263 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
264 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
266 int numNeighborCells = (all_ues_json[p5]).size();
268 std::string neighbor_str = "[";
275 for (int j = 0; j < numNeighborCells; j++) {
276 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
277 nextNbCell = all_ues_json[p8].get<int>();
278 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
279 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
280 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
281 nextNbRsrp = all_ues_json[p9].get<int>();
282 //cout << " RSRP " << nextNbRsrp << endl;
284 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
285 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
286 nextNbRsrq = all_ues_json[p10].get<int>();
287 //cout << " RSRQ " << nextNbRsrq << endl;
289 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
290 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
291 nextNbRssinr = all_ues_json[p11].get<int>();
292 //cout << " RSSINR " << nextNbRssinr << endl;
300 uint8_t *neighbor_cellid_buf = (uint8_t*)calloc(1,5);
301 neighbor_cellid_buf[0] = 0x22;
302 neighbor_cellid_buf[1] = 0x5B;
303 neighbor_cellid_buf[2] = 0xD6;
304 neighbor_cellid_buf[3] = nextNbCell;
305 neighbor_cellid_buf[4] = 0x70;
307 char *cid_buf = (char*)calloc(1,24);
308 get_cell_id(neighbor_cellid_buf,cid_buf);
311 neighbor_str += "{\"CID\" : \"" + std::string(cid_buf) + "\", \"Cell-RF\" : {\"rsrp\": " + std::to_string(nextNbRsrp) +
312 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
318 fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
320 //Creating UE-level RAN-Container CUCP message
322 fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
324 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
327 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
328 nrcellid_buf[0] = 0x22;
329 nrcellid_buf[1] = 0x5B;
330 nrcellid_buf[2] = 0xD6;
331 nrcellid_buf[3] = nextCellId;
332 nrcellid_buf[4] = 0x70;
334 uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
339 uint8_t cuupid_buf[1];
340 cuupid_buf[0] = 20000;
345 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
348 E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
349 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
351 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
353 uint8_t e2sm_message_buf_cucp_ue[8192];
354 size_t e2sm_message_buf_size_cucp_ue = 8192;
356 asn_codec_ctx_t *opt_cod;
359 asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
360 ATS_ALIGNED_BASIC_PER,
361 &asn_DEF_E2SM_KPM_IndicationMessage,
362 ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
364 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
365 fprintf(stderr, "after encoding message\n");
367 E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
368 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
369 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);
370 fprintf(stderr, "Now printing xer outside of function call\n");
371 xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
373 uint8_t e2sm_header_buf_cucp_ue[8192];
374 size_t e2sm_header_buf_size_cucp_ue = 8192;
376 asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
377 ATS_ALIGNED_BASIC_PER,
378 &asn_DEF_E2SM_KPM_IndicationHeader,
379 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
381 fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
382 fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
383 fprintf(stderr, "after encoding header\n");
385 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
387 encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
388 instanceId, ranFunctionId,
389 actionId, seqNum, e2sm_header_buf_cucp_ue,
390 er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
391 er_message_cucp_ue.encoded);
394 e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
398 std::this_thread::sleep_for (std::chrono::milliseconds(50));
400 //Creating UE-level RAN-Container CUUP message
402 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
404 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
405 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
407 long bytes = (long)(tput * 100);
409 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
411 uint8_t e2sm_message_buf_cuup_ue[8192];
412 size_t e2sm_message_buf_size_cuup_ue = 8192;
414 asn_codec_ctx_t *opt_cod2;
417 asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
418 ATS_ALIGNED_BASIC_PER,
419 &asn_DEF_E2SM_KPM_IndicationMessage,
420 ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
422 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
423 fprintf(stderr, "after encoding message\n");
425 E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
426 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
427 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);
429 uint8_t e2sm_header_buf_cuup_ue[8192];
430 size_t e2sm_header_buf_size_cuup_ue = 8192;
432 asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
433 ATS_ALIGNED_BASIC_PER,
434 &asn_DEF_E2SM_KPM_IndicationHeader,
435 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
438 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
440 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
441 instanceId, ranFunctionId,
442 actionId, seqNum, e2sm_header_buf_cuup_ue,
443 er_header_cuup_ue.encoded,
444 e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
446 e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
450 std::this_thread::sleep_for (std::chrono::milliseconds(50));
452 //Creating UE-level RAN-Container DU message
454 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
456 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
457 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
459 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
460 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
462 uint8_t e2sm_message_buf_du_ue[8192];
463 size_t e2sm_message_buf_size_du_ue = 8192;
465 asn_codec_ctx_t *opt_cod3;
468 asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
469 ATS_ALIGNED_BASIC_PER,
470 &asn_DEF_E2SM_KPM_IndicationMessage,
472 e2sm_message_buf_du_ue,
473 e2sm_message_buf_size_du_ue);
475 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
476 fprintf(stderr, "after encoding message\n");
478 E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
479 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
480 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);
482 uint8_t e2sm_header_buf_du_ue[8192];
483 size_t e2sm_header_buf_size_du_ue = 8192;
485 asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
486 ATS_ALIGNED_BASIC_PER,
487 &asn_DEF_E2SM_KPM_IndicationHeader,
488 ind_header_du_ue, e2sm_header_buf_du_ue,
489 e2sm_header_buf_size_du_ue);
492 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
494 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
495 instanceId, ranFunctionId,
497 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
498 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
500 e2sim.encode_and_send_sctp_data(pdu_du_ue);
504 std::this_thread::sleep_for (std::chrono::milliseconds(50));
506 fprintf(stderr, "done with ue meas report\n");
509 } else if (first_key.compare("cellMeasReport") == 0) {
511 fprintf(stderr, "it is equal to cell meas report\n");
513 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
515 for (int i = 0; i < numMeasReports; i++) {
524 fprintf(stderr,"UE number %d\n", i);
526 json::json_pointer p00(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
527 cellid = all_ues_json[p00].get<int>();
528 fprintf(stderr, "Cell ID %d\n", cellid);
530 json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
531 bytes_dl = all_ues_json[p0].get<float>();
532 fprintf(stderr, "Bytes DL %f\n", bytes_dl);
534 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
535 bytes_ul = all_ues_json[p1].get<float>();
536 fprintf(stderr, "Bytes UL %f\n", bytes_ul);
538 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
539 prb_dl = all_ues_json[p2].get<int>();
540 fprintf(stderr, "Avail PRB DL %d\n", prb_dl);
542 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
543 prb_ul = all_ues_json[p3].get<int>();
544 fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
547 uint8_t *sst_buf = (uint8_t*)"1";
548 uint8_t *sd_buf = (uint8_t*)"100";
549 uint8_t *plmnid_buf = (uint8_t*)"747";
551 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
552 nrcellid_buf[0] = 0x22;
553 nrcellid_buf[1] = 0x5B;
554 nrcellid_buf[2] = 0xD6;
555 nrcellid_buf[3] = cellid;
556 nrcellid_buf[4] = 0x70;
558 uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
563 uint8_t cuupid_buf[1];
564 cuupid_buf[0] = 20000;
569 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
572 //Encoding Style 5 Message Body
574 fprintf(stderr, "Encoding Style 5 Message body\n");
576 asn_codec_ctx_t *opt_cod;
578 E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
579 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
580 E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
582 encode_kpm_report_style5_parameterized(ind_msg_style5 , cuupname_buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
584 uint8_t e2sm_message_buf_style5[8192];
585 size_t e2sm_message_buf_size_style5 = 8192;
587 asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
588 ATS_ALIGNED_BASIC_PER,
589 &asn_DEF_E2SM_KPM_IndicationMessage,
590 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
592 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
593 fprintf(stderr, "after encoding message\n");
598 E2SM_KPM_IndicationHeader_t* ind_header_style5 =
599 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
600 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);
602 uint8_t e2sm_header_buf_style5[8192];
603 size_t e2sm_header_buf_size_style5 = 8192;
605 asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
606 ATS_ALIGNED_BASIC_PER,
607 &asn_DEF_E2SM_KPM_IndicationHeader,
609 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
612 encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
613 instanceId, ranFunctionId,
614 actionId, seqNum0, e2sm_header_buf_style5,
615 er_header_style5.encoded, e2sm_message_buf_style5,
616 er_message_style5.encoded);
618 e2sim.encode_and_send_sctp_data(pdu_style5);
622 std::this_thread::sleep_for (std::chrono::milliseconds(50));
625 //Encoding Style 1 Message Body
627 fprintf(stderr, "Encoding Style 1 Message body\n");
628 asn_codec_ctx_t *opt_cod2;
631 E2SM_KPM_IndicationMessage_t *ind_message_style1 =
632 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
633 E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
639 long l_dl_prbs = prb_dl;
640 long l_ul_prbs = prb_ul;
642 encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
643 prb_dl, prb_ul, sst_buf, sd_buf,
644 plmnid_buf, nrcellid_buf, &l_dl_prbs, &l_ul_prbs);
646 uint8_t e2sm_message_buf_style1[8192];
647 size_t e2sm_message_buf_size_style1 = 8192;
649 asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
650 ATS_ALIGNED_BASIC_PER,
651 &asn_DEF_E2SM_KPM_IndicationMessage,
653 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
655 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
656 fprintf(stderr, "after encoding message\n");
659 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
661 fprintf(stderr, "About to encode Indication\n");
663 E2SM_KPM_IndicationHeader_t* ind_header_style1 =
664 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
665 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);
667 uint8_t e2sm_header_buf_style1[8192];
668 size_t e2sm_header_buf_size_style1 = 8192;
670 asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
671 ATS_ALIGNED_BASIC_PER,
672 &asn_DEF_E2SM_KPM_IndicationHeader,
674 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
676 encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
677 instanceId, ranFunctionId,
678 actionId, seqNum, e2sm_header_buf_style1,
679 er_header_style1.encoded,
680 e2sm_message_buf_style1, er_message_style1.encoded);
682 e2sim.encode_and_send_sctp_data(pdu_style1);
684 std::this_thread::sleep_for (std::chrono::milliseconds(50));
693 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
695 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
697 //Record RIC Request ID
698 //Go through RIC action to be Setup List
699 //Find first entry with REPORT action Type
701 //Encode subscription response
703 RICsubscriptionRequest_t orig_req =
704 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
706 RICsubscriptionResponse_IEs_t *ricreqid =
707 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
709 int count = orig_req.protocolIEs.list.count;
710 int size = orig_req.protocolIEs.list.size;
712 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
714 fprintf(stderr, "count%d\n", count);
715 fprintf(stderr, "size%d\n", size);
717 RICsubscriptionRequest_IEs__value_PR pres;
723 std::vector<long> actionIdsAccept;
724 std::vector<long> actionIdsReject;
726 for (int i=0; i < count; i++) {
727 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
728 pres = next_ie->value.present;
730 fprintf(stderr, "The next present value %d\n", pres);
733 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
735 fprintf(stderr,"in case request id\n");
736 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
737 long requestorId = reqId.ricRequestorID;
738 long instanceId = reqId.ricInstanceID;
739 fprintf(stderr, "requestorId %d\n", requestorId);
740 fprintf(stderr, "instanceId %d\n", instanceId);
741 reqRequestorId = requestorId;
742 reqInstanceId = instanceId;
746 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
748 fprintf(stderr,"in case ran func id\n");
751 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
753 fprintf(stderr,"in case subscription details\n");
754 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
755 fprintf(stderr,"in case subscription details 1\n");
756 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
757 fprintf(stderr,"in case subscription details 2\n");
758 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
759 fprintf(stderr,"in case subscription details 3\n");
760 //We are ignoring the trigger definition
762 //We identify the first action whose type is REPORT
763 //That is the only one accepted; all others are rejected
765 int actionCount = actionList.list.count;
766 fprintf(stderr, "action count%d\n", actionCount);
768 auto **item_array = actionList.list.array;
770 bool foundAction = false;
772 for (int i=0; i < actionCount; i++) {
774 auto *next_item = item_array[i];
775 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
776 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
778 if (!foundAction && actionType == RICactionType_report) {
779 reqActionId = actionId;
780 actionIdsAccept.push_back(reqActionId);
781 printf("adding accept\n");
784 reqActionId = actionId;
785 printf("adding reject\n");
786 actionIdsReject.push_back(reqActionId);
794 fprintf(stderr,"in case default\n");
801 fprintf(stderr, "After Processing Subscription Request\n");
803 fprintf(stderr, "requestorId %d\n", reqRequestorId);
804 fprintf(stderr, "instanceId %d\n", reqInstanceId);
807 for (int i=0; i < actionIdsAccept.size(); i++) {
808 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
812 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
814 long *accept_array = &actionIdsAccept[0];
815 long *reject_array = &actionIdsReject[0];
816 int accept_size = actionIdsAccept.size();
817 int reject_size = actionIdsReject.size();
819 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
821 e2sim.encode_and_send_sctp_data(e2ap_pdu);
823 //Start thread for sending REPORT messages
825 // std::thread loop_thread;
829 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
831 // loop_thread = std::thread(&run_report_loop);