examples: fix dirty value issue caused by no flow presents

This commit is contained in:
Heran Yang
2024-01-04 11:00:43 +08:00
parent 7d46a38513
commit 3c52fe41f8

View File

@@ -71,15 +71,18 @@ static void
TraceThroughput(Ptr<FlowMonitor> monitor)
{
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
auto itr = stats.begin();
Time curTime = Now();
std::ofstream thr(dir + "/throughput.dat", std::ios::out | std::ios::app);
thr << curTime << " "
<< 8 * (itr->second.txBytes - prev) /
(1000 * 1000 * (curTime.GetSeconds() - prevTime.GetSeconds()))
<< std::endl;
prevTime = curTime;
prev = itr->second.txBytes;
if (!stats.empty())
{
auto itr = stats.begin();
Time curTime = Now();
std::ofstream thr(dir + "/throughput.dat", std::ios::out | std::ios::app);
thr << curTime << " "
<< 8 * (itr->second.txBytes - prev) /
(1000 * 1000 * (curTime.GetSeconds() - prevTime.GetSeconds()))
<< std::endl;
prevTime = curTime;
prev = itr->second.txBytes;
}
Simulator::Schedule(Seconds(0.2), &TraceThroughput, monitor);
}