No result in using flow monitor in wave-simple-80211p.cc

412 views
Skip to first unread message

ns3-user

unread,
Jun 17, 2015, 6:56:44 AM6/17/15
to ns-3-...@googlegroups.com
Hello everyone,

Iam not able to view any results in flow-monitor when I added the flow monitor piece of code in wave-simple-80211p.cc .Any leads to it would be of great help.
Below is the code.

#include "ns3/vector.h"
#include "ns3/string.h"
#include "ns3/socket.h"
#include "ns3/double.h"
#include "ns3/config.h"
#include "ns3/log.h"
#include "ns3/command-line.h"
#include "ns3/mobility-model.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/position-allocator.h"
#include "ns3/mobility-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/ipv4-interface-container.h"
#include <iostream>

#include "ns3/ocb-wifi-mac.h"
#include "ns3/wifi-80211p-helper.h"
#include "ns3/wave-mac-helper.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/flow-monitor.h"

NS_LOG_COMPONENT_DEFINE ("WifiSimpleOcb");
using namespace ns3;

/*
 * In WAVE module, there is no net device class named like "Wifi80211pNetDevice",
 * instead, we need to use Wifi80211pHelper to create an object of
 * WifiNetDevice class.
 *
 * usage:
 *  NodeContainer nodes;
 *  NetDeviceContainer devices;
 *  nodes.Create (2);
 *  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
 *  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
 *  wifiPhy.SetChannel (wifiChannel.Create ());
 *  NqosWaveMacHelper wifi80211pMac = NqosWave80211pMacHelper::Default();
 *  Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
 *  devices = wifi80211p.Install (wifiPhy, wifi80211pMac, nodes);
 *
 * The reason of not providing a 802.11p class is that most of modeling
 * 802.11p standard has been done in wifi module, so we only need a high
 * MAC class that enables OCB mode.
 */

void ReceivePacket (Ptr<Socket> socket)
{
  NS_LOG_UNCOND ("Received one packet!");
}

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 ();
    }
}

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

  CommandLine cmd;

  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
  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);


  NodeContainer c;
  c.Create (2);

  // The below set of helpers will help us to put together the wifi NICs we want
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  Ptr<YansWifiChannel> channel = wifiChannel.Create ();
  wifiPhy.SetChannel (channel);
  // ns-3 supports generate a pcap trace
  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11);

  NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
  Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
  if (verbose)
    {
      wifi80211p.EnableLogComponents ();      // Turn on all Wifi 802.11p logging
    }

  wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                      "DataMode",StringValue (phyMode),
                                      "ControlMode",StringValue (phyMode));
  NetDeviceContainer devices = wifi80211p.Install (wifiPhy, wifi80211pMac, c);

  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);

  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);

  Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
                                  Seconds (1.0), &GenerateTraffic,
                                  source, packetSize, numPackets, interPacketInterval);

  Simulator::Run ();

Ptr<FlowMonitor> flowMon;
FlowMonitorHelper flowMonHelper;
flowMon = flowMonHelper.InstallAll();
flowMon->SerializeToXmlFile("wave.flowmon", true, true);

  Simulator::Destroy ();
  return 0;
}

Konstantinos

unread,
Jun 17, 2015, 7:08:42 AM6/17/15
to ns-3-...@googlegroups.com, priyanka...@gmail.com
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);

The application traffic in this scenario is broadcast, which FlowMonitor DOES NOT classify. 
You can change the remote address to the node's specific IP instead of broadcast and you should see results with FlowMonitor.

Regards,
K

ns3-user

unread,
Jun 17, 2015, 7:21:06 AM6/17/15
to ns-3-...@googlegroups.com
Thanks a lot!!

Naveen Sheoran

unread,
Jun 17, 2015, 12:16:42 PM6/17/15
to ns-3-...@googlegroups.com, priyanka...@gmail.com
Sir,
I have one doubt about it that if we use the remote address to the node's specific IP instead of "255.255.255.0" then it will calculate the throughput of a particular node. Please clearify my this doubt.

Thanks
with regards
NAVEEN

Konstantinos

unread,
Jun 17, 2015, 12:36:01 PM6/17/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com, priyanka...@gmail.com
FlowMonitor does not classify broadcast packets, and those destined to an IP "255.255.255.255" are broadcast.
If you use the final destination's IP, then those packets will be treated as unicast, hence classified by FlowMonitor. 

Is it clear now?

K.

Naveen Sheoran

unread,
Jun 18, 2015, 2:48:17 AM6/18/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com, priyanka...@gmail.com
I got your point sir.
But my doubt is that if we will give the ipv4 address of a particular node then
will it calculate the throughput of a particular node. and if no then how ?

regards
NAVEEN

Konstantinos

unread,
Jun 18, 2015, 4:57:42 AM6/18/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com, naveenshe...@gmail.com
It will not calculate the throughput for a particular node, but for a particular flow (end-to-end path).
If you want to calculate throughput for broadcast traffic, then you should not use FlowMonitor.

There have been discussed for possible solutions in the list. 
In addition, check in the WAVE module for BsmStats class. 

K.

Michael Cheung

unread,
May 18, 2016, 12:53:30 PM5/18/16
to ns-3-users, naveenshe...@gmail.com
Thank you, so is there a particular way in ns3 to calculate the througput of a broadcast? 

Konstantinos

unread,
May 18, 2016, 1:03:01 PM5/18/16
to ns-3-users, naveenshe...@gmail.com
Hi Naveen,

Check the BsmStats class as reported in the previous reply. 
You can also use the statistical framework (see documentation) to trace received packets and hence calculate throughput.
Reply all
Reply to author
Forward
0 new messages