Applicable Versions
NetSim StandardNetSim Pro


SNR measured by UE can be logged into a text file in a format expected by NetSim metrics window. Upon adding a reference to the SNR plot text files in the Metrics.xml file we can conveniently obtain SNR plots in NetSim Metrics window without having to use other tools like MS Excel, GNU Plot etc. Following is one such example where we log the SNR for each UE in a separate text file and obtain plots in NetSim Metrics window at the end of the simulation.


The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim (please scroll down to see the different version applicability).


Applicable Releases
v10.2
v11.0

i.Open NetSim source code in Visual Studio 2015/2017 by double clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder.

ii.Go to LTE project through the solution explorer and open the LTE.c file. In the function fn_NetSim_LTE_Init(), modify the function definition as shown below:


_declspec(dllexport) int fn_NetSim_LTE_Init()
{
int i = 0, j = 0;
FILE* fp;
char filename[BUFSIZ], nodename[BUFSIZ];
j = fn_NetSim_LTE_Init_F();
for (i = 0; i < NETWORK->nDeviceCount; i++)
{
if (DEVICE_TYPE(i + 1) == UE &&
DEVICE_MACLAYER(i + 1, 1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
sprintf(nodename, "LTE_SNR_UE_%d", i + 1);
sprintf(filename, "%s\\%s.txt", pszIOPath, nodename);
fp = fopen(filename, "w+");
if (fp)
{
fprintf(fp, "#Type=Line\n#Heading=SNR Vs Time\n#XLabel=Time(micro sec)\n#Num_Y=1\n#YLabel=SNR(dBm)");
fclose(fp);
}

}
}
return j;

}


iii. In the function fn_NetSim_LTE_Metrics(), add the lines of code highlighted in red as shown below:


_declspec(dllexport) int fn_NetSim_LTE_Metrics(PMETRICSWRITER file)
{
PMETRICSNODE menu = NULL;
PMETRICSNODE rmenu = NULL;
PMETRICSNODE submenu = NULL;
PMETRICSNODE submenu1 = NULL;
char filename[BUFSIZ], nodename[BUFSIZ];
int i = 0;
if (!rmenu)
rmenu = init_metrics_node(MetricsNode_Menu, "Plots", NULL);
if (!menu)
menu = init_metrics_node(MetricsNode_Menu, "LTE_PLOTS", NULL);
add_node_to_menu(rmenu, menu);
for (i = 0; i < NETWORK->nDeviceCount; i++)
{
if (DEVICE_TYPE(i + 1) == UE &&
DEVICE_MACLAYER(i + 1, 1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
sprintf(nodename, "LTE_SNR_UE_%d", (i + 1));
sprintf(filename, "%s\\%s.txt", pszIOPath, nodename);
submenu1 = init_metrics_node(MetricsNode_Menu, nodename, NULL);
add_node_to_menu(menu, submenu1);
submenu = init_metrics_node(MetricsNode_Plot, nodename, filename);
add_node_to_menu(submenu1, submenu);
}
}
if (menu)
write_metrics_node(file, WriterPosition_Current, NULL, rmenu);

return fn_NetSim_LTE_Metrics_F(file);
}


iv. Open LTE_Phy.c file and add the lines of code highlighted in red in the function fn_NetSim_LTE_Mobility() as shown below:


int fn_NetSim_LTE_Mobility(NETSIM_ID nDeviceId)
{
FILE* fp = NULL;
char filename[BUFSIZ], nodename[BUFSIZ];
double dETime = 0;

unsigned int j;
if(DEVICE_MACLAYER(nDeviceId,1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
.

.

.

.
else
{
info->DLInfo[j].nCQIIndex--;
info->ULInfo[j].nCQIIndex--;
}
}
}
sprintf(nodename, "LTE_SNR_UE_%d.txt", fn_NetSim_GetDeviceIdByConfigId(info->nUEId));
sprintf(filename, "%s\\%s", pszIOPath, nodename);
fp = fopen(filename, "a+");
dETime = pstruEventDetails->dEventTime;
if (fp)
{
fprintf(fp, "\n%lf,%lf", dETime, info->ULInfo[0].dSNR);
fclose(fp);
}

}
else
{
//Do nothing other mac protocol
}
return 1;
}



v. Save the changes and right click on LTE module in the solution explorer and select Rebuild.


vi. Upon successful build, you will get a new libLTE.dll file in the “<NetSim_Install_Directory>/src/Simulation/DLL” folder.

vii. 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).


Applicable Releases
v11.1
v12.0
v12.1


i. Open NetSim source code in Visual Studio 2019 by clicking on the Open Code button present in NetSim Home Screen via Open Simulation->Workspace Options->Open Code. 


ii.Go to LTE project through the solution explorer and open the LTE.c file. In the function fn_NetSim_LTE_Init(), modify the function definition as shown below:


_declspec(dllexport) int fn_NetSim_LTE_Init()
{
int i = 0, j = 0;
FILE* fp;
char filename[BUFSIZ], nodename[BUFSIZ];
j = fn_NetSim_LTE_Init_F();
for (i = 0; i < NETWORK->nDeviceCount; i++)
{
if (DEVICE_TYPE(i + 1) == UE &&
DEVICE_MACLAYER(i + 1, 1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
sprintf(nodename, "LTE_SNR_UE_%d", i + 1);
sprintf(filename, "%s\\%s.txt", pszIOPath, nodename);
fp = fopen(filename, "w+");
if (fp)
{
fprintf(fp, "#Type=Line\n#Heading=SNR Vs Time\n#XLabel=Time(micro sec)\n#Num_Y=1\n#YLabel=SNR(dBm)");
fclose(fp);
}

}
}
return j;

}


iii. In the function fn_NetSim_LTE_Metrics(), add the lines of code highlighted in red as shown below:


_declspec(dllexport) int fn_NetSim_LTE_Metrics(PMETRICSWRITER file)
{
PMETRICSNODE menu = NULL;
PMETRICSNODE rmenu = NULL;
PMETRICSNODE submenu = NULL;
PMETRICSNODE submenu1 = NULL;
char filename[BUFSIZ], nodename[BUFSIZ];
int i = 0;
if (!rmenu)
rmenu = init_metrics_node(MetricsNode_Menu, "Plots", NULL);
if (!menu)
menu = init_metrics_node(MetricsNode_Menu, "LTE_PLOTS", NULL);
add_node_to_menu(rmenu, menu);
for (i = 0; i < NETWORK->nDeviceCount; i++)
{
if (DEVICE_TYPE(i + 1) == UE &&
DEVICE_MACLAYER(i + 1, 1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
sprintf(nodename, "LTE_SNR_UE_%d", (i + 1));
sprintf(filename, "%s\\%s.txt", pszIOPath, nodename);
submenu1 = init_metrics_node(MetricsNode_Menu, nodename, NULL);
add_node_to_menu(menu, submenu1);
submenu = init_metrics_node(MetricsNode_Plot, nodename, filename);
add_node_to_menu(submenu1, submenu);
}
}
if (menu)
write_metrics_node(file, WriterPosition_Current, NULL, rmenu);

return fn_NetSim_LTE_Metrics_F(file);
}


iv. Open LTE_Phy.c file and add the lines of code highlighted in red in the function fn_NetSim_LTE_Mobility() as shown below:


int fn_NetSim_LTE_Mobility(NETSIM_ID nDeviceId)
{
FILE* fp = NULL;
char filename[BUFSIZ], nodename[BUFSIZ];
double dETime = 0;

unsigned int j;
if(DEVICE_MACLAYER(nDeviceId,1)->nMacProtocolId == MAC_PROTOCOL_LTE)
{
.

.

.

.
else
{
info->DLInfo[j].nCQIIndex--;
info->ULInfo[j].nCQIIndex--;
}
}
}
sprintf(nodename, "LTE_SNR_UE_%d.txt", fn_NetSim_GetDeviceIdByConfigId(info->nUEId));
sprintf(filename, "%s\\%s", pszIOPath, nodename);
fp = fopen(filename, "a+");
dETime = pstruEventDetails->dEventTime;
if (fp)
{
fprintf(fp, "\n%lf,%lf", dETime, info->ULInfo[0].dSNR);
fclose(fp);
}

}
else
{
//Do nothing other mac protocol
}
return 1;
}



v. Save the changes and right click on LTE module in the solution explorer and select Rebuild.


vi. Upon successful build, NetSim will automatically update the modified binaries in the respective binary folder.



Results and Analysis


Now on running any simulation in LTE, you will get individual SNR plots for each UE, in the NetSim Metrics window under Plots->LTE_PLOTS as shown below: