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