OMNET 将数据包从一个节点发送到另一个节点,并记录发送的数据包,并以图形为单位



我正在使用Omnet 模拟无线网络。代码如下:

NED文件

import inet.common.figures.DelegateSignalConfigurator;
import inet.networklayer.configurator.ipv4.IPv4NetworkConfigurator;
import inet.node.inet.INetworkNode;
import inet.physicallayer.contract.packetlevel.IRadioMedium;
import inet.visualizer.integrated.IntegratedCanvasVisualizer;
network WirelessA
{
    parameters:
        string hostType = default("WirelessHost");
        string mediumType = default("IdealRadioMedium");
        @display("bgb=2500,2500;bgg=100,1,grey95");
        @figure[title](type=label; pos=0,-1; anchor=sw; color=darkblue);
        @figure[rcvdPkText](type=indicatorText; pos=900,50; anchor=w; font=,50; textFormat="Packets Received: %g"; initialValue=0);
        //@statistic[rcvdPk](source=hostB_rcvdPk; record=figure(count); targetFigure=rcvdPkText);
        //@signal[hostB_rcvdPk];
        //@delegatesignal[rcvdPk](source=hostB.udpApp[0].rcvdPk; target=hostB_rcvdPk);
    submodules:
        visualizer: IntegratedCanvasVisualizer {
            @display("p=2400,50");
        }
        configurator: IPv4NetworkConfigurator {
            @display("p=2400,250");
        }
        radioMedium: <mediumType> like IRadioMedium {
            @display("p=2400,450");
        }
        figureHelper: DelegateSignalConfigurator {
            @display("p=2400,650");
        }
        BaseStation: <hostType> like INetworkNode {
            @display("p=1200,1200;i=device/antennatower");
        }
        SubStationA: <hostType> like INetworkNode {
            @display("p=600,650;i=device/receiverdish");
        }
        SubStationB: <hostType> like INetworkNode {
            @display("p=1750,600;i=device/receiverdish");
        }
        SubStationC: <hostType> like INetworkNode {
            @display("p=1700,1700;i=device/receiverdish");
        }
        SubStationD: <hostType> like INetworkNode {
            @display("p=650,1750;i=device/receiverdish");
        }
        SensorNodeA1: <hostType> like INetworkNode {
            @display("p=875,900;i=device/device");
        }
        SensorNodeA2: <hostType> like INetworkNode {
            @display("p=425,975;i=device/device");
        }
        SensorNodeA3: <hostType> like INetworkNode {
            @display("p=225,625;i=device/device");
        }
        SensorNodeA4: <hostType> like INetworkNode {
            @display("p=475,275;i=device/device");
        }
        SensorNodeA5: <hostType> like INetworkNode {
            @display("p=875,450;i=device/device");
        }
        SensorNodeB1: <hostType> like INetworkNode {
            @display("p=1875,300;i=device/device");
        }
        SensorNodeB2: <hostType> like INetworkNode {
            @display("p=1450,425;i=device/device");
        }
        SensorNodeB3: <hostType> like INetworkNode {
            @display("p=1475,850;i=device/device");
        }
        SensorNodeB4: <hostType> like INetworkNode {
            @display("p=1925,925;i=device/device");
        }
        SensorNodeB5: <hostType> like INetworkNode {
            @display("p=2100,575;i=device/device");
        }
        SensorNodeC1: <hostType> like INetworkNode {
            @display("p=1425,1950;i=device/device");
        }
        SensorNodeC2: <hostType> like INetworkNode {
            @display("p=1450,1500;i=device/device");
        }
        SensorNodeC3: <hostType> like INetworkNode {
            @display("p=1875,2075;i=device/device");
        }
        SensorNodeC4: <hostType> like INetworkNode {
            @display("p=2100,1750;i=device/device");
        }
        SensorNodeC5: <hostType> like INetworkNode {
            @display("p=1900,1400;i=device/device");
        }
        SensorNodeD1: <hostType> like INetworkNode {
            @display("p=800,2075;i=device/device");
        }
        SensorNodeD2: <hostType> like INetworkNode {
            @display("p=1000,1700;i=device/device");
        }
        SensorNodeD3: <hostType> like INetworkNode {
            @display("p=650,1450;i=device/device");
        }
        SensorNodeD4: <hostType> like INetworkNode {
            @display("p=350,2050;i=device/device");
        }
        SensorNodeD5: <hostType> like INetworkNode {
            @display("p=275,1625;i=device/device");
        }
}

ini文件

[Config Wireless01]
description = Militart Based WSN Model
network = WirelessA
sim-time-limit = 5s
*.BaseStation.networkLayer.arpType = "GlobalARP"
*.SubStation*.networkLayer.arpType = "GlobalARP"
*.SensorNode**.networkLayer.arpType = "GlobalARP"
*.BaseStation.wlan[0].typename = "WirelessNic"
*.BaseStation.wlan[0].radioType = "IdealRadio"
*.BaseStation.wlan[0].macType = "CsmaCaMac"
*.BaseStation.wlan[0].mac.useAck = true
#*.BaseStation.wlan[0].mac.fullDuplex = false
*.BaseStation.wlan[0].radio.transmitter.communicationRange = 1300m
*.BaseStation.wlan[0].radio.receiver.ignoreInterference = true
*.BaseStation.wlan[0].radio.displayCommunicationRange = true
*.BaseStation.**.bitrate = 10Mbps
*.BaseStation.wlan[0].radio.energyConsumerType = "StateBasedEnergyConsumer"
*.BaseStation.wlan[0].radio.energyConsumer.offPowerConsumption = -1mW
*.BaseStation.wlan[0].radio.energyConsumer.sleepPowerConsumption = 0mW
*.BaseStation.wlan[0].radio.energyConsumer.switchingPowerConsumption = 1mW
*.BaseStation.wlan[0].radio.energyConsumer.receiverIdlePowerConsumption = 2mW
*.BaseStation.wlan[0].radio.energyConsumer.receiverBusyPowerConsumption = 5mW
*.BaseStation.wlan[0].radio.energyConsumer.receiverReceivingPowerConsumption = 10mW
*.BaseStation.wlan[0].radio.energyConsumer.transmitterIdlePowerConsumption = 2mW
*.BaseStation.wlan[0].radio.energyConsumer.transmitterTransmittingPowerConsumption = 100mW
*.BaseStation.energyStorageType = "IdealEnergyStorage"
*.SubStation*.wlan[0].typename = "WirelessNic"
*.SubStation*.wlan[0].radioType = "IdealRadio"
*.SubStation*.wlan[0].macType = "CsmaCaMac"
*.SubStation*.wlan[0].mac.useAck = true
#*.SubStation*.wlan[0].mac.fullDuplex = true
*.SubStation*.wlan[0].radio.transmitter.communicationRange = 600m
*.SubStation*.wlan[0].radio.receiver.ignoreInterference = true
*.SubStation*.wlan[0].radio.displayCommunicationRange = true
*.SubStation*.**.bitrate = 5Mbps
*.SubStation*.wlan[0].radio.energyConsumerType = "StateBasedEnergyConsumer"
*.SubStation*.wlan[0].radio.energyConsumer.offPowerConsumption = -1mW
*.SubStation*.wlan[0].radio.energyConsumer.sleepPowerConsumption = 0mW
*.SubStation*.wlan[0].radio.energyConsumer.switchingPowerConsumption = 1mW
*.SubStation*.wlan[0].radio.energyConsumer.receiverIdlePowerConsumption = 2mW
*.SubStation*.wlan[0].radio.energyConsumer.receiverBusyPowerConsumption = 5mW
*.SubStation*.wlan[0].radio.energyConsumer.receiverReceivingPowerConsumption = 10mW
*.SubStation*.wlan[0].radio.energyConsumer.transmitterIdlePowerConsumption = 2mW
*.SubStation*.wlan[0].radio.energyConsumer.transmitterTransmittingPowerConsumption = 100mW
*.SubStation*.energyStorageType = "IdealEnergyStorage"
*.SensorNode**.wlan[0].typename = "WirelessNic"
*.SensorNode**.wlan[0].radioType = "IdealRadio"
*.SensorNode**.wlan[0].macType = "CsmaCaMac"
*.SensorNode**.wlan[0].mac.useAck = true
#*.SensorNode**.wlan[0].mac.fullDuplex = true
*.SensorNode**.wlan[0].radio.transmitter.communicationRange = 250m
*.SensorNode**.wlan[0].radio.displayCommunicationRange = true
*.SensorNode**.wlan[0].radio.receiver.ignoreInterference = true
*.SensorNode**.**.bitrate = 1Mbps
*.SensorNode**.wlan[0].radio.energyConsumerType = "StateBasedEnergyConsumer"
*.SensorNode**.wlan[0].radio.energyConsumer.offPowerConsumption = -1mW
*.SensorNode**.wlan[0].radio.energyConsumer.sleepPowerConsumption = 0mW
*.SensorNode**.wlan[0].radio.energyConsumer.switchingPowerConsumption = 1mW
*.SensorNode**.wlan[0].radio.energyConsumer.receiverIdlePowerConsumption = 2mW
*.SensorNode**.wlan[0].radio.energyConsumer.receiverBusyPowerConsumption = 5mW
*.SensorNode**.wlan[0].radio.energyConsumer.receiverReceivingPowerConsumption = 10mW
*.SensorNode**.wlan[0].radio.energyConsumer.transmitterIdlePowerConsumption = 2mW
*.SensorNode**.wlan[0].radio.energyConsumer.transmitterTransmittingPowerConsumption = 100mW
*.SensorNode**.energyStorageType = "IdealEnergyStorage"
*.configurator.addStaticRoutes = false
*.hostType = "AODVRouter"
*.visualizer.dataLinkVisualizer.packetNameFilter = "AODV*"
*.visualizer.mediumVisualizer.displaySignals = true
*.SensorNodeA1.numUdpApps = 1
*.SensorNodeA1.udpApp[0].typename = "UDPBasicApp"
*.SensorNodeA1.udpApp[0].destAddresses = "SubStationA"
*.SensorNodeA1.udpApp[0].destPort = 5000
*.SensorNodeA1.udpApp[0].messageLength = 1000B
*.SensorNodeA1.udpApp[0].sendInterval = exponential(12ms)
*.SensorNodeA1.udpApp[0].packetName = "UDPData"
*.SubStationA.numUdpApps = 1
*.SubStationA.udpApp[0].typename = "UDPSink"
*.SubStationA.udpApp[0].localPort = 5000

在这里,网络正在创建,但是当我尝试将数据包从Sensornodea1发送到fersationa时,在模拟过程中,数据包将从SensorNodea1发送到所有节点。我该怎么做才能将数据包从一个节点发送到另一个节点?我也想记录并绘制随着时间的推移发送的数据包的图表以及每个节点的能耗。我仍然是Omnet 的新手

您确实知道,在无线方案中,一条消息总是在无线介质上"播放",因此该消息传达给无线电范围内的所有接收器。根据您的无线无线电介质型号,它也可能转移到干扰范围内的接收器中以计算干扰水平。无线没有"单播",这是一个共享的媒介,如果他处于相同频率,知道调制等,每个人都可以收到一切。

"单播"或"多播"只能在较高级别上启用,例如通过寻址,就像您使用目标地址"变电站"一样。检查接收数据包的其他节点的输出,他们是否真的在应用程序层上接收到它,还是由于不同的目标地址而在MAC层上丢弃它?再说一次,如果使用某种转发或路由协议,则节点可能会转发一个数据包...

至于统计记录,请检查Omnet手册中有关此复杂部分的信息。

大多数现有的INET仿真模型中的大多数都已经包含了各种统计信息,因此,一旦启用所需的统计信息(通过omnetpp.ini文件),您可以查看创建的结果文件(标量或向量,取决于标量或向量,取决于您要记录的数据 - 再次检查Omnet模拟手册)并使用随附的分析工具过滤您的数据和打印图。

如果您的统计数据尚未包含,则可以手动添加它们,这并不是很复杂。根据您的代码,我想您已经检查了INET无线教程 - 步骤8-建模无线消耗(https://omnetpp.org/doc/inet/api-current/tutorials/tutorials/wireless/step8.html),所以简单地遵循教程,也许还遵循有关统计信息的Tictoctutorial部分(https://omnetpp.org/doc/omnetpp/omnetpp/tictoc-tutorial/part4.ht4.html)。

相关内容

最新更新