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) ) {
132 fprintf(stderr,"De line is %s\n", str.c_str());
137 all_ues_json = json::parse(str);
141 fprintf(stderr, "Exception on reading json\n");
146 fprintf(stderr, "key is valid\n");
148 std::string first_key = all_ues_json.begin().key();
149 fprintf(stderr, "first key is %s\n", first_key.c_str());
151 if (first_key.compare("ueMeasReport") == 0) {
153 fprintf(stderr, "it is equal to ue meas report\n");
155 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
158 for (int i = 0; i < numMeasReports; i++) {
165 fprintf(stderr,"UE number %d\n", i);
167 json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
168 tput = all_ues_json[p0].get<float>();
169 fprintf(stderr, "Throughput %f\n", tput);
171 json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
172 prb_usage = all_ues_json[p00].get<int>();
173 fprintf(stderr, "Throughput %d\n", prb_usage);
175 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
176 nextCellId = all_ues_json[p1].get<int>();
177 fprintf(stderr, "Serving Cell %d\n",nextCellId);
179 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
180 nextRsrp = all_ues_json[p2].get<int>();
181 fprintf(stderr," RSRP %d\n", nextRsrp);
183 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
184 nextRsrq = all_ues_json[p3].get<int>();
185 fprintf(stderr," RSRQ %d\n",nextRsrq);
187 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
188 nextRssinr = all_ues_json[p4].get<int>();
189 fprintf(stderr," RSSINR %d\n", nextRssinr);
191 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
193 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
195 uint8_t *buf2 = (uint8_t*)"12";
196 memcpy(crnti_buf, buf2, 2);
199 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
200 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
201 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
203 int numNeighborCells = (all_ues_json[p5]).size();
205 std::string neighbor_str = "[";
212 for (int j = 0; j < numNeighborCells; j++) {
213 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
214 nextNbCell = all_ues_json[p8].get<int>();
215 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
216 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
217 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
218 nextNbRsrp = all_ues_json[p9].get<int>();
219 //cout << " RSRP " << nextNbRsrp << endl;
221 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
222 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
223 nextNbRsrq = all_ues_json[p10].get<int>();
224 //cout << " RSRQ " << nextNbRsrq << endl;
226 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
227 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
228 nextNbRssinr = all_ues_json[p11].get<int>();
229 //cout << " RSSINR " << nextNbRssinr << endl;
236 neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
237 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
243 fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
245 //Creating UE-level RAN-Container CUCP message
247 fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
249 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
250 uint8_t *plmnid_buf = (uint8_t*)"747";
251 uint8_t *nrcellid_buf = (uint8_t*)"12340";
253 E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
254 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
256 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
258 uint8_t e2sm_message_buf_cucp_ue[8192];
259 size_t e2sm_message_buf_size_cucp_ue = 8192;
261 asn_codec_ctx_t *opt_cod;
264 asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
265 ATS_ALIGNED_BASIC_PER,
266 &asn_DEF_E2SM_KPM_IndicationMessage,
267 ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
269 fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
270 fprintf(stderr, "after encoding message\n");
272 E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
273 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
274 encode_e2sm_kpm_indication_header(ind_header_cucp_ue);
275 fprintf(stderr, "Now printing xer outside of function call\n");
276 xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
278 uint8_t e2sm_header_buf_cucp_ue[8192];
279 size_t e2sm_header_buf_size_cucp_ue = 8192;
281 asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
282 ATS_ALIGNED_BASIC_PER,
283 &asn_DEF_E2SM_KPM_IndicationHeader,
284 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
286 fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
287 fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
288 fprintf(stderr, "after encoding header\n");
290 E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
292 encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
293 instanceId, ranFunctionId,
294 actionId, seqNum, e2sm_header_buf_cucp_ue,
295 er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
296 er_message_cucp_ue.encoded);
299 e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
303 std::this_thread::sleep_for (std::chrono::seconds(2));
305 //Creating UE-level RAN-Container CUUP message
307 fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");
309 E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
310 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
312 long bytes = (long)(tput * 100);
314 encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
316 uint8_t e2sm_message_buf_cuup_ue[8192];
317 size_t e2sm_message_buf_size_cuup_ue = 8192;
319 asn_codec_ctx_t *opt_cod2;
322 asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
323 ATS_ALIGNED_BASIC_PER,
324 &asn_DEF_E2SM_KPM_IndicationMessage,
325 ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
327 fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
328 fprintf(stderr, "after encoding message\n");
330 E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
331 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
332 encode_e2sm_kpm_indication_header(ind_header_cuup_ue);
334 uint8_t e2sm_header_buf_cuup_ue[8192];
335 size_t e2sm_header_buf_size_cuup_ue = 8192;
337 asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
338 ATS_ALIGNED_BASIC_PER,
339 &asn_DEF_E2SM_KPM_IndicationHeader,
340 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
343 E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
345 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
346 instanceId, ranFunctionId,
347 actionId, seqNum, e2sm_header_buf_cuup_ue,
348 er_header_cuup_ue.encoded,
349 e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
351 e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
355 std::this_thread::sleep_for (std::chrono::seconds(2));
357 //Creating UE-level RAN-Container DU message
359 fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
361 E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
362 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
364 encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
365 plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
367 uint8_t e2sm_message_buf_du_ue[8192];
368 size_t e2sm_message_buf_size_du_ue = 8192;
370 asn_codec_ctx_t *opt_cod3;
373 asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
374 ATS_ALIGNED_BASIC_PER,
375 &asn_DEF_E2SM_KPM_IndicationMessage,
377 e2sm_message_buf_du_ue,
378 e2sm_message_buf_size_du_ue);
380 fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
381 fprintf(stderr, "after encoding message\n");
383 E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
384 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
385 encode_e2sm_kpm_indication_header(ind_header_du_ue);
387 uint8_t e2sm_header_buf_du_ue[8192];
388 size_t e2sm_header_buf_size_du_ue = 8192;
390 asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
391 ATS_ALIGNED_BASIC_PER,
392 &asn_DEF_E2SM_KPM_IndicationHeader,
393 ind_header_du_ue, e2sm_header_buf_du_ue,
394 e2sm_header_buf_size_du_ue);
397 E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
399 encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
400 instanceId, ranFunctionId,
402 e2sm_header_buf_du_ue, er_header_du_ue.encoded,
403 e2sm_message_buf_du_ue, er_message_du_ue.encoded);
405 e2sim.encode_and_send_sctp_data(pdu_du_ue);
409 std::this_thread::sleep_for (std::chrono::seconds(2));
411 fprintf(stderr, "done with ue meas report\n");
414 } else if (first_key.compare("cellMeasReport") == 0) {
416 fprintf(stderr, "it is equal to cell meas report\n");
418 int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
420 for (int i = 0; i < numMeasReports; i++) {
428 fprintf(stderr,"UE number %d\n", i);
430 json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
431 bytes_dl = all_ues_json[p0].get<float>();
432 fprintf(stderr, "Bytes DL %f\n", bytes_dl);
434 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
435 bytes_ul = all_ues_json[p1].get<float>();
436 fprintf(stderr, "Bytes UL %f\n", bytes_ul);
438 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
439 prb_dl = all_ues_json[p2].get<int>();
440 fprintf(stderr, "Avail PRB DL %d\n", prb_dl);
442 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
443 prb_ul = all_ues_json[p3].get<int>();
444 fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
446 uint8_t *buf = (uint8_t*)"GNBCUUP5";
448 uint8_t *sst_buf = (uint8_t*)"1";
449 uint8_t *sd_buf = (uint8_t*)"100";
450 uint8_t *plmnid_buf = (uint8_t*)"747";
452 //Encoding Style 5 Message Body
454 fprintf(stderr, "Encoding Style 5 Message body\n");
456 asn_codec_ctx_t *opt_cod;
458 E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
459 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
460 E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
462 encode_kpm_report_style5_parameterized(ind_msg_style5 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
464 uint8_t e2sm_message_buf_style5[8192];
465 size_t e2sm_message_buf_size_style5 = 8192;
467 asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
468 ATS_ALIGNED_BASIC_PER,
469 &asn_DEF_E2SM_KPM_IndicationMessage,
470 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
472 fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
473 fprintf(stderr, "after encoding message\n");
478 E2SM_KPM_IndicationHeader_t* ind_header_style5 =
479 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
480 encode_e2sm_kpm_indication_header(ind_header_style5);
482 uint8_t e2sm_header_buf_style5[8192];
483 size_t e2sm_header_buf_size_style5 = 8192;
485 asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
486 ATS_ALIGNED_BASIC_PER,
487 &asn_DEF_E2SM_KPM_IndicationHeader,
489 e2sm_header_buf_style5, e2sm_header_buf_size_style5);
492 encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
493 instanceId, ranFunctionId,
494 actionId, seqNum0, e2sm_header_buf_style5,
495 er_header_style5.encoded, e2sm_message_buf_style5,
496 er_message_style5.encoded);
498 e2sim.encode_and_send_sctp_data(pdu_style5);
502 std::this_thread::sleep_for (std::chrono::seconds(2));
505 //Encoding Style 1 Message Body
507 fprintf(stderr, "Encoding Style 1 Message body\n");
508 asn_codec_ctx_t *opt_cod2;
511 E2SM_KPM_IndicationMessage_t *ind_message_style1 =
512 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
513 E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
517 uint8_t *nrcellid_buf = (uint8_t*)"12340";
519 long l_dl_prbs = prb_dl;
520 long l_ul_prbs = prb_ul;
522 encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
523 prb_dl, prb_ul, sst_buf, sd_buf,
524 plmnid_buf, nrcellid_buf, &l_dl_prbs, &l_ul_prbs);
526 uint8_t e2sm_message_buf_style1[8192];
527 size_t e2sm_message_buf_size_style1 = 8192;
529 asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
530 ATS_ALIGNED_BASIC_PER,
531 &asn_DEF_E2SM_KPM_IndicationMessage,
533 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
535 fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
536 fprintf(stderr, "after encoding message\n");
539 uint8_t *cpid_buf2 = (uint8_t*)"CPID";
541 fprintf(stderr, "About to encode Indication\n");
543 E2SM_KPM_IndicationHeader_t* ind_header_style1 =
544 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
545 encode_e2sm_kpm_indication_header(ind_header_style1);
547 uint8_t e2sm_header_buf_style1[8192];
548 size_t e2sm_header_buf_size_style1 = 8192;
550 asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
551 ATS_ALIGNED_BASIC_PER,
552 &asn_DEF_E2SM_KPM_IndicationHeader,
554 e2sm_header_buf_style1, e2sm_header_buf_size_style1);
556 encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
557 instanceId, ranFunctionId,
558 actionId, seqNum, e2sm_header_buf_style1,
559 er_header_style1.encoded,
560 e2sm_message_buf_style1, er_message_style1.encoded);
562 e2sim.encode_and_send_sctp_data(pdu_style1);
564 std::this_thread::sleep_for (std::chrono::seconds(2));
573 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
575 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
577 //Record RIC Request ID
578 //Go through RIC action to be Setup List
579 //Find first entry with REPORT action Type
581 //Encode subscription response
583 RICsubscriptionRequest_t orig_req =
584 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
586 RICsubscriptionResponse_IEs_t *ricreqid =
587 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
589 int count = orig_req.protocolIEs.list.count;
590 int size = orig_req.protocolIEs.list.size;
592 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
594 fprintf(stderr, "count%d\n", count);
595 fprintf(stderr, "size%d\n", size);
597 RICsubscriptionRequest_IEs__value_PR pres;
603 std::vector<long> actionIdsAccept;
604 std::vector<long> actionIdsReject;
606 for (int i=0; i < count; i++) {
607 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
608 pres = next_ie->value.present;
610 fprintf(stderr, "The next present value %d\n", pres);
613 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
615 fprintf(stderr,"in case request id\n");
616 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
617 long requestorId = reqId.ricRequestorID;
618 long instanceId = reqId.ricInstanceID;
619 fprintf(stderr, "requestorId %d\n", requestorId);
620 fprintf(stderr, "instanceId %d\n", instanceId);
621 reqRequestorId = requestorId;
622 reqInstanceId = instanceId;
626 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
628 fprintf(stderr,"in case ran func id\n");
631 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
633 fprintf(stderr,"in case subscription details\n");
634 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
635 fprintf(stderr,"in case subscription details 1\n");
636 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
637 fprintf(stderr,"in case subscription details 2\n");
638 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
639 fprintf(stderr,"in case subscription details 3\n");
640 //We are ignoring the trigger definition
642 //We identify the first action whose type is REPORT
643 //That is the only one accepted; all others are rejected
645 int actionCount = actionList.list.count;
646 fprintf(stderr, "action count%d\n", actionCount);
648 auto **item_array = actionList.list.array;
650 bool foundAction = false;
652 for (int i=0; i < actionCount; i++) {
654 auto *next_item = item_array[i];
655 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
656 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
658 if (!foundAction && actionType == RICactionType_report) {
659 reqActionId = actionId;
660 actionIdsAccept.push_back(reqActionId);
661 printf("adding accept\n");
664 reqActionId = actionId;
665 printf("adding reject\n");
666 actionIdsReject.push_back(reqActionId);
674 fprintf(stderr,"in case default\n");
681 fprintf(stderr, "After Processing Subscription Request\n");
683 fprintf(stderr, "requestorId %d\n", reqRequestorId);
684 fprintf(stderr, "instanceId %d\n", reqInstanceId);
687 for (int i=0; i < actionIdsAccept.size(); i++) {
688 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
692 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
694 long *accept_array = &actionIdsAccept[0];
695 long *reject_array = &actionIdsReject[0];
696 int accept_size = actionIdsAccept.size();
697 int reject_size = actionIdsReject.size();
699 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
701 e2sim.encode_and_send_sctp_data(e2ap_pdu);
703 //Start thread for sending REPORT messages
705 // std::thread loop_thread;
709 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
711 // loop_thread = std::thread(&run_report_loop);