I want to generate throughput and delay in function of flow id and time using gnuplot but there is often a problem:
Simulator::Stop (Seconds (m_totalTime));
// Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
m_timeStart=clock();
//Gnuplot parameters
std::string fileNameWithNoExtension = "FlowVSThroughput_";
std::string graphicsFileName = fileNameWithNoExtension + ".png";
std::string plotFileName = fileNameWithNoExtension + ".plt";
std::string plotTitle = "Flow vs Throughput";
std::string dataTitle = "Throughput";
std::string fileNameWithNoExtension1 = "FlowVSdelay_";
std::string graphicsFileName1 = fileNameWithNoExtension1 + ".png";
std::string plotFileName1 = fileNameWithNoExtension1 + ".plt";
std::string plotTitle1 = "Flow vs delay";
std::string dataTitle1 = "delay";
std::string fileNameWithNoExtension2 = "TimeVSThroughput_";
std::string graphicsFileName2 = fileNameWithNoExtension2 + ".png";
std::string plotFileName2 = fileNameWithNoExtension2 + ".plt";
std::string plotTitle2 = "Time vs Throughput";
std::string dataTitle2 = "Throughput";
std::string fileNameWithNoExtension3 = "TimeVSdelay_";
std::string graphicsFileName3 = fileNameWithNoExtension3 + ".png";
std::string plotFileName3 = fileNameWithNoExtension3 + ".plt";
std::string plotTitle3 = "Time vs delay";
std::string dataTitle3 = "delay";
// Instantiate the plot and set its title.
Gnuplot gnuplot (graphicsFileName);
gnuplot.SetTitle (plotTitle);
Gnuplot gnuplot1 (graphicsFileName1);
gnuplot1.SetTitle (plotTitle1);
Gnuplot gnuplot2 (graphicsFileName2);
gnuplot2.SetTitle (plotTitle2);
Gnuplot gnuplot3 (graphicsFileName3);
gnuplot3.SetTitle (plotTitle3);
// Make the graphics file, which the plot file will be when it
// is used with Gnuplot, be a PNG file.
gnuplot.SetTerminal ("png");
gnuplot1.SetTerminal ("png");
gnuplot2.SetTerminal ("png");
gnuplot3.SetTerminal ("png");
// Set the labels for each axis.
gnuplot.SetLegend ("Flow", "Throughput");
gnuplot1.SetLegend ("Flow", "delay");
gnuplot2.SetLegend ("Time (s)", "Throughput (Mbps)");
gnuplot3.SetLegend ("Time (s)", "delay (s)");
Gnuplot2dDataset dataset;
dataset.SetTitle (dataTitle);
dataset.SetStyle (Gnuplot2dDataset::LINES_POINTS);
// call the flow monitor function
ThroughputMonitor1(&flowmon, monitor, dataset);
gnuplot.AddDataset (dataset);
std::ofstream plotFile (plotFileName.c_str());
gnuplot.GenerateOutput (plotFile);
plotFile.close ();
Gnuplot2dDataset dataset1;
dataset1.SetTitle (dataTitle1);
dataset1.SetStyle (Gnuplot2dDataset::LINES_POINTS);
delaymon1(&flowmon, monitor, dataset1);
gnuplot1.AddDataset (dataset1);
std::ofstream plotFile1 (plotFileName1.c_str());
gnuplot1.GenerateOutput (plotFile1);
plotFile.close ();
Gnuplot2dDataset dataset2;
dataset2.SetTitle (dataTitle2);
dataset2.SetStyle (Gnuplot2dDataset::LINES_POINTS);
ThroughputMonitor(&flowmon, monitor, dataset2);
gnuplot2.AddDataset (dataset2);
std::ofstream plotFile2 (plotFileName2.c_str());
gnuplot2.GenerateOutput (plotFile2);
plotFile.close ();
Gnuplot2dDataset dataset3;
dataset3.SetTitle (dataTitle3);
dataset3.SetStyle (Gnuplot2dDataset::POINTS);
delaymon(&flowmon, monitor, dataset3);
gnuplot3.AddDataset (dataset3);
std::ofstream plotFile3 (plotFileName3.c_str());
gnuplot3.GenerateOutput (plotFile);
plotFile.close ();
Simulator::Run ();
.
.
.
.
void MeshTest::delaymon (FlowMonitorHelper *fmhelper, Ptr<FlowMonitor> flowMon,Gnuplot2dDataset DataSet)
{
double localThrou=0;
std::map<FlowId, FlowMonitor::FlowStats> flowStats = flowMon->GetFlowStats();
Ptr<Ipv4FlowClassifier> classing = DynamicCast<Ipv4FlowClassifier> (fmhelper->GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats>::const_iterator stats = flowStats.begin (); stats != flowStats.end (); //++stats
std::cout<<"First Received Packet : "<< stats->second.timeFirstTxPacket.GetMicroSeconds()<<" Microseconds"<<std::endl;
std::cout<<"Last Received Packet : "<< stats->second.timeLastRxPacket.GetMicroSeconds()<<" Microseconds"<<std::endl;
std::cout<<"delay : "<< stats->second.delaySum.GetMicroSeconds()<<" Microseconds"<<std::endl;
localThrou=stats->second.delaySum.GetMicroSeconds();
DataSet.Add((double)Simulator::Now().GetMicroSeconds(),(double) localThrou);
Simulator::Schedule(Seconds(2.5),&MeshTest::delaymon, this , fmhelper, flowMon,DataSet);
//if(flowToXml)
{
flowMon->SerializeToXmlFile ("delaymon.xml", true, true);
}
}
Please help me, how can I do this correctly?where can I put Simulator::Run () and Simulator::Stop (Seconds (m_totalTime))?