Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Plot gNB SNR at UE in NetSim : NetSim Support Portal

Plotting SNR from all gNBs at UE for 5G/LTE in NetSim


Created by: NetSim SUPPORT TEAM
Modified on: Tue, 25 May, 2021 at 6:26 PM

Applicable Versions
NetSim Standard NetSim Pro

SNR measured by UE can be logged into a text file in a format expected by the 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 the 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 the 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
v13.0

Refer to section 10.6.1 of NetSim User Manual on Plotting SNR for each UE-gNB pair in 5G NR.

An instrumented workspace with additional plotting and logging capabilities can also be used to obtain plots and logs of
SNR and other associated parameters. Refer to the following link:
https://www.tetcos.com/pdf/v13/5G-Parameter-Logging-and-Plotting.pdf (https://www.tetcos.com/pdf/v13/5G-
Parameter-Logging-and-Plotting.pdf)

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);

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim
Plot gNB SNR at UE in NetSim : NetSim Support Portal

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)

.
. 
.

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim
Plot gNB SNR at UE in NetSim : NetSim Support Portal

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 the 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.

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);

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim
Plot gNB SNR at UE in NetSim : NetSim Support Portal

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)

.
. 
.

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim
Plot gNB SNR at UE in NetSim : NetSim Support Portal

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

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:

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim
Plot gNB SNR at UE in NetSim : NetSim Support Portal

N NetSim is the author of this solution article.

https://support.tetcos.com/support/solutions/articles/14000086851-plotting-snr-from-all-gnbs-at-ue-for-5g-lte-in-netsim

You might also like