addTrafficSource
Description
This feature also requires the Wireless Network Toolbox™ product.
addTrafficSource(
copies the data traffic source object nodeObj,trafficSource)trafficSource and adds it to the
WLAN node object nodeObj.
addTrafficSource(___,
specifies options using one or more name-value arguments in addition to the previous syntax.Name=Value)
Note
Each time you call this object function, you add a traffic generator (source) to a WLAN node. You can add multiple traffic sources to a node, directing them to the same or different destination nodes.
Reusing the same traffic source object in another
addTrafficSourceobject function call results in an error.
Examples
This example enables you to:
Create and configure a WLAN with an access point (AP) node and a station (STA) node.
Add application traffic from the AP node to the STA node.
Simulate the WLAN and retrieve the statistics of the AP node and the STA node.
Create a wireless network simulator.
networksimulator = wirelessNetworkSimulator.init();
Create a wlanDeviceConfig object, specifying the operating mode and beacon interval. Use this configuration to create a WLAN node and specify its name and position.
deviceCfg = wlanDeviceConfig(Mode="AP",BeaconInterval=5); apNode = wlanNode(Name="AP",Position=[0 10 0],DeviceConfig=deviceCfg);
Create a WLAN node with the default device configuration. Confirm that the default mode is STA.
staNode = wlanNode(Name="STA",Position=[5 0 0]);Add a random waypoint mobility model to the WLAN node with the default device configuration. Set the shape of the node's mobility area to "circle".
addMobility(staNode,BoundaryShape="circle",RefreshInterval=0.1)Associate the STA node with the AP node using the associateStations function.
associateStations(apNode,staNode);
Create a networkTrafficOnOff (Wireless Network Toolbox) object to generate an On-Off application traffic pattern. Specify the data rate in kilobits per second and the packet size in bytes.
traffic = networkTrafficOnOff(DataRate=100,PacketSize=10);
Add application traffic from the AP node to the STA node.
addTrafficSource(apNode,traffic,DestinationNode=staNode);
Add the AP node and STA node to the wireless network simulator.
addNodes(networksimulator,{apNode,staNode});Set the simulation time in seconds and run the simulation.
simulationTime = 0.5; run(networksimulator,simulationTime);
Get and display the physical layer (PHY) statistics that correspond to the AP node and STA node.
apStats = statistics(apNode); staStats = statistics(staNode); disp(apStats.PHY)
TransmittedPackets: 1243
TransmittedPayloadBytes: 58779
ReceivedPackets: 1146
ReceivedPayloadBytes: 16044
DroppedPackets: 0
disp(staStats.PHY)
TransmittedPackets: 1146
TransmittedPayloadBytes: 16044
ReceivedPackets: 1243
ReceivedPayloadBytes: 58779
DroppedPackets: 0
Initialize the wireless network simulator.
networksimulator = wirelessNetworkSimulator.init();
Create a device configuration object for a WLAN node, specifying the operating mode as "AP" and beacon interval in time units.
deviceCfg = wlanDeviceConfig(Mode="AP",BeaconInterval=5);Using the specified device configuration, create a WLAN AP. Specify the name and position of the AP node.
apNode = wlanNode(Name="AP",Position=[0 0 0],DeviceConfig=deviceCfg);Create four WLAN STA nodes with the default device configuration. Specify the positions of each STA in 3-D Cartesian coordinates.
staNodes = wlanNode(Name=["STA1" "STA2" "STA3" "STA4"],Position=[0 1 0; 1 1 0; 0 1 1; 1 1 1]);
Associate the STA nodes with the AP node.
associateStations(apNode,staNodes);
Create a On-Off application traffic pattern object, specifying the data rate (in Kbps) and packet size (in bytes). Add application traffic from the AP node (source) to the four STA nodes (destination).
traffic = networkTrafficOnOff(DataRate=100,PacketSize=10); addTrafficSource(apNode,networkTrafficOnOff,DestinationNode=staNodes,AccessCategory=0)
Add the AP node and STA nodes to the wireless network simulator.
addNodes(networksimulator,[apNode staNodes]);
Specify the simulation time (in seconds) and run the simulation.
simulationTime = 1; run(networksimulator,simulationTime);
Retrieve and display the statistics corresponding to the AP node and STA nodes.
apStats = statistics(apNode)
apStats = struct with fields:
Name: "AP"
ID: 1
App: [1×1 struct]
MAC: [1×1 struct]
PHY: [1×1 struct]
Mesh: [1×1 struct]
staStats = statistics(staNodes)
staStats=1×4 struct array with fields:
Name
ID
App
MAC
PHY
Mesh
Input Arguments
WLAN node, specified as a wlanNode object, or a vector of
wlanNode objects. The object function adds a data traffic source to
this node. When you specify this value as a vector, you must leave the DestinationNode name-value argument unspecified or set it to a
scalar.
Data traffic source, specified as an object of a subclass of the wnet.Traffic (Wireless Network Toolbox)
class, networkTrafficOnOff object, networkTrafficFTP
object, networkTrafficVideoConference object, or
networkTrafficVoIP object. To add On-Off, file transfer protocol
(FTP), video conference, or voice over internet protocol (VoIP) traffic, configure the
networkTrafficOnOff (Wireless Network Toolbox), networkTrafficFTP (Wireless Network Toolbox), networkTrafficVideoConference (Wireless Network Toolbox), or networkTrafficVoIP (Wireless Network Toolbox) objects of the wnet.Traffic class. The
object function adds this data traffic source to the WLAN node that you specify for the
nodeObj argument.
You can also create a custom traffic source using the wnet.Traffic
class.
When you add traffic to a WLAN node using this object function, the
nodeObj object creates a copy of the
trafficSource object and adds it to the node, ensuring that
subsequent changes to the original trafficSource object do not
affect the traffic already added. For more information, see the copy (Wireless Network Toolbox) object
function. The nodeObj automatically calls the generate (Wireless Network Toolbox)
object function of the wnet.Traffic class to create the corresponding
application traffic packets. The generate object function generates
application traffic packets only when the MACModel property of the
WLAN node is set to "full-mac".
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: AccessCategory = 1 specifies that the access category of the
generated traffic is from the Background category.
Destination node of the traffic, specified as a wlanNode object or a vector of
wlanNode objects. If you do not specify this argument, the source
node broadcasts its traffic. If you specify this name-value argument as a vector, the
nodeObj input argument must be a scalar.
If the source node is a STA multilink device (MLD) operating in EMLSR mode or an AP MLD with at least one associated EMLSR STA, you must specify this argument. (since R2024b)
Access category, specified as a scalar integer in the range [0, 3]. The four possible values respectively correspond to the Best Effort, Background, Video, and Voice access categories.
Data Types: single | double
Version History
Introduced in R2023aStarting in R2026a, this feature is available in WLAN Toolbox™ and also requires a Wireless Network Toolbox license. In prior releases, the feature is available through the Communications Toolbox™ Wireless Network Simulation Library add-on.
The addTrafficSource object function now enables you to add a
traffic source from a single source node to multiple destination nodes and from multiple
source nodes to a single destination node in a single function call.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)