主要内容

addNodes

Add wireless nodes to wireless network event tracer

Since R2026a

    Description

    addNodes(eventTracer,node) adds the specified wireless nodes to the wireless network event tracer object eventTracer.

    addNodes(eventTracer,node,EventName=eventName) configures the event tracer to log only events with the specified name eventName from the specified node.

    Examples

    collapse all

    Configure event tracing in a 5G NR wireless network simulation. Log network events to a MAT file using an event tracer, and then extract specific event information, such as the timestamps of application packet generation events at the gNB, for further analysis.

    Initialize the wireless network simulator.

    networkSimulator = wirelessNetworkSimulator.init;

    Create a gNB node with default settings.

    gnb = nrGNB(Name="nrgnb",PHYModel="full-phy");

    Create a UE node with default settings.

    ue = nrUE(Name="nrue",PHYModel="full-phy");

    Establish a connection between the UE and gNB nodes.

    connectUE(gnb,ue)

    Create a voice over Internet protocol (VoIP) application traffic pattern object.

    traffic = networkTrafficVoIP;

    Add the data traffic source to the gNB node. Specify the UE node as the destination node.

    addTrafficSource(gnb,traffic,DestinationNode=ue)

    Add the gNB and UE nodes to the wireless network simulator.

    addNodes(networkSimulator,gnb)
    addNodes(networkSimulator,ue)

    If an event log files exists, delete it.

    if exist("nreventLog.mat","file")
        delete("nreventLog.mat");
    end

    Create an event tracer object to log events to a MAT file during simulation runtime.

    eventTracer = wirelessNetworkEventTracer(FileName="nreventLog.mat");

    Add the gNB and UE nodes to the event tracer.

    addNodes(eventTracer,gnb) % Logs the events "TransmissionStarted", "ReceptionEnded", "AppPacketGenerated", and "AppPacketReceived"
    addNodes(eventTracer,ue)  % Logs the events "TransmissionStarted", "ReceptionEnded", "AppPacketGenerated", and "AppPacketReceived"

    Specify the simulation time, in seconds.

    simulationTime = 0.5;

    Run the simulation for the specified simulation time.

    run(networkSimulator,simulationTime)

    Read only the "AppPacketGenerated" events from node "nrgnb" from the event tracer.

    events = read(eventTracer,EventName="AppPacketGenerated",NodeName="nrgnb");
    disp(events);
      1×4 struct array with fields:
    
        EventName
        NodeName
        NodeID
        Timestamp
        TechnologyType
        EventData
    

    Extract the timestamps for "AppPacketGenerated" events of the gNB node from the event log.

    generationTimes = [events.Timestamp]
    generationTimes = 1×4
    
             0    0.1690    0.3320    0.4990
    
    

    Configure event tracing in a Bluetooth® network simulation. Log network events to a MAT file using an event tracer, and then extract specific event information, such as the timestamps of packet transmission events at a Bluetooth node, for further analysis.

    Initialize the wireless network simulator.

    networkSimulator = wirelessNetworkSimulator.init;

    Create Bluetooth Central and Peripheral nodes.

    centralNode = bluetoothLENode("central",Name="Central1");
    peripheralNode = bluetoothLENode("Peripheral",Name="Peripheral1",Position=[1 0 0]);

    Create and configure the connection.

    cfgConnection = bluetoothLEConnectionConfig;
    configureConnection(cfgConnection,centralNode,peripheralNode)
    ans = 
      bluetoothLEConnectionConfig with properties:
    
        ConnectionInterval: 0.0200
             AccessAddress: "5DA44270"
              UsedChannels: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36]
                 Algorithm: 1
              HopIncrement: 5
         CRCInitialization: "012345"
        SupervisionTimeout: 1
                   PHYMode: "LE1M"
             InstantOffset: 6
          ConnectionOffset: 0
              ActivePeriod: 0.0200
                    MaxPDU: 251
                      TIFS: 1.5000e-04
                     TMCES: 1.5000e-04
    
    

    Configure On-Off traffic.

    traffic = networkTrafficOnOff(DataRate=200,PacketSize=27, ...
        OnTime=inf);

    Add traffic from the Central to Peripheral node.

    addTrafficSource(centralNode,traffic,DestinationNode=peripheralNode)

    Add the Bluetooth nodes to the simulator.

    addNodes(networkSimulator,[centralNode peripheralNode]);

    If an event log files exists, delete it.

    if exist("btEventLog.mat","file")
        delete("btEventLog.mat");
    end

    Create an event tracer object to log events to a MAT file during simulation runtime.

    eventTracer = wirelessNetworkEventTracer(FileName="btEventLog.mat");

    Add the Central and Peripheral nodes to the event tracer.

    addNodes(eventTracer,centralNode,eventName=["TransmissionStarted" "ReceptionEnded"])
    addNodes(eventTracer,peripheralNode,eventName=["TransmissionStarted" "ReceptionEnded"])

    Set the simulation time, and run the simulation.

    simulationTime = 0.3;
    run(networkSimulator,simulationTime)

    Read all the events from the event tracer.

    events = read(eventTracer);

    Extract the timestamps for "TransmissionStarted" events of the Central node from the event log.

    event1 = read(eventTracer,NodeName="Central1",EventName="TransmissionStarted");
    transmissionTimes1 = [event1.Timestamp]
    transmissionTimes1 = 1×268
    
             0    0.0200    0.0207    0.0214    0.0220    0.0227    0.0234    0.0241    0.0247    0.0254    0.0261    0.0268    0.0275    0.0281    0.0288    0.0295    0.0302    0.0308    0.0315    0.0322    0.0329    0.0336    0.0342    0.0349    0.0400    0.0407    0.0414    0.0420    0.0427    0.0434    0.0441    0.0447    0.0454    0.0461    0.0468    0.0475    0.0481    0.0488    0.0495    0.0502    0.0508    0.0515    0.0522    0.0529    0.0536    0.0542    0.0549    0.0600    0.0607    0.0614
    
    

    Alternatively, you can read events from the MAT file "btEventLog.mat" by following these steps.

    eventLog= wirelessNetworkEventTracer("btEventLog.mat");
    event2 = read(eventLog,NodeName="Central1",EventName="TransmissionStarted");
    transmissionTimes2 = [event2.Timestamp]
    transmissionTimes2 = 1×268
    
             0    0.0200    0.0207    0.0214    0.0220    0.0227    0.0234    0.0241    0.0247    0.0254    0.0261    0.0268    0.0275    0.0281    0.0288    0.0295    0.0302    0.0308    0.0315    0.0322    0.0329    0.0336    0.0342    0.0349    0.0400    0.0407    0.0414    0.0420    0.0427    0.0434    0.0441    0.0447    0.0454    0.0461    0.0468    0.0475    0.0481    0.0488    0.0495    0.0502    0.0508    0.0515    0.0522    0.0529    0.0536    0.0542    0.0549    0.0600    0.0607    0.0614
    
    

    Configure event tracing in a wireless local area network (WLAN) simulation. Log network events to a MAT file using an event tracer, and then extract specific event information, such as the timestamps of packet transmission events at the access point, for further analysis.

    Initialize the wireless network simulator.

    networkSimulator = wirelessNetworkSimulator.init;

    Create and configure the AP node.

    deviceCfg = wlanDeviceConfig(Mode="AP");
    apNode = wlanNode(Name="AP",Position=[0 10 0],DeviceConfig=deviceCfg);

    Create the STA node with a default device configuration.

    staNode = wlanNode(Name="STA",Position=[5 0 0]);

    Associate the STA node with the AP node.

    associateStations(apNode,staNode)

    Create On-Off application traffic.

    traffic = networkTrafficOnOff(DataRate=10e6,PacketSize=1500);

    Add application traffic from the AP to the STA.

    addTrafficSource(apNode,traffic,DestinationNode=staNode)

    Add the AP and STA nodes to the simulator.

    addNodes(networkSimulator,[apNode staNode])

    If an event log files exists, delete it.

    if exist("wlanEventLog.mat","file")
        delete("wlanEventLog.mat");
    end

    Create an event tracer object to log events to a MAT file during simulation runtime.

    eventTracer = wirelessNetworkEventTracer(FileName="wlanEventLog.mat");

    Add the AP and STA nodes to the event tracer.

    addNodes(eventTracer,apNode)
    addNodes(eventTracer,staNode)

    Set the simulation time, and run the simulation.

    simulationTime = 0.3;
    run(networkSimulator,simulationTime);

    Read the events from the event tracer.

    events=read(eventTracer);

    Read the "TransmissionStarted" events of the AP node from the event tracer.

    event1 = read(eventTracer,EventName="TransmissionStarted",NodeName="AP");

    Obtain the timestamps for all "TransmissionStarted" events of the AP node from the event log.

    generationTimes = [event1.Timestamp]
    generationTimes = 1×112
    
        0.0001    0.0002    0.0054    0.0056    0.0109    0.0110    0.0164    0.0165    0.0219    0.0220    0.0273    0.0274    0.0327    0.0328    0.0381    0.0383    0.0436    0.0437    0.0490    0.0491    0.0543    0.0545    0.0597    0.0598    0.0652    0.0653    0.0706    0.0707    0.0760    0.0761    0.0814    0.0815    0.0868    0.0869    0.0922    0.0924    0.0977    0.0978    0.1031    0.1032    0.1085    0.1086    0.1138    0.1140    0.1193    0.1194    0.1247    0.1248    0.1301    0.1302
    
    

    Input Arguments

    collapse all

    Wireless network event tracer, specified as a wirelessNetworkEventTracer object.

    Wireless node, specified as an object of a subclass of wnet.node, a vector of objects of a subclass of wnet.Node, or a cell array of objects of a subclass of wnet.Node.

    Event name, specified as one of these options:

    • "TransmissionStarted", "ReceptionEnded", "AppPacketGenerated", "AppPacketReceived", a character vector, a string scalar, or a vector of strings for the nodes such as nrGNB (5G Toolbox), nrUE (5G Toolbox), bluetoothNode (Bluetooth Toolbox), bluetoothLENode (Bluetooth Toolbox), or wlanNode (WLAN Toolbox).

    • A character vector, a string scalar, or a vector of strings for subclasses of wnet.Node.

    By default, the event tracer logs all events associated with the added node. If you add the same node with a different set of events, the object logs those events for that node as well.

    Data Types: string | char

    Version History

    Introduced in R2026a