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