|Applicable Releases||v13.0||v13.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.
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:
DEVICE_MOBILITY(pstruEventDetails->nDeviceId)->dAvgSpeed = coordinates;
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->pstruDeviceMobility->pstruNextPosition->X = coordinates; // Update the coordinates in Network stack
NETWORK->ppstruDeviceList[pstruEventDetails->nDeviceId-1]->pstruDeviceMobility->pstruNextPosition->Y = coordinates;
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 = speed;
return (coordinates); //Return X Y Coordinates
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:
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)
uint32_t key = 16;
double speed = DEVICE_MOBILITY(packet->nSourceId)->dAvgSpeed;
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);
real[i] = custom_data[i];
if (info->encryption == Encryption_TEA)
encryptBlock(real, payload, &key);
else if (info->encryption == Encryption_AES)
else if (info->encryption == Encryption_DES)
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.
if (!packet->szPayload &&
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;
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.