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];
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];
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);
373 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
374 fprintf(stderr, "after encoding message\n");
376 E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
377 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
378 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);
379 fprintf(stderr, "Now printing xer outside of function call\n");
380 xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
382 uint8_t e2sm_header_buf_cucp_ue[8192];
383 size_t e2sm_header_buf_size_cucp_ue = 8192;
385 asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
386 ATS_ALIGNED_BASIC_PER,
387 &asn_DEF_E2SM_KPM_IndicationHeader,
388 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
390 fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
391 fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
392 fprintf(stderr, "after encoding header\n");
394 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
396 encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
397 instanceId, ranFunctionId,
398 actionId, seqNum, e2sm_header_buf_cucp_ue,
399 er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
400 er_message_cucp_ue.encoded);
403 e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
407 std::this_thread::sleep_for (std::chrono::milliseconds(50));
409 //Creating UE-level RAN-Container CUUP message
411 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
413 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
414 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
416 long bytes = (long)(tput * 100);
418 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
420 uint8_t e2sm_message_buf_cuup_ue[8192];
421 size_t e2sm_message_buf_size_cuup_ue = 8192;
423 asn_codec_ctx_t *opt_cod2;
426 asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
427 ATS_ALIGNED_BASIC_PER,
428 &asn_DEF_E2SM_KPM_IndicationMessage,
429 ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
431 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
432 fprintf(stderr, "after encoding message\n");
434 E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
435 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
436 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);
438 uint8_t e2sm_header_buf_cuup_ue[8192];
439 size_t e2sm_header_buf_size_cuup_ue = 8192;
441 asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
442 ATS_ALIGNED_BASIC_PER,
443 &asn_DEF_E2SM_KPM_IndicationHeader,
444 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
447 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
449 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
450 instanceId, ranFunctionId,
451 actionId, seqNum, e2sm_header_buf_cuup_ue,
452 er_header_cuup_ue.encoded,
453 e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
455 e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
459 std::this_thread::sleep_for (std::chrono::milliseconds(50));
461 //Creating UE-level RAN-Container DU message
463 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
465 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
466 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
468 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
469 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
471 uint8_t e2sm_message_buf_du_ue[8192];
472 size_t e2sm_message_buf_size_du_ue = 8192;
474 asn_codec_ctx_t *opt_cod3;
477 asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
478 ATS_ALIGNED_BASIC_PER,
479 &asn_DEF_E2SM_KPM_IndicationMessage,
481 e2sm_message_buf_du_ue,
482 e2sm_message_buf_size_du_ue);
484 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
485 fprintf(stderr, "after encoding message\n");
487 E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
488 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
489 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);
491 uint8_t e2sm_header_buf_du_ue[8192];
492 size_t e2sm_header_buf_size_du_ue = 8192;
494 asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
495 ATS_ALIGNED_BASIC_PER,
496 &asn_DEF_E2SM_KPM_IndicationHeader,
497 ind_header_du_ue, e2sm_header_buf_du_ue,
498 e2sm_header_buf_size_du_ue);
501 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
503 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
504 instanceId, ranFunctionId,
506 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
507 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
509 e2sim.encode_and_send_sctp_data(pdu_du_ue);
513 std::this_thread::sleep_for (std::chrono::milliseconds(50));
515 fprintf(stderr, "done with ue meas report\n");
518 } else if (first_key.compare("cellMeasReport") == 0) {
520 fprintf(stderr, "it is equal to cell meas report\n");
522 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
524 for (int i = 0; i < numMeasReports; i++) {
533 fprintf(stderr,"UE number %d\n", i);
535 json::json_pointer p00(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
536 cellid = all_ues_json[p00].get<int>();
537 fprintf(stderr, "Cell ID %d\n", cellid);
539 json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
540 bytes_dl = all_ues_json[p0].get<float>();
541 fprintf(stderr, "Bytes DL %f\n", bytes_dl);
543 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
544 bytes_ul = all_ues_json[p1].get<float>();
545 fprintf(stderr, "Bytes UL %f\n", bytes_ul);
547 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
548 prb_dl = all_ues_json[p2].get<int>();
549 fprintf(stderr, "Avail PRB DL %d\n", prb_dl);
551 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
552 prb_ul = all_ues_json[p3].get<int>();
553 fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
556 uint8_t *sst_buf = (uint8_t*)"1";
557 uint8_t *sd_buf = (uint8_t*)"100";
558 uint8_t *plmnid_buf = (uint8_t*)"747";
560 uint8_t nrcellid_buf[6] = {0, };
561 nrcellid_buf[0] = 0x22;
562 nrcellid_buf[1] = 0x5B;
563 nrcellid_buf[2] = 0xD6;
564 nrcellid_buf[3] = cellid;
565 nrcellid_buf[4] = 0x70;
567 uint8_t gnbid_buf[4] = {0, };
572 uint8_t cuupid_buf[2] = {0, };
573 cuupid_buf[0] = 20000;
575 uint8_t duid_buf[2] = {0, };
578 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
581 //Encoding Style 5 Message Body
583 fprintf(stderr, "Encoding Style 5 Message body\n");
585 asn_codec_ctx_t *opt_cod;
587 E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
588 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
589 E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
591 encode_kpm_report_style5_parameterized(ind_msg_style5 , cuupname_buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
593 uint8_t e2sm_message_buf_style5[8192];
594 size_t e2sm_message_buf_size_style5 = 8192;
596 asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
597 ATS_ALIGNED_BASIC_PER,
598 &asn_DEF_E2SM_KPM_IndicationMessage,
599 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
601 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
602 fprintf(stderr, "after encoding message\n");
607 E2SM_KPM_IndicationHeader_t* ind_header_style5 =
608 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
609 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);
611 uint8_t e2sm_header_buf_style5[8192];
612 size_t e2sm_header_buf_size_style5 = 8192;
614 asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
615 ATS_ALIGNED_BASIC_PER,
616 &asn_DEF_E2SM_KPM_IndicationHeader,
618 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
621 encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
622 instanceId, ranFunctionId,
623 actionId, seqNum0, e2sm_header_buf_style5,
624 er_header_style5.encoded, e2sm_message_buf_style5,
625 er_message_style5.encoded);
627 e2sim.encode_and_send_sctp_data(pdu_style5);
631 std::this_thread::sleep_for (std::chrono::milliseconds(50));
634 //Encoding Style 1 Message Body
636 fprintf(stderr, "Encoding Style 1 Message body\n");
637 asn_codec_ctx_t *opt_cod2;
640 E2SM_KPM_IndicationMessage_t *ind_message_style1 =
641 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
642 E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
648 long l_dl_prbs = prb_dl;
649 long l_ul_prbs = prb_ul;
651 encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
652 prb_dl, prb_ul, sst_buf, sd_buf,
653 plmnid_buf, nrcellid_buf, &l_dl_prbs, &l_ul_prbs);
655 uint8_t e2sm_message_buf_style1[8192];
656 size_t e2sm_message_buf_size_style1 = 8192;
658 asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
659 ATS_ALIGNED_BASIC_PER,
660 &asn_DEF_E2SM_KPM_IndicationMessage,
662 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
664 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
665 fprintf(stderr, "after encoding message\n");
668 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
670 fprintf(stderr, "About to encode Indication\n");
672 E2SM_KPM_IndicationHeader_t* ind_header_style1 =
673 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
674 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);
676 uint8_t e2sm_header_buf_style1[8192];
677 size_t e2sm_header_buf_size_style1 = 8192;
679 asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
680 ATS_ALIGNED_BASIC_PER,
681 &asn_DEF_E2SM_KPM_IndicationHeader,
683 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
685 encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
686 instanceId, ranFunctionId,
687 actionId, seqNum, e2sm_header_buf_style1,
688 er_header_style1.encoded,
689 e2sm_message_buf_style1, er_message_style1.encoded);
691 e2sim.encode_and_send_sctp_data(pdu_style1);
693 std::this_thread::sleep_for (std::chrono::milliseconds(50));
702 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
704 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
706 //Record RIC Request ID
707 //Go through RIC action to be Setup List
708 //Find first entry with REPORT action Type
710 //Encode subscription response
712 RICsubscriptionRequest_t orig_req =
713 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
715 RICsubscriptionResponse_IEs_t *ricreqid =
716 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
718 int count = orig_req.protocolIEs.list.count;
719 int size = orig_req.protocolIEs.list.size;
721 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
723 fprintf(stderr, "count%d\n", count);
724 fprintf(stderr, "size%d\n", size);
726 RICsubscriptionRequest_IEs__value_PR pres;
732 std::vector<long> actionIdsAccept;
733 std::vector<long> actionIdsReject;
735 for (int i=0; i < count; i++) {
736 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
737 pres = next_ie->value.present;
739 fprintf(stderr, "The next present value %d\n", pres);
742 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
744 fprintf(stderr,"in case request id\n");
745 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
746 long requestorId = reqId.ricRequestorID;
747 long instanceId = reqId.ricInstanceID;
748 fprintf(stderr, "requestorId %d\n", requestorId);
749 fprintf(stderr, "instanceId %d\n", instanceId);
750 reqRequestorId = requestorId;
751 reqInstanceId = instanceId;
755 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
757 fprintf(stderr,"in case ran func id\n");
760 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
762 fprintf(stderr,"in case subscription details\n");
763 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
764 fprintf(stderr,"in case subscription details 1\n");
765 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
766 fprintf(stderr,"in case subscription details 2\n");
767 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
768 fprintf(stderr,"in case subscription details 3\n");
769 //We are ignoring the trigger definition
771 //We identify the first action whose type is REPORT
772 //That is the only one accepted; all others are rejected
774 int actionCount = actionList.list.count;
775 fprintf(stderr, "action count%d\n", actionCount);
777 auto **item_array = actionList.list.array;
779 bool foundAction = false;
781 for (int i=0; i < actionCount; i++) {
783 auto *next_item = item_array[i];
784 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
785 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
787 if (!foundAction && actionType == RICactionType_report) {
788 reqActionId = actionId;
789 actionIdsAccept.push_back(reqActionId);
790 printf("adding accept\n");
793 reqActionId = actionId;
794 printf("adding reject\n");
795 actionIdsReject.push_back(reqActionId);
803 fprintf(stderr,"in case default\n");
810 fprintf(stderr, "After Processing Subscription Request\n");
812 fprintf(stderr, "requestorId %d\n", reqRequestorId);
813 fprintf(stderr, "instanceId %d\n", reqInstanceId);
816 for (int i=0; i < actionIdsAccept.size(); i++) {
817 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
821 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
823 long *accept_array = &actionIdsAccept[0];
824 long *reject_array = &actionIdsReject[0];
825 int accept_size = actionIdsAccept.size();
826 int reject_size = actionIdsReject.size();
828 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
830 e2sim.encode_and_send_sctp_data(e2ap_pdu);
832 //Start thread for sending REPORT messages
834 // std::thread loop_thread;
838 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
840 // loop_thread = std::thread(&run_report_loop);