SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / e2sm_examples / kpm_e2sm / src / kpm / kpm_callbacks.cpp
index fea3a4b..59bd744 100755 (executable)
 
 
 extern "C" {
-  #include "OCUCP-PF-Container.h"
   #include "OCTET_STRING.h"
   #include "asn_application.h"
   #include "E2SM-KPM-IndicationMessage.h"
-  #include "FQIPERSlicesPerPlmnListItem.h"
   #include "E2SM-KPM-RANfunction-Description.h"
   #include "E2SM-KPM-IndicationHeader-Format1.h"
   #include "E2SM-KPM-IndicationHeader.h"
-  #include "Timestamp.h"
   #include "E2AP-PDU.h"
   #include "RICsubscriptionRequest.h"
   #include "RICsubscriptionResponse.h"
@@ -51,7 +48,8 @@ extern "C" {
 #include <chrono>
 
 #include "viavi_connector.hpp"
-
+#include "errno.h"
+#include "e2sim_defs.h"
 using json = nlohmann::json;
 
 using namespace std;
@@ -62,9 +60,7 @@ E2Sim e2sim;
 
 int main(int argc, char* argv[]) {
 
-  fprintf(stderr, "Starting KPM processor sim");
-
-  fprintf(stderr, "JSON Test\n");
+  LOG_I("Starting KPM simulator");
 
   uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
   nrcellid_buf[0] = 0x22;
@@ -73,8 +69,6 @@ int main(int argc, char* argv[]) {
   nrcellid_buf[3] = 0x00;
   nrcellid_buf[4] = 0x70;
 
-  
-
   asn_codec_ctx_t *opt_cod;
   
   E2SM_KPM_RANfunction_Description_t *ranfunc_desc =
@@ -90,33 +84,20 @@ int main(int argc, char* argv[]) {
                         &asn_DEF_E2SM_KPM_RANfunction_Description,
                         ranfunc_desc, e2smbuffer, e2smbuffer_size);
   
-  fprintf(stderr, "er encded is %d\n", er.encoded);
-  fprintf(stderr, "after encoding message\n");
-  fprintf(stderr, "here is encoded message %s\n", e2smbuffer);
-  
+  if(er.encoded == -1) {
+       LOG_I("Failed to serialize function description data. Detail: %s.", asn_DEF_E2SM_KPM_RANfunction_Description.name);
+  } else if(er.encoded > e2smbuffer_size) {
+       LOG_I("Buffer of size %zu is too small for %s, need %zu", e2smbuffer_size, asn_DEF_E2SM_KPM_RANfunction_Description.name, er.encoded);
+  }
+
   uint8_t *ranfuncdesc = (uint8_t*)calloc(1,er.encoded);
   memcpy(ranfuncdesc, e2smbuffer, er.encoded);
   
-  printf("this is the char array %s\n", (char*)ranfuncdesc);
-  
   OCTET_STRING_t *ranfunc_ostr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
   ranfunc_ostr->buf = (uint8_t*)calloc(1,er.encoded);
   ranfunc_ostr->size = er.encoded;
   memcpy(ranfunc_ostr->buf,e2smbuffer,er.encoded);
-
-  printf("!!!lenth of ranfuncdesc is %d\n", strlen((char*)ranfuncdesc));
-  printf("value of this index is %d\n", ranfuncdesc[0]);
-  printf("value of this index is %d\n", ranfuncdesc[1]);
-  printf("value of this index is %d\n", ranfuncdesc[2]);
-  printf("value of this index is %d\n", ranfuncdesc[3]);
-  printf("value of this index is %d\n", ranfuncdesc[4]);
-  printf("value of this index is %d\n", ranfuncdesc[5]);
-  printf("value of this index is %d\n", ranfuncdesc[6]);
-  printf("value of this index is %d\n", ranfuncdesc[10]);
-  printf("value of this index is %d\n", ranfuncdesc[15]);
-  printf("value of this index is %d\n", ranfuncdesc[100]);
-  printf("value of this index is %d\n", ranfuncdesc[101]);
-  
   e2sim.register_e2sm(0,ranfunc_ostr);
   e2sim.register_subscription_callback(0,&callback_kpm_subscription_request);
 
@@ -178,534 +159,371 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
     uint8_t *sd_buf = (uint8_t*)"100";
     
 
-    fprintf(stderr,"De line is %s\n", str.c_str());
+    LOG_I("Current line: %s", str.c_str());
 
     bool valid = false;
 
     try {
       all_ues_json = json::parse(str);
-
       valid = true;
     } catch (...) {
-      fprintf(stderr, "Exception on reading json\n");
+      LOG_I("Exception on reading json");
+         exit(1);
     }
 
     if (valid) {
 
-      fprintf(stderr, "key is valid\n");
-
       std::string first_key = all_ues_json.begin().key();
-      fprintf(stderr, "first key is %s\n", first_key.c_str());
+      LOG_I("First key is %s\n", first_key.c_str());
       
       if (first_key.compare("ueMeasReport") == 0) {
-       
-       fprintf(stderr, "it is equal to ue meas report\n");
 
-       int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
-       
-      
-       for (int i = 0; i < numMeasReports; i++) {
-         int nextCellId;
-         int nextRsrp;
-         int nextRsrq;
-         int nextRssinr;
-         float tput;
-         int prb_usage;
-         std::string ueId;
-         
-         fprintf(stderr,"UE number %d\n", i);
-
-         json::json_pointer p001(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/ue-id");
-         ueId = all_ues_json[p001].get<std::string>();
-         fprintf(stderr, "UEID %s\n", ueId.c_str());     
-         
-         json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
-         tput = all_ues_json[p0].get<float>();
-         fprintf(stderr, "Throughput %f\n", tput);
-         
-         json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
-         prb_usage = all_ues_json[p00].get<int>();
-         fprintf(stderr, "Throughput %d\n", prb_usage);
-         
-         json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
-         nextCellId = all_ues_json[p1].get<int>();
-         fprintf(stderr, "Serving Cell %d\n",nextCellId);
-         
-         json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
-         nextRsrp = all_ues_json[p2].get<int>();
-         fprintf(stderr,"  RSRP %d\n", nextRsrp);
-         
-         json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
-         nextRsrq = all_ues_json[p3].get<int>();
-         fprintf(stderr,"  RSRQ %d\n",nextRsrq);
-         
-         json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
-         nextRssinr = all_ues_json[p4].get<int>();
-         fprintf(stderr,"  RSSINR %d\n", nextRssinr);
-         
-         json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
-         
-         uint8_t crnti_buf[3] = {0, };
-
-         if (ueId.find("Pedestrian") != string::npos) {
-           std::string ind = ueId.substr(11);
-           fprintf(stderr, "ind is %s\n", ind.c_str());
-
-           int indval = std::stoi(ind);
-
-           if (indval < 10) {
-             crnti_buf[1] = indval;
-             crnti_buf[0] = 0;
-           } else {
-             crnti_buf[0] = indval/10;
-             crnti_buf[1] = indval % 10;
-           }
-           
-         } else if (ueId.find("Car") != string::npos) {
-           crnti_buf[0] = 4;
-           crnti_buf[1] = 1;
-         }
-         
-         //      uint8_t *buf2 = (uint8_t*)"12";
-         
-         std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
-           std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
-         const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());   
-         
-         int numNeighborCells = (all_ues_json[p5]).size();
-         
-         std::string neighbor_str = "[";
-         
-         int nextNbCell;
-         int nextNbRsrp;
-         int nextNbRsrq;
-         int nextNbRssinr;
-         
-         for (int j = 0; j < numNeighborCells; j++) {
-           json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
-           nextNbCell = all_ues_json[p8].get<int>();
-           //cout << "Neighbor Cell " << all_ues_json[p8] << endl;
-           json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
-                                 +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
-           nextNbRsrp = all_ues_json[p9].get<int>();
-           //cout << "  RSRP " << nextNbRsrp << endl;
-           
-           json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
-                                  +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
-           nextNbRsrq = all_ues_json[p10].get<int>();
-           //cout << "  RSRQ " << nextNbRsrq << endl;
-           
-           json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
-                                  +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
-           nextNbRssinr = all_ues_json[p11].get<int>();
-           //cout << "  RSSINR " << nextNbRssinr << endl;
-           
-           if (j != 0) {
-             neighbor_str += ",";
-             
-           }
-
-
-           uint8_t neighbor_cellid_buf[6] = {0, };
-           neighbor_cellid_buf[0] = 0x22;
-           neighbor_cellid_buf[1] = 0x5B;
-           neighbor_cellid_buf[2] = 0xD6;
-           neighbor_cellid_buf[3] = nextNbCell;
-           neighbor_cellid_buf[4] = 0x70;
-           
-           char cid_buf[25] = {0, };
-           get_cell_id(neighbor_cellid_buf,cid_buf);
-           
-           
-           neighbor_str += "{\"CID\" : \"" + std::string(cid_buf) + "\", \"Cell-RF\" : {\"rsrp\": " + std::to_string(nextNbRsrp) +
-             ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
-           
-         }
-         
-         neighbor_str += "]";
-         
-         fprintf(stderr,"This is neighbor str %s\n", neighbor_str.c_str());
-         
-         //Creating UE-level RAN-Container CUCP message
-         
-         fprintf(stderr,"Creating UE-level RAN-Container CUCP message\n");
-         
-         const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
-
-
-         uint8_t nrcellid_buf[6] = {0, };
-         nrcellid_buf[0] = 0x22;
-         nrcellid_buf[1] = 0x5B;
-         nrcellid_buf[2] = 0xD6;
-         nrcellid_buf[3] = nextCellId;
-         nrcellid_buf[4] = 0x70;
-
-         uint8_t gnbid_buf[4] = {0, };
-         gnbid_buf[0] = 0x22;
-         gnbid_buf[1] = 0x5B;
-         gnbid_buf[2] = 0xD6;
-
-         uint8_t cuupid_buf[2] = {0, };
-         cuupid_buf[0] = 20000;
-
-         uint8_t duid_buf[2] = {0, };
-         duid_buf[0] = 20000;
-
-         uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";   
-         
-         
-         E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
-           (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
-         
-         encode_kpm_report_rancontainer_cucp_parameterized(ind_msg_cucp_ue, plmnid_buf, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
-         
-         uint8_t e2sm_message_buf_cucp_ue[8192] = {0, };
-         size_t e2sm_message_buf_size_cucp_ue = 8192;
-         
-         asn_codec_ctx_t *opt_cod;
-
-         
-         asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
-                                                                  ATS_ALIGNED_BASIC_PER,
-                                                                  &asn_DEF_E2SM_KPM_IndicationMessage,
-                                                                  ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cucp_ue);
-         
-         fprintf(stderr, "er encded is %d\n", er_message_cucp_ue.encoded);
-         fprintf(stderr, "after encoding message\n");
-
-         E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
-           (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
-         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);
-         fprintf(stderr, "Now printing xer outside of function call\n");
-         xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);     
-
-         uint8_t e2sm_header_buf_cucp_ue[8192] = {0, };
-         size_t e2sm_header_buf_size_cucp_ue = 8192;
-         
-         asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod,
-                                                                 ATS_ALIGNED_BASIC_PER,
-                                                                 &asn_DEF_E2SM_KPM_IndicationHeader,
-                                                                 ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
-
-         fprintf(stderr, "er encded is %d\n", er_header_cucp_ue.encoded);
-         fprintf(stderr, "error buf is %s\n", (char*)e2sm_header_buf_cucp_ue);
-         fprintf(stderr, "after encoding header\n");     
-         
-         E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
-         
-         encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
-                                                                    instanceId, ranFunctionId,
-                                                                    actionId, seqNum, e2sm_header_buf_cucp_ue,
-                                                                    er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
-                                                                    er_message_cucp_ue.encoded);
-         
-         
-         e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
-
-         seqNum++;
-
-         std::this_thread::sleep_for (std::chrono::milliseconds(50));
-         
-         //Creating UE-level RAN-Container CUUP message
-         
-         fprintf(stderr,"Creating UE-level RAN-Container CUUP message\n");     
-         
-         E2SM_KPM_IndicationMessage_t *ind_msg_cuup_ue =
-           (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
-         
-         long bytes = (long)(tput * 100);
-         
-         encode_kpm_report_rancontainer_cuup_parameterized(ind_msg_cuup_ue, plmnid_buf, nrcellid_buf, crnti_buf, bytes, 0);
-         
-         uint8_t e2sm_message_buf_cuup_ue[8192] = {0, };
-         size_t e2sm_message_buf_size_cuup_ue = 8192;
-         
-         asn_codec_ctx_t *opt_cod2;
-         
-         
-         asn_enc_rval_t er_message_cuup_ue = asn_encode_to_buffer(opt_cod2,
-                                                              ATS_ALIGNED_BASIC_PER,
-                                                              &asn_DEF_E2SM_KPM_IndicationMessage,
-                                                              ind_msg_cuup_ue, e2sm_message_buf_cuup_ue, e2sm_message_buf_size_cuup_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cuup_ue);
-         
-         fprintf(stderr, "er encded is %d\n", er_message_cuup_ue.encoded);
-         fprintf(stderr, "after encoding message\n");
-
-         E2SM_KPM_IndicationHeader_t* ind_header_cuup_ue =
-           (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
-         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);
-
-         uint8_t e2sm_header_buf_cuup_ue[8192] = {0, };
-         size_t e2sm_header_buf_size_cuup_ue = 8192;
-         
-         asn_enc_rval_t er_header_cuup_ue = asn_encode_to_buffer(opt_cod,
-                                                                 ATS_ALIGNED_BASIC_PER,
-                                                                 &asn_DEF_E2SM_KPM_IndicationHeader,
-                                                                 ind_header_cuup_ue, e2sm_header_buf_cuup_ue, e2sm_header_buf_size_cuup_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cuup_ue);
-         
-         
-         E2AP_PDU *pdu_cuup_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));        
-         
-         encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue, requestorId,
-                                                                    instanceId, ranFunctionId,
-                                                                    actionId, seqNum, e2sm_header_buf_cuup_ue,
-                                                                    er_header_cuup_ue.encoded,
-                                                                    e2sm_message_buf_cuup_ue, er_message_cuup_ue.encoded);
-
-         e2sim.encode_and_send_sctp_data(pdu_cuup_ue);
-
-         seqNum++;
-
-         std::this_thread::sleep_for (std::chrono::milliseconds(50));
-         
-         //Creating UE-level RAN-Container DU message
-         
-         fprintf(stderr,"Creating UE-level RAN-Container DU message\n");
-         
-         E2SM_KPM_IndicationMessage_t *ind_message_du_ue =
-           (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
-         
-         encode_kpm_report_rancontainer_du_parameterized(ind_message_du_ue,
-                                                         plmnid_buf, nrcellid_buf, crnti_buf, prb_usage, 0);
-         
-         uint8_t e2sm_message_buf_du_ue[8192] = {0, };
-         size_t e2sm_message_buf_size_du_ue = 8192;
-         
-         asn_codec_ctx_t *opt_cod3;
-         
-         
-         asn_enc_rval_t er_message_du_ue = asn_encode_to_buffer(opt_cod3,
-                                                                ATS_ALIGNED_BASIC_PER,
-                                                                &asn_DEF_E2SM_KPM_IndicationMessage,
-                                                                ind_message_du_ue,
-                                                                e2sm_message_buf_du_ue,
-                                                                e2sm_message_buf_size_du_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_du_ue);
-         
-         fprintf(stderr, "er encded is %d\n", er_message_du_ue.encoded);
-         fprintf(stderr, "after encoding message\n");
-
-         E2SM_KPM_IndicationHeader_t* ind_header_du_ue =
-           (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
-         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);
-
-         uint8_t e2sm_header_buf_du_ue[8192] = {0, };
-         size_t e2sm_header_buf_size_du_ue = 8192;
-         
-         asn_enc_rval_t er_header_du_ue = asn_encode_to_buffer(opt_cod,
-                                                               ATS_ALIGNED_BASIC_PER,
-                                                               &asn_DEF_E2SM_KPM_IndicationHeader,
-                                                               ind_header_du_ue, e2sm_header_buf_du_ue,
-                                                               e2sm_header_buf_size_du_ue);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_du_ue);
-         
-         
-         E2AP_PDU *pdu_du_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
-         
-         encoding::generate_e2apv1_indication_request_parameterized(pdu_du_ue, requestorId,
-                                                                    instanceId, ranFunctionId,
-                                                                    actionId, seqNum,
-                                                                    e2sm_header_buf_du_ue, er_header_du_ue.encoded,
-                                                                    e2sm_message_buf_du_ue, er_message_du_ue.encoded);
-
-         e2sim.encode_and_send_sctp_data(pdu_du_ue);
-
-         seqNum++;
-
-         std::this_thread::sleep_for (std::chrono::milliseconds(50));
-         
-         fprintf(stderr, "done with ue meas report\n");
-       }
+               json::json_pointer du_id(std::string("/ueMeasReport/du-id"));
+               int duid = all_ues_json[du_id].get<int>();
        
+               LOG_I("Start sending UE measurement reports with DU id %d", duid);
+
+               int numMeasReports = (all_ues_json["/ueMeasReport/ueMeasReportList"_json_pointer]).size();
+               
+               for (int i = 0; i < numMeasReports; i++) {
+                       int nextCellId;
+                       int nextRsrp;
+                       int nextRsrq;
+                       int nextRssinr;
+                       float tput;
+                       int prb_usage;
+                       std::string ueId;
+
+                       json::json_pointer p001(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/ue-id");
+                       ueId = all_ues_json[p001].get<std::string>();
+
+                       LOG_I("Preparing report data for UE %d with id %s", i, ueId);
+                       
+                       json::json_pointer p0(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/throughput");
+                       tput = all_ues_json[p0].get<float>();
+                       
+                       json::json_pointer p00(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/prb_usage");
+                       prb_usage = all_ues_json[p00].get<int>();
+                       
+                       json::json_pointer p1(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
+                       nextCellId = all_ues_json[p1].get<int>();
+                       
+                       json::json_pointer p2(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrp");
+                       nextRsrp = all_ues_json[p2].get<int>();
+                       
+                       json::json_pointer p3(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rsrq");
+                       nextRsrq = all_ues_json[p3].get<int>();
+                       
+                       json::json_pointer p4(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/servingCellRfReport/rssinr");
+                       nextRssinr = all_ues_json[p4].get<int>();
+                       
+                       json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
+                       
+                       uint8_t crnti_buf[3] = {0, };
+
+                       if (ueId.find("Pedestrian") != string::npos) {
+                               std::string ind = ueId.substr(11);
+                               int indval = std::stoi(ind);
+
+                               if (indval < 10) {
+                               crnti_buf[1] = indval;
+                               crnti_buf[0] = 0;
+                               } else {
+                               crnti_buf[0] = indval/10;
+                               crnti_buf[1] = indval % 10;
+                               }
+                               
+                       } else if (ueId.find("Car") != string::npos) {
+                               crnti_buf[0] = 4;
+                               crnti_buf[1] = 1;
+                       }
+                                       
+                       std::string serving_str = "{\"rsrp\": " + std::to_string(nextRsrp) + ", \"rsrq\": " +
+                               std::to_string(nextRsrq) + ", \"rssinr\": " + std::to_string(nextRssinr) + "}";
+                       const uint8_t *serving_buf = reinterpret_cast<const uint8_t*>(serving_str.c_str());     
+                       
+                       int numNeighborCells = (all_ues_json[p5]).size();
+                       
+                       std::string neighbor_str = "[";
+                       
+                       int nextNbCell;
+                       int nextNbRsrp;
+                       int nextNbRsrq;
+                       int nextNbRssinr;
+                       
+                       for (int j = 0; j < numNeighborCells; j++) {
+                               json::json_pointer p8(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList/" + std::to_string(j) + "/nbCellIdentity");
+                               nextNbCell = all_ues_json[p8].get<int>();
+                               json::json_pointer p9(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
+                                               +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrp");
+                               nextNbRsrp = all_ues_json[p9].get<int>();
+                               
+                               json::json_pointer p10(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
+                                               +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rsrq");
+                               nextNbRsrq = all_ues_json[p10].get<int>();
+                               
+                               json::json_pointer p11(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i)
+                                               +"/neighbourCellList/" + std::to_string(j) + "/nbCellRfReport/rssinr");
+                               nextNbRssinr = all_ues_json[p11].get<int>();
+                               
+                               if (j != 0) {
+                                       neighbor_str += ",";
+                               }
+
+
+                               uint8_t neighbor_cellid_buf[6] = {0, };
+                               neighbor_cellid_buf[0] = 0x22;
+                               neighbor_cellid_buf[1] = 0x5B;
+                               neighbor_cellid_buf[2] = 0xD6;
+                               neighbor_cellid_buf[3] = nextNbCell;
+                               neighbor_cellid_buf[4] = 0x70;
+                               
+                               char cid_buf[25] = {0, };
+                               get_cell_id(neighbor_cellid_buf,cid_buf);
+                               
+                               
+                               neighbor_str += "{\"CID\" : \"" + std::string(cid_buf) + "\", \"Cell-RF\" : {\"rsrp\": " + std::to_string(nextNbRsrp) +
+                               ", \"rsrq\": " + std::to_string(nextNbRsrq) + ", \"rssinr\": " + std::to_string(nextNbRssinr) + "}}";
+                               
+                       }
+                       
+                       neighbor_str += "]";
+                       
+                       LOG_I("This is neighbor str %s\n", neighbor_str.c_str());
+                                                               
+                       const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
+
+
+                       uint8_t nrcellid_buf[6] = {0, };
+                       nrcellid_buf[0] = 0x22;
+                       nrcellid_buf[1] = 0x5B;
+                       nrcellid_buf[2] = 0xD6;
+                       nrcellid_buf[3] = nextCellId;
+                       nrcellid_buf[4] = 0x70;
+
+                       uint8_t gnbid_buf[4] = {0, };
+                       gnbid_buf[0] = 0x22;
+                       gnbid_buf[1] = 0x5B;
+                       gnbid_buf[2] = 0xD6;
+
+                       uint8_t cuupid_buf[2] = {0, };
+                       cuupid_buf[0] = 20000;
+
+                       uint8_t duid_buf[2] = {0, };
+                       duid_buf[0] = 20000;
+
+                       uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";     
+                       
+                       
+                       E2SM_KPM_IndicationMessage_t *ind_msg_cucp_ue =
+                               (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
+                       
+                       ue_meas_kpm_report_indication_message_initialized(ind_msg_cucp_ue, nrcellid_buf, crnti_buf, serving_buf, neighbor_buf);
+                       
+                       uint8_t e2sm_message_buf_cucp_ue[8192] = {0, };
+                       size_t e2sm_message_buf_size_cucp_ue = 8192;
+                       
+                       asn_codec_ctx_t *opt_cod;
+                       
+                       asn_enc_rval_t er_message_cucp_ue = asn_encode_to_buffer(opt_cod,
+                                                                               ATS_ALIGNED_BASIC_PER,
+                                                                               &asn_DEF_E2SM_KPM_IndicationMessage,
+                                                                               ind_msg_cucp_ue, e2sm_message_buf_cucp_ue, e2sm_message_buf_size_cucp_ue);
+                       
+                       if(er_message_cucp_ue.encoded == -1) {
+                               LOG_I("Failed to serialize message data. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name);
+                               exit(1);
+                       } else if(er_message_cucp_ue.encoded > e2sm_message_buf_size_cucp_ue) {
+                               LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_message_buf_size_cucp_ue, asn_DEF_E2SM_KPM_IndicationMessage.name, er_message_cucp_ue.encoded);
+                               exit(1);
+                       } else {
+                               LOG_I("Encoded UE indication message succesfully, size in bytes: %d", er_message_cucp_ue.encoded)
+                       }
+
+                       ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_cucp_ue); 
+
+                       E2SM_KPM_IndicationHeader_t* ind_header_cucp_ue =
+                               (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
+                       kpm_report_indication_header_initialized(ind_header_cucp_ue, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
+
+                       asn_codec_ctx_t *opt_cod1;
+                       uint8_t e2sm_header_buf_cucp_ue[8192] = {0, };
+                       size_t e2sm_header_buf_size_cucp_ue = 8192;
+                       
+                       asn_enc_rval_t er_header_cucp_ue = asn_encode_to_buffer(opt_cod1,
+                                                                               ATS_ALIGNED_BASIC_PER,
+                                                                               &asn_DEF_E2SM_KPM_IndicationHeader,
+                                                                               ind_header_cucp_ue, e2sm_header_buf_cucp_ue, e2sm_header_buf_size_cucp_ue);
+
+                       if(er_header_cucp_ue.encoded == -1) {
+                               LOG_I("Failed to serialize data. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationHeader.name);
+                               exit(1);
+                       } else if(er_header_cucp_ue.encoded > e2sm_header_buf_size_cucp_ue) {
+                               LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_header_buf_size_cucp_ue, asn_DEF_E2SM_KPM_IndicationHeader.name, er_header_cucp_ue.encoded);
+                               exit(1);
+                       } else {
+                               LOG_I("Encoded UE indication header succesfully, size in bytes: %d", er_header_cucp_ue.encoded);
+                               for(int i = 0; i < er_header_cucp_ue.encoded; i ++) {
+                                       printf("%x ", e2sm_header_buf_cucp_ue[i]);
+                               }
+                               
+                       }
+                       
+
+                       ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_cucp_ue);
+                       
+                       E2AP_PDU *pdu_cucp_ue = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
+                       
+                       encoding::generate_e2apv1_indication_request_parameterized(pdu_cucp_ue, requestorId,
+                                                                                       instanceId, ranFunctionId,
+                                                                                       actionId, seqNum, e2sm_header_buf_cucp_ue,
+                                                                                       er_header_cucp_ue.encoded, e2sm_message_buf_cucp_ue,
+                                                                                       er_message_cucp_ue.encoded);
+                       
+                       e2sim.encode_and_send_sctp_data(pdu_cucp_ue);
+                       LOG_I("Measurement report for UE %d has been sent\n", i);
+                       seqNum++;
+                       std::this_thread::sleep_for (std::chrono::milliseconds(50));
+               }
       } else if (first_key.compare("cellMeasReport") == 0) {
 
-       fprintf(stderr, "it is equal to cell meas report\n");
-       
-       int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
+               json::json_pointer du_id(std::string("/cellMeasReport/du-id"));
+               int duid = all_ues_json[du_id].get<int>();
        
-       for (int i = 0; i < numMeasReports; i++) {
-         int nextCellId;
-
-         float bytes_dl;
-         float bytes_ul;
-         int prb_dl;
-         int prb_ul;
-         int cellid;
-         
-         fprintf(stderr,"UE number %d\n", i);
-
-         json::json_pointer p00(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
-         cellid = all_ues_json[p00].get<int>();
-         fprintf(stderr, "Cell ID %d\n", cellid);
-         
-         json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
-         bytes_dl = all_ues_json[p0].get<float>();
-         fprintf(stderr, "Bytes DL %f\n", bytes_dl);
-
-         json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
-         bytes_ul = all_ues_json[p1].get<float>();
-         fprintf(stderr, "Bytes UL %f\n", bytes_ul);     
-         
-         json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
-         prb_dl = all_ues_json[p2].get<int>();
-         fprintf(stderr, "Avail PRB DL %d\n", prb_dl); 
-
-         json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
-         prb_ul = all_ues_json[p3].get<int>();
-         fprintf(stderr, "Avail PRB UL %d\n", prb_ul);
-
-         
-         uint8_t *sst_buf = (uint8_t*)"1";
-         uint8_t *sd_buf = (uint8_t*)"100";
-         uint8_t *plmnid_buf = (uint8_t*)"747";
-
-         uint8_t nrcellid_buf[6] = {0, };
-         nrcellid_buf[0] = 0x22;
-         nrcellid_buf[1] = 0x5B;
-         nrcellid_buf[2] = 0xD6;
-         nrcellid_buf[3] = cellid;
-         nrcellid_buf[4] = 0x70;
-
-         uint8_t gnbid_buf[4] = {0, };
-         gnbid_buf[0] = 0x22;
-         gnbid_buf[1] = 0x5B;
-         gnbid_buf[2] = 0xD6;
-
-         uint8_t cuupid_buf[2] = {0, };
-         cuupid_buf[0] = 20000;
-
-         uint8_t duid_buf[2] = {0, };
-         duid_buf[0] = 20000;
-
-         uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";           
-         
-
-         //Encoding Style 5 Message Body
-         
-         fprintf(stderr, "Encoding Style 5 Message body\n");
-
-         asn_codec_ctx_t *opt_cod;
-
-         E2SM_KPM_IndicationMessage_t *ind_msg_style5 =
-           (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
-         E2AP_PDU *pdu_style5 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
-         
-         encode_kpm_report_style5_parameterized(ind_msg_style5 , cuupname_buf, bytes_dl, bytes_ul, sst_buf, sd_buf, plmnid_buf);
-         
-         uint8_t e2sm_message_buf_style5[8192] = {0, };
-         size_t e2sm_message_buf_size_style5 = 8192;
-         
-         asn_enc_rval_t er_message_style5 = asn_encode_to_buffer(opt_cod,
-                                                                 ATS_ALIGNED_BASIC_PER,
-                                                                 &asn_DEF_E2SM_KPM_IndicationMessage,
-                                                                 ind_msg_style5, e2sm_message_buf_style5, e2sm_message_buf_size_style5);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_msg_style5);
-         
-         fprintf(stderr, "er encded is %d\n", er_message_style5.encoded);
-         fprintf(stderr, "after encoding message\n");
-         
-         int seqNum0 = 1;
-
-
-         E2SM_KPM_IndicationHeader_t* ind_header_style5 =
-           (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
-         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);
-
-         uint8_t e2sm_header_buf_style5[8192] = {0, };
-         size_t e2sm_header_buf_size_style5 = 8192;
-         
-         asn_enc_rval_t er_header_style5 = asn_encode_to_buffer(opt_cod,
-                                                                ATS_ALIGNED_BASIC_PER,
-                                                                &asn_DEF_E2SM_KPM_IndicationHeader,
-                                                                ind_header_style5,
-                                                                e2sm_header_buf_style5, e2sm_header_buf_size_style5);    
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style5);
-         
-         
-         encoding::generate_e2apv1_indication_request_parameterized(pdu_style5, requestorId,
-                                                                    instanceId, ranFunctionId,
-                                                                    actionId, seqNum0, e2sm_header_buf_style5,
-                                                                    er_header_style5.encoded, e2sm_message_buf_style5,
-                                                                    er_message_style5.encoded);
-
-         e2sim.encode_and_send_sctp_data(pdu_style5);
-
-         seqNum++;
-
-         std::this_thread::sleep_for (std::chrono::milliseconds(50));    
-         
-
-         //Encoding Style 1 Message Body
-         
-         fprintf(stderr, "Encoding Style 1 Message body\n");     
-         asn_codec_ctx_t *opt_cod2;
-         
-         
-         E2SM_KPM_IndicationMessage_t *ind_message_style1 =
-           (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
-         E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
-         
-         long fiveqi = 7;
-         
-
-         
-         long *l_dl_prbs = (long*)calloc(1, sizeof(long));
-         long *l_ul_prbs = (long*)calloc(1, sizeof(long));
-         *l_dl_prbs = (long)prb_dl;
-         *l_ul_prbs = (long)prb_ul;
-         
-         encode_kpm_report_style1_parameterized(ind_message_style1, fiveqi,
-                                                prb_dl, prb_ul, sst_buf, sd_buf,
-                                                plmnid_buf, nrcellid_buf, l_dl_prbs, l_ul_prbs);
-         
-         uint8_t e2sm_message_buf_style1[8192] = {0, };
-         size_t e2sm_message_buf_size_style1 = 8192;
-         
-         asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
-                                                                 ATS_ALIGNED_BASIC_PER,
-                                                                 &asn_DEF_E2SM_KPM_IndicationMessage,
-                                                                 ind_message_style1,
-                                                                 e2sm_message_buf_style1, e2sm_message_buf_size_style1);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_style1);
-         
-         fprintf(stderr, "er encded is %d\n", er_message_style1.encoded);
-         fprintf(stderr, "after encoding message\n");
-
-         
-         uint8_t *cpid_buf2 = (uint8_t*)"CPID";
-         
-         fprintf(stderr, "About to encode Indication\n");
-
-         E2SM_KPM_IndicationHeader_t* ind_header_style1 =
-           (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
-         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);
-
-         uint8_t e2sm_header_buf_style1[8192] = {0, };
-         size_t e2sm_header_buf_size_style1 = 8192;
-         
-         asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod,
-                                                                ATS_ALIGNED_BASIC_PER,
-                                                                &asn_DEF_E2SM_KPM_IndicationHeader,
-                                                                ind_header_style1,
-                                                                e2sm_header_buf_style1, e2sm_header_buf_size_style1);
-         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style1);
-         
-         encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
-                                                                    instanceId, ranFunctionId,
-                                                                    actionId, seqNum, e2sm_header_buf_style1,
-                                                                    er_header_style1.encoded,
-                                                                    e2sm_message_buf_style1, er_message_style1.encoded);
-
-         e2sim.encode_and_send_sctp_data(pdu_style1);
-         seqNum++;
-         std::this_thread::sleep_for (std::chrono::milliseconds(50));    
-         
-       }
-      }                                                   
+               LOG_I("Start sending Cell measurement reports with DU id %d", duid);
+               
+               int numMeasReports = (all_ues_json["/cellMeasReport/cellMeasReportList"_json_pointer]).size();
+               
+               for (int i = 0; i < numMeasReports; i++) {
+                       int nextCellId;
+
+                       float bytes_dl;
+                       float bytes_ul;
+                       int prb_dl;
+                       int prb_ul;
+                       int cellid;
+
+                       json::json_pointer p00(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/nrCellIdentity");
+                       cellid = all_ues_json[p00].get<int>();
+
+                       LOG_I("Preparing report data for Cell %d with id %d", i, cellid);
+                       
+                       json::json_pointer p0(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesDl");
+                       bytes_dl = all_ues_json[p0].get<float>();
+
+                       json::json_pointer p1(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/pdcpByteMeasReport/pdcpBytesUl");
+                       bytes_ul = all_ues_json[p1].get<float>();
+                       
+                       json::json_pointer p2(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbDl");
+                       prb_dl = all_ues_json[p2].get<int>();
+
+                       json::json_pointer p3(std::string("/cellMeasReport/cellMeasReportList/") + std::to_string(i) +"/prbMeasReport/availPrbUl");
+                       prb_ul = all_ues_json[p3].get<int>();
+
+                       
+                       uint8_t *sst_buf = (uint8_t*)"1";
+                       uint8_t *sd_buf = (uint8_t*)"100";
+                       uint8_t *plmnid_buf = (uint8_t*)"747";
+
+                       uint8_t nrcellid_buf[6] = {0, };
+                       nrcellid_buf[0] = 0x22;
+                       nrcellid_buf[1] = 0x5B;
+                       nrcellid_buf[2] = 0xD6;
+                       nrcellid_buf[3] = cellid;
+                       nrcellid_buf[4] = 0x70;
+
+                       uint8_t gnbid_buf[4] = {0, };
+                       gnbid_buf[0] = 0x22;
+                       gnbid_buf[1] = 0x5B;
+                       gnbid_buf[2] = 0xD6;
+
+                       uint8_t cuupid_buf[2] = {0, };
+                       cuupid_buf[0] = 20000;
+
+                       uint8_t duid_buf[2] = {0, };
+                       duid_buf[0] = 20000;
+
+                       uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";             
+
+                       //Encoding Style 1 Message Body
+                       
+                       LOG_I("Encoding Style 1 Message body");   
+                       asn_codec_ctx_t *opt_cod2;
+                       
+                       E2SM_KPM_IndicationMessage_t *ind_message_style1 =
+                               (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
+                       E2AP_PDU *pdu_style1 = (E2AP_PDU*)calloc(1,sizeof(E2AP_PDU));
+                       
+                       long fiveqi = 7;
+                       long *l_dl_prbs = (long*)calloc(1, sizeof(long));
+                       long *l_ul_prbs = (long*)calloc(1, sizeof(long));
+                       *l_dl_prbs = (long)prb_dl;
+                       *l_ul_prbs = (long)prb_ul;
+                       
+                       cell_meas_kpm_report_indication_message_style_1_initialized(ind_message_style1, fiveqi,
+                                                               prb_dl, prb_ul, nrcellid_buf, l_dl_prbs, l_ul_prbs);
+                       
+                       uint8_t e2sm_message_buf_style1[8192] = {0, };
+                       size_t e2sm_message_buf_size_style1 = 8192;
+                       
+                       asn_enc_rval_t er_message_style1 = asn_encode_to_buffer(opt_cod2,
+                                                                               ATS_ALIGNED_BASIC_PER,
+                                                                               &asn_DEF_E2SM_KPM_IndicationMessage,
+                                                                               ind_message_style1,
+                                                                               e2sm_message_buf_style1, e2sm_message_buf_size_style1);
+                       
+                       if(er_message_style1.encoded == -1) {
+                               LOG_I("Failed to serialize data. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name);
+                               exit(1);
+                       } else if(er_message_style1.encoded > e2sm_message_buf_size_style1) {
+                               LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_message_buf_size_style1, asn_DEF_E2SM_KPM_IndicationMessage.name, er_message_style1.encoded);
+                               exit(1);
+                       } else {
+                               LOG_I("Encoded Cell indication message succesfully, size in bytes: %d", er_message_style1.encoded)
+                       }
+
+                       ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, ind_message_style1);
+                       
+                       uint8_t *cpid_buf2 = (uint8_t*)"CPID";
+                       
+                       E2SM_KPM_IndicationHeader_t* ind_header_style1 =
+                               (E2SM_KPM_IndicationHeader_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_t));
+                       kpm_report_indication_header_initialized(ind_header_style1, plmnid_buf, sst_buf, sd_buf, fqival, qcival, nrcellid_buf, gnbid_buf, 0, cuupid_buf, duid_buf, cuupname_buf);
+
+                       uint8_t e2sm_header_buf_style1[8192] = {0, };
+                       size_t e2sm_header_buf_size_style1 = 8192;
+                       
+                       asn_enc_rval_t er_header_style1 = asn_encode_to_buffer(opt_cod2,
+                                                                               ATS_ALIGNED_BASIC_PER,
+                                                                               &asn_DEF_E2SM_KPM_IndicationHeader,
+                                                                               ind_header_style1,
+                                                                               e2sm_header_buf_style1, e2sm_header_buf_size_style1);
+
+                       if(er_header_style1.encoded == -1) {
+                               LOG_I("Failed to serialize data. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationHeader.name);
+                               exit(1);
+                       } else if(er_header_style1.encoded > e2sm_header_buf_size_style1) {
+                               LOG_I("Buffer of size %zu is too small for %s, need %zu\n", e2sm_header_buf_size_style1, asn_DEF_E2SM_KPM_IndicationHeader.name, er_header_style1.encoded);
+                               exit(1);
+                       } else {
+                               LOG_I("Encoded Cell indication header succesfully, size in bytes: %d", er_header_style1.encoded)
+                       }
+
+                       ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, ind_header_style1);
+                       
+                       encoding::generate_e2apv1_indication_request_parameterized(pdu_style1, requestorId,
+                                                                                       instanceId, ranFunctionId,
+                                                                                       actionId, seqNum, e2sm_header_buf_style1,
+                                                                                       er_header_style1.encoded,
+                                                                                       e2sm_message_buf_style1, er_message_style1.encoded);
+
+                       e2sim.encode_and_send_sctp_data(pdu_style1);
+                       seqNum++;
+                       LOG_I("Measurement report for Cell %d has been sent\n", i);
+                       std::this_thread::sleep_for (std::chrono::milliseconds(50));      
+                       
+               }
+         }                                                
     }
   }
 }
@@ -713,7 +531,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
 
 void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
 
-  fprintf(stderr, "Calling callback_kpm_subscription_request\n");
+  fprintf(stderr, "[%s:%d]Calling callback_kpm_subscription_request");
 
   //Record RIC Request ID
   //Go through RIC action to be Setup List
@@ -732,9 +550,6 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
   
   RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
 
-  fprintf(stderr, "count%d\n", count);
-  fprintf(stderr, "size%d\n", size);
-
   RICsubscriptionRequest_IEs__value_PR pres;
 
   long reqRequestorId;
@@ -748,17 +563,17 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
     RICsubscriptionRequest_IEs_t *next_ie = ies[i];
     pres = next_ie->value.present;
     
-    fprintf(stderr, "The next present value %d\n", pres);
+    LOG_I("The next present value %d\n", pres);
 
     switch(pres) {
     case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
       {
-       fprintf(stderr,"in case request id\n"); 
+       LOG_I("in case request id");    
        RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
        long requestorId = reqId.ricRequestorID;
        long instanceId = reqId.ricInstanceID;
-       fprintf(stderr, "requestorId %d\n", requestorId);
-       fprintf(stderr, "instanceId %d\n", instanceId);
+       LOG_I("requestorId %d\n", requestorId);
+       LOG_I("instanceId %d\n", instanceId);
        reqRequestorId = requestorId;
        reqInstanceId = instanceId;
 
@@ -766,25 +581,21 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
       }
     case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
       {
-       fprintf(stderr,"in case ran func id\n");        
+       LOG_I("in case ran func id");   
        break;
       }
     case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
       {
-       fprintf(stderr,"in case subscription details\n");
        RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
-       fprintf(stderr,"in case subscription details 1\n");     
        RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
-       fprintf(stderr,"in case subscription details 2\n");     
        RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
-       fprintf(stderr,"in case subscription details 3\n");
        //We are ignoring the trigger definition
 
        //We identify the first action whose type is REPORT
        //That is the only one accepted; all others are rejected
        
        int actionCount = actionList.list.count;
-       fprintf(stderr, "action count%d\n", actionCount);
+       LOG_I("Action count%d\n", actionCount);
 
        auto **item_array = actionList.list.array;
 
@@ -799,11 +610,9 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
          if (!foundAction && actionType == RICactionType_report) {
            reqActionId = actionId;
            actionIdsAccept.push_back(reqActionId);
-           printf("adding accept\n");
            foundAction = true;
          } else {
            reqActionId = actionId;
-           printf("adding reject\n");
            actionIdsReject.push_back(reqActionId);
          }
        }
@@ -812,21 +621,20 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
       }
     default:
       {
-       fprintf(stderr,"in case default\n");    
        break;
       }      
     }
     
   }
 
-  fprintf(stderr, "After Processing Subscription Request\n");
+  LOG_I("After Processing Subscription Request");
 
-  fprintf(stderr, "requestorId %d\n", reqRequestorId);
-  fprintf(stderr, "instanceId %d\n", reqInstanceId);
+  LOG_I("requestorId %d\n", reqRequestorId);
+  LOG_I("instanceId %d\n", reqInstanceId);
 
 
   for (int i=0; i < actionIdsAccept.size(); i++) {
-    fprintf(stderr, "Action ID %d %ld\n", i, actionIdsAccept.at(i));
+    LOG_I("Action ID %d %ld\n", i, actionIdsAccept.at(i));
     
   }
 
@@ -838,17 +646,12 @@ void callback_kpm_subscription_request(E2AP_PDU_t *sub_req_pdu) {
   int reject_size = actionIdsReject.size();
 
   encoding::generate_e2apv1_subscription_response_success(e2ap_pdu, accept_array, reject_array, accept_size, reject_size, reqRequestorId, reqInstanceId);
-
+  
+  LOG_I("Encode and sending E2AP subscription success response via SCTP");
   e2sim.encode_and_send_sctp_data(e2ap_pdu);
 
-  //Start thread for sending REPORT messages
-
-  //  std::thread loop_thread;
-
   long funcId = 0;
 
   run_report_loop(reqRequestorId, reqInstanceId, funcId, reqActionId);
 
-  //  loop_thread = std::thread(&run_report_loop);
-
 }