Applicable Versions
NetSim Standard 
NetSim Pro 


The steps provided may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim you are using.


Applicable Releases
v12.2


The way to do this is,


1. Open Visual studio 2019 through NetSim->Open Simulation ->Workspace Options -> Open Code.

2. Open the LTE_NR.c file in the LTE_NR project from the list of projects displayed in the Solution Explorer.

3. Perform the following modifications in the fn_NetSim_LTE_NR_Init() function (lines shown in red):


_declspec(dllexport) int fn_NetSim_LTE_NR_Init()

{

    FILE* fp;

    char filepath[BUFSIZ];

    sprintf(filepath, "%s/%s", pszIOLogPath, "5G_MCS_CQI_LOG.csv");

    fp = fopen(filepath, "w+");

    if (fp) 

    { 

        fprintf(fp, "TIME(US),gNB_ID,UE_ID,TRAFFIC_TYPE,CQI_INDEX,CQI_MODULATION,CQI_CODERATE,CQI_EFFICIENCY,MCS_INDEX,MCS_MODULATION,MCS_CODERATE,MCS_EFFICIENCY,DISTANCE(m)"); 

        fclose(fp);

    }

    return fn_NetSim_LTE_NR_Init_F();

}


4. Open the LTENR_PHY.c file and perform the following modifications in the LTENR_PHY_setAMCInfo() function (lines shown in red):

static void LTENR_PHY_setAMCInfo(ptrLTENR_GNBPHY phy, ptrLTENR_ASSOCIATEDUEPHYINFO info, int CA_ID)

{

    //Downlink

    info->downlinkAMCInfo[CA_ID]->SpectralEfficiency = info->propagationInfo[CA_ID]->downlink.spectralEfficiency;

    info->downlinkAMCInfo[CA_ID]->cqiTable = LTENR_GetCQITableFromSpectralEfficiency(phy->CSIReportConfig.cqiTable,

        info->downlinkAMCInfo[CA_ID]->SpectralEfficiency);

    info->downlinkAMCInfo[CA_ID]->mcsTable = LTENR_GetMCSIndexTableFromSpectralEfficiency(phy->PDSCHConfig.mcsTable,

        info->downlinkAMCInfo[CA_ID]->cqiTable.efficiency);

    FILE* fp;

    char filepath[BUFSIZ];

    sprintf(filepath, "%s/%s", pszIOLogPath, "5G_MCS_CQI_LOG.csv");

    fp = fopen(filepath, "a+");

    

    print_ltenr_log("\tAMC info between gNB %d:%d and UE %d:%d for downlink-\n",

        phy->gnbId, phy->gnbIf,

        info->ueId, info->ueIf);

    print_ltenr_log("\t\tSpectral Efficiency = %lf\n", info->downlinkAMCInfo[CA_ID]->SpectralEfficiency);

    print_ltenr_log("\t\tCQI Table\n");

    print_ltenr_log("\t\t\t%d\t%s\t%d\t%lf\n",

        info->downlinkAMCInfo[CA_ID]->cqiTable.CQIIndex,

        strPHY_MODULATION[info->downlinkAMCInfo[CA_ID]->cqiTable.modulation],

        info->downlinkAMCInfo[CA_ID]->cqiTable.codeRate,

        info->downlinkAMCInfo[CA_ID]->cqiTable.efficiency);

    print_ltenr_log("\t\tMCS Table\n");

    print_ltenr_log("\t\t\t%d\t%s\t%d\t%lf\t%lf\n",

        info->downlinkAMCInfo[CA_ID]->mcsTable.mcsIndex,

        strPHY_MODULATION[info->downlinkAMCInfo[CA_ID]->mcsTable.modulation],

        info->downlinkAMCInfo[CA_ID]->mcsTable.modulationOrder,

        info->downlinkAMCInfo[CA_ID]->mcsTable.codeRate,

        info->downlinkAMCInfo[CA_ID]->mcsTable.spectralEfficiency);


    //Uplink

    info->uplinkAMCInfo[CA_ID]->SpectralEfficiency = info->propagationInfo[CA_ID]->uplink.spectralEfficiency;

    info->uplinkAMCInfo[CA_ID]->cqiTable = LTENR_GetCQITableFromSpectralEfficiency(phy->CSIReportConfig.cqiTable,

        info->uplinkAMCInfo[CA_ID]->SpectralEfficiency);

    info->uplinkAMCInfo[CA_ID]->mcsTable = LTENR_GetMCSIndexTableFromSpectralEfficiency(phy->PUSCHConfig.mcsTable,

        info->uplinkAMCInfo[CA_ID]->cqiTable.efficiency);

    if (fp)

    {

        fprintf(fp, "\n%lf,%d,%d,%s,%d,%s,%d,%lf,%d,%s,%lf,%lf,%lf", pstruEventDetails->dEventTime, 

            phy->gnbId, info->ueId, "Downlink" , info->downlinkAMCInfo[CA_ID]->cqiTable.CQIIndex,

            strPHY_MODULATION[info->downlinkAMCInfo[CA_ID]->cqiTable.modulation],

            info->downlinkAMCInfo[CA_ID]->cqiTable.codeRate,

            info->downlinkAMCInfo[CA_ID]->cqiTable.efficiency, info->downlinkAMCInfo[CA_ID]->mcsTable.mcsIndex,

            strPHY_MODULATION[info->downlinkAMCInfo[CA_ID]->mcsTable.modulation],

            info->downlinkAMCInfo[CA_ID]->mcsTable.codeRate,

            info->downlinkAMCInfo[CA_ID]->mcsTable.spectralEfficiency, DEVICE_DISTANCE(phy->gnbId, info->ueId));

        fprintf(fp, "\n%lf,%d,%d,%s,%d,%s,%d,%lf,%d,%s,%lf,%lf,%lf", pstruEventDetails->dEventTime, 

            phy->gnbId, info->ueId, "Uplink" , info->uplinkAMCInfo[CA_ID]->cqiTable.CQIIndex,

            strPHY_MODULATION[info->uplinkAMCInfo[CA_ID]->cqiTable.modulation],

            info->uplinkAMCInfo[CA_ID]->cqiTable.codeRate,

            info->uplinkAMCInfo[CA_ID]->cqiTable.efficiency, info->uplinkAMCInfo[CA_ID]->mcsTable.mcsIndex,

            strPHY_MODULATION[info->uplinkAMCInfo[CA_ID]->mcsTable.modulation],

            info->uplinkAMCInfo[CA_ID]->mcsTable.codeRate,

            info->uplinkAMCInfo[CA_ID]->mcsTable.spectralEfficiency, DEVICE_DISTANCE(phy->gnbId,info->ueId));

        fclose(fp);

    }

    print_ltenr_log("\tAMC info between gNB %d:%d and UE %d:%d for uplink-\n",

        phy->gnbId, phy->gnbIf,

        info->ueId, info->ueIf);

.

.

.

}


5. After performing the modifications, right-click on the LTE_NR project, and select Rebuild.

6. Upon successful build, the LTE_NR binaries in the current workspace will get updated as per the modification done to the code.

7. Now create a NetSim scenario in the LTE_NR network and run the simulation.

8. After the simulation, the 5G_MCS_CQI_LOG.csv file can be accessed directly from the results dashboard from the Log Files drop-down as shown below:


The log file contains information such as the timestamp, gNB ID, UE ID, Traffic Type, CQI Index, CQI Modulation, MCS INDEX, MCS Modulation, the distance between gNB and UE, etc as shown below:



Applicable Releases
v11.0v11.1v12.0v12.1


The way to do this is,


1. Open Visual studio 2019 through NetSim->Open Simulation ->Workspace Options -> Open Code.

2. Open the LTE_Phy.c file in the LTE project from the list of projects displayed in the Solution Explorer.

3. Perform the following modifications at the beginning of the file (lines shown in red):


#include "main.h"

#include "LTE.h"

#define devid(id) fn_NetSim_GetDeviceIdByConfigId(id)

char* get_modulation(UINT);

NETSIM_ID fn_NetSim_LTE_FindNearesteNB(NETSIM_ID nDeviceId);

FILE* fp;

int fn_NetSim_LTE_CalculateReceivedPower()

{

 NETSIM_ID i;

 fp=fopen("LTE_PARAMETERS.txt","w+");

 fprintf(fp,"\nLTE_PARAMETERS\t\t\t\t\tLTE_PARAMETERS");

 fprintf(fp,"\n****************************\t\t\t****************************\n");

 fprintf(fp,"\nUPLINK\t\t\t\t\t\tDOWNLINK");

 fprintf(fp,"\n****************************\t\t\t****************************\n");

 for(i=0;i<NETWORK->nDeviceCount;i++)

 {

  if(NETWORK->ppstruDeviceList[i]->nDeviceType==eNB ||

   DEVICE_TYPE(i+1)==RELAY)

  {

   NETSIM_ID ifid=get_eNB_Interface(i+1);

   LTE_ENB_MAC* enbMac=(LTE_ENB_MAC*)DEVICE_MACVAR(i+1,ifid);

   LTE_ASSOCIATEUE_INFO* info=enbMac->associatedUEInfo;

   while(info)

   {

    unsigned int j;

    for(j=0;j<enbMac->ca_count;j++)

    {

     fn_NetSim_LTE_CalculateRxPower(i+1,ifid,info,j);

     fn_NetSim_LTE_CalculateSNR(i+1,ifid,info,j);

     fn_NetSim_LTE_GetCQIIndex(i+1,ifid,info,j);

     fn_NetSim_LTE_GetMCS_TBS_Index(info,j);

     while(info->DLInfo[j].nCQIIndex>1 && info->ULInfo[j].nCQIIndex>1)

     {

      double ber;

      fn_NetSim_LTE_GetMCS_TBS_Index(info,j);

      ber = fn_NetSim_LTE_CalculateBER(0,info->DLInfo[j].MCSIndex,info->DLInfo[j].dSNR);

      if(ber<TARGET_BER)

       break;

      else

      {

       info->DLInfo[j].nCQIIndex--;

       info->ULInfo[j].nCQIIndex--;

      }

     }

 

  fprintf(fp,"\nENB ID: %d\t\t\t\t\tENB ID: %d",i+1,i+1);

  fprintf(fp,"\nCARRIER ID: %u\t\t\t\t\tCARRIER ID: %u",j+1,j+1);

  fprintf(fp,"\nUE ID: %d\t\t\t\t\tUE Id: %d",devid(info->nUEId),info->nUEId);

  fprintf(fp,"\nSNR: %lf\t\t\t\t\tSNR: %lf",info->ULInfo[j].dSNR,info->DLInfo[j].dSNR);

 

  fprintf(fp,"\nCQI INDEX: %d\t\t\t\t\tCQI INDEX: %d",info->ULInfo[j].nCQIIndex,info->DLInfo[j].nCQIIndex);

 

  fprintf(fp,"\nMODULATION: %s\t\t\tMODULATION: %s",get_modulation(info->ULInfo[j].modulation),get_modulation(info->DLInfo[j].modulation));

 

  fprintf(fp,"\nMCS INDEX: %d\t\t\t\t\tMCS INDEX: %d",info->ULInfo[j].MCSIndex,info->DLInfo[j].MCSIndex);

 

  fprintf(fp,"\nTBS INDEX: %d\t\t\t\t\tTBS INDEX: %d",info->ULInfo[j].TBSIndex,info->DLInfo[j].TBSIndex);

  fprintf(fp,"\n****************************\t\t\t****************************\n");

 

    }

 

 

    info=(LTE_ASSOCIATEUE_INFO*)LIST_NEXT(info);

   }

  }

 }

 fclose(fp);

 return 1;

}

char* get_modulation(UINT modulation)

{

 char* mod="\0";

 

  switch(modulation)

  {

  case 5:

   mod="Modulation_QPSK";

   break;

  case 6:

   mod="Modulation_16QAM";

   break;

  case 7:

   mod="Modulation_64QAM";

   break;

  default:

   fprintf(stderr,"\nunknown modulation type\n");

   break;

  }

  return mod;

}


4. After performing the modifications, choose the platform either(win32/x64) according to the NetSim version used (32/64 bits) and right-click on the LTE project, and select Rebuild.

5. libLTE.dll in the bin directory of the current workspace will get modified automatically upon successful build.

6. Now create a NetSim scenario in the LTE network.

7. Run the scenario.


The SNR, CQI, MCS Index, and TBS Index will be written to a file named LTE_PARAMETERS.txt inside the bin folder of NetSim.


Note:

The modifications suggested are related to NetSim v11.1, v12.0, and V12.1 we recommend you perform code modifications and create scenarios in the respective version that you have.