How I can calculate Throughput using Flowmonitor?

852 views
Skip to first unread message

Dina Dina

unread,
Jan 20, 2016, 8:15:17 AM1/20/16
to ns-3-users

I did it but I get an error like this

../example/tcp-outdoor.cc: In function ‘int main(int, char**)’:
../example/tcp-outdoor.cc:165:1: error: ‘lowMonitorHelper’ was not declared in this scope
 lowMonitorHelper flowmon; 
 ^
../example/tcp-outdoor.cc:165:18: error: expected ‘;’ before ‘flowmon’
 lowMonitorHelper flowmon; 
                  ^
../example/tcp-outdoor.cc:168:11: error: ‘flowmon’ was not declared in this scope
 monitor = flowmon.InstallAll();


Could anyone help me please

This my code 

// Calculate Throughput using Flowmonitor


Ptr<FlowMonitor> monitor;

lowMonitorHelper flowmon; 

monitor = flowmon.InstallAll();


// Now, do the actual simulation.


  NS_LOG_INFO ("Run Simulation.");

  Simulator::Stop (Seconds(11.0));

  Simulator::Run ();


  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 i = stats.begin (); i != stats.end (); ++i)

    {

 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);

      if ((t.sourceAddress=="10.1.1.1" && t.destinationAddress == "10.1.2.2"))

      {

          std::cout << "Flow " << i->first  << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";

          std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";

          std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";

       std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds() - i->second.timeFirstTxPacket.GetSeconds())/1024/1024  << " Mbps\n";

      }

     }


  monitor->SerializeToXmlFile("tcp-outdoor", true, true);

Simulator::Stop (Seconds (simTime));

  Simulator::Destroy ();

  NS_LOG_INFO ("Done.");

}

Konstantinos

unread,
Jan 20, 2016, 8:31:20 AM1/20/16
to ns-3-users
Hi, 

The error is clear. Just check your code again. 
It is only a typo. Instead of FlowMonitorHelper, you copied lowMonitorHelper.
Message has been deleted

Dina Dina

unread,
Jan 21, 2016, 3:30:50 AM1/21/16
to ns-3-users

Thank you so much simulation is working now, but when I change the number of users I get the same results but I want to see the effect of the number of users in terms of delays and Throughput how can I do that . Could you help me 

On Wednesday, January 20, 2016 at 5:15:17 AM UTC-8, Dina Dina wrote:


Konstantinos

unread,
Jan 21, 2016, 3:37:05 AM1/21/16
to ns-3-users
Hi Dina,

Perhaps there is no change on the throughput if the channel is not getting congested (if you do not have increase in collisions etc).

K.
Message has been deleted

Dina Dina

unread,
Jan 22, 2016, 7:15:40 AM1/22/16
to ns-3-users
Thank you so much for helping me. I was working down-link but when you told me that I should have a congestion even I get a change in throughput I tried to squint my work from the down-link to the up-link even I have congestion and can to see the change in each of throughput and delay but when I do a change in application output is become each of throughput and delay = 0. Could you help me please 

This me code 

#include "ns3/network-module.h"

#include "ns3/core-module.h"

#include "ns3/internet-module.h"

#include "ns3/point-to-point-module.h"

#include "ns3/wifi-module.h"

#include "ns3/lte-module.h"

#include "ns3/mobility-module.h"

#include "ns3/applications-module.h"

#include "ns3/netanim-module.h"

#include "ns3/constant-position-mobility-model.h"

#include "ns3/config-store-module.h"

#include "ns3/ipv4-global-routing-helper.h"

#include "ns3/flow-monitor.h"

 #include "ns3/ipv4-flow-classifier.h"

 #include "ns3/ipv4-flow-probe.h"

  #include "ns3/ipv4-l3-protocol.h"

  #include "ns3/ipv6-flow-classifier.h"

  #include "ns3/ipv6-flow-probe.h"

  #include "ns3/ipv6-l3-protocol.h"

 #include "ns3/node.h"

 #include "ns3/node-list.h"

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

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



using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("Ns-3-TCP");





std::string sock_factory = "ns3::TcpSocketFactory";



int main (int argc, char *argv[])

{

  LogComponentEnable ("Ns-3-TCP", LOG_LEVEL_ALL);



  double simTime = 30.0;

  std::string datarate = "10Mbps";

  

  CommandLine cmd;

  cmd.AddValue ("stopTime", "StopTime of simulatino.", simTime);

  cmd.Parse (argc, argv);



  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));

  NodeContainer remoteHostContainer;

  remoteHostContainer.Create (1);



 

  InternetStackHelper stack;

  stack.Install (remoteHostContainer);

  



  PointToPointHelper pointToPoint;

  NetDeviceContainer devices1, devices2;

  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();

  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();



  Ipv4AddressHelper address1, address2;

  std::ostringstream cmd_oss;

  address1.SetBase ("10.1.0.0", "255.255.255.0");

  address2.SetBase ("10.2.0.0", "255.255.255.0");

  Ipv4InterfaceContainer ueIpFace, rmIpFace;



  pointToPoint.SetDeviceAttribute ("DataRate", StringValue (datarate));

  pointToPoint.SetDeviceAttribute ("Mtu", UintegerValue (1500));

  Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue (320));

  Ptr<RateErrorModel> em1 =

    CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0,Max=1.0]"),

                                                "ErrorRate", DoubleValue (0.01),

                                                "ErrorUnit", EnumValue (RateErrorModel::ERROR_UNIT_PACKET)

                                                );



  

    

 

      // Left link: H1 <-> LTE-R

      NodeContainer enbNodes;

      enbNodes.Create (1);

      NodeContainer ueNodes;

      ueNodes.Create (30);

      stack.Install (ueNodes);





 lteHelper->SetEpcHelper (epcHelper);

      Ptr<Node> pgw = epcHelper->GetPgwNode ();

 MobilityHelper mobility;

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

   mobility.Install (enbNodes);

    

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

    mobility.Install (ueNodes);



     

      NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);

      NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);

     



      // Assign ip addresses



      ueIpFace = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));

      lteHelper->Attach (ueLteDevs, enbLteDevs.Get (0));

     

 

  Ptr<Ipv4StaticRouting> ueStaticRouting;

 Ipv4StaticRoutingHelper ipv4RoutingHelper;

    ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNodes.Get (0)->GetObject<Ipv4> ());

   

    ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);



      // LTE-R <-> H2

      // Right link

      devices2 = pointToPoint.Install (pgw, remoteHostContainer.Get (0));

      devices2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em1));

      rmIpFace = address2.Assign (devices2);

 Ptr<Node> remoteHost = remoteHostContainer.Get (0);

      

  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());

  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);



  ApplicationContainer clientApps;

  ApplicationContainer serverApps;



  PacketSinkHelper ulPacketSinkHelper (sock_factory, InetSocketAddress (Ipv4Address::GetAny (), 1000));



  serverApps.Add (ulPacketSinkHelper.Install (remoteHostContainer.Get (0)));

 


  OnOffHelper ulClient = OnOffHelper (sock_factory,InetSocketAddress (ueIpFace.GetAddress (0), 1000));

         ulClient.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));

         ulClient.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));

         ulClient.SetAttribute ("PacketSize", StringValue ("1024"));

         ulClient.SetAttribute ("DataRate", StringValue (datarate));



    clientApps.Add (ulClient.Install (ueNodes));

    serverApps.Start (Seconds (0.01));

    clientApps.Start (Seconds (4.0));



  //LTE QoS bearer    

  EpsBearer bearer (EpsBearer::NGBR_VOICE_VIDEO_GAMING);

  lteHelper->ActivateDedicatedEpsBearer (ueLteDevs, bearer, EpcTft::Default ()); 



    pointToPoint.EnablePcapAll ("tcp-outdoor", false);

  
   lteHelper->EnableTraces ();

// Calculate Throughput using Flowmonitor

Ptr<FlowMonitor> monitor;



FlowMonitorHelper flowmon; 

monitor = flowmon.InstallAll();

// Now, do the actual simulation.

//

  NS_LOG_INFO ("Run Simulation.");

  Simulator::Stop (Seconds(11.0));

  Simulator::Run ();



  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 i = stats.begin (); i != stats.end (); ++i)

    {

  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);

      if ((t.sourceAddress=="10.1.1.1" && t.destinationAddress == "10.1.2.2"))

      {

          std::cout << "Flow " << i->first  << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";

          std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";

          std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";

         std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds() - i->second.timeFirstTxPacket.GetSeconds())/1024/1024  << " Mbps\n";

      }

     }


  monitor->SerializeToXmlFile ("tcp-outdoor", true, true);

Simulator::Stop (Seconds (simTime));

  Simulator::Destroy ();

  NS_LOG_INFO ("Done.");

}

Konstantinos

unread,
Jan 22, 2016, 12:43:26 PM1/22/16
to ns-3-users
Hi Dina,

Please use attachments to share code in the list, do not post it in the both of your message.

I am sorry by I can not understand your problem. It may be an issue with the language. Try to write simple sentences, describe your system model, what is the expected output and what you get (or not get).

Switching from DL to UL traffic should not be an issue (if properly configured).
I mentioned creating some sort of congestion because if you do not put enough traffic, then all UEs will be served without any problem (all will get as much as they ask).

In your code there are some issues. Have a more structured method in writing your scenario. 
First create all the nodes, their mobility, then their NetDevices, then install the IP stack on them and finally the apps. 
In your scenario all these steps are a bit mixed and it is difficult to follow.

Regards,
K.

Dina Dina

unread,
Jan 23, 2016, 12:32:07 AM1/23/16
to ns-3-users
Hi Konstantinos

This simulation is downlink I want to change it to the uplink with a lot number of users will get congestion. But when I change it to uplink the delay is become = 0 as well as throughput.
 I want is to see a change in throughput and delay whenever I change the number of users.

my system model is a point to point

remoteHost ------ PGW -------- ENB ------ USERS

I mean that I want to do the congestion at the uplink by the many of users send to ENB to get the difference in the delay and throughput by the number of users.

Konstantinos

unread,
Jan 23, 2016, 1:08:53 PM1/23/16
to ns-3-users
Your scenario (at least the one you have uploaded) is not configured for uplink.

You have configured the OnOff application like this:
OnOffHelper ulClient = OnOffHelper (sock_factory,InetSocketAddress (ueIpFace.GetAddress (0), 1000));

This will send all traffic towards ueIpFace.GetAddress(0), i.e. all nodes send traffic to the first UE.
You need to change that to send the traffic to the remote host if you want to have UL traffic.

You can see different delays also in the downlink traffic.

Note that in your scenario the bottleneck that will introduce delay and drops is the wired p2p link between the remote host and the PGW because you have configured it only with 10MBps and your application sends at the same rate.


Regards,
K.

Dina Dina

unread,
Jan 24, 2016, 5:04:07 AM1/24/16
to ns-3-users
Hi Konstantinos

the Simulation has become work in uplink thank you so much I'm sorry to bother you. But I'm still in the same problem my results fixed whatever I change the number of users in the same rate because as you know my Scenario measures the performance of delay between remotehost and pgw. The number of users will not affect the delay this space. This area or epc will remain constant regardless of the number of users

 I mean Whatever I add the number of users the delay will not change in the same rate because in this space will not exist congestion between remotehost and pgw.

Is there a way that I can measure the delay from the number of users to the remotehost. Or Is there a way that I can measure the delay by changing the number of users at the same rate. In order to get various delay when I change the number of users in the same rate.
Reply all
Reply to author
Forward
0 new messages