Ns-3 flow monitor examples

9,972 views
Skip to first unread message

Alexandra Aden

unread,
Dec 5, 2012, 9:59:16 AM12/5/12
to ns-3-...@googlegroups.com
Do you have or know of any good examples on how to use flow monitor? 

Konstantinos

unread,
Dec 5, 2012, 10:46:00 AM12/5/12
to ns-3-...@googlegroups.com
Dear Alexandra,

Have a look at the tutorial slides I have created http://personal.ee.surrey.ac.uk/Personal/K.Katsaros/ns-3-workshop-part1.html

The example solutions at the end use FlowMonitor to calculate some statistics. Hope they are of help

Regards,
Konstantinos

Alexandra Aden

unread,
Dec 5, 2012, 11:22:40 AM12/5/12
to ns-3-...@googlegroups.com
Yes those helped me, but I think it helped me determine that my code dealing with flowmonitor wasn't my issue. 
If you would help me here: https://groups.google.com/forum/?fromgroups=#!topic/ns-3-users/37-v0SPJRBk
I would be very thankful. 

ram teja

unread,
Nov 3, 2013, 12:26:21 AM11/3/13
to ns-3-...@googlegroups.com
Hi Konstantinos,
       Can u suggest some links about flow monitor, the link you have given is not working.

Konstantinos

unread,
Nov 3, 2013, 6:09:19 AM11/3/13
to ns-3-...@googlegroups.com

Wang Tao

unread,
Apr 8, 2014, 4:53:00 AM4/8/14
to ns-3-...@googlegroups.com
Hi, K.

I am wondering that how can I calculate the throughput of one flow by using flow monitor.

Could you give me some advice?

Best,
Tao

Tommaso Pecorella

unread,
Apr 8, 2014, 4:57:09 AM4/8/14
to ns-3-...@googlegroups.com
Hi,

the answer is: by using FlowMonitor and basic math (addition, multiplication, and such).

T.


Oh... also not replying to years-old topics can help a lot.

Wang Tao

unread,
Apr 8, 2014, 5:31:36 AM4/8/14
to ns-3-...@googlegroups.com
Hi,

Equation: TxBytes*8 / (LastRxTime-FirstTxTime) ?

Best,
Tao

Tommaso Pecorella

unread,
Apr 8, 2014, 5:37:35 AM4/8/14
to ns-3-...@googlegroups.com
Nope, that would include the time to flight. Plus, it would include all the Tx bytes, even the lost ones.

RxBytes*8 / (LastRxTime-FirstRxTime)

T.

Imen

unread,
Jan 12, 2015, 5:25:58 AM1/12/15
to ns-3-...@googlegroups.com
Hi Tomas,
can you tell me if can I use flow monitor with ndn nodes ? and how?
I have ndn nodes and and want to calculate the average throughput of the network.
Can you help me please.
thnx a lot.

Konstantinos

unread,
Jan 12, 2015, 5:45:29 AM1/12/15
to ns-3-...@googlegroups.com
Hi Imen,

No, Maybe, it could be possible but not readily available. First of all, FlowMonitor is not available in the NDN release. Even if you port it, it would require significant alternations to trace packets.

However, there is a method to calculate throughput in your NDN network as explained in the documentation of NDN.

Regards,
K.

Dankof ZN

unread,
Apr 23, 2015, 4:12:24 PM4/23/15
to ns-3-...@googlegroups.com
Hi mates,

I've added Flow Monitor lines to the file I'm working with, an MPTCPTopology (attached), line 298.

But the XML is not generated and I don't know why ...

Should I add some code to " wscript " ?
mpTopology.cc

Konstantinos

unread,
Apr 23, 2015, 4:35:32 PM4/23/15
to ns-3-...@googlegroups.com
FlowMonitor works only with TCP/UDP over IP, it can not classify packets if there is a different header.
I do not know the implementation MPTCP, if the header is the same as in TCP, it should not be a problem, with minor modifications you should be able to make it work.

However, as it has been discussed several times in the list, there are other means to calculate statistics other than FlowMonitor

Tommaso Pecorella

unread,
Apr 23, 2015, 5:05:15 PM4/23/15
to ns-3-...@googlegroups.com
It should work, but as Kostantinos pointed out, it depends on how MP-TCP works.
If it's developed correctly, then FlowMonitor should work.
Without the code I can't tell anything more.

Cheers,

T.

Dankof ZN

unread,
Apr 23, 2015, 5:13:03 PM4/23/15
to ns-3-...@googlegroups.com
Hi, I've attached the code, it seems to use TCP headers ...

Did I implemented fine the lines for Flow Monitor ?

I'm working with NS-3.13.

Which alternative do you recommend me for statistical data ?

Thanks a lot for your help, I'm really lost with this tool.

Tommaso Pecorella

unread,
Apr 23, 2015, 5:25:56 PM4/23/15
to ns-3-...@googlegroups.com
Hi,

I recommend to NOT use ns-3.13. We can not provide help on releases that old.
Moreover, mp-tcp is not in the standard ns-3 distribution, attaching your script doesn't help in any way if we can not run it.
The lines to use FlowMonitor seems to be right (beside the fact that changing the attributes after using it is not really a good idea).

Alternatives to FlowMonitor ?
Sorry if I ask it, but who did we write the manual and tutorial for ? Do you think we wrote them for the aliens, in case they'll finally arrive and they want to use ns-3 ?

Have fun,

T.

Ravneet Kaur

unread,
Jan 11, 2016, 4:24:19 AM1/11/16
to ns-3-users
hii,
Can you pls guide me about the error. actually the code is running correctly but data is not collect.. have a look and suggest me the appropriate .. thanks..

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/ns2-mobility-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/flow-classifier.h"
#include "ns3/flow-probe.h"
#include "ns3/histogram.h"
#include "ns3/ipv4-flow-classifier.h"
#include "ns3/ipv4-flow-probe.h"
#include <iostream>
#include <fstream>
#include <vector>
#include "ns3/string.h"
#include "ns3/gnuplot.h"
#include "ns3/netanim-module.h"
NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");

using namespace ns3;

void ReceivePacket (Ptr<Socket> socket)
{
for(int i=1;i<15;i++)
  NS_LOG_UNCOND ("Received packet!"<<i);
}

static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
                             uint32_t pktCount, Time pktInterval )
{
  if (pktCount > 0)
    {
      socket->Send (Create<Packet> (pktSize));
      Simulator::Schedule (pktInterval, &GenerateTraffic,
                           socket, pktSize,pktCount-1, pktInterval);
    }
  else
    {
      socket->Close ();
    }
}

//Gnuplot parameters
void Create2DPlotFile(){
 std::string fileNameWithNoExtension = "FlowVSThroughput";
      std::string graphicsFileName        = fileNameWithNoExtension + ".png";
      std::string plotFileName            = fileNameWithNoExtension + ".plt";
      std::string plotTitle               = "Flow vs Throughput";
      std::string dataTitle               = "Throughput";

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

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

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

    
      Gnuplot2dDataset dataset;
      dataset.SetTitle (dataTitle);
      dataset.SetStyle (Gnuplot2dDataset::LINES_POINTS);
double x;
  double y;

  // Create the 2-D dataset.
  for (x = -5.0; x <= +5.0; x += 1.0)
    {
      // Calculate the 2-D curve
      //
      //            2
      //     y  =  x   .
      // 
      y = x * x;

      // Add this point.
      dataset.Add (x, y);
    }

  // Add the dataset to the plot.
  plot.AddDataset (dataset);

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

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

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


int main (int argc, char *argv[])
{
  std::string phyMode ("DsssRate1Mbps");
  double rss = -80;  // -dBm
  uint32_t packetSize = 1000; // bytes
  uint32_t numPackets = 20;
  double interval = 1.0; // seconds
  bool verbose = false;

  CommandLine cmd;

  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
  cmd.AddValue ("rss", "received signal strength", rss);
  cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
  cmd.AddValue ("numPackets", "number of packets generated", numPackets);
  cmd.AddValue ("interval", "interval (seconds) between packets", interval);
  cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);

  cmd.Parse (argc, argv);
  // Convert to time object
  Time interPacketInterval = Seconds (interval);

  // disable fragmentation for frames below 2200 bytes
  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
  // turn off RTS/CTS for frames below 2200 bytes
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
  // Fix non-unicast data rate to be the same as that of unicast
  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
                      StringValue (phyMode));

  NodeContainer c;
  c.Create (16);

  // The below set of helpers will help us to put together the wifi NICs we want
  WifiHelper wifi;
  if (verbose)
    {
      wifi.EnableLogComponents ();  // Turn on all Wifi logging
    }
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);

  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
  // This is one parameter that matters when using FixedRssLossModel
  // set it to zero; otherwise, gain will be added
  wifiPhy.Set ("RxGain", DoubleValue (0) );
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);

  YansWifiChannelHelper wifiChannel;
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  // The below FixedRssLossModel will cause the rss to be fixed regardless
  // of the distance between the two stations, and the transmit power
  wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
  wifiPhy.SetChannel (wifiChannel.Create ());

  // Add a non-QoS upper mac, and disable rate control
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode",StringValue (phyMode),
                                "ControlMode",StringValue (phyMode));
  // Set it to adhoc mode
  wifiMac.SetType ("ns3::AdhocWifiMac");
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);

  // Note that with FixedRssLossModel, the positions below are not
  // used for received signal strength.
 
  /*
  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
  mobility.SetPositionAllocator (positionAlloc);
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (c);
*/

  Ns2MobilityHelper ns2 = Ns2MobilityHelper ("scratch/mapmobility.tcl");
  ns2.Install ();
 
  InternetStackHelper internet;
  internet.Install (c);

  Ipv4AddressHelper ipv4;
  NS_LOG_INFO ("Assign IP Addresses.");
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign (devices);

  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
  Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink->Bind (local);
  recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

  Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
  InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
  source->SetAllowBroadcast (true);
  source->Connect (remote);

  // Tracing
  wifiPhy.EnablePcap ("scratch/aodv", devices);

  // Output what we are doing
  NS_LOG_UNCOND ("Testing " << numPackets  << " packets sent with receiver rss " << rss );
 AnimationInterface anim ("animation.xml");
  Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
                                  Seconds (1.0), &GenerateTraffic,
                                  source, packetSize, numPackets, interPacketInterval);

 Simulator::Run ();

  // Flow Monitor
  Ptr<FlowMonitor> monitor;
           FlowMonitorHelper flowmon_helper;
 
           monitor = flowmon_helper.InstallAll();
monitor.SetAttribute ("DelayBinWidth", ns3.DoubleValue(0.001));

  NS_LOG_INFO ("Run Simulation.");
   Simulator::Stop (Seconds (40));
 // Simulator::Run ();
  NS_LOG_UNCOND("Flow monitor statistics: ");

 monitor->SerializeToXmlFile ("results.xml" , true, true );


  // Print per flow statistics
    monitor->CheckForLostPackets ();
    Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon_helper.GetClassifier ());

    std::map< FlowId, FlowMonitor::FlowStats > stats = monitor->GetFlowStats ();



double Thrput=0.0;
double transmit_packets=0.0;
double recieve_packets=0.0;
  
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);
 transmit_packets=transmit_packets+iter->second.txPackets;
std::cout<<"Tx Packets = " <<transmit_packets;

        NS_LOG_UNCOND("Rx Packets = " << iter->second.rxPackets);
recieve_packets=recieve_packets+iter->second.rxPackets;
std::cout<<"\t Rx Packets = " <<recieve_packets;

        NS_LOG_UNCOND("Throughput="<<iter->second.rxBytes * 8.0 /(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/ 1024<<"Kbps");
   Thrput=iter->second.rxBytes * 8.0 /(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/ 1024;
      }

std::cout<<"Tx Packets = " <<transmit_packets;
std::cout<<"\t Rx Packets = " <<recieve_packets;
std::cout<<"\t Throughput="<<Thrput<<"Kbps";    
std::cout<<"\n";
NS_LOG_UNCOND("\nDone");


 
   Simulator::Destroy ();

  return 0;

Konstantinos

unread,
Jan 11, 2016, 4:30:38 AM1/11/16
to ns-3-users
Hi Revneet,

Please do not put your code within your message. Attach it as a file. It is easier to inspect.
The problem is that you install FlowMonitor on the nodes after the simulation has run. Hence, no results are collected.

Regards,
K.

Ravneet Kaur

unread,
Jan 11, 2016, 5:05:35 AM1/11/16
to ns-3-...@googlegroups.com
Thank you so Much.. :)

Ravneet Kaur

--
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/NuScxlCA8H0/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 https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Ravneet Kaur

unread,
Jan 12, 2016, 4:00:28 AM1/12/16
to ns-3-users
Hii,
i have one more problem that is packet sent and recieved are only 39(max) . Can you pls guide that is their any any problem in my tcl file. I have attached the output , tcl file and code file. pls guide me for the same
ip-1.cc
pmobility.tcl
output.png

Konstantinos

unread,
Jan 12, 2016, 5:01:50 AM1/12/16
to ns-3-users
There is nothing wrong with your code or the tcl file. It does exactly what it is told to do.
The problem is that you haven't read/understood your code.
Read it line by line and you should be able to spot it.

Regards,
K

PS: Do not post unrelated questions to old/existing threads. Read the guidelines for posting https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting

Ravneet Kaur

unread,
Jan 12, 2016, 5:35:33 AM1/12/16
to ns-3-...@googlegroups.com
ok thanks .. I ll see it again

Ravneet Kaur

--

Ravneet Kaur

unread,
Jan 16, 2016, 2:32:35 AM1/16/16
to ns-3-users
hii,
Konstantinos
can you pls guide me how I can transfer packets between to nodes. In the Earlier code I was doing broadcast but if I want to transmit packets between two nodes
definitely number of nodes between source and destination node would be their which ll affect its throughput, pdr etc. can you guide me for the code in this context
using Aodv.. This can be done by using UDP but is their any example or from where I would take help...Please Help
Thanks in Advance..

Ravneet Kaur

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

Konstantinos

unread,
Jan 16, 2016, 4:31:37 AM1/16/16
to ns-3-users
Hi,

Please open a new thread for new questions.
Study the documentation. There are examples for unicast connections with AODV (e.g. src/aodv/examples/aodv.cc)

Ravneet Kaur

unread,
Jan 16, 2016, 5:16:02 AM1/16/16
to ns-3-...@googlegroups.com
thank you sir g..

Ravneet Kaur


Ravneet Kaur

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 https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

--
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/NuScxlCA8H0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.

Sohail Ahmad

unread,
Nov 21, 2016, 8:56:27 AM11/21/16
to ns-3-users
Hi, 
Dear Konstantinos
I am using Flow monitor in my simulation where 25 nodes start tx to WiFi and these nodes can switch their packets to eNb node after comparing signal strength. Packets are successfully switched, tx and rx, when signal strength is compared after 10 seconds (total simulation time is 60 seconds), but when I changed comparing time with 5 seconds than flow successfully tx and rx at flow id 176 and after that node didnt received any packets. please suggest me some solution. is this the problem of flow monitor or some thing with application or packets? output is like

Flow ID: 176 Src Addr 7.0.0.26 Dst             Addr 1.0.0.2

Tx Packets = 250

Rx Packets = 184

Throughput: 90.4715 Kbps

Delay Sum = 20.9593

Mean Delay = 0.113909

Flow ID: 177 Src Addr 7.0.0.2 Dst                Addr 1.0.0.2

Tx Packets = 200

Rx Packets = 0

Throughput: -0 Kbps

Delay Sum = 0

Mean Delay = nan

Flow ID: 178 Src Addr 7.0.0.3 Dst                Addr 1.0.0.2

Tx Packets = 200

Rx Packets = 0

Throughput: -0 Kbps

Delay Sum = 0

Mean Delay = nan

Reply all
Reply to author
Forward
0 new messages