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/core-module.h"
22 #include "ns3/applications-module.h"
23 #include "ns3/wifi-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/internet-module.h"
26 
27 // This example considers two hidden stations in an 802.11n network which supports MPDU aggregation.
28 // The user can specify whether RTS/CTS is used and can set the number of aggregated MPDUs.
29 //
30 // Example: ./waf --run "simple-ht-hidden-stations --enableRts=1 --nMpdus=8"
31 //
32 // Network topology:
33 //
34 // Wifi 192.168.1.0
35 //
36 // AP
37 // * * *
38 // | | |
39 // n1 n2 n3
40 //
41 // Packets in this simulation aren't marked with a QosTag so they are considered
42 // belonging to BestEffort Access Class (AC_BE).
43 
44 using namespace ns3;
45 
46 NS_LOG_COMPONENT_DEFINE ("SimplesHtHiddenStations");
47 
48 int main (int argc, char *argv[])
49 {
50  uint32_t payloadSize = 1472; //bytes
51  uint64_t simulationTime = 10; //seconds
52  uint32_t nMpdus = 1;
53  uint32_t maxAmpduSize = 0;
54  bool enableRts = 0;
55  double minExpectedThroughput = 0;
56  double maxExpectedThroughput = 0;
57 
59  cmd.AddValue ("nMpdus", "Number of aggregated MPDUs", nMpdus);
60  cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
61  cmd.AddValue ("enableRts", "Enable RTS/CTS", enableRts);
62  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
63  cmd.AddValue ("minExpectedThroughput", "if set, simulation fails if the lowest throughput is below this value", minExpectedThroughput);
64  cmd.AddValue ("maxExpectedThroughput", "if set, simulation fails if the highest throughput is above this value", maxExpectedThroughput);
65  cmd.Parse (argc, argv);
66 
67  if (!enableRts)
68  {
69  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
70  }
71  else
72  {
73  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
74  }
75 
76  //Set the maximum size for A-MPDU with regards to the payload size
77  maxAmpduSize = nMpdus * (payloadSize + 200);
78 
79  // 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
80  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (5));
81 
83  wifiStaNodes.Create (2);
85  wifiApNode.Create (1);
86 
88  channel.AddPropagationLoss ("ns3::RangePropagationLossModel"); //wireless range limited to 5 meters!
89 
92  phy.SetChannel (channel.Create ());
93 
96  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
98 
99  Ssid ssid = Ssid ("simple-mpdu-aggregation");
100  mac.SetType ("ns3::StaWifiMac",
101  "Ssid", SsidValue (ssid),
102  "BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
103 
105  staDevices = wifi.Install (phy, mac, wifiStaNodes);
106 
107  mac.SetType ("ns3::ApWifiMac",
108  "Ssid", SsidValue (ssid),
109  "EnableBeaconJitter", BooleanValue (false),
110  "BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
111 
112  NetDeviceContainer apDevice;
113  apDevice = wifi.Install (phy, mac, wifiApNode);
114 
115  // Setting mobility model
117  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
118 
119  // AP is between the two stations, each station being located at 5 meters from the AP.
120  // The distance between the two stations is thus equal to 10 meters.
121  // Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
122  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
123  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
124  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
125  mobility.SetPositionAllocator (positionAlloc);
126 
127  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
128 
129  mobility.Install (wifiApNode);
130  mobility.Install (wifiStaNodes);
131 
132  // Internet stack
134  stack.Install (wifiApNode);
135  stack.Install (wifiStaNodes);
136 
138  address.SetBase ("192.168.1.0", "255.255.255.0");
139  Ipv4InterfaceContainer StaInterface;
140  StaInterface = address.Assign (staDevices);
141  Ipv4InterfaceContainer ApInterface;
142  ApInterface = address.Assign (apDevice);
143 
144  // Setting applications
145  uint16_t port = 9;
146  UdpServerHelper server (port);
147  ApplicationContainer serverApp = server.Install (wifiApNode);
148  serverApp.Start (Seconds (0.0));
149  serverApp.Stop (Seconds (simulationTime + 1));
150 
151  UdpClientHelper client (ApInterface.GetAddress (0), port);
152  client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
153  client.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
154  client.SetAttribute ("PacketSize", UintegerValue (payloadSize));
155 
156  // Saturated UDP traffic from stations to AP
157  ApplicationContainer clientApp1 = client.Install (wifiStaNodes);
158  clientApp1.Start (Seconds (1.0));
159  clientApp1.Stop (Seconds (simulationTime + 1));
160 
161  phy.EnablePcap ("SimpleHtHiddenStations_Ap", apDevice.Get (0));
162  phy.EnablePcap ("SimpleHtHiddenStations_Sta1", staDevices.Get (0));
163  phy.EnablePcap ("SimpleHtHiddenStations_Sta2", staDevices.Get (1));
164 
165  Simulator::Stop (Seconds (simulationTime + 1));
166 
167  Simulator::Run ();
169 
170  uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
171  double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
172  std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
173  if (throughput < minExpectedThroughput || (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
174  {
175  NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
176  exit (1);
177  }
178  return 0;
179 }
void AddPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
tuple channel
Definition: third.py:85
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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 and interface index.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:719
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
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.
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
aggregate IP/TCP/UDP functionality to existing Nodes.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:213
tuple cmd
Definition: second.py:35
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:566
uint16_t port
Definition: dsdv-manet.cc:44
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
tuple 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:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:742
Create a server application which waits for input UDP packets and uses the information carried into t...
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
tuple staDevices
Definition: third.py:96
tuple mac
Definition: third.py:92
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:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
tuple wifiApNode
Definition: third.py:83
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
tuple ssid
Definition: third.py:93
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
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...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
void Add(Vector v)
Add a position to the list of positions.
void Parse(int argc, char *argv[])
Parse the program arguments.
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:253
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Include Radiotap link layer information.
Definition: wifi-helper.h:111
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
tuple wifiStaNodes
Definition: third.py:81