How do you calculate throughput for a node in a point to point network?

9,363 views
Skip to first unread message

Syd

unread,
Aug 25, 2011, 3:20:17 PM8/25/11
to ns-3-users
Hi Everyone,
Can anyone tell me why my throughput measurements are
always 0 and perhaps how I can obtain the right throughput values?
Below is a simplified version of my network:


p2p link
Node1 ------------------------- Node2


I have installed the onOff application source on Node 1 and sink on
Node2. After installing the sink on Node2, I use the following script
(obtained and modified from a previous thread) to obtain the
throughput.

Config::Connect ("/NodeList/1/DeviceList/*/Phy/State/RxOk",
MakeCallback
(&PhyRxOkTrace, this));
Throughput ();


void Throughput () // in Mbps calculated every 2s
{
double mbps = (((m_bytesTotal * 8.0) / 1000000)/2);
double time_tp = Simulator::Now ().GetSeconds ();
cout << "time: " << time_tp <<"\t"<< "Throughput: " << mbps <<endl;
m_bytesTotal = 0;
Simulator::Schedule (Seconds (0.1), &Throughput);
}


void PhyRxOkTrace (Ptr<Packet> packet)
{
m_bytesTotal += packet->GetSize ();
}

Cheers!
Syd

Ali Sydney

unread,
Aug 31, 2011, 3:45:34 PM8/31/11
to ns-3-...@googlegroups.com
Hi Jorge/Lalith,
                      Jorge, your second option of measuring the throughput at the application level worked just fine. However, I have decided to use flowmonitor since it easily provides a number of network performance metrics (throughput, delay, PLR etc.)  Thanks for all your support, both you and Lalith.

Cheers!
-Syd

On Fri, Aug 26, 2011 at 2:45 AM, Lalith Suresh <suresh...@gmail.com> wrote:


Unless you're trying to measure something too specific, I think it's best to use the flow monitor for computing end to end throughput.
 
Cheers!
Syd

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Lalith Suresh
Department of Computer Science and Engineering
Instituto Superior Técnico
www.lalith.in

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Mark Sammut

unread,
Oct 15, 2012, 5:21:08 AM10/15/12
to ns-3-...@googlegroups.com
Hye guys,
 
Noticed your post and I too am trying to figure out a way to get throughput at a PacketSink application.
 
I have a problem with using FlowMonitor.

In my code, I set FlowMonitor this way:

" Ptr<FlowMonitor> monitor;
  FlowMonitorHelper flowhelp;
  flowhelp.SetMonitorAttribute("DelayBinWidth",DoubleValue(0.001));
  flowhelp.SetMonitorAttribute("JitterBinWidth",DoubleValue(0.001));
  flowhelp.SetMonitorAttribute("PacketSizeBinWidth",DoubleValue(20));
  monitor = flowhelp.Install(nodeL);
"

Then, I tried to output it to an XML file by: monitor->SerializeToXmlFile("testresults.xml",true,true);

Program compiles, but on running it, the following error is output:
Command ['/home/mark/ns-3-dev/build/scratch/UDP_flow_codel-exp_p2p'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").

Using gdb to check the backtrace stack, I got the following:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff756fb9e in ns3::Time::Time (this=0x7fffffffbf50, o=...)
    at ./ns3/nstime.h:175
175        : m_data (o.m_data)
(gdb) back
#0  0x00007ffff756fb9e in ns3::Time::Time (this=0x7fffffffbf50, o=...)
    at ./ns3/nstime.h:175
#1  0x00007ffff478644a in ns3::FlowMonitor::CheckForLostPackets (this=0x0)
    at ../src/flow-monitor/model/flow-monitor.cc:305
#2  0x00007ffff4786832 in ns3::FlowMonitor::SerializeToXmlStream (this=0x0,
    os=..., indent=0, enableHistograms=true, enableProbes=true)
    at ../src/flow-monitor/model/flow-monitor.cc:389
#3  0x00007ffff4787578 in ns3::FlowMonitor::SerializeToXmlFile (this=0x0,
    fileName=..., enableHistograms=true, enableProbes=true)
    at ../src/flow-monitor/model/flow-monitor.cc:481

#4  0x0000000000412d5a in main (argc=1, argv=0x7fffffffe128)
    at ../scratch/UDP_flow_codel-exp_p2p.cc:304


Any idea what might be causing the problem, or can you suggest another way how I can access the result without using XML? There seems to be a method to GetFlowStats but I can't quite figure out how to get them and output them.

Thanks a lot for any help and best regards,
Mark

Syd

unread,
Nov 4, 2012, 10:30:13 PM11/4/12
to ns-3-...@googlegroups.com
Below are a few snippets that should help:

NB. I have created a class called "NS3ElectricalModel" and I have also created a function called "Throughput" within this class to calculate the throughput.


#include "ns3/flow-monitor-helper.h"
#include "ns3/flow-monitor-module.h"


// This goes in your main simulation program
ofstream   netStatsOut; // Create an output file stream (optional)
 netStatsOut.open("netStatsMPLS.txt"); //Write Network measurements to output file
Ptr<FlowMonitor>    monitor;
monitor = flowmon_helper.InstallAll();
monitor->SetAttribute("DelayBinWidth", DoubleValue(0.001));
monitor->SetAttribute("JitterBinWidth", DoubleValue(0.001));
monitor->SetAttribute("PacketSizeBinWidth", DoubleValue(20));
NS3ElectricalModel::Throughput();


void
NS3ElectricalModel::Throughput () // in Mbps calculated every 0.5s
{
     Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier>(flowmon_helper.GetClassifier());

     string proto;
     map< FlowId, FlowMonitor::FlowStats > stats = monitor->GetFlowStats();
     netStatsOut << "  Time: " << Simulator::Now ().GetSeconds () << endl;
     for (map< FlowId, FlowMonitor::FlowStats>::iterator
flow=stats.begin(); flow!=stats.end(); flow++)
         {
          Ipv4FlowClassifier::FiveTuple  t = classifier->FindFlow(flow->first);
             switch(t.protocol)
             {
             case(6):
                 proto = "TCP";
                 break;
             case(17):
                 proto = "UDP";
                 break;
             default:
                 exit(1);
             }
             netStatsOut << "FlowID: " << flow->first << " (" << proto << " "
             << t.sourceAddress << " / " << t.sourcePort << " --> "
             << t.destinationAddress << " / " << t.destinationPort << ")" << endl;

                 //  printStats(flow->second);

     netStatsOut << "  Tx Bytes: " << flow->second.txBytes << endl;
     netStatsOut << "  Rx Bytes: " << flow->second.rxBytes << endl;
     netStatsOut << "  Tx Packets: " << flow->second.txPackets << endl;
     netStatsOut << "  Rx Packets: " << flow->second.rxPackets << endl;
     netStatsOut << "  Lost Packets: " << flow->second.lostPackets << endl;
     netStatsOut << "  Pkt Lost Ratio: " << ((double)flow->second.txPackets-(double)flow->second.rxPackets)/(double)flow->second.txPackets << endl;
     

     netStatsOut << "  Throughput: " << (( ((double)flow->second.rxBytes*8)/(1000000) ) / .5) << endl;

     netStatsOut << "  Mean{Delay}: " << (flow->second.delaySum.GetSeconds()/flow->second.rxPackets) << endl;
     netStatsOut << "  Mean{Jitter}: " << (flow->second.jitterSum.GetSeconds()/(flow->second.rxPackets)) << endl;

         }
Simulator::Schedule (Seconds (.5), &NS3ElectricalModel::Throughput, this); // Callback every 0.5s

}

Hope this helps..

Cheers!
Syd


To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/sFoYwdAg-XwJ.

Larissa Marinho Eglem de Oliveira

unread,
Nov 7, 2012, 5:06:30 PM11/7/12
to ns-3-...@googlegroups.com
Hi!

I'd like to know if it is possible to set FlowMonitor in two different interfaces that are installed in the same node container.

Thank you!



2012/11/5 Syd <asydn...@gmail.com>

Syd

unread,
Nov 7, 2012, 6:04:54 PM11/7/12
to ns-3-...@googlegroups.com
Are you referring to a setup like below? 

eth0--srcHost--eth1--------------eth0--dstHost--eth1 

Above we have two nodes (srcHost and dstHost) and they each have 2 interfaces. srcHost is connected to dstHost on interface 1 (eth1) and dstHost is connected to srcHost on interface 1 (eth0). 

If this is the case, it doesn't matter if your nodes are in different containers, you can simply use the snippet in the previous reply to achieve this. Observe that in the snippet, every single flow (and its corresponding statistics) is saved in a file "netStatsMPLS.txt." In your case, since you know the IP addresses of srcHost and dstHost, you can write a python/C++ script to parse the document and only search for flows between these two IP addresses.  There may be some other elegant ways of doing this though..

Cheers!
Syd 

Larissa Marinho Eglem de Oliveira

unread,
Nov 7, 2012, 6:16:47 PM11/7/12
to ns-3-...@googlegroups.com
Hi,

Thank you for your reply.  My setup is actually this:

A node has two interfaces, so it has two wifi devices on it and two different IPs.

For example, each node has two networks: 10.1.1.0 and 192.1.1.0. Also every node sends packets from both networks

So, when I use FlowMonitor I get this kind of output:

Flow 1 (10.1.1.2 -> 10.1.1.1)
  Tx Bytes:   3211472
  Rx Bytes:   2543272
  Throughput: 1.94036 Mbps
Flow 2 (10.1.1.3 -> 10.1.1.1)
  Tx Bytes:   3198108
  Rx Bytes:   1028
  Throughput: 0.000784302 Mbps
Flow 3 (10.1.1.1 -> 10.1.1.2)
  Tx Bytes:   3185772
  Rx Bytes:   2679996
  Throughput: 2.04467 Mbps

When what I actually wanted was:

Flow 1 (10.1.1.2 -> 10.1.1.1)
  Tx Bytes:   3211472
  Rx Bytes:   2543272
  Throughput: 1.94036 Mbps
Flow 2 (10.1.1.3 -> 10.1.1.1)
  Tx Bytes:   3198108
  Rx Bytes:   1028
  Throughput: 0.000784302 Mbps
Flow 3 (10.1.1.1 -> 10.1.1.2)
  Tx Bytes:   3185772
  Rx Bytes:   2679996
  Throughput: 2.04467 Mbps
Flow 4 (192.1.1.2 -> 192.1.1.1)
  Tx Bytes:   3211472
  Rx Bytes:   2543272
  Throughput: 1.94036 Mbps
Flow 5 (192.1.1.3 -> 192.1.1.1)
  Tx Bytes:   3198108
  Rx Bytes:   1028
  Throughput: 0.000784302 Mbps
Flow 6 (192.1.1.1 -> 19.1.1.2)
  Tx Bytes:   3185772
  Rx Bytes:   2679996
  Throughput: 2.04467 Mbps




2012/11/7 Syd <asydn...@gmail.com>

Syd

unread,
Nov 7, 2012, 6:42:56 PM11/7/12
to ns-3-...@googlegroups.com
I don't quite understand the problem as yet. From your description, it appears that flowMonitor is only providing stats from 1 network (10.1.1.0) where as you would like flows from both networks (10.1.1.0 and 192.1.1.0), right?

Larissa Eglem

unread,
Nov 7, 2012, 6:49:06 PM11/7/12
to ns-3-...@googlegroups.com, asydn...@gmail.com
Right!

Papagei

unread,
Jan 15, 2013, 8:20:58 AM1/15/13
to ns-3-...@googlegroups.com
Dear Syd,

I am quite new to ns-3. Could you please explain or give some hints how to add this class to the main program.
If I have to add new class to the ns-3 with the following the part.
and write the left ....
 
// This goes in your main simulation program
ofstream   netStatsOut; // Create an output file stream (optional)
 netStatsOut.open("netStatsMPLS.txt"); //Write Network measurements to output file
Ptr<FlowMonitor>    monitor;
monitor = flowmon_helper.InstallAll();
monitor->SetAttribute("DelayBinWidth", DoubleValue(0.001));
monitor->SetAttribute("JitterBinWidth", DoubleValue(0.001));
monitor->SetAttribute("PacketSizeBinWidth", DoubleValue(20));
NS3ElectricalModel::Throughput();


to my main program.?

I have tried to write the void throughput function in the beginning of my main program but it doesn't work. The compiler does not know flowmon_helper. 
How can I pass this parameter? 
Sorry for stupid question but I am not good at programming.

Thanks

Sara Lakani

unread,
Feb 12, 2013, 11:08:29 PM2/12/13
to ns-3-...@googlegroups.com
Hi
have you added this declaration

#include "ns3/flow-monitor-module.h"

at the beginning of your program?

salma subh

unread,
Jun 22, 2013, 8:00:23 PM6/22/13
to ns-3-...@googlegroups.com
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/gtk-config-store.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/flow-monitor-helper.h"




// Default Network Topology
//
//   Wifi 10.1.3.0
//                 AP
//  *    *    *    *
//  |    |    |    |    10.1.1.0
// n5   n6   n7   n0 -------------- n1   n2   n3   n4
//                   point-to-point  |    |    |    |
//                                   ================
//                                     LAN 10.1.2.0

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("MyThirdScriptExample");
/////////////////////////////////////////////////
////////////////////////////////////////////////
int
main (int argc, char *argv[])
{
  bool verbose = true;
  uint32_t nCsma = 3;
  uint32_t nWifi = 3;

  CommandLine cmd;
  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
  cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);

  cmd.Parse (argc,argv);

  if (nWifi > 18)
    {
      std::cout << "Number of wifi nodes " << nWifi <<
                   " specified exceeds the mobility bounding box" << std::endl;
      exit (1);
    }

 if (verbose)
    {
     LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
     LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
    }

  NodeContainer p2pNodes;
  p2pNodes.Create (2);

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

  NetDeviceContainer p2pDevices;
  p2pDevices = pointToPoint.Install (p2pNodes);

  NodeContainer csmaNodes;
  csmaNodes.Add (p2pNodes.Get (1));
  csmaNodes.Create (nCsma);

  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));

  NetDeviceContainer csmaDevices;
  csmaDevices = csma.Install (csmaNodes);

  NodeContainer wifiStaNodes;
  wifiStaNodes.Create (nWifi);
  NodeContainer wifiApNode = p2pNodes.Get (0);

  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
  phy.SetChannel (channel.Create ());

  WifiHelper wifi = WifiHelper::Default ();
  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

  NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();

  Ssid ssid = Ssid ("ns-3-ssid");
  mac.SetType ("ns3::StaWifiMac",
               "Ssid", SsidValue (ssid),
               "ActiveProbing", BooleanValue (false));

  NetDeviceContainer staDevices;
  staDevices = wifi.Install (phy, mac, wifiStaNodes);

  mac.SetType ("ns3::ApWifiMac",
               "Ssid", SsidValue (ssid));

  NetDeviceContainer apDevices;
  apDevices = wifi.Install (phy, mac, wifiApNode);

  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (5.0),
                                 "DeltaY", DoubleValue (10.0),
                                 "GridWidth", UintegerValue (3),
                                 "LayoutType", StringValue ("RowFirst"));

  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
                             "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
  mobility.Install (wifiStaNodes);

  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (wifiApNode);

  InternetStackHelper stack;
  stack.Install (csmaNodes);
  stack.Install (wifiApNode);
  stack.Install (wifiStaNodes);

  Ipv4AddressHelper address;

  address.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer p2pInterfaces;
  p2pInterfaces = address.Assign (p2pDevices);

  address.SetBase ("10.1.2.0", "255.255.255.0");
  Ipv4InterfaceContainer csmaInterfaces;
  csmaInterfaces = address.Assign (csmaDevices);

  address.SetBase ("10.1.3.0", "255.255.255.0");
  address.Assign (staDevices);
  address.Assign (apDevices);

  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address("10.1.2.4"), 9));
  onoff.SetAttribute ("OnTime",  StringValue("ns3::ConstantRandomVariable[Constant=0.5]"));
  onoff.SetAttribute ("OffTime",  StringValue("ns3::ConstantRandomVariable[Constant=0]"));
  onoff.SetAttribute ("PacketSize", StringValue ("512"));
  onoff.SetAttribute ("DataRate", StringValue ("512kbps"));
 
  ApplicationContainer apps = onoff.Install (wifiStaNodes.Get (nWifi));
  apps.Start (Seconds (1.0));
  apps.Stop (Seconds (60.0));

  PacketSinkHelper sink ("ns3::UdpSocketFactory",InetSocketAddress ("10.1.2.4", 9));
  apps = sink.Install (csmaNodes.Get(nCsma));

  apps.Start (Seconds (1.0));
  apps.Stop (Seconds (60.0));


 
// This goes in your main simulation program

 //ofstream   netStatsOut; // Create an output file stream (optional)
 //netStatsOut.open("netStatsMPLS.txt"); //Write Network measurements to output file


FlowMonirtorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();

monitor->SetAttribute("DelayBinWidth", DoubleValue(0.001));
monitor->SetAttribute("JitterBinWidth", DoubleValue(0.001));
monitor->SetAttribute("PacketSizeBinWidth", DoubleValue(20));
NS3ElectricalModel::Throughput();

////////////////////////////////////////////////////////////////
  Simulator::Stop (Seconds (70.0));
  Simulator::Run ();




 
  Simulator::Destroy ();
 
  return 0;
}

do you plz check my code when i used uor class

Yan Boven

unread,
Dec 21, 2013, 5:16:11 PM12/21/13
to ns-3-...@googlegroups.com
Hi... I wonder how did NS3ElectricalModel class get the global view including monitor and how did you run the ThroughPut function in a static way?

Jorge Sousa

unread,
Aug 25, 2011, 3:34:28 PM8/25/11
to ns-3-...@googlegroups.com
Hi,

I would try 

Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", 
MakeCallback (&PhyRxOkTrace)); 

or if you will to go directly to the application level, try this:

void
ReceivedPacket (std::string context, Ptr<const Packet> p, const
Address& addr)
{
 m_bytesTotal += p->GetSize ();
}

// Measure PacketSinks
std::string sink = "/NodeList/1/ApplicationList/*/$ns3::PacketSink/Rx";

Config::Connect (sinks, MakeCallback(&ReceivedPacket));

Regards,

JS

2011/8/25 Syd <asydn...@gmail.com>

Lalith Suresh

unread,
Aug 26, 2011, 3:45:16 AM8/26/11
to ns-3-...@googlegroups.com
On Thu, Aug 25, 2011 at 9:20 PM, Syd <asydn...@gmail.com> wrote:
Unless you're trying to measure something too specific, I think it's best to use the flow monitor for computing end to end throughput.
 
Cheers!

Syd

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Reply all
Reply to author
Forward
0 new messages