From 3c52fe41f81ec94671774dc96b0823adf32bd685 Mon Sep 17 00:00:00 2001 From: Heran Yang Date: Thu, 4 Jan 2024 11:00:43 +0800 Subject: [PATCH] examples: fix dirty value issue caused by no flow presents --- examples/tcp/tcp-bbr-example.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/tcp/tcp-bbr-example.cc b/examples/tcp/tcp-bbr-example.cc index 6c027a5e4..571db943c 100644 --- a/examples/tcp/tcp-bbr-example.cc +++ b/examples/tcp/tcp-bbr-example.cc @@ -71,15 +71,18 @@ static void TraceThroughput(Ptr 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); }