Applicable Versions
Academic
StandardPro


Applicable Releases
v13.0v13.1


The parameters such as vehicle speed, vehicle direction, and vehicle position are associated with SUMO and can be obtained by using TraCI API's.  

In this example, we will see how the speed parameter can be added to the payload of a packet prior to being transmitted. 

1. Perform the code changes as explained in the article: https://support.tetcos.com/en/support/solutions/articles/14000090988-how-can-parameters-associated-with-vehicles-be-retrieved-from-sumo-in-netsim-

2. Go to the Sumo_interface.c file which is part of the Mobility source code project, and add a line of code to the if condition present in sumo_run() function as highlighted below:
if (coordinates!=NULL)
        {
            DEVICE_MOBILITY(pstruEventDetails->nDeviceId)->dAvgSpeed = coordinates[2];
            NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->pstruDeviceMobility->pstruNextPosition->X = coordinates[0];    // Update the coordinates in Network stack
            NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->pstruDeviceMobility->pstruNextPosition->Y = coordinates[1];
            free(coordinates);            // Free memory of pointer
        }


3. Go to the *corr(char* id) function and perform the modifications at the end as highlighted below:
        fprintf(stderr, "\n%s Direction: %f(Degrees)\tSpeed: %f(m/s)\n", id, direction, speed);
        coordinates = (double*)malloc(3*sizeof* coordinates);
        coordinates[0]=xcor1;
        coordinates[1]=ycor1;
        coordinates[2] = speed;
        return (coordinates);                //Return X Y Coordinates
    }

    else
    {
        return(NULL);        // If vehicle not found, return NULL
    }

}

4. Go to the BSM.c file in the Application source code project, and include the Mobility header at the beginning of the file as highlighted below:
#include "Application.h"
#include "../Mobility/Mobility.h"

5. Add a new function copy_bsm_payload() above the already existing function add_sae_j2735_payload() using the following defenition:

void copy_bsm_payload(UINT8 real[], NetSim_PACKET* packet, unsigned int* payload, ptrAPPLICATION_INFO info)
{
    u_short i;
    uint32_t key = 16;
    char custom_data[BUFSIZ];
    double speed = DEVICE_MOBILITY(packet->nSourceId)->dAvgSpeed;
    sprintf(custom_data,"speed=\"%lf\"",speed);
    if (payload)
    {
        size_t custom_data_len = strlen(custom_data);
        for (i = 0; i < custom_data_len; i++)
        {
            if (info->encryption == Encryption_XOR)
                real[i] = xor_encrypt(custom_data[i], 16);
            else
                real[i] = custom_data[i];
        }
        if (info->encryption == Encryption_TEA)
            encryptBlock(real, payload, &key);
        else if (info->encryption == Encryption_AES)
            aes256(real, payload);
        else if (info->encryption == Encryption_DES)
            des(real, payload);
    }
}


6. Modify the add_sae_j2735_payload() function as shown below:

bool add_sae_j2735_payload(NetSim_PACKET* packet, ptrAPPLICATION_INFO info)
{
    // Add the payload based on SAE J2735 or any other standard
    // return true after adding.
    
    while (packet)
    {
        if (!packet->szPayload &&
            packet->pstruAppData &&
            packet->pstruAppData->dPacketSize &&
            packet->pstruAppData->nAppType != TRAFFIC_EMULATION /* Don't set payload in emulation */)
        {
            unsigned int size = (unsigned int)packet->pstruAppData->dPacketSize;
            packet->szPayload = (PPACKET_INFO)calloc(1, sizeof * packet->szPayload);
            copy_bsm_payload(packet->szPayload->packet, packet, &size, info);
            packet->szPayload->packet_len = size;
            packet->pstruAppData->dPacketSize = (double)size;
        }
        packet = packet->pstruNextPacket;
    }

    return true;

}

7. Save all changes and rebuild the Application and Mobility source code projects. 


8. Now run any simulations in VANET that involves SUMO mobility with Wireshark set to online/offline in the nodes that are either source/destination of BSM traffic.


9. After the simulation you will be able to see in the Wireshark packet capture file that the payload of the BSM packets now contains the speed information.


NetSim VANET webpage: https://www.tetcos.com/vanets.html