1 /*****************************************************************************
3 # Copyright 2020 AT&T Intellectual Property *
5 # Copyright (c) 2020 HCL Technologies Limited. *
7 # Licensed under the Apache License, Version 2.0 (the "License"); *
8 # you may not use this file except in compliance with the License. *
9 # You may obtain a copy of the License at *
11 # http://www.apache.org/licenses/LICENSE-2.0 *
13 # Unless required by applicable law or agreed to in writing, software *
14 # distributed under the License is distributed on an "AS IS" BASIS, *
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
16 # See the License for the specific language governing permissions and *
17 # limitations under the License. *
19 ******************************************************************************/
28 #include "OCUCP-PF-Container.h"
29 #include "OCTET_STRING.h"
30 #include "asn_application.h"
31 #include "E2SM-KPM-IndicationMessage.h"
32 #include "FQIPERSlicesPerPlmnListItem.h"
33 #include "E2SM-KPM-RANfunction-Description.h"
34 #include "E2SM-KPM-IndicationHeader-Format1.h"
35 #include "E2SM-KPM-IndicationHeader.h"
36 #include "Timestamp.h"
38 #include "RICsubscriptionRequest.h"
39 #include "RICsubscriptionResponse.h"
40 #include "RICactionType.h"
41 #include "ProtocolIE-Field.h"
42 #include "ProtocolIE-SingleContainer.h"
43 #include "InitiatingMessage.h"
46 #include "kpm_callbacks.hpp"
47 #include "encode_kpm.hpp"
49 #include "encode_e2apv1.hpp"
51 #include <nlohmann/json.hpp>
55 using json = nlohmann::json;
63 int main(int argc, char* argv[]) {
65 fprintf(stderr, "Starting KPM processor sim");
67 asn_codec_ctx_t *opt_cod;
69 E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
70 (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
71 encode_kpm_function_description(ranfunc_desc);
73 uint8_t e2smbuffer[8192];
74 size_t e2smbuffer_size = 8192;
77 asn_encode_to_buffer(opt_cod,
78 ATS_ALIGNED_BASIC_PER,
79 &asn_DEF_E2SM_KPM_RANfunction_Description,
80 ranfunc_desc, e2smbuffer, e2smbuffer_size);
82 fprintf(stderr, "er encded is %d\n", er.encoded);
83 fprintf(stderr, "after encoding message\n");
84 fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
86 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
87 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
89 printf("this is the char array %s\n", (char*)ranfuncdesc);
91 OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
92 ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
93 ranfunc_ostr->size = er.encoded;
94 memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
96 printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
97 printf("value of this index is %d\n", ranfuncdesc[0]);
98 printf("value of this index is %d\n", ranfuncdesc[1]);
99 printf("value of this index is %d\n", ranfuncdesc[2]);
100 printf("value of this index is %d\n", ranfuncdesc[3]);
101 printf("value of this index is %d\n", ranfuncdesc[4]);
102 printf("value of this index is %d\n", ranfuncdesc[5]);
103 printf("value of this index is %d\n", ranfuncdesc[6]);
104 printf("value of this index is %d\n", ranfuncdesc[10]);
105 printf("value of this index is %d\n", ranfuncdesc[15]);
106 printf("value of this index is %d\n", ranfuncdesc[100]);
107 printf("value of this index is %d\n", ranfuncdesc[101]);
109 e2sim.register_e2sm(0,ranfunc_ostr);
110 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
112 e2sim.run_loop(argc, argv);
117 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
122 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
124 //Process simulation file
131 int maxInd = 1000; //1000 no of indication to send
133 simfile.open("simulation.txt", ios::in);
135 // cout << "step1" << endl;
137 std::ifstream ue_stream("/playpen/src/ueMeasReport.txt");
138 std::ifstream cell_stream("/playpen/src/cellMeasReport.txt");
142 ue_stream >> all_ues_json;
146 cell_stream >> all_cells_json;
148 asn_codec_ctx_t *opt_cod;
150 // cout << "UE RF Measurements" << endl;
151 // cout << "******************" << endl;
153 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
155 for (int i = 0; i < numMeasReports; i++) {
160 // cout << "UE number " + i << endl;
161 // cout << "**********" << endl;
162 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
163 nextCellId = all_ues_json[p1].get<int>();
164 // cout << "Serving Cell " << nextCellId << endl;
166 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
167 nextRsrp = all_ues_json[p2].get<int>();
168 // cout << " RSRP " << nextRsrp << endl;
169 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
170 nextRsrq = all_ues_json[p3].get<int>();
171 // cout << " RSRQ " << nextRsrq << endl;
172 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
173 nextRssinr = all_ues_json[p4].get<int>();
174 // cout << " RSSINR " << nextRssinr << endl;
176 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
178 int numNeighborCells = (all_ues_json[p5]).size();
181 //REPORT Message 3 -- Encode and send OCUCP user-level report
183 E2SM_KPM_IndicationMessage_t *ind_msg3 =
184 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
185 E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
187 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
189 if (nextCellId == 0) {
190 uint8_t *buf2 = (uint8_t*)"12";
191 memcpy(crnti_buf, buf2, 2);
192 } else if (nextCellId == 1) {
193 uint8_t *buf2 = (uint8_t*)"22";
194 memcpy(crnti_buf, buf2, 2);
197 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
198 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
199 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
201 std::string neighbor_str = "[";
208 for (int j = 0; j < numNeighborCells; j++) {
209 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
210 nextNbCell = all_ues_json[p8].get<int>();
211 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
212 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
213 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
214 nextNbRsrp = all_ues_json[p9].get<int>();
215 //cout << " RSRP " << nextNbRsrp << endl;
217 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
218 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
219 nextNbRsrq = all_ues_json[p10].get<int>();
220 //cout << " RSRQ " << nextNbRsrq << endl;
222 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
223 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
224 nextNbRssinr = all_ues_json[p11].get<int>();
225 //cout << " RSSINR " << nextNbRssinr << endl;
232 neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
233 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
239 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
241 // printf("Neighbor string\n%s", neighbor_buf);
243 uint8_t *plmnid_buf = (uint8_t*)"747";
244 uint8_t *nrcellid_buf = (uint8_t*)"12340";
247 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
249 uint8_t e2smbuffer3[8192];
250 size_t e2smbuffer_size3 = 8192;
253 asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
254 ATS_ALIGNED_BASIC_PER,
255 &asn_DEF_E2SM_KPM_IndicationMessage,
256 ind_msg3, e2smbuffer3, e2smbuffer_size3);
258 fprintf(stderr, "er encded is %d\n", er3.encoded);
259 fprintf(stderr, "after encoding message\n");
260 uint8_t *e2smheader_buf3 = (uint8_t*)"";
262 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
263 instanceId, ranFunctionId,
264 actionId, seqNum, e2smheader_buf3, 0, e2smbuffer3, er3.encoded);
266 e2sim.encode_and_send_sctp_data(pdu3);
274 // cout << "Cell Measurements" << endl;
275 // cout << "******************" << endl;
277 int numCellMeasReports = (all_cells_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
279 uint8_t *sst_buf = (uint8_t*)"1";
280 uint8_t *sd_buf = (uint8_t*)"100";
281 uint8_t *plmnid_buf = (uint8_t*)"747";
283 for (int i = 0; i < numCellMeasReports; i++) {
291 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
292 nextCellId = all_cells_json[p1].get<int>();
293 // cout << std::string("Cell number ") << nextCellId << endl;
295 // cout << "**********" << endl;
297 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
298 nextPdcpBytesDL = all_cells_json[p2].get<int>();
299 // cout << std::string(" PDCP Bytes DL ") << nextPdcpBytesDL << endl;
301 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
302 nextPdcpBytesUL = all_cells_json[p3].get<int>();
303 // cout << std::string(" PDCP Bytes UL ") << nextPdcpBytesUL << endl;
305 uint8_t *buf = (uint8_t*)"GNBCUUP5";
307 int bytes_dl = nextPdcpBytesDL;
309 int bytes_ul = nextPdcpBytesUL;
311 // int bytes_dl = 3905;
312 // int bytes_ul = 1609321;
314 E2SM_KPM_IndicationMessage_t *ind_msg2 =
315 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
316 E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
318 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
320 uint8_t e2smbuffer2[8192];
321 size_t e2smbuffer_size2 = 8192;
323 asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
324 ATS_ALIGNED_BASIC_PER,
325 &asn_DEF_E2SM_KPM_IndicationMessage,
326 ind_msg2, e2smbuffer2, e2smbuffer_size2);
328 //fprintf(stderr, "er encded is %d\n", er2.encoded);
329 //fprintf(stderr, "after encoding message\n");
331 E2SM_KPM_IndicationHeader_t *ihead =
332 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
335 E2SM_KPM_IndicationHeader_Format1_t* ind_header =
336 (E2SM_KPM_IndicationHeader_Format1_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_Format1_t));
338 OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
339 plmnid->buf = (uint8_t*)calloc(3,1);
341 memcpy(plmnid->buf, plmnid_buf, plmnid->size);
346 OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
348 sst->buf = (uint8_t*)calloc(1,6);
349 memcpy(sst->buf,sst_buf,sst->size);
352 OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
354 sds->buf = (uint8_t*)calloc(1,3);
355 memcpy(sds->buf, sd_buf, sds->size);
358 SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
359 ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
360 snssai->sST.buf = (uint8_t*)calloc(1,1);
361 snssai->sST.size = 1;
362 memcpy(snssai->sST.buf, sst_buf, 1);
363 snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
364 snssai->sD->buf = (uint8_t*)calloc(1,3);
365 snssai->sD->size = 3;
366 memcpy(snssai->sD->buf, sd_buf, 3);
369 ind_header->pLMN_Identity = plmnid;
370 ind_header->fiveQI = &fqival;
372 BIT_STRING_t *nrcellid = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
373 nrcellid->buf = (uint8_t*)calloc(1,5);
375 nrcellid->buf[0] = 0x22;
376 nrcellid->buf[1] = 0x5B;
377 nrcellid->buf[2] = 0xD6;
378 nrcellid->buf[3] = 0x00;
379 nrcellid->buf[4] = 0x70;
381 nrcellid->bits_unused = 4;
383 BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
384 gnb_bstring->buf = (uint8_t*)calloc(1,4);
385 gnb_bstring->size = 4;
386 gnb_bstring->buf[0] = 0xB5;
387 gnb_bstring->buf[1] = 0xC6;
388 gnb_bstring->buf[2] = 0x77;
389 gnb_bstring->buf[3] = 0x88;
391 gnb_bstring->bits_unused = 3;
393 INTEGER_t *cuup_id = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
396 cuup_id->buf = (uint8_t*)calloc(1,1);
397 memcpy(cuup_id->buf, buffer, 1);
400 ind_header->id_GlobalKPMnode_ID = (GlobalKPMnode_ID*)calloc(1,sizeof(GlobalKPMnode_ID));
401 ind_header->id_GlobalKPMnode_ID->present = GlobalKPMnode_ID_PR_gNB;
402 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
403 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.choice.gnb_ID = *gnb_bstring;
404 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.plmn_id = *plmnid;
405 ind_header->id_GlobalKPMnode_ID->choice.gNB.gNB_CU_UP_ID = cuup_id;
407 ind_header->nRCGI = (NRCGI*)calloc(1,sizeof(NRCGI));
408 ind_header->nRCGI->pLMN_Identity = *plmnid;
409 ind_header->nRCGI->nRCellIdentity = *nrcellid;
411 ind_header->sliceID = snssai;
412 ind_header->qci = &qcival;
413 // ind_header->message_Type = ;
414 // ind_header->gNB_DU_ID = ;
417 uint8_t *buf5 = (uint8_t*)"GNBCUUP5";
418 OCTET_STRING_t *cuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
420 cuupname->buf = (uint8_t*)calloc(1,8);
421 memcpy(cuupname->buf, buf5, cuupname->size);
424 ind_header->gNB_Name = (GNB_Name*)calloc(1,sizeof(GNB_Name));
425 ind_header->gNB_Name->present = GNB_Name_PR_gNB_CU_UP_Name;
426 ind_header->gNB_Name->choice.gNB_CU_UP_Name = *cuupname;
429 ind_header->global_GNB_ID = (GlobalgNB_ID*)calloc(1,sizeof(GlobalgNB_ID));
430 ind_header->global_GNB_ID->plmn_id = *plmnid;
431 ind_header->global_GNB_ID->gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
432 ind_header->global_GNB_ID->gnb_id.choice.gnb_ID = *gnb_bstring;
435 ihead->present = E2SM_KPM_IndicationHeader_PR_indicationHeader_Format1;
436 ihead->choice.indicationHeader_Format1 = *ind_header;
438 //printf("IndicationHeader - now printing xer\n");
439 //xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ihead);
440 //printf("IndicationHeader - done printing xer\n");
442 uint8_t e2sm_header_buffer[8192];
443 size_t e2sm_header_buffer_size = 8192;
445 asn_enc_rval_t er4 = asn_encode_to_buffer(opt_cod,
446 ATS_ALIGNED_BASIC_PER,
447 &asn_DEF_E2SM_KPM_IndicationHeader,
448 ihead, e2sm_header_buffer, e2sm_header_buffer_size);
450 uint8_t *e2smheader_buf2 = (uint8_t*)"";
456 sleep(10); //added sleep before sending indication because bouncer xapp need to some time to receive subscription response properly
458 for(int ind=0; ind<maxInd; ind++) {
460 fprintf(stderr,"\nSending RIC Indication with seqnum = %d max_num_of_Ind = %d \n", seqNum0,maxInd);
462 encoding::generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
463 instanceId, ranFunctionId,
464 actionId, seqNum0, e2sm_header_buffer, er4.encoded, e2smbuffer2, er2.encoded);
466 e2sim.encode_and_send_sctp_data(pdu2);
476 json::json_pointer p4(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
477 nextPRBBytesDL = all_cells_json[p4].get<int>();
478 // cout << std::string(" PRB Bytes DL ") << all_cells_json[p4] << endl;
480 json::json_pointer p5(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
481 nextPRBBytesUL = all_cells_json[p5].get<int>();
482 // cout << std::string(" PRB Bytes UL ") << all_cells_json[p5] << endl;
485 //REPORT Message 1 -- Encode and send ODU cell-level report
487 E2SM_KPM_IndicationMessage_t *ind_msg1 =
488 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
489 E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
493 uint8_t *nrcellid_buf = (uint8_t*)"12340";
494 long dl_prbs = nextPRBBytesDL;
495 long ul_prbs = nextPRBBytesUL;
498 encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
500 uint8_t e2smbuffer[8192];
501 size_t e2smbuffer_size = 8192;
503 asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
504 ATS_ALIGNED_BASIC_PER,
505 &asn_DEF_E2SM_KPM_IndicationMessage,
506 ind_msg1, e2smbuffer, e2smbuffer_size);
508 fprintf(stderr, "er encded is %d\n", er.encoded);
509 fprintf(stderr, "after encoding message\n");
510 uint8_t *e2smheader_buf = (uint8_t*)"";
512 uint8_t *cpid_buf = (uint8_t*)"CPID";
514 fprintf(stderr, "About to encode Indication\n");
515 generate_e2apv1_indication_request_parameterized(pdu, requestorId,
516 instanceId, ranFunctionId,
517 actionId, seqNum, e2smheader_buf, 0, e2smbuffer, er.encoded);
519 e2sim.encode_and_send_sctp_data(pdu);
528 if (simfile.is_open()) {
530 while (getline(simfile, line)) {
531 cout << line << "\n";
533 //REPORT Message 1 -- Encode and send ODU cell-level report
535 E2SM_KPM_IndicationMessage_t *ind_msg1 =
536 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
537 E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
540 uint8_t *sst_buf = (uint8_t*)"1";
541 uint8_t *sd_buf = (uint8_t*)"100";
542 uint8_t *plmnid_buf = (uint8_t*)"747";
543 uint8_t *nrcellid_buf = (uint8_t*)"12340";
547 encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
549 uint8_t e2smbuffer[8192];
550 size_t e2smbuffer_size = 8192;
551 asn_codec_ctx_t *opt_cod;
553 asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
554 ATS_ALIGNED_BASIC_PER,
555 &asn_DEF_E2SM_KPM_IndicationMessage,
556 ind_msg1, e2smbuffer, e2smbuffer_size);
558 fprintf(stderr, "er encded is %d\n", er.encoded);
559 fprintf(stderr, "after encoding message\n");
560 uint8_t *e2smheader_buf = (uint8_t*)"header";
562 uint8_t *cpid_buf = (uint8_t*)"CPID";
564 fprintf(stderr, "About to encode Indication\n");
565 generate_e2apv1_indication_request_parameterized(pdu, requestorId,
566 instanceId, ranFunctionId,
567 actionId, seqNum, e2smheader_buf, 6, e2smbuffer, er.encoded);
569 encode_and_send_sctp_data(pdu, socket_fd);
573 //REPORT Message 2 -- Encode and send OCUUP cell-level report
575 uint8_t *buf = (uint8_t*)"GNBCUUP5";
577 int bytes_dl = 40000;
578 int bytes_ul = 50000;
580 E2SM_KPM_IndicationMessage_t *ind_msg2 =
581 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
582 E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
584 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
586 uint8_t e2smbuffer2[8192];
587 size_t e2smbuffer_size2 = 8192;
590 asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
591 ATS_ALIGNED_BASIC_PER,
592 &asn_DEF_E2SM_KPM_IndicationMessage,
593 ind_msg2, e2smbuffer2, e2smbuffer_size2);
595 fprintf(stderr, "er encded is %d\n", er2.encoded);
596 fprintf(stderr, "after encoding message\n");
597 uint8_t *e2smheader_buf2 = (uint8_t*)"header";
599 generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
600 instanceId, ranFunctionId,
601 actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
603 encode_and_send_sctp_data(pdu2, socket_fd);
607 //REPORT Message 3 -- Encode and send OCUCP user-level report
609 E2SM_KPM_IndicationMessage_t *ind_msg3 =
610 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
611 E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
613 uint8_t *crnti_buf = (uint8_t*)"12";
614 // uint8_t *serving_buf = (uint8_t*)"RSRP10";
615 //uint8_t *neighbor_buf = (uint8_t*)"-10,-15";
620 std::string serving_str = "{\"rsrp\": " + std::to_string(rsrpServ) + ", \"rsrq\": " +
621 std::to_string(rsrqServ) + ", \"rssinr\": " + std::to_string(rssinrServ) + "}";
622 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
625 neighbor_cell_entry n_entries[3];
626 n_entries[0] = {"123", 10, 0, 0};
627 n_entries[1] = {"456", 10, 0, 0};
628 n_entries[2] = {"789", 10, 0, 0};
630 std::string neighbor_str = "[";
632 for (int i=0; i < sizeof(n_entries)/sizeof(n_entries[0]); i++) {
637 neighbor_str += "{\"CID\" : \"" + std::string(n_entries[i].cellid) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(n_entries[i].rsrp) +
638 ", \"rsrq\": " + std::to_string(n_entries[i].rsrq) + ", \"rssinr\": " + std::to_string(n_entries[i].rsrp) + "}}";
643 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
645 printf("Neighbor string\n%s", neighbor_buf);
647 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
649 uint8_t e2smbuffer3[8192];
650 size_t e2smbuffer_size3 = 8192;
652 asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
653 ATS_ALIGNED_BASIC_PER,
654 &asn_DEF_E2SM_KPM_IndicationMessage,
655 ind_msg3, e2smbuffer3, e2smbuffer_size3);
657 fprintf(stderr, "er encded is %d\n", er3.encoded);
658 fprintf(stderr, "after encoding message\n");
659 uint8_t *e2smheader_buf3 = (uint8_t*)"header";
661 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
662 instanceId, ranFunctionId,
663 actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
665 encode_and_send_sctp_data(pdu3, socket_fd);
669 //Encode and send OCUUP user-level report
673 //Encode and send ODU user-level report
688 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
690 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
692 //Record RIC Request ID
693 //Go through RIC action to be Setup List
694 //Find first entry with REPORT action Type
696 //Encode subscription response
698 RICsubscriptionRequest_t orig_req =
699 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
701 RICsubscriptionResponse_IEs_t *ricreqid =
702 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
704 int count = orig_req.protocolIEs.list.count;
705 int size = orig_req.protocolIEs.list.size;
707 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
709 fprintf(stderr, "count%d\n", count);
710 fprintf(stderr, "size%d\n", size);
712 RICsubscriptionRequest_IEs__value_PR pres;
718 std::vector<long> actionIdsAccept;
719 std::vector<long> actionIdsReject;
721 for (int i=0; i < count; i++) {
722 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
723 pres = next_ie->value.present;
725 fprintf(stderr, "The next present value %d\n", pres);
728 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
730 fprintf(stderr,"in case request id\n");
731 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
732 long requestorId = reqId.ricRequestorID;
733 long instanceId = reqId.ricInstanceID;
734 fprintf(stderr, "requestorId %d\n", requestorId);
735 fprintf(stderr, "instanceId %d\n", instanceId);
736 reqRequestorId = requestorId;
737 reqInstanceId = instanceId;
741 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
743 fprintf(stderr,"in case ran func id\n");
746 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
748 fprintf(stderr,"in case subscription details\n");
749 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
750 fprintf(stderr,"in case subscription details 1\n");
751 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
752 fprintf(stderr,"in case subscription details 2\n");
753 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
754 fprintf(stderr,"in case subscription details 3\n");
755 //We are ignoring the trigger definition
757 //We identify the first action whose type is REPORT
758 //That is the only one accepted; all others are rejected
760 int actionCount = actionList.list.count;
761 fprintf(stderr, "action count%d\n", actionCount);
763 auto **item_array = actionList.list.array;
765 bool foundAction = false;
767 for (int i=0; i < actionCount; i++) {
769 auto *next_item = item_array[i];
770 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
771 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
773 if (!foundAction && actionType == RICactionType_report) {
774 reqActionId = actionId;
775 actionIdsAccept.push_back(reqActionId);
776 printf("adding accept\n");
779 reqActionId = actionId;
780 printf("adding reject\n");
781 actionIdsReject.push_back(reqActionId);
789 fprintf(stderr,"in case default\n");
796 fprintf(stderr, "After Processing Subscription Request\n");
798 fprintf(stderr, "requestorId %d\n", reqRequestorId);
799 fprintf(stderr, "instanceId %d\n", reqInstanceId);
802 for (int i=0; i < actionIdsAccept.size(); i++) {
803 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
807 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
809 long *accept_array = &actionIdsAccept[0];
810 long *reject_array = &actionIdsReject[0];
811 int accept_size = actionIdsAccept.size();
812 int reject_size = actionIdsReject.size();
814 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
816 e2sim.encode_and_send_sctp_data(e2ap_pdu);
818 //Start thread for sending REPORT messages
820 // std::thread loop_thread;
824 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
826 // loop_thread = std::thread(&run_report_loop);