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;
73 //int main(int argc, char* argv[]) {
75 void *initparam(void *input){
76 fprintf(stderr, "Starting KPM processor sim\n");
78 //struct args *value1 = (struct args *)malloc(sizeof(struct args));
79 //fprintf(stderr,"ip address at initparam :%s port:%s\n",(char *)input->args2[1],(char *)input->args2[2]);
80 //struct args *value1 = (struct args *)input;
81 // value1 = (struct args *)input;
82 struct args *value1 = ( args *) input;
83 //fprintf(stderr,"ip address at initparam :%s port:%s\n",value1->args2[1],value1->args2[2]);
86 asn_codec_ctx_t *opt_cod;
88 E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
89 (E2SM_KPM_RANfunction_Description_t*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t));
90 encode_kpm_function_description(ranfunc_desc);
92 uint8_t e2smbuffer[8192];
93 size_t e2smbuffer_size = 8192;
96 asn_encode_to_buffer(opt_cod,
97 ATS_ALIGNED_BASIC_PER,
98 &asn_DEF_E2SM_KPM_RANfunction_Description,
99 ranfunc_desc, e2smbuffer, e2smbuffer_size);
101 fprintf(stderr, "er encded is %d\n", er.encoded);
102 fprintf(stderr, "after encoding message\n");
103 fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
105 uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
106 memcpy(ranfuncdesc, e2smbuffer, er.encoded);
108 printf("this is the char array %s\n", (char*)ranfuncdesc);
110 OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
111 ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
112 ranfunc_ostr->size = er.encoded;
113 memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
115 printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
116 /* printf("value of this index is %d\n", ranfuncdesc[0]);
117 printf("value of this index is %d\n", ranfuncdesc[1]);
118 printf("value of this index is %d\n", ranfuncdesc[2]);
119 printf("value of this index is %d\n", ranfuncdesc[3]);
120 printf("value of this index is %d\n", ranfuncdesc[4]);
121 printf("value of this index is %d\n", ranfuncdesc[5]);
122 printf("value of this index is %d\n", ranfuncdesc[6]);
123 printf("value of this index is %d\n", ranfuncdesc[10]);
124 printf("value of this index is %d\n", ranfuncdesc[15]);
125 printf("value of this index is %d\n", ranfuncdesc[100]);
126 printf("value of this index is %d\n", ranfuncdesc[101]);
128 e2sim.register_e2sm(0,ranfunc_ostr);
129 e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
131 fprintf(stderr,"ip address at run loop call:%s port:%s\n",value1->args2[1],value1->args2[2]);
132 e2sim.run_loop(value1->args1,value1->args2,value1->plmnId);//(argc, argv);
137 int main(int argc, char **argv) {
139 struct args *value = (struct args *)malloc(sizeof(struct args));
142 // printf("Enter number of e2sim\n");
143 // int num_of_e2sim = getch();
148 if (value->args2[3] != NULL)
150 num_of_e2sim = atoi(value->args2[3]);//500;
151 fprintf(stderr,"number of e2sim : %d\n", num_of_e2sim);
158 //int num_of_e2sim = atoi(value->args2[3]);//500;
160 //options_t read_input_options(int argc, char* argv[]);
162 fprintf(stderr,"value of thread id is %d\n", num_of_e2sim);
164 fprintf(stderr,"argc : %d ,ip address:%s, port:%s\n", value->args1,value->args2[1], value->args2[2]);
166 pthread_t threads[10000];
169 for( i = 0; i < num_of_e2sim; i++ ) {
171 //struct args *value = (struct args *)malloc(sizeof(struct args));
174 //struct args *value = (struct args *)malloc(sizeof(struct args));
175 //value->args1 = argc;
176 //value->args2 = argv;
177 //value->plmnId = plmnid;
180 fprintf(stderr,"\n****************************************************************************************************\n");
181 //fprintf(stderr,"argc: %d, argv ip address is:%s,argv port:%s\n",argc, argv[1],argv[2]);
183 fprintf(stderr,"value of thread id is %d\n", i);
184 fprintf(stderr,"value of plmn id is %d\n", value->plmnId);
185 fprintf(stderr,"ip address is:%s, port:%s\n", value->args2[1],value->args2[2]);
186 retvalue = pthread_create(&threads[i], NULL, initparam, (void *)value);
193 fprintf(stderr,"Error:unable to create thread, %d\n", retvalue);
202 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
207 void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long actionId) {
209 //Process simulation file
216 int maxInd = 1;//500; //1000 no of indication to send
218 simfile.open("simulation.txt", ios::in);
220 // cout << "step1" << endl;
222 std::ifstream ue_stream("/playpen/src/ueMeasReport.txt");
223 std::ifstream cell_stream("/playpen/src/cellMeasReport.txt");
227 ue_stream >> all_ues_json;
231 cell_stream >> all_cells_json;
233 asn_codec_ctx_t *opt_cod;
235 // cout << "UE RF Measurements" << endl;
236 // cout << "******************" << endl;
238 int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
240 for (int i = 0; i < numMeasReports; i++) {
245 // cout << "UE number " + i << endl;
246 // cout << "**********" << endl;
247 json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
248 nextCellId = all_ues_json[p1].get<int>();
249 // cout << "Serving Cell " << nextCellId << endl;
251 json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
252 nextRsrp = all_ues_json[p2].get<int>();
253 // cout << " RSRP " << nextRsrp << endl;
254 json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
255 nextRsrq = all_ues_json[p3].get<int>();
256 // cout << " RSRQ " << nextRsrq << endl;
257 json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
258 nextRssinr = all_ues_json[p4].get<int>();
259 // cout << " RSSINR " << nextRssinr << endl;
261 json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
263 int numNeighborCells = (all_ues_json[p5]).size();
266 //REPORT Message 3 -- Encode and send OCUCP user-level report
268 E2SM_KPM_IndicationMessage_t *ind_msg3 =
269 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
270 E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
272 uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
274 if (nextCellId == 0) {
275 uint8_t *buf2 = (uint8_t*)"12";
276 memcpy(crnti_buf, buf2, 2);
277 } else if (nextCellId == 1) {
278 uint8_t *buf2 = (uint8_t*)"22";
279 memcpy(crnti_buf, buf2, 2);
282 std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
283 std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
284 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
286 std::string neighbor_str = "[";
293 for (int j = 0; j < numNeighborCells; j++) {
294 json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
295 nextNbCell = all_ues_json[p8].get<int>();
296 //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
297 json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
298 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
299 nextNbRsrp = all_ues_json[p9].get<int>();
300 //cout << " RSRP " << nextNbRsrp << endl;
302 json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
303 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
304 nextNbRsrq = all_ues_json[p10].get<int>();
305 //cout << " RSRQ " << nextNbRsrq << endl;
307 json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
308 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
309 nextNbRssinr = all_ues_json[p11].get<int>();
310 //cout << " RSSINR " << nextNbRssinr << endl;
317 neighbor_str += "{\"CID\" : \"" + std::to_string(nextNbCell) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(nextNbRsrp) +
318 ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
324 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
326 // printf("Neighbor string\n%s", neighbor_buf);
328 uint8_t *plmnid_buf = (uint8_t*)"747";
329 uint8_t *nrcellid_buf = (uint8_t*)"12340";
332 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
334 uint8_t e2smbuffer3[8192];
335 size_t e2smbuffer_size3 = 8192;
338 asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
339 ATS_ALIGNED_BASIC_PER,
340 &asn_DEF_E2SM_KPM_IndicationMessage,
341 ind_msg3, e2smbuffer3, e2smbuffer_size3);
343 fprintf(stderr, "er encded is %d\n", er3.encoded);
344 fprintf(stderr, "after encoding message\n");
345 uint8_t *e2smheader_buf3 = (uint8_t*)"";
347 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
348 instanceId, ranFunctionId,
349 actionId, seqNum, e2smheader_buf3, 0, e2smbuffer3, er3.encoded);
351 e2sim.encode_and_send_sctp_data(pdu3);
359 // cout << "Cell Measurements" << endl;
360 // cout << "******************" << endl;
362 int numCellMeasReports = (all_cells_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
364 uint8_t *sst_buf = (uint8_t*)"1";
365 uint8_t *sd_buf = (uint8_t*)"100";
366 uint8_t *plmnid_buf = (uint8_t*)"747";
368 for (int i = 0; i < numCellMeasReports; i++) {
376 json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
377 nextCellId = all_cells_json[p1].get<int>();
378 // cout << std::string("Cell number ") << nextCellId << endl;
380 // cout << "**********" << endl;
382 json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
383 nextPdcpBytesDL = all_cells_json[p2].get<int>();
384 // cout << std::string(" PDCP Bytes DL ") << nextPdcpBytesDL << endl;
386 json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
387 nextPdcpBytesUL = all_cells_json[p3].get<int>();
388 // cout << std::string(" PDCP Bytes UL ") << nextPdcpBytesUL << endl;
390 uint8_t *buf = (uint8_t*)"GNBCUUP5";
392 int bytes_dl = nextPdcpBytesDL;
394 int bytes_ul = nextPdcpBytesUL;
396 // int bytes_dl = 3905;
397 // int bytes_ul = 1609321;
399 E2SM_KPM_IndicationMessage_t *ind_msg2 =
400 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
401 E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
403 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
405 uint8_t e2smbuffer2[8192];
406 size_t e2smbuffer_size2 = 8192;
408 asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
409 ATS_ALIGNED_BASIC_PER,
410 &asn_DEF_E2SM_KPM_IndicationMessage,
411 ind_msg2, e2smbuffer2, e2smbuffer_size2);
413 //fprintf(stderr, "er encded is %d\n", er2.encoded);
414 //fprintf(stderr, "after encoding message\n");
416 E2SM_KPM_IndicationHeader_t *ihead =
417 (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
420 E2SM_KPM_IndicationHeader_Format1_t* ind_header =
421 (E2SM_KPM_IndicationHeader_Format1_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_Format1_t));
423 OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
424 plmnid->buf = (uint8_t*)calloc(3,1);
426 memcpy(plmnid->buf, plmnid_buf, plmnid->size);
431 OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
433 sst->buf = (uint8_t*)calloc(1,6);
434 memcpy(sst->buf,sst_buf,sst->size);
437 OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
439 sds->buf = (uint8_t*)calloc(1,3);
440 memcpy(sds->buf, sd_buf, sds->size);
443 SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
444 ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
445 snssai->sST.buf = (uint8_t*)calloc(1,1);
446 snssai->sST.size = 1;
447 memcpy(snssai->sST.buf, sst_buf, 1);
448 snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
449 snssai->sD->buf = (uint8_t*)calloc(1,3);
450 snssai->sD->size = 3;
451 memcpy(snssai->sD->buf, sd_buf, 3);
454 ind_header->pLMN_Identity = plmnid;
455 ind_header->fiveQI = &fqival;
457 BIT_STRING_t *nrcellid = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
458 nrcellid->buf = (uint8_t*)calloc(1,5);
460 nrcellid->buf[0] = 0x22;
461 nrcellid->buf[1] = 0x5B;
462 nrcellid->buf[2] = 0xD6;
463 nrcellid->buf[3] = 0x00;
464 nrcellid->buf[4] = 0x70;
466 nrcellid->bits_unused = 4;
468 BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
469 gnb_bstring->buf = (uint8_t*)calloc(1,4);
470 gnb_bstring->size = 4;
471 gnb_bstring->buf[0] = 0xB5;
472 gnb_bstring->buf[1] = 0xC6;
473 gnb_bstring->buf[2] = 0x77;
474 gnb_bstring->buf[3] = 0x88;
476 gnb_bstring->bits_unused = 3;
478 INTEGER_t *cuup_id = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
481 cuup_id->buf = (uint8_t*)calloc(1,1);
482 memcpy(cuup_id->buf, buffer, 1);
485 ind_header->id_GlobalKPMnode_ID = (GlobalKPMnode_ID*)calloc(1,sizeof(GlobalKPMnode_ID));
486 ind_header->id_GlobalKPMnode_ID->present = GlobalKPMnode_ID_PR_gNB;
487 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
488 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.choice.gnb_ID = *gnb_bstring;
489 ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.plmn_id = *plmnid;
490 ind_header->id_GlobalKPMnode_ID->choice.gNB.gNB_CU_UP_ID = cuup_id;
492 ind_header->nRCGI = (NRCGI*)calloc(1,sizeof(NRCGI));
493 ind_header->nRCGI->pLMN_Identity = *plmnid;
494 ind_header->nRCGI->nRCellIdentity = *nrcellid;
496 ind_header->sliceID = snssai;
497 ind_header->qci = &qcival;
498 // ind_header->message_Type = ;
499 // ind_header->gNB_DU_ID = ;
502 uint8_t *buf5 = (uint8_t*)"GNBCUUP5";
503 OCTET_STRING_t *cuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
505 cuupname->buf = (uint8_t*)calloc(1,8);
506 memcpy(cuupname->buf, buf5, cuupname->size);
509 ind_header->gNB_Name = (GNB_Name*)calloc(1,sizeof(GNB_Name));
510 ind_header->gNB_Name->present = GNB_Name_PR_gNB_CU_UP_Name;
511 ind_header->gNB_Name->choice.gNB_CU_UP_Name = *cuupname;
514 ind_header->global_GNB_ID = (GlobalgNB_ID*)calloc(1,sizeof(GlobalgNB_ID));
515 ind_header->global_GNB_ID->plmn_id = *plmnid;
516 ind_header->global_GNB_ID->gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
517 ind_header->global_GNB_ID->gnb_id.choice.gnb_ID = *gnb_bstring;
520 ihead->present = E2SM_KPM_IndicationHeader_PR_indicationHeader_Format1;
521 ihead->choice.indicationHeader_Format1 = *ind_header;
523 //printf("IndicationHeader - now printing xer\n");
524 //xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ihead);
525 //printf("IndicationHeader - done printing xer\n");
527 uint8_t e2sm_header_buffer[8192];
528 size_t e2sm_header_buffer_size = 8192;
530 asn_enc_rval_t er4 = asn_encode_to_buffer(opt_cod,
531 ATS_ALIGNED_BASIC_PER,
532 &asn_DEF_E2SM_KPM_IndicationHeader,
533 ihead, e2sm_header_buffer, e2sm_header_buffer_size);
535 uint8_t *e2smheader_buf2 = (uint8_t*)"";
541 sleep(10); //added sleep before sending indication because bouncer xapp need to some time to receive subscription response properly
543 for(int ind=0; ind<maxInd; ind++) {
545 fprintf(stderr,"\nSending RIC Indication with seqnum = %d max_num_of_Ind = %d \n", seqNum0,maxInd);
547 encoding::generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
548 instanceId, ranFunctionId,
549 actionId, seqNum0, e2sm_header_buffer, er4.encoded, e2smbuffer2, er2.encoded);
551 e2sim.encode_and_send_sctp_data(pdu2);
561 json::json_pointer p4(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
562 nextPRBBytesDL = all_cells_json[p4].get<int>();
563 // cout << std::string(" PRB Bytes DL ") << all_cells_json[p4] << endl;
565 json::json_pointer p5(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
566 nextPRBBytesUL = all_cells_json[p5].get<int>();
567 // cout << std::string(" PRB Bytes UL ") << all_cells_json[p5] << endl;
570 //REPORT Message 1 -- Encode and send ODU cell-level report
572 E2SM_KPM_IndicationMessage_t *ind_msg1 =
573 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
574 E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
578 uint8_t *nrcellid_buf = (uint8_t*)"12340";
579 long dl_prbs = nextPRBBytesDL;
580 long ul_prbs = nextPRBBytesUL;
583 encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
585 uint8_t e2smbuffer[8192];
586 size_t e2smbuffer_size = 8192;
588 asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
589 ATS_ALIGNED_BASIC_PER,
590 &asn_DEF_E2SM_KPM_IndicationMessage,
591 ind_msg1, e2smbuffer, e2smbuffer_size);
593 fprintf(stderr, "er encded is %d\n", er.encoded);
594 fprintf(stderr, "after encoding message\n");
595 uint8_t *e2smheader_buf = (uint8_t*)"";
597 uint8_t *cpid_buf = (uint8_t*)"CPID";
599 fprintf(stderr, "About to encode Indication\n");
600 generate_e2apv1_indication_request_parameterized(pdu, requestorId,
601 instanceId, ranFunctionId,
602 actionId, seqNum, e2smheader_buf, 0, e2smbuffer, er.encoded);
604 e2sim.encode_and_send_sctp_data(pdu);
613 if (simfile.is_open()) {
615 while (getline(simfile, line)) {
616 cout << line << "\n";
618 //REPORT Message 1 -- Encode and send ODU cell-level report
620 E2SM_KPM_IndicationMessage_t *ind_msg1 =
621 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
622 E2AP_PDU *pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
625 uint8_t *sst_buf = (uint8_t*)"1";
626 uint8_t *sd_buf = (uint8_t*)"100";
627 uint8_t *plmnid_buf = (uint8_t*)"747";
628 uint8_t *nrcellid_buf = (uint8_t*)"12340";
632 encode_kpm_report_style1_parameterized(ind_msg1, fiveqi, dl_prbs, ul_prbs, sst_buf, sd_buf, plmnid_buf, nrcellid_buf, &dl_prbs, &ul_prbs);
634 uint8_t e2smbuffer[8192];
635 size_t e2smbuffer_size = 8192;
636 asn_codec_ctx_t *opt_cod;
638 asn_enc_rval_t er = asn_encode_to_buffer(opt_cod,
639 ATS_ALIGNED_BASIC_PER,
640 &asn_DEF_E2SM_KPM_IndicationMessage,
641 ind_msg1, e2smbuffer, e2smbuffer_size);
643 fprintf(stderr, "er encded is %d\n", er.encoded);
644 fprintf(stderr, "after encoding message\n");
645 uint8_t *e2smheader_buf = (uint8_t*)"header";
647 uint8_t *cpid_buf = (uint8_t*)"CPID";
649 fprintf(stderr, "About to encode Indication\n");
650 generate_e2apv1_indication_request_parameterized(pdu, requestorId,
651 instanceId, ranFunctionId,
652 actionId, seqNum, e2smheader_buf, 6, e2smbuffer, er.encoded);
654 encode_and_send_sctp_data(pdu, socket_fd);
658 //REPORT Message 2 -- Encode and send OCUUP cell-level report
660 uint8_t *buf = (uint8_t*)"GNBCUUP5";
662 int bytes_dl = 40000;
663 int bytes_ul = 50000;
665 E2SM_KPM_IndicationMessage_t *ind_msg2 =
666 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
667 E2AP_PDU *pdu2 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
669 encode_kpm_report_style5_parameterized(ind_msg2 , buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
671 uint8_t e2smbuffer2[8192];
672 size_t e2smbuffer_size2 = 8192;
675 asn_enc_rval_t er2 = asn_encode_to_buffer(opt_cod,
676 ATS_ALIGNED_BASIC_PER,
677 &asn_DEF_E2SM_KPM_IndicationMessage,
678 ind_msg2, e2smbuffer2, e2smbuffer_size2);
680 fprintf(stderr, "er encded is %d\n", er2.encoded);
681 fprintf(stderr, "after encoding message\n");
682 uint8_t *e2smheader_buf2 = (uint8_t*)"header";
684 generate_e2apv1_indication_request_parameterized(pdu2, requestorId,
685 instanceId, ranFunctionId,
686 actionId, seqNum, e2smheader_buf2, 6, e2smbuffer2, er2.encoded);
688 encode_and_send_sctp_data(pdu2, socket_fd);
692 //REPORT Message 3 -- Encode and send OCUCP user-level report
694 E2SM_KPM_IndicationMessage_t *ind_msg3 =
695 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
696 E2AP_PDU *pdu3 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
698 uint8_t *crnti_buf = (uint8_t*)"12";
699 // uint8_t *serving_buf = (uint8_t*)"RSRP10";
700 //uint8_t *neighbor_buf = (uint8_t*)"-10,-15";
705 std::string serving_str = "{\"rsrp\": " + std::to_string(rsrpServ) + ", \"rsrq\": " +
706 std::to_string(rsrqServ) + ", \"rssinr\": " + std::to_string(rssinrServ) + "}";
707 const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());
710 neighbor_cell_entry n_entries[3];
711 n_entries[0] = {"123", 10, 0, 0};
712 n_entries[1] = {"456", 10, 0, 0};
713 n_entries[2] = {"789", 10, 0, 0};
715 std::string neighbor_str = "[";
717 for (int i=0; i < sizeof(n_entries)/sizeof(n_entries[0]); i++) {
722 neighbor_str += "{\"CID\" : \"" + std::string(n_entries[i].cellid) + "\", \"Cell-RF\" : \"{\"rsrp\": " + std::to_string(n_entries[i].rsrp) +
723 ", \"rsrq\": " + std::to_string(n_entries[i].rsrq) + ", \"rssinr\": " + std::to_string(n_entries[i].rsrp) + "}}";
728 const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
730 printf("Neighbor string\n%s", neighbor_buf);
732 encode_kpm_report_rancontainer_cucp_parameterized(ind_msg3, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
734 uint8_t e2smbuffer3[8192];
735 size_t e2smbuffer_size3 = 8192;
737 asn_enc_rval_t er3 = asn_encode_to_buffer(opt_cod,
738 ATS_ALIGNED_BASIC_PER,
739 &asn_DEF_E2SM_KPM_IndicationMessage,
740 ind_msg3, e2smbuffer3, e2smbuffer_size3);
742 fprintf(stderr, "er encded is %d\n", er3.encoded);
743 fprintf(stderr, "after encoding message\n");
744 uint8_t *e2smheader_buf3 = (uint8_t*)"header";
746 generate_e2apv1_indication_request_parameterized(pdu3, requestorId,
747 instanceId, ranFunctionId,
748 actionId, seqNum, e2smheader_buf3, 6, e2smbuffer3, er3.encoded);
750 encode_and_send_sctp_data(pdu3, socket_fd);
754 //Encode and send OCUUP user-level report
758 //Encode and send ODU user-level report
773 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
775 fprintf(stderr, "Calling callback_kpm_subscription_request\n");
777 //Record RIC Request ID
778 //Go through RIC action to be Setup List
779 //Find first entry with REPORT action Type
781 //Encode subscription response
783 RICsubscriptionRequest_t orig_req =
784 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
786 RICsubscriptionResponse_IEs_t *ricreqid =
787 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
789 int count = orig_req.protocolIEs.list.count;
790 int size = orig_req.protocolIEs.list.size;
792 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
794 fprintf(stderr, "count%d\n", count);
795 fprintf(stderr, "size%d\n", size);
797 RICsubscriptionRequest_IEs__value_PR pres;
803 std::vector<long> actionIdsAccept;
804 std::vector<long> actionIdsReject;
806 for (int i=0; i < count; i++) {
807 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
808 pres = next_ie->value.present;
810 fprintf(stderr, "The next present value %d\n", pres);
813 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
815 fprintf(stderr,"in case request id\n");
816 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
817 long requestorId = reqId.ricRequestorID;
818 long instanceId = reqId.ricInstanceID;
819 fprintf(stderr, "requestorId %d\n", requestorId);
820 fprintf(stderr, "instanceId %d\n", instanceId);
821 reqRequestorId = requestorId;
822 reqInstanceId = instanceId;
826 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
828 fprintf(stderr,"in case ran func id\n");
831 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
833 fprintf(stderr,"in case subscription details\n");
834 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
835 fprintf(stderr,"in case subscription details 1\n");
836 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
837 fprintf(stderr,"in case subscription details 2\n");
838 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
839 fprintf(stderr,"in case subscription details 3\n");
840 //We are ignoring the trigger definition
842 //We identify the first action whose type is REPORT
843 //That is the only one accepted; all others are rejected
845 int actionCount = actionList.list.count;
846 fprintf(stderr, "action count%d\n", actionCount);
848 auto **item_array = actionList.list.array;
850 bool foundAction = false;
852 for (int i=0; i < actionCount; i++) {
854 auto *next_item = item_array[i];
855 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
856 RICactionType_t actionType = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionType;
858 if (!foundAction && actionType == RICactionType_report) {
859 reqActionId = actionId;
860 actionIdsAccept.push_back(reqActionId);
861 printf("adding accept\n");
864 reqActionId = actionId;
865 printf("adding reject\n");
866 actionIdsReject.push_back(reqActionId);
874 fprintf(stderr,"in case default\n");
881 fprintf(stderr, "After Processing Subscription Request\n");
883 fprintf(stderr, "requestorId %d\n", reqRequestorId);
884 fprintf(stderr, "instanceId %d\n", reqInstanceId);
887 for (int i=0; i < actionIdsAccept.size(); i++) {
888 fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
892 E2AP_PDU *e2ap_pdu = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
894 long *accept_array = &actionIdsAccept[0];
895 long *reject_array = &actionIdsReject[0];
896 int accept_size = actionIdsAccept.size();
897 int reject_size = actionIdsReject.size();
899 encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
901 e2sim.encode_and_send_sctp_data(e2ap_pdu);
903 //Start thread for sending REPORT messages
905 // std::thread loop_thread;
909 run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
911 // loop_thread = std::thread(&run_report_loop);