ns3测吞吐量

    xiaoxiao2023-03-24  4

    ———————10月14日更—————————- 发现在goal-topo.cc中,由于Node#14被放在初始位置为0的地方,然后它会收到来自AP1和AP2的STA的OLSR消息(距离他们太近了吧)。 然而与goal-topo-trad.cc不同,goal-topo-trad.cc中Node#14可以在很远就跟自己的AP3通信,吞吐量比较稳定。而goal-topo.cc在开始的很长时间内并不能发送UDP包,直到它出现在AP3的信号覆盖范围内之后才开始成功发包。我将csmaHelper从原来的只有唯一一个改成了三个,仍然没有效果。待续… ———————10月10日更—————————- 这次换成了测Node#10(10.0.2.2)->Node#6(192.168.0.8)之间发送UDP包时的吞吐量。 有一个问题,我看GitHub上一哥们儿写的代码跟我有点不一样。我不知道该把 那个dataset.Add()的代码放到for循环里面还是外面。于是我测了一下两种情况,看有什么区别。

    dataset.Add()代码放在for外面

    void CheckThroughput (FlowMonitorHelper* fmhelper, Ptr<FlowMonitor> monitor, Gnuplot2dDataset dataset) { double localThrou = 0.0; monitor->CheckForLostPackets (); std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats (); /* since fmhelper is a pointer, we should use it as a pointer. * `fmhelper->GetClassifier ()` instead of `fmhelper.GetClassifier ()` */ Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (fmhelper->GetClassifier ()); for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i) { /* * `Ipv4FlowClassifier` * Classifies packets by looking at their IP and TCP/UDP headers. * FiveTuple五元组是:(source-ip, destination-ip, protocol, source-port, destination-port) */ /* 每个flow是根据包的五元组(协议,源IP/端口,目的IP/端口)来区分的 */ Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first); // `10.0.3.2`是client(Node#14)的IP, `192.168.0.8`是server(Node#6)的IP // `10.0.2.2`是 Node#10 的IP // `10.0.1.2`是 Node#7 的IP if ((t.sourceAddress=="10.0.2.2" && t.destinationAddress == "192.168.0.5")) { // UDP_PROT_NUMBER = 17 std::cout << "Flow " << i->first << " Protocol " << unsigned(t.protocol) << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n"; std::cout << "Time: " << Simulator::Now ().GetSeconds () << " s\n"; std::cout << "Lost Packets = " << i->second.lostPackets << "\n"; localThrou = i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds() - i->second.timeFirstTxPacket.GetSeconds())/1024/1024 ; std::cout << " Throughput: " << localThrou << " Mbps\n"; } } dataset.Add ((Simulator::Now ()).GetSeconds (), localThrou); Simulator::Schedule (Seconds(nSamplingPeriod), &CheckThroughput, fmhelper, monitor, dataset); }

    得到的吞吐量随时间变化的图

    dataset.Add()代码放在for里面

    得到的吞吐量随时间变化的图

    后来发现这里之所以在19秒左右有一个明显的下降,也许是因为同信道干扰。因为我将traditional和SDN的代码变成一致的(给不同的WIFI网络设置不同的信道1,6,11之后,就没有了这个明显的下降,而是保持平稳)。 由于我们要做相邻AP之间的切换,故这里不能用三个不同的信道,还是改回去了。

    wifiPhy.Set("ChannelNumber", UintegerValue(1 + (i % 3) * 5)); // i =0,1,2时,信道分别为1,6,11

    设置最大包个数,和包与包之间的时间间隔,测Node#14(10.0.3.2)->Node#6(192.168.0.8)之间发送UDP包时的吞吐量。

    nMaxPackets=400; nInterval=0.02

    uint32_t nMaxPackets = 400; // The maximum packets to be sent. ns3::Time nInterval = ns3::Seconds (0.02); // The interval between two packet sent.

    nMaxPackets=400; nInterval=0.01

    nMaxPackets=4000; nInterval=0.01

    把UdpEchoClientHelper/UdpEchoServerHelper换成UdpClientHelper/UdpServerHelper之后输出结果跟上一个一样。

    转载请注明原文地址: https://ju.6miu.com/read-1200877.html
    最新回复(0)