problem with many plots

91 views
Skip to first unread message

sofi

unread,
Dec 14, 2017, 10:42:26 AM12/14/17
to ns-3-users
Dear NS3 users
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))?

Tommaso Pecorella

unread,
Dec 14, 2017, 6:09:56 PM12/14/17
to ns-3-users
Describe the problem, we're not here to guess.

Thanks,

T.

sofi

unread,
Dec 15, 2017, 1:21:56 AM12/15/17
to ns-3-users
Yes you are right. The problem is presented in output files FlowVsThroughput_.plt , TimeVsThroughput_.plt, TimeVsTime_.plt and FlowVsTime_.plt. The results in these files are unacceptable, I think datasets are mismatched. 
When I use a simple scenario (attached file) with just FlowVsThroughput_.plt, the plot must be like this (as mentioned in another discussion):




but using ns-3.26, I find this plot:

I don't understand why I have two throughput values for one time:

1 0.0887358

1 0.0806378

2 0.0842856

2 0.0762142

3 0.0828983

3 0.0748335

4 0.0822267

4 0.0741705

5 0.0818225

5 0.0737735

6 0.0815597

6 0.0735128

Please can you help me, why if I use many datasets and many plots, output files are unacceptable? and if I use a different scenario with just one output file, I find two throughput values for the same time?  

meshFlowMex.cc

Tommaso Pecorella

unread,
Dec 17, 2017, 6:28:25 AM12/17/17
to ns-3-users
Hi,

the answer is simple - you have different flows and you're adding them to the same dataset:
---------------------------------------------------------------------------
Flow ID : 1 ; 10.1.1.3 -----> 10.1.1.1
Tx Packets = 990
Rx Packets = 276
Duration : 98.4389
Last Received Packet : 98.4389 Seconds
Throughput: 0.0225034 Mbps
---------------------------------------------------------------------------
Flow ID : 2 ; 10.1.1.1 -----> 10.1.1.3
Tx Packets = 276
Rx Packets = 137
Duration : 97.4278
Last Received Packet : 98.4573 Seconds
Throughput: 0.0112861 Mbps
---------------------------------------------------------------------------

Each flow has its own throughput, and it should be added to its own dataset.

T.

sofi

unread,
Dec 17, 2017, 7:54:10 AM12/17/17
to ns-3-users
Thank you for your response. 
Many datasets don't work for me, I used a table of datasets and I tried to match each one with a gnuplot, I tried a gnuplot for all datasets. But, this induced incorrect graphs:
1) I should use one gnuplot for all datasets or one is sufficient without mismatching???
2) there is an example uses many datasets for flows and others for delays and lostpackets rate? I don't find any things based on multi-dataset in ns3 manual or tutorials?!

I tried also to put all flows in a matrix and after sorting it I extract values in dataset but values often are 0:

int k=0; double matrice[1000][3]{};
void ThroughputMonitor (FlowMonitorHelper *fmhelper, Ptr<FlowMonitor> flowMon, Gnuplot2dDataset DataSet)
{
        double localThrou=0;
        double x=0,y=0,z=0;
        std::map<FlowId, FlowMonitor::FlowStats> flowStats = flowMon->GetFlowStats();
Ptr<Ipv4FlowClassifier> classing = DynamicCast<Ipv4FlowClassifier> (fmhelper->GetClassifier());
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator stats = flowStats.begin (); stats != flowStats.end (); ++stats)
{
Ipv4FlowClassifier::FiveTuple fiveTuple = classing->FindFlow (stats->first);
std::cout<<"Flow ID : " << stats->first <<" ; "<< fiveTuple.sourceAddress <<" -----> "<<fiveTuple.destinationAddress<<std::endl;
std::cout<<"Tx Packets = " << stats->second.txPackets<<std::endl;
std::cout<<"Rx Packets = " << stats->second.rxPackets<<std::endl;
            std::cout<<"Duration : "<<(stats->second.timeLastRxPacket.GetSeconds()-stats->second.timeFirstTxPacket.GetSeconds())<<std::endl;
std::cout<<"Last Received Packet : "<< stats->second.timeLastRxPacket.GetSeconds()<<" Seconds"<<std::endl;
std::cout<<"Throughput: " << stats->second.rxBytes * 8.0 / (stats->second.timeLastRxPacket.GetSeconds()-stats->second.timeFirstTxPacket.GetSeconds())/1024/1024  << " Mbps"<<std::endl;
            localThrou=(stats->second.rxBytes * 8.0 / (stats->second.timeLastRxPacket.GetSeconds()-stats->second.timeFirstTxPacket.GetSeconds())/1024/1024);
// updata gnuplot data
                                                matrice[k][0] = stats->first;
matrice[k][1] = Simulator::Now().GetSeconds();
std::cout<<"matrice[k][1] = " << matrice[k][1]<<std::endl; //  I verify that matrice[k][1] # 0

matrice[k][2] = localThrou;
k++;
if (matrice[k][0]<= matrice[k-1][0])
{
x= matrice[k][0];
y= matrice[k][1];
z= matrice[k][2];
matrice[k][0]=matrice[k-1][0];
matrice[k][1]=matrice[k-1][1];
matrice[k][2]=matrice[k-1][2];
matrice[k-1][0]=x;
matrice[k-1][0]=y;
matrice[k-1][0]=z;
}
DataSet.Add((double)matrice[k][1],(double)matrice[k][2]);// why values in the output file are 0  0  with matrice[k][1] # 0
std::cout<<"---------------------------------------------------------------------------"<<std::endl;

            }


Simulator::Schedule(Seconds(1),&ThroughputMonitor, fmhelper, flowMon,DataSet);
   //if(flowToXml)
      flowMon->SerializeToXmlFile ("ThroughputMonitor.xml", true, true);

Tommaso Pecorella

unread,
Dec 17, 2017, 6:28:28 PM12/17/17
to ns-3-users
Hi,

answers in line.


On Sunday, December 17, 2017 at 1:54:10 PM UTC+1, sofi wrote:
Thank you for your response. 
Many datasets don't work for me, I used a table of datasets and I tried to match each one with a gnuplot, I tried a gnuplot for all datasets. But, this induced incorrect graphs:
1) I should use one gnuplot for all datasets or one is sufficient without mismatching???

No idea, I haven't tried before.
 
2) there is an example uses many datasets for flows and others for delays and lostpackets rate? I don't find any things based on multi-dataset in ns3 manual or tutorials?!

As far as I know, no. There's another thread asking a similar question:
I'll try to provide an answer there.

T.

Mouna Gassara

unread,
Dec 18, 2017, 12:32:41 AM12/18/17
to ns-3-users
Thank you for your replay.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/B3ssum54lSU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages