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); }