Gnuplot in NS-3

2,063 views
Skip to first unread message

Pavel Mašek

unread,
Mar 28, 2013, 3:59:20 AM3/28/13
to ns-3-...@googlegroups.com
Hello,

I try to create  *.png file from my simulation with using Gnuplot, but after finish simulation only *.plt file is created. 

Here is a part of code: 


//GnuPlot

  string fileNameWithNoExtension = "FlowVSThroughput";
        string graphicsFileName        = fileNameWithNoExtension + ".png";
        string plotFileName            = fileNameWithNoExtension + ".plt";
        string plotTitle               = "Flow vs Throughput";
        string dataTitle               = "Throughput";

        // Instantiate the plot and set its title.
        Gnuplot gnuplot (graphicsFileName);
        gnuplot.SetTitle (plotTitle);

        // Make the graphics file, which the plot file will be when it
        // is used with Gnuplot, be a PNG file.
        gnuplot.SetTerminal ("png");

        // Set the labels for each axis.
        gnuplot.SetLegend ("Flow", "Throughput");


        Gnuplot2dDataset dataset;
        dataset.SetTitle (dataTitle);
        dataset.SetStyle (Gnuplot2dDataset::LINES_POINTS);

  //Flow Monitor ... continued

  if (enableFlowMonitor)
     {
  double Throughput=0.0;

  monitor->CheckForLostPackets ();
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowMonHelper.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("Delay Sum = " << iter->second.delaySum);
      NS_LOG_UNCOND("Delay = " << iter->second.delaySum / iter->second.rxPackets << "ns");
      NS_LOG_UNCOND("Delay = " << (iter->second.delaySum / iter->second.rxPackets)/1000000 << "ms");
      NS_LOG_UNCOND("Jitter Sum = " << iter->second.jitterSum);
      NS_LOG_UNCOND("Jitter = " << iter->second.jitterSum / (iter->second.rxPackets - 1) << "ns");
      //NS_LOG_UNCOND("Jitter = " << (iter->second.jitterSum / (iter->second.rxPackets - 1))/1000000 << "ms");
      NS_LOG_UNCOND("Throughput: " << iter->second.rxBytes * 8.0 / (iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds()) / 1024  << " Kbps");
      Throughput=iter->second.rxBytes * 8.0 /
                (iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())
                / 1024;

      dataset.Add((double)iter->first,(double) Throughput);
      NS_LOG_UNCOND("Lost Packets = " << iter->second.lostPackets);
      NS_LOG_UNCOND("-------------------------------------------------");
      NS_LOG_UNCOND("-------------------------------------------------");

    }

     monitor->SerializeToXmlFile ("manetrouting.flowmon", true, true);

   }

  //Gnuplot ...continued

      gnuplot.AddDataset (dataset);

               // Open the plot file.
               ofstream plotFile (plotFileName.c_str());

               // Write the plot file.
               gnuplot.GenerateOutput (plotFile);

               // Close the plot file.
               plotFile.close ();

Simulator::Destroy ();

Karsten

unread,
Mar 28, 2013, 5:38:27 AM3/28/13
to ns-3-...@googlegroups.com
Hi,

the generated *.plt file should be used as an input for gnuplot. So just
execute "gnuplot yourfile.plt" after you ran your simulation and you'll
have your png.

The ns-3 gnuplot classes create only the gnuplot input, they do not
invoke gnuplot directly.

Kind regards,
Karsten
> --
> You received this message because you are subscribed to the Google
> Groups "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
PGP Public Key: http://www.karstenroscher.de/sfx.asc
Fingerprint: 2584 325A 69A5 5B29 A245 65A6 D04D 55A4 A3B7 3237

Pavel Mašek

unread,
Mar 29, 2013, 4:55:11 AM3/29/13
to ns-3-...@googlegroups.com
Hi,

thank you for your advice, it works.

Now I am trying to create graph with Delay. I know, that the variable Delay must be double, but i don´t know, how convert time to double.

Here is part of my code:

double Delay;
NS_LOG_UNCOND("Delay Sum = " << iter->second.delaySum);
Delay = iter->second.delaySum;
dataset.Add((double)iter->first,(double) Delay);

After compilation I receive error: error: cannot convert ‘const ns3::Time’ to ‘double’ in assignment

Dne čtvrtek, 28. března 2013 10:38:27 UTC+1 Karsten napsal(a):

Karsten

unread,
Mar 29, 2013, 1:55:44 PM3/29/13
to ns-3-...@googlegroups.com
Hi,

use the member method GetSeconds () on the Time object, to get the
seconds as a double. In your case it would be:

Dely = iter->second.delaySum.GetSeconds ();

Kind regards,
Karsten
> > an email to ns-3-users+...@googlegroups.com <javascript:>.
> > To post to this group, send email to ns-3-...@googlegroups.com
> <javascript:>.
> <http://groups.google.com/group/ns-3-users?hl=en>.
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.

Pavel Mašek

unread,
Mar 29, 2013, 2:35:13 PM3/29/13
to ns-3-...@googlegroups.com
Hi,

thank you for your help!

Dne pátek, 29. března 2013 18:55:44 UTC+1 Karsten napsal(a):

Pham Quoc Viet

unread,
Feb 17, 2014, 1:36:36 AM2/17/14
to ns-3-...@googlegroups.com
Dear all,

I have used this code to generate .png file, but I have nothing in .plt output file.

Please help me in this situation.

Thanks in advance.
lena-x2-handover-measures.cc

Pham Quoc Viet

unread,
Feb 17, 2014, 2:08:17 AM2/17/14
to ns-3-...@googlegroups.com
The problem has been solved.

It is due to that I place the invoking function before function Simulator::Run().

Stefania Zinno

unread,
Mar 23, 2014, 4:36:58 PM3/23/14
to ns-3-...@googlegroups.com
So where did you put it? can you paste the new code here? 

Pham Quoc Viet

unread,
Mar 23, 2014, 10:07:56 PM3/23/14
to ns-3-...@googlegroups.com
Hello Stefania Zinno,

Please find it in attached file.
myX2-MultiUes6-TrialHandover.cc

Stefania Zinno

unread,
Mar 24, 2014, 11:00:59 AM3/24/14
to ns-3-...@googlegroups.com

if (fiveTuple.destinationAddress == Ipv4Address("7.0.0.0"))

  {


this means you are printing out the statistics of the node 7.0.0.0?

Message has been deleted

Pham Quoc Viet

unread,
Mar 25, 2014, 12:36:48 AM3/25/14
to ns-3-...@googlegroups.com
Hi Stefania Zinno,

Yes, you are right.
You can change its address depending on your simulation script.

Stefania Zinno

unread,
Mar 25, 2014, 6:07:53 AM3/25/14
to ns-3-...@googlegroups.com
It only creates a times throughput and time vs packet loss right? Anything for the delay?

Agnes Ling

unread,
Apr 2, 2014, 6:22:31 AM4/2/14
to ns-3-...@googlegroups.com
Hi Everyone,

I would like to ask....

Do you have any idea about how to apply the gnuplot in IPv6?

 i need some guide for this...

Thanks,

Regards,
Agnes
<div style="font: 13px/normal Arial, Helvetica, sans-serif; margin: 0px; padding: 0px; border: 0px currentColor; color: rgb(34, 34, 34); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; vertical...

Konstantinos

unread,
Apr 2, 2014, 6:28:04 AM4/2/14
to ns-3-...@googlegroups.com
Hi,

Gnuplot has nothing to do with IP (either v4 or v6). It is a tool to plot data.
So, you need to get the proper data. Are you able to get the data you need for IPv6? 

Agnes Ling

unread,
Apr 2, 2014, 7:10:23 AM4/2/14
to ns-3-...@googlegroups.com
Hi Konstantinos,


Thanks for replying.

 I get what you meant...

i did face some problem in my programme.

my programme only can simulate for not more than 2seconds, which mean it stopped sending packets. Perhaps, i have set the simulation time for 100seconds.

I tried to find and fix the bugs. but i still can't find where is the errors. it just looks fine.


can you please guide me here?


here i have attached my file.  please have a look it.


Thanks in advanced.


regards,
Agnes
node2.cc

Konstantinos

unread,
Apr 2, 2014, 7:26:33 AM4/2/14
to ns-3-...@googlegroups.com
Please post on a new thread specifying what you want to achieve, what release of NS-3 you are using and what is the error you get.

Agnes Ling

unread,
Apr 2, 2014, 7:32:54 AM4/2/14
to ns-3-...@googlegroups.com
Hi,


thanks.

i will post a new thread..... :)


regards,
Agnes

Pushpendra Mishra

unread,
Sep 4, 2014, 12:00:34 AM9/4/14
to ns-3-...@googlegroups.com

Dear Pham Quoc Viet,
                                   pls tell me the commands to plot 3D graph for this output using GNUPLOT. I had attached the output file with the name hand2.dat
hand2.dat

Tommaso Pecorella

unread,
Sep 4, 2014, 1:18:46 AM9/4/14
to ns-3-...@googlegroups.com
Hi,

you asked the same question (more or less) in another thread.
It has been told you already that the best thing to do is to read the GNUPLOT manual.
Now you ask the very same thing (with almost the same file attached) in a different thread.

Question: do you think that this will not make people upset ?
How shall we react to this ? Do you understand that our reaction could be... unfriendly ?

Now, I opened your data file, and I have some more questions.

Do you have any vague idea about what's GNUPLOT ?
Or... did you open your "hand2.dat" file to look inside it ? I think the answer is yes, since you modified it.

But you did not do what Kostas told you to do: read the Gnuplot manual and the ns-3 data collection manual section.

As a consequence, what is your request ? "Please reformat my file for me or give me a system to do it since [insert here a motivation]" ?
It is this one your true goal ?

And I'll stop here, as going further on would lead me where I don't wanna be: on the hate section.

If you have specific question, feel free to ask. Do not ever post again the same question twice, especially when you had a proper answer the first time.

T.

Pushpendra Mishra

unread,
Sep 4, 2014, 9:52:40 AM9/4/14
to ns-3-...@googlegroups.com

Dear Tommaso Pecorella,
                                          I am extremely sorry for your inconvenience. The matter is this project is handled by team of two persons with same id and that is mine.
Because of this reason it had been posted twice UNFORTUNATELY. Anyway it is completely our fault so again I regretting this from the bottom of my heart. From
now onwards We will take care that these activities will not happen again. Yes you are right and this can upset any one also your response is straight and tight one
but not unfriendly.
                          Anyway because of   "
Kostas" our problem is solved and thank's to your team very cordially.

I will take care that these activities will not happen again in future.                                      

Tommaso Pecorella

unread,
Sep 4, 2014, 10:17:08 AM9/4/14
to ns-3-...@googlegroups.com
Hi (dunno your name, and you're two as you said).

Apologies completely accepted. I'd suggest to use two different accounts to avoid confusion tho.
I'm also happy you found the solution to your problem.

Of course, feel free to ask if you have questions.

Best regards,

T.

PS: "Kostas" is Kostantinos. It's more or less like referring to someone named William as Bill.
PPS: yes, Bill is now also a "normal" name, but it is the short version of William.

Pushpendra Mishra

unread,
Sep 4, 2014, 10:34:40 AM9/4/14
to ns-3-...@googlegroups.com
thanx a lot.

Sushil Sawdekar

unread,
Jan 20, 2015, 12:54:39 AM1/20/15
to ns-3-...@googlegroups.com
hi ....
I am trying to open a .plt file in gnuplot by using the following command in the folder where that .plt file is saved
gnuplot *.plt
but it shows me the warning as
 warning: Warning - difficulty fitting plot titles into key
So please suggest something to solve this problem and it generates the required png file..
i am using gnuplot 5.0.0.

Tommaso Pecorella

unread,
Jan 20, 2015, 3:08:25 AM1/20/15
to ns-3-...@googlegroups.com
Hi,

that's a Gnuplot error, and without the .plt file it's quite hard to say what's going bad.
A simple internet search shows that the error may be caused by insufficient privileges (i.e., Gnuplot can't open the terminal), too many lines in a plot and so on.
In any case I'd suggest to check the Gnuplot script (the .plt file) and consult the Gnuplot forums / mailing lists.

Hope this helps,

T.

Sushil Sawdekar

unread,
Jan 20, 2015, 4:09:53 AM1/20/15
to ns-3-...@googlegroups.com
tahnk you sir ... i am sending you that .plt file ... plz chech it out and tell me whats wrong in that ..

--
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/fhlXOPK6x44/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.
AodvCompareRoutingpacket-byte-count.plt

Tommaso Pecorella

unread,
Jan 20, 2015, 5:24:58 AM1/20/15
to ns-3-...@googlegroups.com
Good, and how do you think we can check what's going on without the data file ?
Think !

Sushil Sawdekar

unread,
Jan 20, 2015, 6:40:11 AM1/20/15
to ns-3-users@googlegroups com

:) ok...
Thank you...

Anto pravin

unread,
Apr 23, 2018, 7:48:21 AM4/23/18
to ns-3-users
HI,
   I done successfully for plotting a single file in gnuplot.
   At this time, I get 1 graph for flow vs throughput.
  My requirement is i need to compare throughput with 2 graphs (existing and proposed).
  I two two .cc files and i get two graphs separately.
  I need to merge those two graphs in single file to show the performance of the proposed work.
  Your help is appreciated.

ritwik jain

unread,
Apr 23, 2018, 9:34:26 AM4/23/18
to ns-3-...@googlegroups.com
how you have calculated the value and plot the graph can you help
me.and by using gnu plot i thunk you can compare them.
what is the file generated through which you got the value.
> --
> 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 the Google Groups
> "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, 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 https://groups.google.com/group/ns-3-users.
Reply all
Reply to author
Forward
0 new messages