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");
68 asn_codec_ctx_t *opt_cod;
70 E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
71 (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
72 encode_kpm_function_description(ranfunc_desc);
74 uint8_t e2smbuffer[8192];
75 size_t e2smbuffer_size = 8192;
78 asn_encode_to_buffer(opt_cod,
79 ATS_ALIGNED_BASIC_PER,
80 &asn_DEF_E2SM_KPM_RANfunction_Description,
81 ranfunc_desc, e2smbuffer, e2smbuffer_size);
83 fprintf(stderr, "er encded is %d\n", er.encoded);
84 fprintf(stderr, "after encoding message\n");
85 fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
87 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
88 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
90 printf("this is the char array %s\n", (char*)ranfuncdesc);
92 OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
93 ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
94 ranfunc_ostr->size = er.encoded;
95 memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
97 printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
98 printf("value of this index is %d\n", ranfuncdesc[0]);
99 printf("value of this index is %d\n", ranfuncdesc[1]);
100 printf("value of this index is %d\n", ranfuncdesc[2]);
101 printf("value of this index is %d\n", ranfuncdesc[3]);
102 printf("value of this index is %d\n", ranfuncdesc[4]);
103 printf("value of this index is %d\n", ranfuncdesc[5]);
104 printf("value of this index is %d\n", ranfuncdesc[6]);
105 printf("value of this index is %d\n", ranfuncdesc[10]);
106 printf("value of this index is %d\n", ranfuncdesc[15]);
107 printf("value of this index is %d\n", ranfuncdesc[100]);
108 printf("value of this index is %d\n", ranfuncdesc[101]);
110 e2sim.register_e2sm(0,ranfunc_ostr);
111 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
113 e2sim.run_loop(argc, argv);
117 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
119 std::ifstream input("/playpen/src/reports.json");
120 bool x = input.good();
122 fprintf(stderr, "%s\n", x ? "true" : "false");
128 while ( getline(input, str) ) {
135 uint8_t *plmnid_buf = (uint8_t*)"747";
136 uint8_t *sst_buf = (uint8_t*)"1";
137 uint8_t *sd_buf = (uint8_t*)"100";
140 fprintf(stderr,"De line is %s\n", str.c_str());
145 all_ues_json = json::parse(str);
149 fprintf(stderr, "Exception on reading json\n");
154 fprintf(stderr, "key is valid\n");
156 std::string first_key = all_ues_json.begin().key();
157 fprintf(stderr, "first key is %s\n", first_key.c_str());
159 if (first_key.compare("ueMeasReport") == 0) {
161 fprintf(stderr, "it is equal to ue meas report\n");
163 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
166 for (int i = 0; i < numMeasReports; i++) {
173 fprintf(stderr,"UE number %d\n", i);
175 json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
176 tput = all_ues_json[p0].get<float>();
177 fprintf(stderr, "Throughput %f\n", tput);
179 json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
180 prb_usage = all_ues_json[p00].get<int>();
181 fprintf(stderr, "Throughput %d\n", prb_usage);
183 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
184 nextCellId = all_ues_json[p1].get<int>();
185 fprintf(stderr, "Serving Cell %d\n",nextCellId);
187 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
188 nextRsrp = all_ues_json[p2].get<int>();
189 fprintf(stderr," RSRP %d\n", nextRsrp);
191 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
192 nextRsrq = all_ues_json[p3].get<int>();
193 fprintf(stderr," RSRQ %d\n",nextRsrq);
195 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
196 nextRssinr = all_ues_json[p4].get<int>();
197 fprintf(stderr," RSSINR %d\n", nextRssinr);
199 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
201 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
203 uint8_t *buf2 = (uint8_t*)"12";
204 memcpy(crnti_buf, buf2, 2);
207 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
208 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
209 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
211 int numNeighborCells = (all_ues_json[p5]).size();
213 std::string neighbor_str = "[";
220 for (int j = 0; j < numNeighborCells; j++) {
221 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
222 nextNbCell = all_ues_json[p8].get<int>();
223 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
224 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
225 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
226 nextNbRsrp = all_ues_json[p9].get<int>();
227 //cout << " RSRP " << nextNbRsrp << endl;
229 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
230 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
231 nextNbRsrq = all_ues_json[p10].get<int>();
232 //cout << " RSRQ " << nextNbRsrq << endl;
234 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
235 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
236 nextNbRssinr = all_ues_json[p11].get<int>();
237 //cout << " RSSINR " << nextNbRssinr << endl;
244 neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
245 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
251 fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
253 //Creating UE-level RAN-Container CUCP message
255 fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
257 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
259 // uint8_t *nrcellid_buf = (uint8_t*)"12340";
260 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
261 nrcellid_buf[0] = 0x22;
262 nrcellid_buf[1] = 0x5B;
263 nrcellid_buf[2] = 0xD6;
264 nrcellid_buf[3] = 0x00;
265 nrcellid_buf[4] = 0x70;
267 uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
272 uint8_t cuupid_buf[1];
273 cuupid_buf[0] = 20000;
278 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
281 E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
282 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
284 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
286 uint8_t e2sm_message_buf_cucp_ue[8192];
287 size_t e2sm_message_buf_size_cucp_ue = 8192;
289 asn_codec_ctx_t *opt_cod;
292 asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
293 ATS_ALIGNED_BASIC_PER,
294 &asn_DEF_E2SM_KPM_IndicationMessage,
295 ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
297 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
298 fprintf(stderr, "after encoding message\n");
300 E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
301 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
302 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);
303 fprintf(stderr, "Now printing xer outside of function call\n");
304 xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
306 uint8_t e2sm_header_buf_cucp_ue[8192];
307 size_t e2sm_header_buf_size_cucp_ue = 8192;
309 asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
310 ATS_ALIGNED_BASIC_PER,
311 &asn_DEF_E2SM_KPM_IndicationHeader,
312 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
314 fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
315 fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
316 fprintf(stderr, "after encoding header\n");
318 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
320 encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
321 instanceId, ranFunctionId,
322 actionId, seqNum, e2sm_header_buf_cucp_ue,
323 er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
324 er_message_cucp_ue.encoded);
327 e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
331 std::this_thread::sleep_for (std::chrono::seconds(2));
333 //Creating UE-level RAN-Container CUUP message
335 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
337 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
338 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
340 long bytes = (long)(tput * 100);
342 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
344 uint8_t e2sm_message_buf_cuup_ue[8192];
345 size_t e2sm_message_buf_size_cuup_ue = 8192;
347 asn_codec_ctx_t *opt_cod2;
350 asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
351 ATS_ALIGNED_BASIC_PER,
352 &asn_DEF_E2SM_KPM_IndicationMessage,
353 ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
355 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
356 fprintf(stderr, "after encoding message\n");
358 E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
359 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
360 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);
362 uint8_t e2sm_header_buf_cuup_ue[8192];
363 size_t e2sm_header_buf_size_cuup_ue = 8192;
365 asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
366 ATS_ALIGNED_BASIC_PER,
367 &asn_DEF_E2SM_KPM_IndicationHeader,
368 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
371 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
373 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
374 instanceId, ranFunctionId,
375 actionId, seqNum, e2sm_header_buf_cuup_ue,
376 er_header_cuup_ue.encoded,
377 e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
379 e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
383 std::this_thread::sleep_for (std::chrono::seconds(2));
385 //Creating UE-level RAN-Container DU message
387 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
389 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
390 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
392 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
393 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
395 uint8_t e2sm_message_buf_du_ue[8192];
396 size_t e2sm_message_buf_size_du_ue = 8192;
398 asn_codec_ctx_t *opt_cod3;
401 asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
402 ATS_ALIGNED_BASIC_PER,
403 &asn_DEF_E2SM_KPM_IndicationMessage,
405 e2sm_message_buf_du_ue,
406 e2sm_message_buf_size_du_ue);
408 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
409 fprintf(stderr, "after encoding message\n");
411 E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
412 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
413 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);
415 uint8_t e2sm_header_buf_du_ue[8192];
416 size_t e2sm_header_buf_size_du_ue = 8192;
418 asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
419 ATS_ALIGNED_BASIC_PER,
420 &asn_DEF_E2SM_KPM_IndicationHeader,
421 ind_header_du_ue, e2sm_header_buf_du_ue,
422 e2sm_header_buf_size_du_ue);
425 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
427 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
428 instanceId, ranFunctionId,
430 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
431 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
433 e2sim.encode_and_send_sctp_data(pdu_du_ue);
437 std::this_thread::sleep_for (std::chrono::seconds(2));
439 fprintf(stderr, "done with ue meas report\n");
442 } else if (first_key.compare("cellMeasReport") == 0) {
444 fprintf(stderr, "it is equal to cell meas report\n");
446 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
448 for (int i = 0; i < numMeasReports; i++) {
456 fprintf(stderr,"UE number %d\n", i);
458 json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
459 bytes_dl = all_ues_json[p0].get<float>();
460 fprintf(stderr, "Bytes DL %f\n", bytes_dl);
462 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
463 bytes_ul = all_ues_json[p1].get<float>();
464 fprintf(stderr, "Bytes UL %f\n", bytes_ul);
466 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
467 prb_dl = all_ues_json[p2].get<int>();
468 fprintf(stderr, "Avail PRB DL %d\n", prb_dl);
470 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
471 prb_ul = all_ues_json[p3].get<int>();
472 fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
475 uint8_t *sst_buf = (uint8_t*)"1";
476 uint8_t *sd_buf = (uint8_t*)"100";
477 uint8_t *plmnid_buf = (uint8_t*)"747";
479 uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
480 nrcellid_buf[0] = 0x22;
481 nrcellid_buf[1] = 0x5B;
482 nrcellid_buf[2] = 0xD6;
483 nrcellid_buf[3] = 0x00;
484 nrcellid_buf[4] = 0x70;
486 uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
491 uint8_t cuupid_buf[1];
497 uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";
500 //Encoding Style 5 Message Body
502 fprintf(stderr, "Encoding Style 5 Message body\n");
504 asn_codec_ctx_t *opt_cod;
506 E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
507 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
508 E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
510 encode_kpm_report_style5_parameterized(ind_msg_style5 , cuupname_buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
512 uint8_t e2sm_message_buf_style5[8192];
513 size_t e2sm_message_buf_size_style5 = 8192;
515 asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
516 ATS_ALIGNED_BASIC_PER,
517 &asn_DEF_E2SM_KPM_IndicationMessage,
518 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
520 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
521 fprintf(stderr, "after encoding message\n");
526 E2SM_KPM_IndicationHeader_t* ind_header_style5 =
527 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
528 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);
530 uint8_t e2sm_header_buf_style5[8192];
531 size_t e2sm_header_buf_size_style5 = 8192;
533 asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
534 ATS_ALIGNED_BASIC_PER,
535 &asn_DEF_E2SM_KPM_IndicationHeader,
537 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
540 encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
541 instanceId, ranFunctionId,
542 actionId, seqNum0, e2sm_header_buf_style5,
543 er_header_style5.encoded, e2sm_message_buf_style5,
544 er_message_style5.encoded);
546 e2sim.encode_and_send_sctp_data(pdu_style5);
550 std::this_thread::sleep_for (std::chrono::seconds(2));
553 //Encoding Style 1 Message Body
555 fprintf(stderr, "Encoding Style 1 Message body\n");
556 asn_codec_ctx_t *opt_cod2;
559 E2SM_KPM_IndicationMessage_t *ind_message_style1 =
560 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
561 E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
567 long l_dl_prbs = prb_dl;
568 long l_ul_prbs = prb_ul;
570 encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
571 prb_dl, prb_ul, sst_buf, sd_buf,
572 plmnid_buf, nrcellid_buf, &l_dl_prbs, &l_ul_prbs);
574 uint8_t e2sm_message_buf_style1[8192];
575 size_t e2sm_message_buf_size_style1 = 8192;
577 asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
578 ATS_ALIGNED_BASIC_PER,
579 &asn_DEF_E2SM_KPM_IndicationMessage,
581 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
583 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
584 fprintf(stderr, "after encoding message\n");
587 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
589 fprintf(stderr, "About to encode Indication\n");
591 E2SM_KPM_IndicationHeader_t* ind_header_style1 =
592 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
593 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);
595 uint8_t e2sm_header_buf_style1[8192];
596 size_t e2sm_header_buf_size_style1 = 8192;
598 asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
599 ATS_ALIGNED_BASIC_PER,
600 &asn_DEF_E2SM_KPM_IndicationHeader,
602 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
604 encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
605 instanceId, ranFunctionId,
606 actionId, seqNum, e2sm_header_buf_style1,
607 er_header_style1.encoded,
608 e2sm_message_buf_style1, er_message_style1.encoded);
610 e2sim.encode_and_send_sctp_data(pdu_style1);
612 std::this_thread::sleep_for (std::chrono::seconds(2));
621 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
623 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
625 //Record RIC Request ID
626 //Go through RIC action to be Setup List
627 //Find first entry with REPORT action Type
629 //Encode subscription response
631 RICsubscriptionRequest_t orig_req =
632 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
634 RICsubscriptionResponse_IEs_t *ricreqid =
635 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
637 int count = orig_req.protocolIEs.list.count;
638 int size = orig_req.protocolIEs.list.size;
640 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
642 fprintf(stderr, "count%d\n", count);
643 fprintf(stderr, "size%d\n", size);
645 RICsubscriptionRequest_IEs__value_PR pres;
651 std::vector<long> actionIdsAccept;
652 std::vector<long> actionIdsReject;
654 for (int i=0; i < count; i++) {
655 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
656 pres = next_ie->value.present;
658 fprintf(stderr, "The next present value %d\n", pres);
661 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
663 fprintf(stderr,"in case request id\n");
664 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
665 long requestorId = reqId.ricRequestorID;
666 long instanceId = reqId.ricInstanceID;
667 fprintf(stderr, "requestorId %d\n", requestorId);
668 fprintf(stderr, "instanceId %d\n", instanceId);
669 reqRequestorId = requestorId;
670 reqInstanceId = instanceId;
674 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
676 fprintf(stderr,"in case ran func id\n");
679 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
681 fprintf(stderr,"in case subscription details\n");
682 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
683 fprintf(stderr,"in case subscription details 1\n");
684 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
685 fprintf(stderr,"in case subscription details 2\n");
686 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
687 fprintf(stderr,"in case subscription details 3\n");
688 //We are ignoring the trigger definition
690 //We identify the first action whose type is REPORT
691 //That is the only one accepted; all others are rejected
693 int actionCount = actionList.list.count;
694 fprintf(stderr, "action count%d\n", actionCount);
696 auto **item_array = actionList.list.array;
698 bool foundAction = false;
700 for (int i=0; i < actionCount; i++) {
702 auto *next_item = item_array[i];
703 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
704 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
706 if (!foundAction && actionType == RICactionType_report) {
707 reqActionId = actionId;
708 actionIdsAccept.push_back(reqActionId);
709 printf("adding accept\n");
712 reqActionId = actionId;
713 printf("adding reject\n");
714 actionIdsReject.push_back(reqActionId);
722 fprintf(stderr,"in case default\n");
729 fprintf(stderr, "After Processing Subscription Request\n");
731 fprintf(stderr, "requestorId %d\n", reqRequestorId);
732 fprintf(stderr, "instanceId %d\n", reqInstanceId);
735 for (int i=0; i < actionIdsAccept.size(); i++) {
736 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
740 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
742 long *accept_array = &actionIdsAccept[0];
743 long *reject_array = &actionIdsReject[0];
744 int accept_size = actionIdsAccept.size();
745 int reject_size = actionIdsReject.size();
747 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
749 e2sim.encode_and_send_sctp_data(e2ap_pdu);
751 //Start thread for sending REPORT messages
753 // std::thread loop_thread;
757 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
759 // loop_thread = std::thread(&run_report_loop);