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 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::WIFI_STANDARD_80211n_5GHZ
@ WIFI_STANDARD_80211n_5GHZ
Definition: wifi-standards.h:132
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::ApplicationContainer::Get
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Definition: application-container.cc:62
ns3::YansWifiChannelHelper::Default
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Definition: yans-wifi-helper.cc:41
ns3::UdpClientHelper
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Definition: udp-client-server-helper.h:94
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::ListPositionAllocator::Add
void Add(Vector v)
Add a position to the list of positions.
Definition: position-allocator.cc:70
ns3::Config::Set
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
third.staDevices
staDevices
Definition: third.py:103
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:327
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
third.channel
channel
Definition: third.py:92
ns3::WifiPhyHelper::DLT_IEEE802_11_RADIO
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:180
third.mac
mac
Definition: third.py:99
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
ns3::UdpServerHelper
Create a server application which waits for input UDP packets and uses the information carried into t...
Definition: udp-client-server-helper.h:38
third.wifi
wifi
Definition: third.py:96
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::AsciiTraceHelper::CreateFileStream
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.
Definition: trace-helper.cc:191
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
first.address
address
Definition: first.py:44
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
third.wifiApNode
wifiApNode
Definition: third.py:90
second.cmd
cmd
Definition: second.py:35
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
NS_LOG_ERROR
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition: trace-helper.h:163
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
third.ssid
ssid
Definition: third.py:100
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
third.wifiStaNodes
wifiStaNodes
Definition: third.py:88
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108
third.phy
phy
Definition: third.py:93
port
uint16_t port
Definition: dsdv-manet.cc:45