LTE Air Interface Packet loss 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 Packet Loss in each air interface into a separate file 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.

ii.Go to LTE project through the solution explorer and open the file LTE.h. Add the lines of code highlighted in red as shown below:


#include "LTE_enum.h"
#include "PDCP.h"
#include "CA.h"
#include "MIMO.h"

    int PACKETS_SENT[100];
    int PACKETS_LOST[100];


/***** Default Config Parameter ****/
#define LTE_TX_POWER_DEFAULT                20        //mw
#define LTE_TX_ANTENNAS_COUNT_DEFAULT        1


iii. In the file, LTE.c make the following changes(highlighted in red) in the fn_NetSim_LTE_Init() function:


_declspec(dllexport) int fn_NetSim_LTE_Init()
{
    FILE *fp;
    char filename[BUFSIZ];
    int i = 0, enb_count = 0;
    for (i = 0; i < NETWORK->nDeviceCount; i++)
    {
        if (DEVICE_TYPE(i + 1) == eNB)
        {

            enb_count++;
            sprintf(filename, "LTE_PACKET_LOSS_AIR_INTERFACE_%d.csv", DEVICE_INTERFACE(i+1, 1)->pstruPhysicalLayer->nLinkId);
            fp = fopen(filename, "w+");
            if (fp)
            {
                fprintf(fp, "SIMULTAION_TIME(micro sec),TOTAL_PACKETS_LOST,TOTAL_PACKETS_SENT");
                fclose(fp);
            }
        }

    }


    return fn_NetSim_LTE_Init_F();
}


iv. In the file, LTE.c make the following changes(highlighted in red) in the fn_NetSim_LTE_Run() function under the case PHYSICAL_IN_EVENT:


case PHYSICAL_IN_EVENT:
        {
        FILE *fp;
        int Air_Inter_id = 0;
        int device_id = 0;
        char logname[BUFSIZ];

            unsigned int carrier_index = get_carrier_index(pstruEventDetails->pPacket);
            if(pstruEventDetails->nDeviceType==eNB)
            {
                LTE_ASSOCIATEUE_INFO* info=fn_NetSim_LTE_FindInfo(get_enb_mac(pstruEventDetails->nDeviceId,1),pstruEventDetails->pPacket->nTransmitterId);
                if(!info)
                {
                    //Handover is in progress
                    PACKETS_LOST[pstruEventDetails->nDeviceId]++;
                    pstruEventDetails->pPacket->nPacketStatus = PacketStatus_Dropped;
                    fn_NetSim_WritePacketTrace(pstruEventDetails->pPacket);
                    fn_NetSim_Metrics_Add(pstruEventDetails->pPacket);
                    return -1;
                }
            }

            if (DEVICE_TYPE(pstruEventDetails->pPacket->nTransmitterId) == eNB)
            {
                device_id = pstruEventDetails->pPacket->nTransmitterId;
                Air_Inter_id = DEVICE_INTERFACE(device_id, 1)->pstruPhysicalLayer->nLinkId;
                PACKETS_SENT[device_id]++;
            }
            else if (DEVICE_TYPE(pstruEventDetails->pPacket->nReceiverId) == eNB)
            {
                device_id = pstruEventDetails->pPacket->nReceiverId;
                Air_Inter_id = DEVICE_INTERFACE(device_id, 1)->pstruPhysicalLayer->nLinkId;
                PACKETS_SENT[device_id]++;
            }

           
            if(fn_NetSim_LTE_DecideError(carrier_index))
            {
                pstruEventDetails->nEventType=MAC_IN_EVENT;
                fnpAddEvent(pstruEventDetails);
            }

            else                
                PACKETS_LOST[device_id]++;
               
            sprintf(logname, "LTE_PACKET_LOSS_AIR_INTERFACE_%d.csv", Air_Inter_id);
            fp = fopen(logname, "a+");
            if (fp)
            {
                fprintf(fp, "\n%f,%d,%d", pstruEventDetails->dEventTime, PACKETS_LOST[device_id], PACKETS_SENT[device_id]);
                fclose(fp);
            }


            fn_NetSim_WritePacketTrace(pstruEventDetails->pPacket);
            fn_NetSim_Metrics_Add(pstruEventDetails->pPacket);
        }
        break; //PHYSICAL_IN


v.Now 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).

viii.Now on running any simulation in LTE, you will get individual packet loss logs with respect to time for each LTE Air interface, in the bin folder of NetSim (“<NetSim_Install_Directory>/bin”) as shown below:


The file contains the fields - SIMULATION_TIME(micro-sec),TOTAL_PACKETS_LOST and TOTAL_PACKETS_SENT. Further Packet loss can be calculated from packets sent and packets lost at each instant of time.