flowmonitor

625 views
Skip to first unread message

GAURAV JAIN

unread,
Jun 3, 2013, 12:36:00 AM6/3/13
to ns-3-...@googlegroups.com
"  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);

      if ((t.sourceAddress == Ipv4Address("10.1.1.1") && t.destinationAddress == Ipv4Address("10.1.1.25"))
        || (t.sourceAddress == Ipv4Address("10.1.1.11") && t.destinationAddress == Ipv4Address("10.1.1.15"))
        || (t.sourceAddress == Ipv4Address("10.1.1.21") && t.destinationAddress == Ipv4Address("10.1.1.5")))
        {
          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");
        }
    }"

i read this part of the code from the following reference:

http://personal.ee.surrey.ac.uk/Personal/K.Katsaros/ns-3-workshop-part1.html#step5-1

But I am not able to understand it and need explanation on how
the programmer arrived on this code.

Konstantinos

unread,
Jun 3, 2013, 10:45:14 AM6/3/13
to ns-3-...@googlegroups.com
Hi,

You should look the API that defines these methods. http://www.nsnam.org/doxygen/classns3_1_1_flow_monitor.html


On Monday, 3 June 2013 05:36:00 UTC+1, GAURAV JAIN wrote:
"  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();



std::map< FlowId, FlowMonitor::FlowStats > ns3::FlowMonitor::GetFlowStats
(
) const

Retrieve all collected the flow statistics. Note, if the FlowMonitor has not stopped monitoring yet, you should call CheckForLostPackets() to make sure all possibly lost packets are accounted for.

Then You go through each element of the std::map and get the results.
 
  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin (); iter != stats.end (); ++iter)
    {
      Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (iter->first);


For each element of the map you get the FiveTuple which is used to identify a specific Flow: http://www.nsnam.org/doxygen/structns3_1_1_ipv4_flow_classifier_1_1_five_tuple.html

Then you don't want to see ALL the results that are logged be FlowMonitor, you filter them based on the specific flows you want. For example in this code you filter them based on the Source/Destination addresses.
There are 5 'variables' that you can play around and create your particular filters. If you do not use this 'if' statement, you will just get ALL the flows.

      if ((t.sourceAddress == Ipv4Address("10.1.1.1") && t.destinationAddress == Ipv4Address("10.1.1.25"))
        || (t.sourceAddress == Ipv4Address("10.1.1.11") && t.destinationAddress == Ipv4Address("10.1.1.15"))
        || (t.sourceAddress == Ipv4Address("10.1.1.21") && t.destinationAddress == Ipv4Address("10.1.1.5")))
        {

Here just print the statistics of a particular flow.
 
          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");
        }
    }"

i read this part of the code from the following reference:

http://personal.ee.surrey.ac.uk/Personal/K.Katsaros/ns-3-workshop-part1.html#step5-1

But I am not able to understand it and need explanation on how
the programmer arrived on this code.


For more information related to FlowMonitor and its uses you can read the paper and the presentation here
http://paginas.fe.up.pt/~mricardo/doc/conferences/nstools2009/flowmon-paper.pdf
http://telecom.inescporto.pt/~gjc/flowmon-presentation.pdf

GAURAV JAIN

unread,
Jun 3, 2013, 1:04:43 PM6/3/13
to ns-3-...@googlegroups.com
Hi Konstantinos

std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter

does this line mean iter is a object of class const_iterator which inturn is subclass of map?

Konstantinos

unread,
Jun 3, 2013, 1:45:42 PM6/3/13
to ns-3-...@googlegroups.com
iter is not an object/instance, because const_iterator is not a class, it is a member type of the std::map class.

GAURAV JAIN

unread,
Jun 3, 2013, 1:49:59 PM6/3/13
to ns-3-...@googlegroups.com
so what does it do?? if its a member, then what is the line doing if its not creating any object..


--
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/TXk7CU8fzGQ/unsubscribe?hl=en.
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Konstantinos

unread,
Jun 3, 2013, 2:11:09 PM6/3/13
to ns-3-...@googlegroups.com
It creates a variable of a type const_iterator. 
Like "int tmp;" creates a variable of type int. 'int' is not a class it is a data type. 

GAURAV JAIN

unread,
Jun 4, 2013, 1:00:49 AM6/4/13
to ns-3-...@googlegroups.com
Ptr<FlowMonitor> flowMon;
if (enableFlowMonitor)
{
FlowMonitorHelper flowMonHelper;
flowMon = flowMonHelper.InstallAll();
}

  Simulator::Stop (Seconds (100.0));
  Simulator::Run ();

if (enableFlowMonitor)
{
flowMon->SerializeToXmlFile("mygrid.flowmonitor", true, true);
}


the above is the code i am using for flow monitor. However it makes and xml file reading which seems
quite difficult. I want to compare the throughput for two different routing protocol. How can it be done and displayed with little modifications in the code

Konstantinos

unread,
Jun 4, 2013, 6:22:34 AM6/4/13
to ns-3-...@googlegroups.com
There are two ways you can do this.

Either you can keep your xml output as you have it and use a parser to read it and get statistics -- see the example in flow-monitor module

Or you can scrap the xml generation, and get your statistics within the script (base on the code you have posted in your first question).

You can save the output of both ways in a file and then do your comparisons.
See this discussion for more information https://groups.google.com/d/msg/ns-3-users/teE-cTfkV_Q/mN-futk4ZNUJ

GAURAV JAIN

unread,
Jun 4, 2013, 12:48:29 PM6/4/13
to ns-3-...@googlegroups.com
the second option which you have given, i have tried that.
I was following this discussion, tried the solution but the program does not
seem to even enter the for loop.
Is it that I need to create random number of packets? In my program,
I have taken number of packets as 10.


GAURAV JAIN

unread,
Jun 5, 2013, 1:18:21 AM6/5/13
to ns-3-...@googlegroups.com

the second option which you have given, i have tried that.
I was following this discussion, tried the solution but the program does not
seem to even enter the for loop.
Is it that I need to create random number of packets? In my program,
I have taken number of packets as 10.


To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.

Konstantinos

unread,
Jun 5, 2013, 5:14:20 AM6/5/13
to ns-3-...@googlegroups.com
Have you tested the first option to see what it gives you as an output?

If your flowmonitor XML file has flows inside and the "in-script" code does not give any output, then either you have put that script in the wrong place or you still have the "filter" selection and your flows do not match that filter.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages