Applicable Versions | NetSim Standard | NetSim Pro |
The steps to plot SNR measured by UE across different versions of NetSim are given below.
Applicable Releases | v12.2 | v13.0 |
Step 1: Open NetSim source code in NetSim current workspace. For more information, please refer section “3.12 How does a user open and modify source codes”.
Step 2: Go to LTE_NR project through the solution explorer and open the LTE_NR.c file. In the function fn_NetSim_LTE_NR_Init(), modify code as shown below:
_declspec(dllexport) int fn_NetSim_LTE_NR_Init()
{
//custom plot
int ret = fn_NetSim_LTE_NR_Init_F();
for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
{
for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
{
if (!isLTE_NRInterface(r + 1, rin + 1))
continue;
ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(r + 1, rin + 1);
switch (data->deviceType)
{
case LTENR_DEVICETYPE_UE:
{
for (NETSIM_ID r1 = 0; r1 < NETWORK->nDeviceCount; r1++)
{
for (NETSIM_ID rin1 = 0; rin1 < DEVICE(r1 + 1)->nNumOfInterface; rin1++)
{
if (!isLTE_NRInterface(r1 + 1, rin1 + 1))
continue;
ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(r1 + 1, rin1 + 1);
switch (data->deviceType)
{
case LTENR_DEVICETYPE_GNB:
{
char heading[BUFSIZ], plotname[BUFSIZ];
sprintf(heading, "UE_%d_GNB_%d_SNR", r + 1, r1 + 1);
sprintf(plotname, "plot_UE_%d_GNB_%d_SNR", r + 1, r1 + 1);
fn_NetSim_Install_Metrics_Plot(Plot_Custom, "LTE_NR SNR Plot", heading, "SNR(dB)", 1, plotname);
}
break;
default:
break;
}
}
}
break;
default:
break;
}
break;
}
}
}
return ret;
//custom plot
}
Step 3: In the file LTENR_GNBRRC.c go to the function fn_NetSim_LTENR_RRC_GENERATE_UE_MEASUREMENT_REPORT() and add the lines of code highlighted in red as shown below:
void fn_NetSIM_LTENR_RRC_GENERATE_UE_MEASUREMENT_REPORT()
{
NETSIM_ID d = pstruEventDetails->nDeviceId;
NETSIM_ID in = pstruEventDetails->nInterfaceId;
ptrLTENR_UERRC ueRRC = LTENR_UERRC_GET(d, in);
ptrLTENR_GNBRRC gnbRRC = LTENR_GNBRRC_GET(ueRRC->SelectedCellID, ueRRC- >SelectedCellIF); ptrLTENR_RRC_UE_MEASUREMENT_REPORT report = NULL;
ptrLTENR_RRC_UE_MEASUREMENT_REPORT temp = NULL;
ptrLTENR_GNBPHY phy = NULL;
for (NETSIM_ID r = 0; r < NETWORK->nDeviceCount; r++)
{
for (NETSIM_ID rin = 0; rin < DEVICE(r + 1)->nNumOfInterface; rin++)
{
if (!isLTE_NRInterface(r + 1, rin + 1))
continue;
ptrLTENR_PROTODATA data = LTENR_PROTODATA_GET(r + 1, rin + 1);
switch (data->deviceType)
{
case LTENR_DEVICETYPE_GNB: temp = MEASUREMENT_REPORT_ALLOC();
temp->ueID = d;
temp->cellID = r + 1;
temp->cellIF = rin + 1;
temp->rs_type = RS_TYPE_SSB;
temp->reportAmount = ReportAmount_r1;
temp->reportInteval = gnbRRC->ueMeasReportInterval;
phy = LTENR_GNBPHY_GET(r + 1, rin + 1);
temp->sinr = LTENR_PHY_RRC_RSRP_SINR(r + 1, rin + 1, d, in);
//custom plot
char plotname[BUFSIZ];
sprintf(plotname, "%s\\plot_UE_%d_GNB_%d_SNR.txt",pszIOPath, d, r + 1);
FILE* fp = fopen(plotname, "a+");
if (fp)
{
fprintf(fp, "%lf,%lf\n",pstruEventDetails->dEventTime,temp->sinr);
fclose(fp);
}
//custom plot
LIST_ADD_LAST((void**)&report, temp);
break;
default:
break;
}
}
}
ptrLTENR_RRC_Hdr hdr = calloc(1, sizeof * hdr);
hdr->msg = report;
hdr->msgType = LTENR_MSG_RRC_UE_MEASUREMENT_REPORT;
hdr->SenderID = d;
hdr->SenderIF = in;
fn_NetSIm_LTENR_RRC_ADD_HDR_INTO_PACKET(pstruEventDetails->pPacket, hdr, ueMEASID, LTENR_MSG_RRC_UE_MEASUREMENT_REPORT);
LTENR_CallPDCPOut();
}
Step 4: In LTENR.c add the following lines #include "NetSim_Plot.h".
Step 5: Save the changes and right-click on the LTE_NR module in the solution explorer and select Rebuild.
Step 6: Upon a successful build, NetSim will automatically update the modified binaries in the respective binary folder.
Step 7: Now on running any simulation in LTE/5G NR networks, you will get individual SNR plots for each UE-GNB/UE-ENB pair, in the NetSim Metrics window under Plots ->LTE_NR SNR Plot shown below :
Applicable Releases | v11 | v12.0 | v12.1 |
SNR measured by UE can be logged into a single or a separate file and then be plotted as per your requirement. Following is one such example where we log the SNR for each UE in a separate file with respect to each ENB along with the event time.
i.Open NetSim source code in Visual Studio 2015 by double clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder.
(From v11.1 onwards, user must open visual studio 2017/2019 through Netsim->open simulation->workspace options->open code)
ii.Go to LTE project through the solution explorer and open the file LTE_Phy.c. Add the lines of code highlighted in red as shown below:
#include "main.h"
#include "LTE.h"
#define devid(id) fn_NetSim_GetDeviceIdByConfigId(id)
NETSIM_ID fn_NetSim_LTE_FindNearesteNB(NETSIM_ID nDeviceId);
FILE* fp;
char snrlog[100];
int fn_NetSim_LTE_CalculateReceivedPower()
{
NETSIM_ID i;
//fp = fopen("LTE_UE_SNR.txt", "w+");
for(i=0;i<NETWORK->nDeviceCount;i++)
{
…………………………………………………………
if(ber<TARGET_BER)
break;
else
{
info->DLInfo[j].nCQIIndex--;
info->ULInfo[j].nCQIIndex--;
}
}
sprintf(snrlog, "LTE_UE_%d_SNR.csv", devid(info->nUEId));
fp = fopen(snrlog, "w+");
if (fp)
{
fprintf(fp, "UE_ID,ENB_ID,Time,SNR");
fclose(fp);
}
}
info=(LTE_ASSOCIATEUE_INFO*)LIST_NEXT(info);
}
}
}
return 1;
}
iii.In the file NAS.c add the lines of code highlighted in red as shown below:
#define MEASUREMENT_REPORT_SIZE 184/8.0
#define HO_REQUEST_SIZE 288/8.0
#define HO_CONFIRM_SIZE 112/8.0
#define HANDOVER_DIFF 3 //db
#define devid(id) fn_NetSim_GetDeviceIdByConfigId(id)
int fn_NetSim_LTE_InitHandover(NETSIM_ID ueId,NETSIM_ID nENBId)
{
//Prepare the measurement report
NetSim_PACKET* packet;
LTE_MAC_PACKET* macPacket;
LTE_PHY_PACKET* phyPacket;
LTE_MEASUREMENT_REPORT* report=NULL;
NETSIM_ID i;
FILE* fp=NULL;
char snrlog[100];
double dETime=0;
for(i=0;i<NETWORK->nDeviceCount;i++)
{
…………………………………………….
if(ber<TARGET_BER)
break;
else
{
info->DLInfo[j].nCQIIndex--;
info->ULInfo[j].nCQIIndex--;
}
}
temp->nCQIIndex_DL[j]=info->DLInfo[j].nCQIIndex;
temp->dSNR_DL[j]=info->DLInfo[j].dSNR;
sprintf(snrlog, "LTE_UE_%d_SNR.csv", devid(info->nUEId));
fp = fopen(snrlog, "a+");
dETime = pstruEventDetails->dEventTime;
if (fp)
{
fprintf(fp, "\n%d,%d,%lf,%lf",devid(info->nUEId), devid(i+1), dETime, info->ULInfo[j].dSNR);
fclose(fp);
}
}
LIST_FREE((void**)&info,info);
LIST_ADD_LAST((void**)&report,temp);
}
}
iv.Now choose the platform according to 32 bit or 64 bit of Netsim, then right click on LTE module in the solution explorer and select rebuild.
v.Upon successful build, you will get a new libLTE.dll file in the “<NetSim_Install_Directory>/src/Simulation/DLL” folder. (From v11.1 onwards, dll will get automatically updated in the bin directory of the current workspace)
vi.Copy this newly built DLL file and replace it in the bin folder of NetSim after you rename the original libLTE.dll file which is already existing there(as a backup). (This step can be ignored for v11.1 and higher versions)
vii.Now on running any simulation in LTE, you will get individual SNR logs with respect to time for each UE, in the bin folder of NetSim (“<NetSim_Install_Directory>/bin”) as shown below:
viii.These log files can be used to further plot the SNR of each UE with respect to time using excel plots.