A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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/rng-seed-manager.h"
29 #include "ns3/ssid.h"
30 #include "ns3/string.h"
31 #include "ns3/udp-client-server-helper.h"
32 #include "ns3/udp-server.h"
33 #include "ns3/uinteger.h"
34 #include "ns3/yans-wifi-channel.h"
35 #include "ns3/yans-wifi-helper.h"
36 
37 // This example considers two hidden stations in an 802.11n network which supports MPDU aggregation.
38 // The user can specify whether RTS/CTS is used and can set the number of aggregated MPDUs.
39 //
40 // Example: ./ns3 run "wifi-simple-ht-hidden-stations --enableRts=1 --nMpdus=8"
41 //
42 // Network topology:
43 //
44 // Wifi 192.168.1.0
45 //
46 // AP
47 // * * *
48 // | | |
49 // n1 n2 n3
50 //
51 // Packets in this simulation belong to BestEffort Access Class (AC_BE).
52 
53 using namespace ns3;
54 
55 NS_LOG_COMPONENT_DEFINE("SimplesHtHiddenStations");
56 
57 int
58 main(int argc, char* argv[])
59 {
60  uint32_t payloadSize = 1472; // bytes
61  double simulationTime = 10; // seconds
62  uint32_t nMpdus = 1;
63  uint32_t maxAmpduSize = 0;
64  bool enableRts = false;
65  double minExpectedThroughput = 0;
66  double maxExpectedThroughput = 0;
67 
70 
71  CommandLine cmd(__FILE__);
72  cmd.AddValue("nMpdus", "Number of aggregated MPDUs", nMpdus);
73  cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize);
74  cmd.AddValue("enableRts", "Enable RTS/CTS", enableRts);
75  cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime);
76  cmd.AddValue("minExpectedThroughput",
77  "if set, simulation fails if the lowest throughput is below this value",
78  minExpectedThroughput);
79  cmd.AddValue("maxExpectedThroughput",
80  "if set, simulation fails if the highest throughput is above this value",
81  maxExpectedThroughput);
82  cmd.Parse(argc, argv);
83 
84  if (!enableRts)
85  {
86  Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("999999"));
87  }
88  else
89  {
90  Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("0"));
91  }
92 
93  // Set the maximum size for A-MPDU with regards to the payload size
94  maxAmpduSize = nMpdus * (payloadSize + 200);
95 
96  // Set the maximum wireless range to 5 meters in order to reproduce a hidden nodes scenario,
97  // i.e. the distance between hidden stations is larger than 5 meters
98  Config::SetDefault("ns3::RangePropagationLossModel::MaxRange", DoubleValue(5));
99 
101  wifiStaNodes.Create(2);
103  wifiApNode.Create(1);
104 
106  channel.AddPropagationLoss(
107  "ns3::RangePropagationLossModel"); // wireless range limited to 5 meters!
108 
110  phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
111  phy.SetChannel(channel.Create());
112  phy.Set("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
113 
115  wifi.SetStandard(WIFI_STANDARD_80211n);
116  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
117  "DataMode",
118  StringValue("HtMcs7"),
119  "ControlMode",
120  StringValue("HtMcs0"));
122 
123  Ssid ssid = Ssid("simple-mpdu-aggregation");
124  mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
125 
127  staDevices = wifi.Install(phy, mac, wifiStaNodes);
128 
129  mac.SetType("ns3::ApWifiMac",
130  "Ssid",
131  SsidValue(ssid),
132  "EnableBeaconJitter",
133  BooleanValue(false));
134 
135  NetDeviceContainer apDevice;
136  apDevice = wifi.Install(phy, mac, wifiApNode);
137 
138  Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
139  UintegerValue(maxAmpduSize));
140 
141  // Setting mobility model
143  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
144 
145  // AP is between the two stations, each station being located at 5 meters from the AP.
146  // The distance between the two stations is thus equal to 10 meters.
147  // Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
148  positionAlloc->Add(Vector(5.0, 0.0, 0.0));
149  positionAlloc->Add(Vector(0.0, 0.0, 0.0));
150  positionAlloc->Add(Vector(10.0, 0.0, 0.0));
151  mobility.SetPositionAllocator(positionAlloc);
152 
153  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
154 
155  mobility.Install(wifiApNode);
156  mobility.Install(wifiStaNodes);
157 
158  // Internet stack
160  stack.Install(wifiApNode);
161  stack.Install(wifiStaNodes);
162 
164  address.SetBase("192.168.1.0", "255.255.255.0");
165  Ipv4InterfaceContainer StaInterface;
166  StaInterface = address.Assign(staDevices);
167  Ipv4InterfaceContainer ApInterface;
168  ApInterface = address.Assign(apDevice);
169 
170  // Setting applications
171  uint16_t port = 9;
173  ApplicationContainer serverApp = server.Install(wifiApNode);
174  serverApp.Start(Seconds(0.0));
175  serverApp.Stop(Seconds(simulationTime + 1));
176 
177  UdpClientHelper client(ApInterface.GetAddress(0), port);
178  client.SetAttribute("MaxPackets", UintegerValue(4294967295U));
179  client.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
180  client.SetAttribute("PacketSize", UintegerValue(payloadSize));
181 
182  // Saturated UDP traffic from stations to AP
183  ApplicationContainer clientApp1 = client.Install(wifiStaNodes);
184  clientApp1.Start(Seconds(1.0));
185  clientApp1.Stop(Seconds(simulationTime + 1));
186 
187  phy.EnablePcap("SimpleHtHiddenStations_Ap", apDevice.Get(0));
188  phy.EnablePcap("SimpleHtHiddenStations_Sta1", staDevices.Get(0));
189  phy.EnablePcap("SimpleHtHiddenStations_Sta2", staDevices.Get(1));
190 
191  AsciiTraceHelper ascii;
192  phy.EnableAsciiAll(ascii.CreateFileStream("SimpleHtHiddenStations.tr"));
193 
194  Simulator::Stop(Seconds(simulationTime + 1));
195 
196  Simulator::Run();
197 
198  uint64_t totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get(0))->GetReceived();
199 
201 
202  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
203  std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
204  if (throughput < minExpectedThroughput ||
205  (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
206  {
207  NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
208  exit(1);
209  }
210  return 0;
211 }
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:174
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.
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:77
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
Hold variables of type string.
Definition: string.h:56
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:324
create MAC layers for a ns3::WifiNetDevice.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:178
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:44
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:890
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:876
#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:1326
@ WIFI_STANDARD_80211n
address
Definition: first.py:47
stack
Definition: first.py:44
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:40
staDevices
Definition: third.py:100
ssid
Definition: third.py:93
channel
Definition: third.py:88
mac
Definition: third.py:92
wifi
Definition: third.py:95
wifiApNode
Definition: third.py:86
mobility
Definition: third.py:105
wifiStaNodes
Definition: third.py:84
phy
Definition: third.py:89
std::ofstream throughput