A Discrete-Event Network Simulator
API
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 "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 aren't marked with a QosTag so they are considered
51 // belonging to BestEffort Access Class (AC_BE).
52 
53 using namespace ns3;
54 
55 NS_LOG_COMPONENT_DEFINE ("SimplesHtHiddenStations");
56 
57 int main (int argc, char *argv[])
58 {
59  uint32_t payloadSize = 1472; //bytes
60  double simulationTime = 10; //seconds
61  uint32_t nMpdus = 1;
62  uint32_t maxAmpduSize = 0;
63  bool enableRts = 0;
64  double minExpectedThroughput = 0;
65  double maxExpectedThroughput = 0;
66 
68  cmd.AddValue ("nMpdus", "Number of aggregated MPDUs", nMpdus);
69  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
70  cmd.AddValue ("enableRts", "Enable RTS/CTS", enableRts);
71  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
72  cmd.AddValue ("minExpectedThroughput", "if set, simulation fails if the lowest throughput is below this value", minExpectedThroughput);
73  cmd.AddValue ("maxExpectedThroughput", "if set, simulation fails if the highest throughput is above this value", maxExpectedThroughput);
74  cmd.Parse (argc, argv);
75 
76  if (!enableRts)
77  {
78  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
79  }
80  else
81  {
82  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
83  }
84 
85  //Set the maximum size for A-MPDU with regards to the payload size
86  maxAmpduSize = nMpdus * (payloadSize + 200);
87 
88  // 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
89  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (5));
90 
92  wifiStaNodes.Create (2);
94  wifiApNode.Create (1);
95 
97  channel.AddPropagationLoss ("ns3::RangePropagationLossModel"); //wireless range limited to 5 meters!
98 
100  phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
101  phy.SetChannel (channel.Create ());
102 
104  wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
105  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
107 
108  Ssid ssid = Ssid ("simple-mpdu-aggregation");
109  mac.SetType ("ns3::StaWifiMac",
110  "Ssid", SsidValue (ssid));
111 
113  staDevices = wifi.Install (phy, mac, wifiStaNodes);
114 
115  mac.SetType ("ns3::ApWifiMac",
116  "Ssid", SsidValue (ssid),
117  "EnableBeaconJitter", BooleanValue (false));
118 
119  NetDeviceContainer apDevice;
120  apDevice = wifi.Install (phy, mac, wifiApNode);
121 
122  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
123 
124  // Setting mobility model
126  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
127 
128  // AP is between the two stations, each station being located at 5 meters from the AP.
129  // The distance between the two stations is thus equal to 10 meters.
130  // Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
131  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
132  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
133  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
134  mobility.SetPositionAllocator (positionAlloc);
135 
136  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
137 
138  mobility.Install (wifiApNode);
139  mobility.Install (wifiStaNodes);
140 
141  // Internet stack
143  stack.Install (wifiApNode);
144  stack.Install (wifiStaNodes);
145 
147  address.SetBase ("192.168.1.0", "255.255.255.0");
148  Ipv4InterfaceContainer StaInterface;
149  StaInterface = address.Assign (staDevices);
150  Ipv4InterfaceContainer ApInterface;
151  ApInterface = address.Assign (apDevice);
152 
153  // Setting applications
154  uint16_t port = 9;
155  UdpServerHelper server (port);
156  ApplicationContainer serverApp = server.Install (wifiApNode);
157  serverApp.Start (Seconds (0.0));
158  serverApp.Stop (Seconds (simulationTime + 1));
159 
160  UdpClientHelper client (ApInterface.GetAddress (0), port);
161  client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
162  client.SetAttribute ("Interval", TimeValue (Time ("0.0001"))); //packets/s
163  client.SetAttribute ("PacketSize", UintegerValue (payloadSize));
164 
165  // Saturated UDP traffic from stations to AP
166  ApplicationContainer clientApp1 = client.Install (wifiStaNodes);
167  clientApp1.Start (Seconds (1.0));
168  clientApp1.Stop (Seconds (simulationTime + 1));
169 
170  phy.EnablePcap ("SimpleHtHiddenStations_Ap", apDevice.Get (0));
171  phy.EnablePcap ("SimpleHtHiddenStations_Sta1", staDevices.Get (0));
172  phy.EnablePcap ("SimpleHtHiddenStations_Sta2", staDevices.Get (1));
173 
174  AsciiTraceHelper ascii;
175  phy.EnableAsciiAll (ascii.CreateFileStream ("SimpleHtHiddenStations.tr"));
176 
177  Simulator::Stop (Seconds (simulationTime + 1));
178 
179  Simulator::Run ();
180 
181  uint64_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
182 
184 
185  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
186  std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
187  if (throughput < minExpectedThroughput || (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
188  {
189  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
190  exit (1);
191  }
192  return 0;
193 }
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:102
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:36
HT PHY for the 5 GHz band (clause 20)
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:805
static void Run(void)
Run the simulation.
Definition: simulator.cc:170
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
aggregate IP/TCP/UDP functionality to existing Nodes.
staDevices
Definition: third.py:96
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. ...
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:299
stack
Definition: first.py:34
uint16_t port
Definition: dsdv-manet.cc:45
channel
Definition: third.py:85
mobility
Definition: third.py:101
phy
Definition: third.py:86
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:1124
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
ssid
Definition: third.py:93
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:92
Create a server application which waits for input UDP packets and uses the information carried into t...
wifiApNode
Definition: third.py:83
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:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:134
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:37
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:89
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:178
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
AttributeValue implementation for Ssid.
Definition: ssid.h:110
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
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:256
wifiStaNodes
Definition: third.py:81
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:178
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.