how to plot flow monitor results with gnuplot in ns3

10,089 views
Skip to first unread message

Ahmed Alhamdany

unread,
Jun 25, 2012, 3:29:41 AM6/25/12
to ns-3-...@googlegroups.com
Hello everyone,

I just want to know if there is any possibility to plot the XML data resulted from flow monitor with Gnuplot. I know that "Element Tree" which is a python XML parsing module can read the XML file, and the "Matplotlib" module can generate the plots. But, I really need any way to plot the results using Gnuplot. For example, I want to generate a plot of throughput vs number of selfish nodes in MANET.

Thank you,

Ahmed

Ahmed Alhamdany

unread,
Jun 25, 2012, 4:04:21 AM6/25/12
to ns-3-...@googlegroups.com
If there is no possibility for that, is there any way to convert the results of flow monitor("directly in the program") into dataset to be added to the output of gnuplot.

Thank you again and waiting for your help

Ahmed

Konstantinos

unread,
Jun 25, 2012, 7:19:28 AM6/25/12
to ns-3-...@googlegroups.com
Hi Ahmed,
 
You can read the FlowMonitor data within your script, extract the useful information, manipulate it and then save it into a gnuplot dataset that can be plotted.
 
Otherwise, save the (usefull) output in a file, run more scenarios that will accumulate in the output file and then plot from that file.
 
For example see this code snippet:
 
 // Print per flow statistics
  monitor->CheckForLostPackets ();
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();

  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin (); iter != stats.end (); ++iter)
    {
  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (iter->first);
       NS_LOG_UNCOND("Flow ID: " << iter->first << " Src Addr " << t.sourceAddress << " Dst Addr " << t.destinationAddress);
      NS_LOG_UNCOND("Tx Packets = " << iter->second.txPackets);
      NS_LOG_UNCOND("Rx Packets = " << iter->second.rxPackets);
      NS_LOG_UNCOND("Throughput: " << iter->second.rxBytes * 8.0 / (iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds()) / 1024  << " Kbps");
    }

Mitch Watrous

unread,
Jun 25, 2012, 1:16:08 PM6/25/12
to ns-3-...@googlegroups.com
There are 2 common methods to make a plot using ns-3 and gnuplot:

   1. Create a gnuplot control file using ns-3‘s Gnuplot class.
   2. Create a gnuplot data file using values generated by ns-3.

If you are interested in method 1, see the “Making Plots using the Gnuplot Class” section in the ns-3 Manual:

    http://www.nsnam.org/docs/release/3.13/manual/html/gnuplot.html

If you are interested in method 2, see the “A Real Example” subsection under the “Tracing” section in the ns-3 Tutorial:

    http://www.nsnam.org/docs/release/3.13/tutorial/html/tracing.html

Mitch

Ahmed Alhamdany

unread,
Jun 27, 2012, 1:31:29 AM6/27/12
to ns-3-...@googlegroups.com
Thank  you so much Konstantinos,
Thank you so much Mitch,

I have a problem here. It seems that " monitor->GetFlowStats (); " doesn't give me any statistics. Here is my XML file :

 <FlowMonitor>
<FlowStats>
  </FlowStats>
<Ipv4FlowClassifier>
  </Ipv4FlowClassifier>

<FlowProbes>
<FlowProbe index="0">
    </FlowProbe>
<FlowProbe index="1">
    </FlowProbe>
<FlowProbe index="2">
    </FlowProbe>
<FlowProbe index="3">
    </FlowProbe>
<FlowProbe index="4">
    </FlowProbe>
<FlowProbe index="5">
    </FlowProbe>
<FlowProbe index="6">
    </FlowProbe>
<FlowProbe index="7">
    </FlowProbe>
<FlowProbe index="8">
    </FlowProbe>
<FlowProbe index="9">
    </FlowProbe>
</FlowProbes>
</FlowMonitor>

Konstantinos, I tried the following statements before the for loop that you mentioned to see what it results:

NS_LOG_UNCOND("Throughput: " <<stats.begin()->second.rxBytes * 8.0 /
                 (stats.begin()->second.timeLastRxPacket.GetSeconds()-stats.begin()->second.timeFirstTxPacket.GetSeconds())
                 / 1024/1024 << "Mbps");
NS_LOG_UNCOND("last_flow= " << stats.end()->first);

But the result is strange :

Throughput: -22790.1Mbps
last_flow= 0

The last_flow should be 9 and the throughput should be positive

Any suggestions please,

Ahmed

Ahmed Alhamdany

unread,
Jun 27, 2012, 2:56:06 AM6/27/12
to ns-3-...@googlegroups.com
I am sorry I got the problem,

The problem is not with flow monitor at all. It is with ( DSR ) routing protocol because when I use (OLSR), everything works fine. But, when I set DSR as the routing protocol, no routing is done. I don't know exactly how to make DSR works in my network.

I set the DSR as follows:

InternetStackHelper internet;
internet.Install (adhocNodes);
DsrMainHelper dsrMain;
DsrHelper dsr;
dsrMain.Install (dsr, adhocNodes);

But, there is no DSR routing table entries in the routing table of any node.

Any help, please

Ahmed






Message has been deleted

aymen dawood

unread,
Feb 20, 2014, 6:26:58 PM2/20/14
to ns-3-...@googlegroups.com
Dear Konstantinos,
can you help me, about how can  plot flow monitor results with gnuplot in ns3, if you have sample code about this plotting.
many thanks 
Aymen   

Mark Anthoni

unread,
Feb 22, 2014, 5:37:10 AM2/22/14
to ns-3-...@googlegroups.com
Hi Ahmad,

Attached an example. The default mesh.cc examples is used to plot flow monitor data ( Time Vs throughput) using gnuplot class. After finish building the code a FlowVSThroughput_.plt file will be created. Then you have to execute "gnuplot FlowVSThroughput_.plt" in the command promot to get (*.png) graph.

Cheers.
Mark
meshFlowMex.cc

Nicole Cui

unread,
Mar 5, 2014, 5:53:01 PM3/5/14
to ns-3-...@googlegroups.com, wat...@u.washington.edu
Hi Mitch,

I am a beginner in NS3, now I'd like to try plot in method 1, but doesn't work. The processing shown as follows,

cuimei@ubuntu:~/tarballs/ns-allinone-3.19/ns-3.19$ cd src/stats/examples

cuimei@ubuntu:~/tarballs/ns-allinone-3.19/ns-3.19/src/stats/examples$ ./gnuplot-example
bash: ./gnuplot-example: No such file or directory

cuimei@ubuntu:~/tarballs/ns-allinone-3.19/ns-3.19/src/stats/examples$ ls
double-probe-example.cc     gnuplot-aggregator-example.cc  wscript
file-aggregator-example.cc  gnuplot-example.cc
file-helper-example.cc      gnuplot-helper-example.cc

In fact, gnuplot-example.cc exists, why it displayed no ?

Could you give me a help? thanks

nicole

Mitch Watrous於 2012年6月25日星期一UTC-4下午1時16分08秒寫道:

Konstantinos

unread,
Mar 5, 2014, 6:34:08 PM3/5/14
to ns-3-...@googlegroups.com
Dear Nicole,

Please read the tutorial of NS-3 in order to understand how you can run an ns-3 scenario, such as gnuplot-example

The way you are trying to do this, is not correct.

Sindhuja Kasam

unread,
Jun 5, 2014, 4:39:40 AM6/5/14
to ns-3-...@googlegroups.com
hi,
 i would like to plot throughput and delay vs path length.will u plz help me in achieving the graph...
thanks in advance.

Peshal Nayak

unread,
Oct 27, 2014, 1:46:23 AM10/27/14
to ns-3-...@googlegroups.com
Hey Mark,

I was going through the code and I realized upon running it that the throughput becomes zero when the mesh is symmetric i.e. when m_xSize =m_ySize. Do you know any possible reason why this might be happening?

Regards,
Peshal

Tommaso Pecorella

unread,
Oct 27, 2014, 2:58:55 AM10/27/14
to ns-3-...@googlegroups.com
$ export x=ns-3-manual
$ ./open $x
$ ./read $x

This should do, if you can read it.

T.


On Monday, October 27, 2014 7:20:33 AM UTC+1, bala subramani wrote:


I want to plot the graph using GNU file....what command can I use?

Prudhvi Chandra Simhadri

unread,
Oct 29, 2014, 6:25:43 PM10/29/14
to ns-3-...@googlegroups.com
Hi Mark,
I executed the code given by you and realized that the packets does not reach the server from client in case of symmetric networks. i.e., when m_xSize =m_ySize. Can you please tell why this is happening?


On Saturday, February 22, 2014 4:37:10 AM UTC-6, Mark Anthoni wrote:

Abdelbasset KABOU

unread,
Jan 8, 2015, 9:46:58 AM1/8/15
to ns-3-...@googlegroups.com

Well, i think there is still a problem in capturing DSR using FlowMonitor see the folowing discussion:

https://www.nsnam.org/bugzilla/show_bug.cgi?id=1844

pedi pedro

unread,
May 21, 2015, 5:04:33 AM5/21/15
to ns-3-...@googlegroups.com
Dear all,

please let me ask question about my error that got from [mesh.cc examples] that  (Mark Anthoni) posted here. After building the codeI received this error .(the screenshot of this error I posted)
I received (assert failed) and also after when I execute the  "gnuplot FlowVSThroughput_.plt" shows that cannot open file . Also I installed  gnuplot as " sudo synaptic" in  command promot .

Could you tell me how can I do that?


Thank you,

assert failed.jpg
gnuplot problem.jpg

Tommaso Pecorella

unread,
May 21, 2015, 6:20:25 AM5/21/15
to ns-3-...@googlegroups.com
(SIGH).

We said 100.000.000 times already. Upgrade your ns-3 to the latest release before calling for help for errors. We are at 3.23 and you're using 3.21.
With 3.23 there is no exception raised (this doesn't means that there's no error at all).

T.

Abdelbasset KABOU

unread,
May 24, 2015, 3:48:16 AM5/24/15
to ns-3-...@googlegroups.com

Dear pedi pedro,

Even when using NS-3.20 the code works well and it gives me the attached plot. Review your code

FlowVSThroughput_.png

pedi pedro

unread,
May 24, 2015, 4:38:41 AM5/24/15
to ns-3-...@googlegroups.com

Dear Abdelbasset,

thanks alot for giving your comment. Actually with upgrading my version of Ns3 I could get plot.

All the best,
Pedi


2015-05-24 9:48 GMT+02:00 Abdelbasset KABOU <kabou.ab...@gmail.com>:

Dear pedi pedro,

Even when using NS-3.20 the code works well and it gives me the attached plot. Review your code

--
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/-BnPRmJwcGs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

bala subramani

unread,
Oct 27, 2014, 2:20:33 AM10/27/14
to ns-3-...@googlegroups.com

DeanB

unread,
Jun 29, 2017, 11:13:31 AM6/29/17
to ns-3-users
Hello Mark and Other Contributors,

   Mark, your meshFlowMex.cc script, and contributions from others are very appreciated. It has been a great starting point to work with mesh networks.

   In MeshTest, attempts to a second ping node to the ApplicationContatiner (line 226) should be possible with "Add" (per https://www.nsnam.org/doxygen/classns3_1_1_application_container.html#ad09ab1a1ad5849d518d5f4c262e38152) should be a one-line modification, but attempts have failed.

   Can you suggest a method of adding a second node to the ApplicationContainer?

Respectfully,
Dean Bailey

rabahifa...@gmail.com

unread,
Sep 26, 2017, 1:40:34 PM9/26/17
to ns-3-users

Hello everybody
currently i am working with ns3.26 and i want to have the throughput delay and pdr depending on number of nodes in MANET i want to have that with the gnuplot can you help me please

Majji Upendra Narasimha Sai

unread,
Aug 19, 2018, 10:08:56 PM8/19/18
to ns-3-users

Can anyone help me on this please?
Assignment 1 & 2.pdf

Amrit Kaur

unread,
May 18, 2019, 2:23:14 AM5/18/19
to ns-3-users
How we can draw this graph in NS3 as i am new NS3 user please help me in this

PC House Islamabad

unread,
Dec 11, 2019, 9:31:23 PM12/11/19
to ns-3-users
Hi 
i want to work with manet routing example from ns3. I want to plot the data from flow monitor on gnu plot. Kindly tell me will the following code be enough to do so?

//flowMonitor declaration

  FlowMonitorHelper fmHelper;

  Ptr<FlowMonitor> allMon = fmHelper.InstallAll();

  // call the flow monitor function

  ThroughputMonitor(&fmHelper, allMon, dataset); 


  Simulator::Schedule (Seconds (m_totalTime), &MeshTest::Report, this);

  Simulator::Stop (Seconds (m_totalTime));

  Simulator::Run ();


  //Gnuplot ...continued

  gnuplot.AddDataset (dataset);

  // Open the plot file.

  std::ofstream plotFile (plotFileName.c_str());

  // Write the plot file.

  gnuplot.GenerateOutput (plotFile);

  // Close the plot file.

  plotFile.close ();


  Simulator::Destroy ();

  return 0;

}




or do i need to add other code as well.Kindly guide me

Reply all
Reply to author
Forward
0 new messages