Applicable Versions
NetSim StandardNetSim Pro



ARP protocol implementation in NetSim is based on RFC 826. This protocol is supported in the Ethernet interface of Layer 3 devices in NetSim.


The Address Resolution Protocol (ARP) is a communication protocol used for discovering the link layer address, such as a MAC address, associated with a given internet layer address, typically an IPv4 address. This mapping is a critical function in the Internet protocol suite. 


ARP table update logs can be obtained for each node in a NetSim network, by modifying the underlying source codes of ARP protocol as explained below.  The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim. 


Please follow the steps given below to modify ARP source codes to obtain log files: 


Applicable Releasesv12.1v12.2v13

  

1. Open NetSim Source codes using the open code button from Your Work-> Workspace options (in v12.1 and v12.2, Open Simulation->Workspace options)

2. Go to ARP project in the solution explorer and open ARP.c  file Add the following code(shown in red) in the function fn_NetSim_ARP_Init()


_declspec (dllexport) int fn_NetSim_ARP_Init(struct stru_NetSim_Network *NETWORK_Formal,\

 NetSim_EVENTDETAILS *pstruEventDetails_Formal,char *pszAppPath_Formal,\

 char *pszWritePath_Formal,int nVersion_Type,void **fnPointer)

{

    fn_NetSim_ARP_Init_F(NETWORK_Formal,pstruEventDetails_Formal,pszAppPath_Formal,\

        pszWritePath_Formal,nVersion_Type,fnPointer);

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

    {

        for (int ci = 0; ci < DEVICE(c + 1)->nNumOfInterface; ci++)

        {

            if(DEVICE_INTERFACE(c+1, ci+1)->ipVar)

            fn_NetSim_ARP_Table_Update_Log(c + 1, ci+1, "w+");

        }

    }

    return 0;

}


2. In the same file and add the following function definition at the end of the file:


int fn_NetSim_ARP_Table_Update_Log(NETSIM_ID devid, NETSIM_ID nIfId, char* filemode)

{

    char ARP_Log_filename[BUFSIZ];

    FILE* ARP_log_fp;

    sprintf(ARP_Log_filename, "%s\\%s_%d_ARP_log.txt", pszIOLogPath, DEVICE_NAME(devid),nIfId);

    

    ARP_log_fp = fopen(ARP_Log_filename, filemode);

    if (ARP_log_fp && !strcmp(filemode, "w+"))

    {

        fprintf(ARP_log_fp, "IP_ADDRESS,MAC_ADDRESS,TYPE");

        fclose(ARP_log_fp);

    }

    else if (ARP_log_fp && !strcmp(filemode, "a+"))

    {

        ARP_VARIABLES* pstruArpVariables;

        pstruArpVariables = DEVICE_INTERFACE(devid, nIfId)->ipVar;

        ARP_TABLE* table = pstruArpVariables->pstruArpTable;

        fprintf(ARP_log_fp, "\n\nTIME(micro sec)  %f", pstruEventDetails->dEventTime);

        while (table)

        {            

            char* entry_type = (table->nType == 0) ? "STATIC" : "DYNAMIC";

            fprintf(ARP_log_fp, "\n%s,%s,%s", (table->szIPAddress)->str_ip, table->szMACAddress->szmacaddress, entry_type);

            table = table->pstruNextEntry;

        }

        

        fclose(ARP_log_fp);

    }

    return 0;

}


3. In the ARP.h file add the prototype of the function as shown below:


/* NetSim specific global variable for configuration and metrics */

STATIC_TABLE_CONFIG *g_pstruStaticTableConfig;

// ************ Other Functions in ARP **********************************************************

int fn_NetSim_ARP_Table_Update_Log(NETSIM_ID devid, NETSIM_ID nIfId, char* filemode);

/// Function to Read the static table and assign to the ARP_TABLE 

int fn_NetSim_StaticArpTable_Read(char* pszARPstasticTablePath);

/// Function to add the new entry to the ARP_TABLE(IP add, MAC add and Type)

int fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(ARP_TABLE** ,NETSIM_IPAddress , PNETSIM_MACADDRESS , int  );


4. In the file GenerateArpReply.c add a call to the table update function inside the fn_NetSim_Generate_ARP_Reply() function as shown below:


// Source entry not there in the ARP table, update the table.

    if(nMerge_flag == 0)

    {        

        nType = DYNAMIC;

        fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(&pstruTableHead,pstruArpRequestPkt->sz_ar$spa,pstruArpRequestPkt->sz_ar$sha,nType);    

        pstruArpVariables->pstruArpTable = pstruTableHead;

        nMerge_flag =1;

        fn_NetSim_ARP_Table_Update_Log(nDeviceId, nInterfaceId, "a+");

    }


5. In the file UpdateArpTable.c add a call to the table update function inside the fn_NetSim_Update_ARP_Table_ForwardPacket() function as shown below:


// Get the Arp Packet from the NetworkData of temp packet

    pstruPacketArp = pstruTemp_Data->pstruNetworkData->Packet_NetworkProtocol;        

    szSrcIPadd = IP_COPY(pstruPacketArp->sz_ar$spa);

    szTempMAC = pstruPacketArp->sz_ar$sha;

    nType = DYNAMIC;

    // call the function to update the table entry by adding the destination MAC

    fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(&pstruTableHead,szSrcIPadd,szTempMAC,nType);    

    fn_NetSim_ARP_Table_Update_Log(nDeviceId, nInterfaceId, "a+");

    // Write to Log file    

    szDestIPadd =  pstruPacketArp->sz_ar$tpa;    


6. After modifying the ARP source codes as explained above, right click on the ARP project and select rebuild. Ensure that you have set the platform settings in Visual studio to win32/x64 as per the build of NetSim that you have installed, before building.


7. Upon successful build, running simulations involving ARP protocol will generate individual log files for each node when run with Static ARP option disabled in the Run Simulation window as shown below:



8. The ARP table logs will be created for each Ethernet interface of and L3 device, which can be accessed from the results dashboard as shown below:





Applicable Releases
v12.0


1. Open NetSim Source codes using the open code button from Open Simulation->Workspace options

2. Go to ARP project in the solution explorer and open ARP.c  file Add the following code(shown in red) in the function fn_NetSim_ARP_Init()


_declspec (dllexport) int fn_NetSim_ARP_Init(struct stru_NetSim_Network *NETWORK_Formal,\

 NetSim_EVENTDETAILS *pstruEventDetails_Formal,char *pszAppPath_Formal,\

 char *pszWritePath_Formal,int nVersion_Type,void **fnPointer)

{

    fn_NetSim_ARP_Init_F(NETWORK_Formal,pstruEventDetails_Formal,pszAppPath_Formal,\

        pszWritePath_Formal,nVersion_Type,fnPointer);

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

    {

        for (int ci = 0; ci < DEVICE(c + 1)->nNumOfInterface; ci++)

        {

            if(DEVICE_INTERFACE(c+1, ci+1)->ipVar)

            fn_NetSim_ARP_Table_Update_Log(c + 1, ci+1, "w+");

        }

    }

    return 0;

}


2. In the same file and add the following function definition at the end of the file:


int fn_NetSim_ARP_Table_Update_Log(NETSIM_ID devid, NETSIM_ID nIfId, char* filemode)

{

    char ARP_Log_filename[BUFSIZ];

    FILE* ARP_log_fp;

    sprintf(ARP_Log_filename, "%s_%d_ARP_log.txt", DEVICE_NAME(devid),nIfId);

    ARP_log_fp = fopen(ARP_Log_filename, filemode);


    if (ARP_log_fp && !strcmp(filemode, "w+"))

    {

        fprintf(ARP_log_fp, "IP_ADDRESS,MAC_ADDRESS,TYPE");

        fclose(ARP_log_fp);

    }

    else if (ARP_log_fp && !strcmp(filemode, "a+"))

    {

        ARP_VARIABLES* pstruArpVariables;

        pstruArpVariables = DEVICE_INTERFACE(devid, nIfId)->ipVar;

        ARP_TABLE* table = pstruArpVariables->pstruArpTable;

        fprintf(ARP_log_fp, "\n\nTIME(micro sec)  %f", pstruEventDetails->dEventTime);

        while (table)

        {            

            char* entry_type = (table->nType == 0) ? "STATIC" : "DYNAMIC";

            fprintf(ARP_log_fp, "\n%s,%s,%s", (table->szIPAddress)->str_ip, table->szMACAddress->szmacaddress, entry_type);

            table = table->pstruNextEntry;

        }

        

        fclose(ARP_log_fp);

    }

    return 0;

}


3. In the ARP.h file add the prototype of the function as shown below:


/* NetSim specific global variable for configuration and metrics */

STATIC_TABLE_CONFIG *g_pstruStaticTableConfig;

// ************ Other Functions in ARP **********************************************************

int fn_NetSim_ARP_Table_Update_Log(NETSIM_ID devid, NETSIM_ID nIfId, char* filemode);

/// Function to Read the static table and assign to the ARP_TABLE 

int fn_NetSim_StaticArpTable_Read(char* pszARPstasticTablePath);

/// Function to add the new entry to the ARP_TABLE(IP add, MAC add and Type)

int fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(ARP_TABLE** ,NETSIM_IPAddress , PNETSIM_MACADDRESS , int  );


4. In the file GenerateArpReply.c add a call to the table update function inside the fn_NetSim_Generate_ARP_Reply() function as shown below:


// Source entry not there in the ARP table, update the table.

    if(nMerge_flag == 0)

    {        

        nType = DYNAMIC;

        fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(&pstruTableHead,pstruArpRequestPkt->sz_ar$spa,pstruArpRequestPkt->sz_ar$sha,nType);    

        pstruArpVariables->pstruArpTable = pstruTableHead;

        nMerge_flag =1;

        fn_NetSim_ARP_Table_Update_Log(nDeviceId, nInterfaceId, "a+");

    }


5. In the file UpdateArpTable.c add a call to the table update function inside the fn_NetSim_Update_ARP_Table_ForwardPacket() function as shown below:


// Get the Arp Packet from the NetworkData of temp packet

    pstruPacketArp = pstruTemp_Data->pstruNetworkData->Packet_NetworkProtocol;        

    szSrcIPadd = IP_COPY(pstruPacketArp->sz_ar$spa);

    szTempMAC = pstruPacketArp->sz_ar$sha;

    nType = DYNAMIC;

    // call the function to update the table entry by adding the destination MAC

    fn_NetSim_Add_IP_MAC_AddressTo_ARP_Table(&pstruTableHead,szSrcIPadd,szTempMAC,nType);    

    fn_NetSim_ARP_Table_Update_Log(nDeviceId, nInterfaceId, "a+");

    // Write to Log file    

    szDestIPadd =  pstruPacketArp->sz_ar$tpa;    


6. After modifying the ARP source codes as explained above, right click on the ARP project and select rebuild. Ensure that you have set the platform settings in Visual studio to win32/x64 as per the build of NetSim that you have installed, before building.


7. Upon successful build, running simulations involving ARP protocol will generate individual log files for each node when run with Static ARP option disabled in the Run Simulation window as shown below:



8. The ARP table logs will be created for each Ethernet interface of and L3 device, which can be accessed from <NetSim_Install_Directory>/bin folder. For Eg: Eg: C:\Program Files\NetSim Standard\bin