Main Content

Generate Periodic and Bursty Traffic in Wireless Network

This example demonstrates how to generate periodic and bursty traffic patterns, for network performance analysis, by using the networkTrafficOnOff object of the Communications Toolbox™ Wireless Network Simulation Library.

Periodic Traffic

Periodic traffic involves transmitting data packets at regular intervals. Instances of periodic traffic include sensor networks reporting at fixed intervals, heartbeat messages in network protocols, and timed updates in control systems.

To simulate periodic traffic using the networkTrafficOnOff object, follow these steps:

Create a networkTrafficOnOff object with these properties.

  • On state duration — Inf

  • Packet generation rate during On state — 10 kbps

  • Length of packet to be generated — 1000 bytes

  • Flag to indicate whether to generate application packet — true

cfgPeriodic = networkTrafficOnOff(OnTime=Inf,DataRate=10, ...
                                  PacketSize=1000, ...
                                  GeneratePacket=true);      % Configuration for periodic traffic

Set the simulation duration.

simulationDuration = 20; % Seconds

Initialize the current simulation time.

currentTime = 0;         % Current simulation time

Calculate the time to generate one packet. The tiime to generate one packet equals the packet size, in bits, divided by the data rate, in bits per second.

packetSizeBits = cfgPeriodic.PacketSize*8;		         % Convert packet size from bytes to bits
dataRateSeconds = cfgPeriodic.DataRate*1000;		     % Convert data rate from bits/ms to bits/second
timePerPacket = packetSizeBits/dataRateSeconds		     % Time to generate one packet in seconds
timePerPacket = 
0.8000

Estimate the number of packets to be generated.

numPackets = ceil(simulationDuration/timePerPacket);

Preallocate arrays for storing the packet times and sizes.

packetTimes = zeros(1,numPackets);
packetSizes = zeros(1,numPackets);

Generate periodic traffic by using the generate object function of the the networkTrafficOnOff object

packetCount = 0;
% Generate Periodic Traffic
while currentTime < simulationDuration
    % Generate packet and calculate next packet generation time
    [dt,packetSize] = generate(cfgPeriodic);
    currentTime = currentTime + dt/1000; % Convert ms to seconds for the next iteration
    packetCount = packetCount + 1;
    packetTimes(packetCount) = currentTime;
    packetSizes(packetCount) = packetSize;
    fprintf("Time: %f s - Generated a periodic packet of size %d bytes\n", currentTime, packetSize);
end
Time: 0.800000 s - Generated a periodic packet of size 1000 bytes
Time: 1.600000 s - Generated a periodic packet of size 1000 bytes
Time: 2.400000 s - Generated a periodic packet of size 1000 bytes
Time: 3.200000 s - Generated a periodic packet of size 1000 bytes
Time: 4.000000 s - Generated a periodic packet of size 1000 bytes
Time: 4.800000 s - Generated a periodic packet of size 1000 bytes
Time: 5.600000 s - Generated a periodic packet of size 1000 bytes
Time: 6.400000 s - Generated a periodic packet of size 1000 bytes
Time: 7.200000 s - Generated a periodic packet of size 1000 bytes
Time: 8.000000 s - Generated a periodic packet of size 1000 bytes
Time: 8.800000 s - Generated a periodic packet of size 1000 bytes
Time: 9.600000 s - Generated a periodic packet of size 1000 bytes
Time: 10.400000 s - Generated a periodic packet of size 1000 bytes
Time: 11.200000 s - Generated a periodic packet of size 1000 bytes
Time: 12.000000 s - Generated a periodic packet of size 1000 bytes
Time: 12.800000 s - Generated a periodic packet of size 1000 bytes
Time: 13.600000 s - Generated a periodic packet of size 1000 bytes
Time: 14.400000 s - Generated a periodic packet of size 1000 bytes
Time: 15.200000 s - Generated a periodic packet of size 1000 bytes
Time: 16.000000 s - Generated a periodic packet of size 1000 bytes
Time: 16.800000 s - Generated a periodic packet of size 1000 bytes
Time: 17.600000 s - Generated a periodic packet of size 1000 bytes
Time: 18.400000 s - Generated a periodic packet of size 1000 bytes
Time: 19.200000 s - Generated a periodic packet of size 1000 bytes
Time: 20.000000 s - Generated a periodic packet of size 1000 bytes
% Trim the packetTimes and packetSizes arrays to remove any unused preallocated space
packetTimes = packetTimes(1:packetCount);
packetSizes = packetSizes(1:packetCount);

Plot the packet generation times and sizes.

figure % Creates a new figure window
stem(packetTimes, packetSizes,"filled", ...
    Marker="v",MarkerSize=6,MarkerFaceColor="b")
xlabel("Time (s)")
ylabel("Packet Size (bytes)")
title("Packet Generation Over Time")
xlim([0 simulationDuration])
ylim([0 max(packetSizes) * 1.1]) % Adjust Y-axis to clearly show packet sizes

Figure contains an axes object. The axes object with title Packet Generation Over Time, xlabel Time (s), ylabel Packet Size (bytes) contains an object of type stem.

The figure illustrates the packet generation over the 20-second simulation duration. Each vertical line (stem) represents a packet generation event, which occur at regular 0.800-second intervals, confirming the periodic nature of the traffic.

Bursty Traffic

Bursty traffic includes periods of high activity (bursts) followed by periods of low or no activity (silence). The application examples include, but are not limited to, video streaming and web browsing, where user actions or data delivery occur in bursts followed by periods of inactivity.

To simulate bursty traffic using the the networkTrafficOnOff object, follow these steps:

Create a networkTrafficOnOff object with these properties. In this configuration, the On state duration is shorter than the Off state duration and set a high value for DataRate to simulate the bursty nature of the traffic during the On state. This reflects the sudden spikes in network activity common in bursty traffic patterns.

  • On state duration — 0.8 seconds

  • Off state duration — 3.5 seconds

  • Packet generation rate during On state — 1000 kbps

  • Length of packet to be generated — 1400 bytes

  • Flag to indicate whether to generate application packet — true

cfgBursty = networkTrafficOnOff(OnTime=0.8,OffTime=3.5, ...
                                  DataRate=1e3,PacketSize=1400, ...
                                  GeneratePacket=true);   % Configuration for Periodic Traffic

Set the simulation duration.

simulationDuration = 20; % seconds

Initialize the current simulation time.

currentTime = 0;         % Current simulation time

Calculate the time to generate one packet. Time to generate one packet equals the packet size in bits divided by the data rate in bits per second.

packetSizeBits = cfgBursty.PacketSize*8;		         % Convert packet size from bytes to bits
dataRateSeconds = cfgBursty.DataRate*1000;		         % Convert data rate from bits/ms to bits/second
timePerPacket = packetSizeBits/dataRateSeconds;		     % Time to generate one packet in seconds

Estimate the number of packets to be generated.

numPackets = ceil(simulationDuration/timePerPacket);

Preallocate arrays for storing packet times and sizes.

packetTimes = zeros(1,numPackets);
packetSizes = zeros(1,numPackets);

Generate bursty Traffic by using the generate object function of the the networkTrafficOnOff object

packetCount = 0;
% Generate Periodic Traffic
while currentTime < simulationDuration
    % Generate packet and calculate next packet generation time
    [dt,packetSize] = generate(cfgBursty);
    currentTime = currentTime + dt/1000; % Convert ms to seconds for the next iteration
    packetCount = packetCount + 1;
    packetTimes(packetCount) = currentTime;
    packetSizes(packetCount) = packetSize;
end
% Trim the packetTimes and packetSizes arrays to remove any unused preallocated space
packetTimes = packetTimes(1:packetCount);
packetSizes = packetSizes(1:packetCount);

Plot the packet generation times and sizes.

figure % Creates a new figure window
stem(packetTimes,packetSizes,"filled", ...
    Marker="v",MarkerSize=6,MarkerFaceColor="b")
xlabel("Time (s)")
ylabel("Packet Size (bytes)")
title("Packet Generation Over Time")
xlim([0 simulationDuration])
ylim([0 max(packetSizes) * 1.1]) % Adjust Y-axis to clearly show packet sizes

Figure contains an axes object. The axes object with title Packet Generation Over Time, xlabel Time (s), ylabel Packet Size (bytes) contains an object of type stem.

The figure illustrates the bursty traffic generation over the 20-second simulation duration. In the first on period, which lasts from 0 to 0.8 seconds, the generate function generates packets at regular intervals of 0.0112 seconds. This results in 71 packets, as the remaining 0.0048 seconds in the first on period is insufficient to generate an additional packet. To calculate the total number of packets generated during the On state, multiply the On state duration in seconds by the packet generation rate in bits per second, and then divide by 8 times the length of each packet in bytes. The On duration accommodates only whole packets, as the generate function does not support fractions. The networkTrafficOnOff object carries over any leftover data to the next On state, accounting for the remaining time from the previous On state.

During the OffTime period (3.5 seconds), the generate function generates no packets. This Off period spans from 0.8 seconds to 4.3 seconds. The second On period begins at 4.3 seconds. Due to the shortfall of 0.0064 seconds from the first On period, the generate function generates the first packet in the second On period at 4.3064 seconds. During this second On period, the generate function continues to generate packets at regular intervals of 0.0112 seconds, resulting in a total of 71 packets by the end of this period. This process continues for subsequent On and Off periods throughout the simulation.

Related Topics