Applicable Versions
NetSim Standard 
NetSim Pro

Applicable Releases

The source codes of the Application Source code project needs to be modified to automatically create applications between all sensors and the sink in a Wireless Sensor Network Scenario of NetSim. 
Follow the steps given below to modify the source codes:
1. In the Home Screen of NetSim go to Open Simulation -> Workspace Options and click on the Open Code button to open NetSim source codes in Visual Studio.
2. Now go to the Application Project in the solution explorer and double click on the Application.c file to open it.
3. Modify the function fn_NetSim_Application_Configure() as shown below:

_declspec(dllexport) int fn_NetSim_Application_Configure(void** var)
    char* tagname = (char*)var[0];
    if (!strcmp(tagname, "APPLICATION_CONFIGURATION"))
        unsigned int i, sinkid;
        NETWORK = (struct stru_NetSim_Network*)var[1];
        nApplicationCount = NETWORK->nDeviceCount - 1;//number of applications
        NETWORK->nApplicationCount = nApplicationCount;

        if (nApplicationCount)
            applicationInfo = (ptrAPPLICATION_INFO*)calloc(nApplicationCount, sizeof * applicationInfo);

        NETWORK->appInfo = (void**)applicationInfo;

        for (i = 0; i < NETWORK->nDeviceCount; i++)
            if (!strcmp(DEVICE(i + 1)->type, "SENSOR"))
                sinkid = i + 1;

        for (i = 0; i < nApplicationCount; i++)
            applicationInfo[i] = (ptrAPPLICATION_INFO)calloc(1, sizeof * applicationInfo[i]);
            applicationInfo[i]->id = i + 1;
            applicationInfo[i]->name = (char*)calloc(BUFSIZ, sizeof * applicationInfo[i]->name);
            sprintf(applicationInfo[i]->name, "App%d_SENSOR_APP", applicationInfo[i]->id);
            applicationInfo[i]->nConfigId = i + 1;
            applicationInfo[i]->nAppType = TRAFFIC_SENSING;
            applicationInfo[i]->encryption = Encryption_None;
            applicationInfo[i]->qos = QOS_BE;
            applicationInfo[i]->nTransmissionType = UNICAST;
            applicationInfo[i]->nSourceCount = 1;
            applicationInfo[i]->sourceList = (NETSIM_ID*)calloc(applicationInfo[i]->nSourceCount, sizeof * applicationInfo[i]->sourceList);
            if ((i + 1) != sinkid)
                applicationInfo[i]->sourceList[0] = i + 1;
                applicationInfo[i]->sourceList[0] = NETWORK->nDeviceCount;

            applicationInfo[i]->nDestCount = 1;
            applicationInfo[i]->destList = (NETSIM_ID*)calloc(applicationInfo[i]->nDestCount, sizeof *       applicationInfo[i]->destList);
            applicationInfo[i]->destList[0] = sinkid;
            applicationInfo[i]->dStartTime = 0;
            applicationInfo[i]->isStartupDelay = FALSE;
            applicationInfo[i]->dEndTime = 1000000 * SECOND;
            //applicationInfo[i]->protocol = APP_PROTOCOL_NULL;
            //applicationInfo[i]->trxProtocol = TX_PROTOCOL_UDP;
            APP_DATA_INFO* info = (APP_DATA_INFO*)calloc(1, sizeof * info);
            applicationInfo[i]->appData = info;
            info->packetSizeDistribution = Distribution_Constant;
            info->dPacketSize = 50;
            info->IATDistribution = Distribution_Constant;
            info->dIAT = 1000000;
        return 1;

        return fn_NetSim_Application_Configure_F(var);

4. Set the solution platform to win32 or x64 based on the build of NetSim (32 bit/64 bit) that you have installed.
5. Right-click on the Application project in the solution explorer and select Rebuild.

This code modification is done with the following assumptions:
1. An application will be created between each sensor node and the sink node in the WSN network.
2. The application that is created will be SENSOR_APP with the default properties. However, if users want to change the default properties, it can be modified in the code section accordingly.

Users can create a WSN network with any number of devices and create one dummy application between any two nodes since GUI will not permit running simulation without at least one application configured.

After the simulation, we can see the results for application from all the sensors to the sink node.

This code modification works only in the case of the Sensor network. In order to perform simulation in other networks, users will have to either reset binaries or switch to a different workspace.