A Discrete-Event Network Simulator
API
wifi-simple-ht-hidden-stations.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Sébastien Deronne
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "ns3/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/boolean.h"
25 #include "ns3/double.h"
26 #include "ns3/string.h"
27 #include "ns3/log.h"
28 #include "ns3/yans-wifi-helper.h"
29 #include "ns3/ssid.h"
30 #include "ns3/mobility-helper.h"
31 #include "ns3/internet-stack-helper.h"
32 #include "ns3/ipv4-address-helper.h"
33 #include "ns3/udp-client-server-helper.h"
34 #include "ns3/yans-wifi-channel.h"
35 
36 // This example considers two hidden stations in an 802.11n network which supports MPDU aggregation.
37 // The user can specify whether RTS/CTS is used and can set the number of aggregated MPDUs.
38 //
39 // Example: ./waf --run "wifi-simple-ht-hidden-stations --enableRts=1 --nMpdus=8"
40 //
41 // Network topology:
42 //
43 // Wifi 192.168.1.0
44 //
45 // AP
46 // * * *
47 // | | |
48 // n1 n2 n3
49 //
50 //Packets in this simulation belong to BestEffort Access Class (AC_BE).
51 
52 using namespace ns3;
53 
54 NS_LOG_COMPONENT_DEFINE ("SimplesHtHiddenStations");
55 
56 int main (int argc, char *argv[])
57 {
58  uint32_t payloadSize = 1472; //bytes
59  double simulationTime = 10; //seconds
60  uint32_t nMpdus = 1;
61  uint32_t maxAmpduSize = 0;
62  bool enableRts = 0;
63  double minExpectedThroughput = 0;
64  double maxExpectedThroughput = 0;
65 
66  CommandLine cmd (__FILE__);
67  cmd.AddValue ("nMpdus", "Number of aggregated MPDUs", nMpdus);
68  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
69  cmd.AddValue ("enableRts", "Enable RTS/CTS", enableRts);
70  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
71  cmd.AddValue ("minExpectedThroughput", "if set, simulation fails if the lowest throughput is below this value", minExpectedThroughput);
72  cmd.AddValue ("maxExpectedThroughput", "if set, simulation fails if the highest throughput is above this value", maxExpectedThroughput);
73  cmd.Parse (argc, argv);
74 
75  if (!enableRts)
76  {
77  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
78  }
79  else
80  {
81  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
82  }
83 
84  //Set the maximum size for A-MPDU with regards to the payload size
85  maxAmpduSize = nMpdus * (payloadSize + 200);
86 
87  // Set the maximum wireless range to 5 meters in order to reproduce a hidden nodes scenario, i.e. the distance between hidden stations is larger than 5 meters
88  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (5));
89 
91  wifiStaNodes.Create (2);
93  wifiApNode.Create (1);
94 
96  channel.AddPropagationLoss ("ns3::RangePropagationLossModel"); //wireless range limited to 5 meters!
97 
99  phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
100  phy.SetChannel (channel.Create ());
101 
103  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
104  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
106 
107  Ssid ssid = Ssid ("simple-mpdu-aggregation");
108  mac.SetType ("ns3::StaWifiMac",
109  "Ssid", SsidValue (ssid));
110 
112  staDevices = wifi.Install (phy, mac, wifiStaNodes);
113 
114  mac.SetType ("ns3::ApWifiMac",
115  "Ssid", SsidValue (ssid),
116  "EnableBeaconJitter", BooleanValue (false));
117 
118  NetDeviceContainer apDevice;
119  apDevice = wifi.Install (phy, mac, wifiApNode);
120 
121  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
122 
123  // Setting mobility model
125  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
126 
127  // AP is between the two stations, each station being located at 5 meters from the AP.
128  // The distance between the two stations is thus equal to 10 meters.
129  // Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
130  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
131  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
132  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
133  mobility.SetPositionAllocator (positionAlloc);
134 
135  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
136 
137  mobility.Install (wifiApNode);
138  mobility.Install (wifiStaNodes);
139 
140  // Internet stack
142  stack.Install (wifiApNode);
143  stack.Install (wifiStaNodes);
144 
146  address.SetBase ("192.168.1.0", "255.255.255.0");
147  Ipv4InterfaceContainer StaInterface;
148  StaInterface = address.Assign (staDevices);
149  Ipv4InterfaceContainer ApInterface;
150  ApInterface = address.Assign (apDevice);
151 
152  // Setting applications
153  uint16_t port = 9;
154  UdpServerHelper server (port);
155  ApplicationContainer serverApp = server.Install (wifiApNode);
156  serverApp.Start (Seconds (0.0));
157  serverApp.Stop (Seconds (simulationTime + 1));
158 
159  UdpClientHelper client (ApInterface.GetAddress (0), port);
160  client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
161  client.SetAttribute ("Interval", TimeValue (Time ("0.0001"))); //packets/s
162  client.SetAttribute ("PacketSize", UintegerValue (payloadSize));
163 
164  // Saturated UDP traffic from stations to AP
165  ApplicationContainer clientApp1 = client.Install (wifiStaNodes);
166  clientApp1.Start (Seconds (1.0));
167  clientApp1.Stop (Seconds (simulationTime + 1));
168 
169  phy.EnablePcap ("SimpleHtHiddenStations_Ap", apDevice.Get (0));
170  phy.EnablePcap ("SimpleHtHiddenStations_Sta1", staDevices.Get (0));
171  phy.EnablePcap ("SimpleHtHiddenStations_Sta2", staDevices.Get (1));
172 
173  AsciiTraceHelper ascii;
174  phy.EnableAsciiAll (ascii.CreateFileStream ("SimpleHtHiddenStations.tr"));
175 
176  Simulator::Stop (Seconds (simulationTime + 1));
177 
178  Simulator::Run ();
179 
180  uint64_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
181 
183 
184  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
185  std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
186  if (throughput < minExpectedThroughput || (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
187  {
188  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
189  exit (1);
190  }
191  return 0;
192 }
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Manage ASCII trace files for device models.
Definition: trace-helper.h:162
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:36
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Hold variables of type string.
Definition: string.h:41
Make it easy to create and manage PHY objects for the YANS model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
aggregate IP/TCP/UDP functionality to existing Nodes.
staDevices
Definition: third.py:103
cmd
Definition: second.py:35
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we&#39;ll use to write the traced bits. ...
helps to create WifiNetDevice objects
Definition: wifi-helper.h:326
stack
Definition: first.py:41
uint16_t port
Definition: dsdv-manet.cc:45
channel
Definition: third.py:92
mobility
Definition: third.py:108
phy
Definition: third.py:93
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
AttributeValue implementation for Time.
Definition: nstime.h:1353
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:100
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
Create a server application which waits for input UDP packets and uses the information carried into t...
wifiApNode
Definition: third.py:90
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:227
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
address
Definition: first.py:44
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
wifi
Definition: third.py:96
Helper class used to assign positions and mobility models to nodes.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
AttributeValue implementation for Ssid.
Definition: ssid.h:105
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
void Add(Vector v)
Add a position to the list of positions.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
wifiStaNodes
Definition: third.py:88
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Include Radiotap link layer information.
Definition: wifi-helper.h:180
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.