36 #include "ns3/core-module.h"
37 #include "ns3/network-module.h"
38 #include "ns3/wifi-module.h"
39 #include "ns3/stats-module.h"
40 #include "ns3/mobility-module.h"
41 #include "ns3/propagation-module.h"
64 NS_LOG_DEBUG (
"Change from " << oldVal <<
" to " << newVal);
80 StandardInfo (std::string name,
enum WifiPhyStandard standard, uint32_t width,
bool sgi,
double snrLow,
double snrHigh,
double xMin,
double xMax,
double yMax)
82 m_standard (standard),
108 actualDataset.
Add (snr, currentRate);
115 int main (
int argc,
char *argv[])
117 std::vector <StandardInfo> standards;
120 uint32_t rtsThreshold = 999999;
122 double stepTime = 0.5;
130 bool shortGuardInterval =
false;
131 uint32_t channelWidth = 20;
132 std::string standard (
"802.11b");
136 cmd.
AddValue (
"rtsThreshold",
"RTS threshold", rtsThreshold);
137 cmd.
AddValue (
"stepSize",
"Power between steps (dBm)", stepSize);
138 cmd.
AddValue (
"stepTime",
"Time on each step (seconds)", stepTime);
139 cmd.
AddValue (
"broadcast",
"Send broadcast instead of unicast", broadcast);
140 cmd.
AddValue (
"channelWidth",
"Set channel width (valid only for 802.11n or ac)", channelWidth);
141 cmd.
AddValue (
"nss",
"Set nss (valid only for 802.11n or ac)", nss);
142 cmd.
AddValue (
"shortGuard",
"Set short guard interval (802.11n/ac)", shortGuardInterval);
143 cmd.
AddValue (
"standard",
"Set standard (802.11a, 802.11b, 802.11g, 802.11n-5GHz, 802.11n-2.4GHz, 802.11ac, 802.11-holland, 802.11-10MHz, 802.11-5MHz)", standard);
144 cmd.
Parse (argc, argv);
146 if (standard ==
"802.11b")
148 NS_ABORT_MSG_IF (channelWidth != 20 && channelWidth != 22,
"Invalid channel width for standard " << standard);
151 else if (standard ==
"802.11a" || standard ==
"802.11g")
153 NS_ABORT_MSG_IF (channelWidth != 20,
"Invalid channel width for standard " << standard);
156 else if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz")
158 NS_ABORT_MSG_IF (channelWidth != 20 && channelWidth != 40,
"Invalid channel width for standard " << standard);
159 NS_ABORT_MSG_IF (nss == 0 || nss > 4,
"Invalid nss " << nss <<
" for standard " << standard);
161 else if (standard ==
"802.11ac")
163 NS_ABORT_MSG_IF (channelWidth != 20 && channelWidth != 40 && channelWidth != 80 && channelWidth != 160,
"Invalid channel width for standard " << standard);
164 NS_ABORT_MSG_IF (nss == 0 || nss > 4,
"Invalid nss " << nss <<
" for standard " << standard);
167 std::string plotName =
"ideal-wifi-manager-example-";
168 std::string dataName =
"ideal-wifi-manager-example-";
169 plotName += standard;
170 dataName += standard;
171 if (standard ==
"802.11n-5GHz" || standard ==
"802.11n-2.4GHz" || standard ==
"802.11ac")
173 std::ostringstream oss;
175 if (shortGuardInterval)
183 oss <<
"-" << channelWidth <<
"MHz-" << gi <<
"-" <<nss <<
"SS";
184 plotName += oss.str ();
185 dataName += oss.str ();
189 std::ofstream outfile (dataName.c_str ());
193 uint32_t channelRateFactor = channelWidth / 20;
194 channelRateFactor = channelRateFactor * nss;
209 for (std::vector<StandardInfo>::size_type i = 0; i != standards.size(); i++)
211 if (standard == standards[i].m_name)
213 selectedStandard = standards[i];
217 std::cout <<
"Testing " << selectedStandard.
m_name <<
"..." << std::endl;
219 steps =
static_cast<uint32_t
> (std::floor ((selectedStandard.
m_snrHigh - selectedStandard.
m_snrLow )/stepSize)) + 1;
221 Ptr<Node> clientNode = CreateObject<Node> ();
222 Ptr<Node> serverNode = CreateObject<Node> ();
225 wifi.SetStandard (selectedStandard.
m_standard);
239 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager",
"RtsCtsThreshold",
UintegerValue (rtsThreshold));
246 wifiMac.
SetType (
"ns3::AdhocWifiMac");
247 serverDevice = wifi.Install (wifiPhy, wifiMac, serverNode);
248 clientDevice = wifi.Install (wifiPhy, wifiMac, clientNode);
255 positionAlloc->
Add (Vector (ap1_x, ap1_y, 0.0));
256 NS_LOG_INFO (
"Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
257 positionAlloc->
Add (Vector (sta1_x, sta1_y, 0.0));
258 NS_LOG_INFO (
"Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
280 wifiPhyPtrClient->SetNumberOfReceiveAntennas (nss);
284 if (selectedStandard.
m_name ==
"802.11n-5GHz" ||
285 selectedStandard.
m_name ==
"802.11n-2.4GHz" ||
286 selectedStandard.
m_name ==
"802.11ac")
288 wifiPhyPtrClient->SetChannelWidth (selectedStandard.
m_width);
290 wifiPhyPtrClient->SetGuardInterval (shortGuardInterval);
293 NS_LOG_DEBUG (
"Channel width " << wifiPhyPtrClient->GetChannelWidth () <<
" noiseDbm " <<
noiseDbm);
294 NS_LOG_DEBUG (
"NSS " << wifiPhyPtrClient->GetSupportedTxSpatialStreams ());
299 rssLossModel->
SetRss (rssCurrent);
300 NS_LOG_INFO (
"Setting initial Rss to " << rssCurrent);
305 packetSocketHelper.
Install (serverNode);
306 packetSocketHelper.
Install (clientNode);
330 double rate = selectedStandard.
m_yMax * 1e6 * 1.10;
331 double clientInterval =
static_cast<double> (
packetSize) * 8 / rate;
332 NS_LOG_DEBUG (
"Setting interval to " << clientInterval <<
" sec for rate of " << rate <<
" bits/sec");
340 serverNode->AddApplication (server);
346 gnuplot.AddDataset (rateDataset);
347 gnuplot.AddDataset (actualDataset);
349 std::ostringstream xMinStr, xMaxStr, yMaxStr;
350 std::string xRangeStr (
"set xrange [");
351 xMinStr << selectedStandard.
m_xMin;
352 xRangeStr.append (xMinStr.str ());
353 xRangeStr.append (
":");
354 xMaxStr << selectedStandard.
m_xMax;
355 xRangeStr.append (xMaxStr.str ());
356 xRangeStr.append (
"]");
357 std::string yRangeStr (
"set yrange [0:");
358 yMaxStr << selectedStandard.
m_yMax;
359 yRangeStr.append (yMaxStr.str ());
360 yRangeStr.append (
"]");
362 std::ostringstream widthStrStr;
363 std::ostringstream nssStrStr;
364 std::string title (
"Wi-Fi ideal rate control: ");
365 title.append (standard);
366 title.append (
" channel width: ");
367 widthStrStr << selectedStandard.
m_width;
368 title.append (widthStrStr.str ());
369 title.append (
" MHz nss: ");
371 title.append (nssStrStr.str ());
372 if (shortGuardInterval ==
true)
374 title.append (
" shortGuard: true");
377 gnuplot.SetTerminal (
"postscript eps color enh \"Times-BoldItalic\"");
378 gnuplot.SetLegend (
"SNR (dB)",
"Rate (Mb/s)");
379 gnuplot.SetTitle (title);
380 gnuplot.SetExtra (xRangeStr);
381 gnuplot.AppendExtra (yRangeStr);
382 gnuplot.AppendExtra (
"set key top left");
383 gnuplot.GenerateOutput (outfile);
ERP-OFDM PHY (Clause 19, Section 19.5)
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
void ChangeSignalAndReportRate(Ptr< FixedRssLossModel > rssModel, struct Step step, double rss, Gnuplot2dDataset &rateDataset, Gnuplot2dDataset &actualDataset)
const double NOISE_DBM_Hz
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
HT OFDM PHY for the 5 GHz band (clause 20)
Class to represent a 2D points plot.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Make it easy to create and manage PHY objects for the yans model.
void PacketRx(Ptr< const Packet > pkt, const Address &addr)
void SetPropagationLossModel(Ptr< PropagationLossModel > loss)
an address for a packet socket
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
virtual void SetNumberOfReceiveAntennas(uint32_t rx)=0
void Set(std::string name, const AttributeValue &v)
HT OFDM PHY for the 2.4 GHz band (clause 20)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
StandardInfo(std::string name, enum WifiPhyStandard standard, uint32_t width, bool sgi, double snrLow, double snrHigh, double xMin, double xMax, double yMax)
Give ns3::PacketSocket powers to ns3::Node.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
a polymophic address class
void SetChannel(Ptr< YansWifiChannel > channel)
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
Ptr< WifiPhy > GetPhy(void) const
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
AttributeValue implementation for Time.
Hold an unsigned integer type.
virtual void SetGuardInterval(bool guardInterval)=0
holds a vector of ns3::NetDevice pointers
Hold together all Wifi-related objects.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
void Add(double x, double y)
virtual void SetNumberOfTransmitAntennas(uint32_t tx)=0
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
enum WifiPhyStandard m_standard
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPhysicalAddress(const Address address)
Set the destination address.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
create MAC layers for a ns3::WifiNetDevice.
static Time Now(void)
Return the current simulation virtual time.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Helper class used to assign positions and mobility models to nodes.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetProtocol(uint16_t protocol)
Set the protocol.
void Add(Vector v)
Add a position to the list of positions.
void Parse(int argc, char *argv[])
Parse the program arguments.
static const uint32_t packetSize
void RateChange(uint64_t oldVal, uint64_t newVal)
virtual void SetChannelWidth(uint32_t channelwidth)=0
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void SetStartTime(Time start)
Specify application start time.