A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-simple-ht-hidden-stations.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Sébastien Deronne
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "ns3/boolean.h"
10#include "ns3/command-line.h"
11#include "ns3/config.h"
12#include "ns3/double.h"
13#include "ns3/internet-stack-helper.h"
14#include "ns3/ipv4-address-helper.h"
15#include "ns3/log.h"
16#include "ns3/mobility-helper.h"
17#include "ns3/rng-seed-manager.h"
18#include "ns3/ssid.h"
19#include "ns3/string.h"
20#include "ns3/udp-client-server-helper.h"
21#include "ns3/udp-server.h"
22#include "ns3/uinteger.h"
23#include "ns3/yans-wifi-channel.h"
24#include "ns3/yans-wifi-helper.h"
25
26// This example considers two hidden stations in an 802.11n network which supports MPDU aggregation.
27// The user can specify whether RTS/CTS is used and can set the number of aggregated MPDUs.
28//
29// Example: ./ns3 run "wifi-simple-ht-hidden-stations --enableRts=1 --nMpdus=8"
30//
31// Network topology:
32//
33// Wifi 192.168.1.0
34//
35// AP
36// * * *
37// | | |
38// n1 n2 n3
39//
40// Packets in this simulation belong to BestEffort Access Class (AC_BE).
41
42using namespace ns3;
43
44NS_LOG_COMPONENT_DEFINE("SimplesHtHiddenStations");
45
46int
47main(int argc, char* argv[])
48{
49 uint32_t payloadSize{1472}; // bytes
50 Time simulationTime{"10s"};
51 uint32_t nMpdus{1};
52 uint32_t maxAmpduSize{0};
53 bool enableRts{false};
54 double minExpectedThroughput{0};
55 double maxExpectedThroughput{0};
56
59
60 CommandLine cmd(__FILE__);
61 cmd.AddValue("nMpdus", "Number of aggregated MPDUs", nMpdus);
62 cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize);
63 cmd.AddValue("enableRts", "Enable RTS/CTS", enableRts);
64 cmd.AddValue("simulationTime", "Simulation time", simulationTime);
65 cmd.AddValue("minExpectedThroughput",
66 "if set, simulation fails if the lowest throughput is below this value",
67 minExpectedThroughput);
68 cmd.AddValue("maxExpectedThroughput",
69 "if set, simulation fails if the highest throughput is above this value",
70 maxExpectedThroughput);
71 cmd.Parse(argc, argv);
72
73 if (!enableRts)
74 {
75 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("999999"));
76 }
77 else
78 {
79 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("0"));
80 }
81
82 // Set the maximum size for A-MPDU with regards to the payload size
83 maxAmpduSize = nMpdus * (payloadSize + 200);
84
85 // Set the maximum wireless range to 5 meters in order to reproduce a hidden nodes scenario,
86 // i.e. the distance between hidden stations is larger than 5 meters
87 Config::SetDefault("ns3::RangePropagationLossModel::MaxRange", DoubleValue(5));
88
90 wifiStaNodes.Create(2);
92 wifiApNode.Create(1);
93
95 channel.AddPropagationLoss(
96 "ns3::RangePropagationLossModel"); // wireless range limited to 5 meters!
97
99 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
100 phy.SetChannel(channel.Create());
101 phy.Set("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
102
104 wifi.SetStandard(WIFI_STANDARD_80211n);
105 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
106 "DataMode",
107 StringValue("HtMcs7"),
108 "ControlMode",
109 StringValue("HtMcs0"));
111
112 Ssid ssid = Ssid("simple-mpdu-aggregation");
113 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
114
116 staDevices = wifi.Install(phy, mac, wifiStaNodes);
117
118 mac.SetType("ns3::ApWifiMac",
119 "Ssid",
120 SsidValue(ssid),
121 "EnableBeaconJitter",
122 BooleanValue(false));
123
124 NetDeviceContainer apDevice;
125 apDevice = wifi.Install(phy, mac, wifiApNode);
126
127 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
128 UintegerValue(maxAmpduSize));
129
130 int64_t streamNumber = 20;
131 streamNumber += WifiHelper::AssignStreams(apDevice, streamNumber);
132 streamNumber += WifiHelper::AssignStreams(staDevices, streamNumber);
133
134 // Setting mobility model
137
138 // AP is between the two stations, each station being located at 5 meters from the AP.
139 // The distance between the two stations is thus equal to 10 meters.
140 // Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
141 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
142 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
143 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
144 mobility.SetPositionAllocator(positionAlloc);
145
146 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
147
148 mobility.Install(wifiApNode);
149 mobility.Install(wifiStaNodes);
150
151 // Internet stack
153 stack.Install(wifiApNode);
154 stack.Install(wifiStaNodes);
155 streamNumber += stack.AssignStreams(wifiApNode, streamNumber);
156 streamNumber += stack.AssignStreams(wifiStaNodes, streamNumber);
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;
168 ApplicationContainer serverApp = server.Install(wifiApNode);
169 serverApp.Start(Seconds(0.0));
170 serverApp.Stop(simulationTime + Seconds(1.0));
171 streamNumber += server.AssignStreams(wifiApNode, streamNumber);
172
173 UdpClientHelper client(ApInterface.GetAddress(0), port);
174 client.SetAttribute("MaxPackets", UintegerValue(4294967295U));
175 client.SetAttribute("Interval", TimeValue(Time("0.0001"))); // packets/s
176 client.SetAttribute("PacketSize", UintegerValue(payloadSize));
177
178 // Saturated UDP traffic from stations to AP
179 ApplicationContainer clientApp1 = client.Install(wifiStaNodes);
180 clientApp1.Start(Seconds(1.0));
181 clientApp1.Stop(simulationTime + Seconds(1.0));
182 streamNumber += client.AssignStreams(wifiStaNodes, streamNumber);
183
184 phy.EnablePcap("SimpleHtHiddenStations_Ap", apDevice.Get(0));
185 phy.EnablePcap("SimpleHtHiddenStations_Sta1", staDevices.Get(0));
186 phy.EnablePcap("SimpleHtHiddenStations_Sta2", staDevices.Get(1));
187
188 AsciiTraceHelper ascii;
189 phy.EnableAsciiAll(ascii.CreateFileStream("SimpleHtHiddenStations.tr"));
190
191 Simulator::Stop(simulationTime + Seconds(1.0));
192
194
195 double totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get(0))->GetReceived();
196
198
199 auto throughput = totalPacketsThrough * payloadSize * 8 / simulationTime.GetMicroSeconds();
200 std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
201 if (throughput < minExpectedThroughput ||
202 (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
203 {
204 NS_LOG_ERROR("Obtained throughput " << throughput << " is not in the expected boundaries!");
205 exit(1);
206 }
207 return 0;
208}
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.
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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.
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:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
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:34
helps to create WifiNetDevice objects
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
create MAC layers for a ns3::WifiNetDevice.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
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:33
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
void Set(std::string path, const AttributeValue &value)
Definition config.cc:869
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
@ WIFI_STANDARD_80211n
address
Definition first.py:36
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
staDevices
Definition third.py:87
ssid
Definition third.py:82
channel
Definition third.py:77
mac
Definition third.py:81
wifi
Definition third.py:84
wifiApNode
Definition third.py:75
mobility
Definition third.py:92
wifiStaNodes
Definition third.py:73
phy
Definition third.py:78
std::ofstream throughput