error: ‘WIFI_PHY_STANDARD_80211n’ was not declared in this scope 155 | wifi.SetStandard (WIFI_PHY_STANDARD_80211n);

689 views
Skip to first unread message

Aboli Katkar

unread,
Mar 19, 2023, 6:56:23 PM3/19/23
to ns-3-users
Hello,
I am using the ns-3-allinone where I am trying to connect the UAVs to each other. However, I get an erorr error: ‘WIFI_PHY_STANDARD_80211n’ was not declared in this scope
  155 |   wifi.SetStandard (WIFI_PHY_STANDARD_80211n);

Below is my code: 
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "ns3/core-module.h"
#include "ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/traffic-control-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/wifi-mac-queue.h"
#include "ns3/netanim-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/config-store-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/lte-module.h"
#include "ns3/lte-helper.h"
#include "ns3/csma-module.h"
using namespace ns3;

// Ptr<PacketSink> sink; /* Pointer to the packet sink application */
// uint64_t lastTotalRx = 0; /* The value of the last total received bytes */


NS_LOG_COMPONENT_DEFINE ("trial1");

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

  uint32_t payloadSize = 1472; /* Transport layer payload size in bytes. */
  std::string phyMode ("DsssRate1Mbps");
  std::string dataRate = "100Mbps"; /* Application layer datarate. */
  std::string tcpVariant = "ns3::TcpNewReno"; /* TCP variant type. */

  /* Command line argument parser setup. */
  CommandLine cmd;
  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
  cmd.AddValue ("dataRate", "Application data ate", dataRate);
  cmd.AddValue (
      "tcpVariant",
      "Transport protocol to use: TcpTahoe, TcpReno, TcpNewReno, TcpWestwood, TcpWestwoodPlus ",
      tcpVariant);

  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);

  /* Configure TCP Options */
  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));
  NS_LOG_UNCOND ("trial1");

  //  std::string phyMode ("DsssRate1Mbps");

 
  NodeContainer nodes;
 nodes.Create (5); // create 5 UAV nodes
  //NodeContainer bs;
  //bs.Create (1); // create 1 base station node
 
  // Create and configure point-to-point links between the UAVs and the base station

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

  //NetDeviceContainer devices;
//for (uint32_t i = 0; i < nodes.GetN (); ++i) {
  //  devices.Add(p2p.Install (nodes.Get (i)));
  //}


 //Mobility Model -3D for uav nodes
 MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::GaussMarkovMobilityModel",
  "Bounds", BoxValue (Box (0, 100, 0, 100, 0, 100)),
  "TimeStep", TimeValue (Seconds (0.5)),
  "Alpha", DoubleValue (0.85),
  "MeanVelocity", StringValue ("ns3::UniformRandomVariable[Min=800|Max=1200]"),
  "MeanDirection", StringValue ("ns3::UniformRandomVariable[Min=0|Max=6.283185307]"),
  "MeanPitch", StringValue ("ns3::UniformRandomVariable[Min=0.05|Max=0.05]"),
  "NormalVelocity", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.0|Bound=0.0]"),
  "NormalDirection", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.2|Bound=0.4]"),
  "NormalPitch", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.02|Bound=0.04]"));
mobility.SetPositionAllocator ("ns3::RandomBoxPositionAllocator",
  "X", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  "Y", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  "Z", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"));
mobility.Install (nodes);


// Set up the mobility model for the base station
 
  //mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
 // mobility.Install (bs);
  /* // Configure mobility
  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); //AP
  // positionAlloc->Add (Vector (5.0, 0.0, 0.0)); //UE
  positionAlloc->Add (Vector (0.0, 5.0, 0.0)); //UE
  positionAlloc->Add (Vector (0.0, 0.0, 8.0)); //bs
  mobility.SetPositionAllocator (positionAlloc);
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

  // 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",
  //   "Mode", StringValue ("Time"),
  //   "Time", StringValue ("2s"),
  //   "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
  //         "Bounds", RectangleValue (Rectangle (-2000, 2000, -2000, 2000)));
  mobility.Install (sta);

  //for the mobility of access point.
  // mobility.SetMobilityModel ("ns3::GaussMarkovMobilityModel",
  //   "Bounds", BoxValue (Box (20, 20, 20, 20, 20, 20)),
  //   "TimeStep", TimeValue (Seconds (0.5)),
  //   "Alpha", DoubleValue (0.85),
  //   "MeanVelocity", StringValue ("ns3::UniformRandomVariable[Min=800|Max=1200]"),
  //   "MeanDirection", StringValue ("ns3::UniformRandomVariable[Min=0|Max=6.283185307]"),
  //   "MeanPitch", StringValue ("ns3::UniformRandomVariable[Min=0.05|Max=0.05]"),
  //   "NormalVelocity", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.0|Bound=0.0]"),
  //   "NormalDirection", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.2|Bound=0.4]"),
  //   "NormalPitch", StringValue ("ns3::NormalRandomVariable[Mean=0.0|Variance=0.02|Bound=0.04]"));
  // mobility.SetPositionAllocator ("ns3::RandomBoxPositionAllocator",
  //   "X", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  //   "Y", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"),
  //   "Z", StringValue ("ns3::UniformRandomVariable[Min=0|Max=100]"));
  mobility.Install (ap);

  mobility.Install (bs);
*/
  WifiHelper wifi;
  wifi.SetStandard (WIFI_PHY_STANDARD_80211n);

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper ();
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11
//  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);

  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  // reference loss must be changed since 802.11b is operating at 2.4GHz
   wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
   wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel",
                                   "Exponent", DoubleValue (3.0),
                                   "ReferenceLoss", DoubleValue (40.0459));
  wifiPhy.SetChannel (wifiChannel.Create ());

  // Add a non-QoS upper mac, and disable rate control
  WifiMacHelper wifiMac;
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                 "DataMode",StringValue (phyMode),
                                 "ControlMode",StringValue (phyMode));

  // Setup the rest of the upper mac
  Ssid ssid = Ssid ("wifi-default");

  // setup ap.

  // setup sta.
  wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid));
  NetDeviceContainer nodesDevice = wifi.Install (wifiPhy, wifiMac, nodes);
  //devices.Add (nodesDevice);

  // 3a. Set up MAC for base stations

  // wifiMac.SetType ("ns3::StaWifiMac",
  //                  "Ssid", SsidValue (ssid));
  //NetDeviceContainer bsDevice = wifi.Install (wifiPhy, wifiMac, bs);
  //devices.Add (bsDevice);

  // other set up (e.g. InternetStack, Application)
  // Internet stack

  InternetStackHelper stack;
  stack.Install (nodes);

  //stack.Install (bs);

  Ipv4AddressHelper address;
  address.SetBase ("10.0.0.0", "255.255.255.0");

  Ipv4InterfaceContainer nodesInterface;
  nodesInterface = address.Assign (nodesDevice);
 // Ipv4InterfaceContainer bsInterface;
 // bsInterface = address.Assign (bsDevice);

  /*/1

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (ap.Get (0));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient (apInterface.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (10));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (sta.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  UdpEchoServerHelper echoServer2 (10);
  ApplicationContainer serverApps2 = echoServer2.Install (bs.Get (0));
  serverApps2.Start (Seconds (1.0));
  serverApps2.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient2 (bsInterface.GetAddress (0), 10);
  echoClient2.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient2.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient2.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps2 = echoClient2.Install (ap.Get (0));
  clientApps2.Start (Seconds (2.0));
  clientApps2.Stop (Seconds (10.0));
*/

  // Install a simple UDP application at the base station node to send data to the UAVs
  UdpEchoServerHelper echoServer (9);
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  // Install a simple UDP application at each UAV node to receive data from the base station
  UdpEchoClientHelper echoClient (nodesInterface.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps;
  for (uint32_t i = 0; i < nodes.GetN (); ++i) {
    clientApps.Add (echoClient.Install (nodes.Get (i)));
  }
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (9.0));

  // Enable global routing
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  /* Install TCP Receiver on the bs
        PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 9));
        ApplicationContainer sinkApp = sinkHelper.Install (bs.Get(0));
        sink = StaticCast<PacketSink> (sinkApp.Get (0));

       Install TCP/UDP Transmitter on the ap
        OnOffHelper server ("ns3::TcpSocketFactory", (InetSocketAddress (bsInterface.GetAddress (0), 9)));
        server.SetAttribute ("PacketSize", UintegerValue (payloadSize));
        server.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
        server.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
        server.SetAttribute ("DataRate", DataRateValue (DataRate (dataRate)));
        ApplicationContainer serverApp;

        for(uint32_t i=0; i<ap.GetN (); ++i)
        {
            AddressValue remoteAddress(InetSocketAddress (apInterface.GetAddress (0), 9));
            server.SetAttribute ("Remote", remoteAddress);
            serverApp.Add (server.Install (ap.Get (i)));
        }

        */

  //Set the stop time
  Simulator::Stop (Seconds (10));

  //Run the simulation
  AnimationInterface anim ("UetoUavtoBS.xml");
  anim.SetMobilityPollInterval(Seconds(1.00));

  // 8. Enable tracing (optional)
  wifiPhy.EnablePcapAll ("trial1cap");

  AsciiTraceHelper ascii;
  wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("trial1.tr"));

  // Ptr<FlowMonitor> flow_monitor;
  // FlowMonitorHelper flow_monitor_helper;
  // flow_monitor = flow_monitor_helper.InstallAll ();

  Simulator::Run ();

  // flow_monitor->CheckForLostPackets ();
  // flow_monitor->SerializeToXmlFile ("project-part1.xml", true, true);

  Simulator::Destroy ();

  //throughput and delay using tracemetrics

  /*
  double averageThroughput = ((sink->GetTotalRx() * 8) / (1e6  * Simulator::Now().GetSeconds()));
   if (averageThroughput < 50)
     {
       NS_LOG_ERROR ("Obtained throughput is not in the expected boundaries!");
       exit (1);
     }
   std::cout << "\nAverage throughtput: " << averageThroughput << " Mbit/s" << std::endl;
   return 0;
*/

  Simulator::Run ();
  Simulator::Destroy ();
}

Tommaso Pecorella

unread,
Mar 19, 2023, 7:26:56 PM3/19/23
to ns-3-users
I promised to be nice. I promised to be nice. I promised to be nice...

src/wifi/model/wifi-standards.h - line 37:
enum WifiStandard
{
    WIFI_STANDARD_UNSPECIFIED,
    WIFI_STANDARD_80211a,
    WIFI_STANDARD_80211b,
    WIFI_STANDARD_80211g,
    WIFI_STANDARD_80211p,
    WIFI_STANDARD_80211n,
    WIFI_STANDARD_80211ac,
    WIFI_STANDARD_80211ad,
    WIFI_STANDARD_80211ax,
    WIFI_STANDARD_80211be
};

Do you see "WIFI_PHY_STANDARD_80211n" in this list?
I don't.

Now, let's see how old is the source you're following. Let's read CHANGES.md
Line 1254 and following:
Changes from ns-3.31 to ns-3.32
....
* The `WifiHelper::SetStandard (WifiPhyStandard standard)` method no longer takes a WifiPhyStandard enum, but instead takes a similarly named WifiStandard enum. If before you specified a value such as `WIFI_PHY_STANDARD_xxx`, now you must specify `WIFI_STANDARD_xxx`.

Hence, you're following something (a tutorial, some old YouTube video, etc.) that was made before 3.32, which was released Oct 7, 2020.
Just 2 years and 6 months ago (more or less).

Aboli Katkar

unread,
Mar 19, 2023, 11:08:45 PM3/19/23
to ns-3-users
Thank you. 
Well, this worked. I am trying to connect 5 UAVs to each other. Used Adhoc too. 

I am trying to generate date through flowmonitor but I don;t see any delay sum, jitter sum at all.

what must be wrong here? 

#include "ns3/core-module.h"
#include "ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/traffic-control-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/wifi-mac-queue.h"
#include "ns3/netanim-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/config-store-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/lte-module.h"
#include "ns3/lte-helper.h"
#include "ns3/csma-module.h"
#include "ns3/dsdv-helper.h"
#include "ns3/aodv-helper.h"
#include "ns3/aodv-routing-protocol.h"
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("march102");


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

  uint32_t payloadSize = 1472; /* Transport layer payload size in bytes. */
  std::string dataRate = "100Mbps"; /* Application layer datarate. */
  std::string tcpVariant = "ns3::TcpNewReno"; /* TCP variant type. */

  /* Command line argument parser setup. */
  CommandLine cmd;
  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
  cmd.AddValue ("dataRate", "Application data ate", dataRate);
  cmd.AddValue (
      "tcpVariant",
      "Transport protocol to use: TcpTahoe, TcpReno, TcpNewReno, TcpWestwood, TcpWestwoodPlus ",
      tcpVariant);

  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);

  /* Configure TCP Options */
  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));
  NS_LOG_UNCOND ("march102");


  std::string phyMode ("DsssRate1Mbps");

 
  NodeContainer nodes;
 nodes.Create (5); // create 5 UAV nodes
 
 //Mobility Model - 2D
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 (-100, 100, -100, 100)));
mobility.Install (nodes);

 WifiHelper wifi;
 wifi.SetStandard (WIFI_STANDARD_80211b );


  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper ();
 
   wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);

  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  // reference loss must be changed since 802.11b is operating at 2.4GHz
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel",
                                  "Exponent", DoubleValue (3.0),
                                  "ReferenceLoss", DoubleValue (40.0459));
  wifiPhy.SetChannel (wifiChannel.Create ());

  // Add a non-QoS upper mac, and disable rate control
  WifiMacHelper wifiMac;
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
                                "DataMode",StringValue (phyMode),
                                "ControlMode",StringValue (phyMode));

  // Setup the rest of the upper mac
  Ssid ssid = Ssid ("wifi-default");
   wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid));
  NetDeviceContainer nodesDevice = wifi.Install (wifiPhy, wifiMac, nodes);
 
 // InternetStackHelper stack;
 // stack.Install (nodes);
 
 
 NS_LOG_INFO ("Enabling AODV routing on all backbone nodes");
  AodvHelper aodv;
  //AODV protocol is being using FANETs.
  InternetStackHelper internet;
  internet.SetRoutingHelper (aodv); // has effect on the next Install ()
  internet.Install (nodes);


 
  Ipv4AddressHelper address;
  address.SetBase ("10.0.0.0", "255.255.255.0");

  Ipv4InterfaceContainer nodesInterface;
  nodesInterface = address.Assign (nodesDevice);
 
   // Install a simple UDP application at the base station node to send data to the UAVs
  UdpEchoServerHelper echoServer (9);
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  // Install a simple UDP application at each UAV node to receive data from the base station
  UdpEchoClientHelper echoClient (nodesInterface.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (100));

  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps;
  for (uint32_t i = 0; i < nodes.GetN (); ++i) {
    clientApps.Add (echoClient.Install (nodes.Get (i)));
  }
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (9.0));

  // Enable global routing
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
  //Set the stop time
  Simulator::Stop (Seconds (10));

  //Run the simulation
  AnimationInterface anim ("march102.xml");

  anim.SetMobilityPollInterval(Seconds(1.00));

  // 8. Enable tracing (optional)
  wifiPhy.EnablePcapAll ("trial1cap");

  AsciiTraceHelper ascii;
  wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("trial1.tr"));

  Ptr<FlowMonitor> flow_monitor;
  FlowMonitorHelper flow_monitor_helper;

  flow_monitor = flow_monitor_helper.InstallAll ();

  Simulator::Run ();

  flow_monitor->CheckForLostPackets ();

  flow_monitor->SerializeToXmlFile ("project-part1.xml", true, true);

  Simulator::Destroy ();
 
  Simulator::Run ();
  Simulator::Destroy ();
}

Tommaso Pecorella

unread,
Mar 20, 2023, 6:12:27 AM3/20/23
to ns-3-users
> Well, this worked. I am trying to connect 5 UAVs to each other. Used Adhoc too. 

No, you didn't. The code says "wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));".
About the script, debugging it and finding the right values for your scenario is your task, otherwise it won't be your project, it will be mine.
If I fix it it will work but you won't learn.

I can give you a suggestion tho: most probably your channel and propagation model are set in a way that all the packets are lost. Study the meaning of each instruction, each value, and don't copy-paste code if you didn't understand what does it do and why it was in an example or scenario.

Aboli Katkar

unread,
Mar 21, 2023, 7:16:05 PM3/21/23
to ns-3-users
I do have the corrected code now. However, I cannot see the results in flowmonitor. Not sure what's wrong in here. This is an example wifi-simple-adhoc-grid.cc from ns3.

/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2009 University of Washington

 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

//
// This program configures a grid (default 5x5) of nodes on an
// 802.11b physical layer, with
// 802.11b NICs in adhoc mode, and by default, sends one packet of 1000
// (application) bytes to node 1.
//
// The default layout is like this, on a 2-D grid.
//
// n20  n21  n22  n23  n24
// n15  n16  n17  n18  n19
// n10  n11  n12  n13  n14
// n5   n6   n7   n8   n9
// n0   n1   n2   n3   n4
//
// the layout is affected by the parameters given to GridPositionAllocator;
// by default, GridWidth is 5 and numNodes is 25..
//
// There are a number of command-line options available to control
// the default behavior.  The list of available command-line options
// can be listed with the following command:
// ./waf --run "wifi-simple-adhoc-grid --help"
//
// Note that all ns-3 attributes (not just the ones exposed in the below
// script) can be changed at command line; see the ns-3 documentation.
//
// For instance, for this configuration, the physical layer will
// stop successfully receiving packets when distance increases beyond
// the default of 500m.
// To see this effect, try running:
//
// ./waf --run "wifi-simple-adhoc-grid --distance=500"
// ./waf --run "wifi-simple-adhoc-grid --distance=1000"
// ./waf --run "wifi-simple-adhoc-grid --distance=1500"
//
// The source node and sink node can be changed like this:
//
// ./waf --run "wifi-simple-adhoc-grid --sourceNode=20 --sinkNode=10"
//
// This script can also be helpful to put the Wifi layer into verbose
// logging mode; this command will turn on all wifi logging:
//
// ./waf --run "wifi-simple-adhoc-grid --verbose=1"
//
// By default, trace file writing is off-- to enable it, try:
// ./waf --run "wifi-simple-adhoc-grid --tracing=1"
//
// When you are done tracing, you will notice many pcap trace files
// in your directory.  If you have tcpdump installed, you can try this:
//
// tcpdump -r wifi-simple-adhoc-grid-0-0.pcap -nn -tt
//

#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/uinteger.h"
#include "ns3/double.h"
#include "ns3/string.h"
#include "ns3/log.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/mobility-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/mobility-model.h"
#include "ns3/olsr-helper.h"
#include "ns3/netanim-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/flow-monitor-helper.h"
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhocGrid");

void ReceivePacket (Ptr<Socket> socket)
{
  while (socket->Recv ())
    {
      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 ("DsssRate1Mbps");
  double distance = 500;  // m
  uint32_t packetSize = 1000; // bytes
  uint32_t numPackets = 1;
  uint32_t numNodes = 25;  // by default, 5x5
  uint32_t sinkNode = 0;
  uint32_t sourceNode = 24;
  double interval = 1.0; // seconds
  bool verbose = false;
  bool tracing = true;

  CommandLine cmd;
  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
  cmd.AddValue ("distance", "distance (m)", distance);
  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.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
  cmd.AddValue ("numNodes", "number of nodes", numNodes);
  cmd.AddValue ("sinkNode", "Receiver node number", sinkNode);
  cmd.AddValue ("sourceNode", "Sender node number", sourceNode);
  cmd.Parse (argc, argv);
  // Convert to time object
  Time interPacketInterval = Seconds (interval);
 
// Fix non-unicast data rate to be the same as that of unicast
  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
                      StringValue (phyMode));
 
  NodeContainer c;
  c.Create (numNodes);

  // 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
    }

  YansWifiPhyHelper wifiPhy;
  // set it to zero; otherwise, gain will be added
  wifiPhy.Set ("RxGain", DoubleValue (-10) );
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);

  YansWifiChannelHelper wifiChannel;

  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
  wifiPhy.SetChannel (wifiChannel.Create ());

  // Add an upper mac and disable rate control
  WifiMacHelper wifiMac;
  wifi.SetStandard (WIFI_STANDARD_80211b);

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


  MobilityHelper mobility;
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                                 "MinX", DoubleValue (0.0),
                                 "MinY", DoubleValue (0.0),
                                 "DeltaX", DoubleValue (distance),
                                 "DeltaY", DoubleValue (distance),
                                 "GridWidth", UintegerValue (5),

                                 "LayoutType", StringValue ("RowFirst"));
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (c);

  // Enable OLSR
  OlsrHelper olsr;
  Ipv4StaticRoutingHelper staticRouting;

  Ipv4ListRoutingHelper list;
  list.Add (staticRouting, 0);
  list.Add (olsr, 10);

  InternetStackHelper internet;
  internet.SetRoutingHelper (list); // has effect on the next Install ()
  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 (sinkNode), tid);
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink->Bind (local);
  recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

  Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
  InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
  source->Connect (remote);

  if (tracing == true)
    {
      AsciiTraceHelper ascii;
      wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("wifiadhoc.tr"));
      wifiPhy.EnablePcap ("wifiadhoc", devices);
      // Trace routing tables
      Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("wifi-simple-adhoc-grid.routes", std::ios::out);
      olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream);
      Ptr<OutputStreamWrapper> neighborStream = Create<OutputStreamWrapper> ("wifi-simple-adhoc-grid.neighbors", std::ios::out);
      olsr.PrintNeighborCacheAllEvery (Seconds (2), neighborStream);

      // To do-- enable an IP-level trace that shows forwarding events only
    }
  // Flow Monitor
  Ptr<FlowMonitor> flowmon;
  FlowMonitorHelper flowmonHelper;
  flowmon = flowmonHelper.InstallAll ();
   
   NS_LOG_INFO ("Run Simulation.");
 
  AnimationInterface anim(std::string ("wifigrid.xml")); // For network animator (NETANIM)
  // Give OLSR time to converge-- 30 seconds perhaps
  Simulator::Schedule (Seconds (30.0), &GenerateTraffic,
                       source, packetSize, numPackets, interPacketInterval);

  // Output what we are doing
  NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance);

flowmon->SerializeToXmlFile ("wifiadhocgrid.flowmon", true, true); // FLOWMON
  Simulator::Stop (Seconds (33.0));

  Simulator::Run ();
  Simulator::Destroy ();

  return 0;
}

Tommaso Pecorella

unread,
Mar 22, 2023, 5:16:55 AM3/22/23
to ns-3-users
Look, I can be nice or I can be extremely harsh. Your call from now on.

I'll be nice one last time.
Next time I'll be extremely harsh, unless I see clearly that you did everything in your power to understand what you're doing and you didn't slam code together hoping for the best - and post your code here hoping that someone will fix it for you.

Mind: when I say "extremely harsh", I don't mean I'll insult you. No, I'll find where you work or study and I'll have a chat with your supervisor.

About your code (and stop posting it in the message, attachments aren't there just for pictures containing cats).
  1. WiFi nodes distant 500m? Fat chance that they'll receive anything.
  2. flowmon->SerializeToXmlFile before running the simulation? Fat chance that it will write anything meaningful.
Reply all
Reply to author
Forward
0 new messages