86#include "ns3/ap-wifi-mac.h"
87#include "ns3/application-container.h"
88#include "ns3/command-line.h"
89#include "ns3/config.h"
90#include "ns3/double.h"
91#include "ns3/he-configuration.h"
92#include "ns3/mobility-helper.h"
93#include "ns3/multi-model-spectrum-channel.h"
94#include "ns3/packet-socket-client.h"
95#include "ns3/packet-socket-helper.h"
96#include "ns3/packet-socket-server.h"
97#include "ns3/spectrum-wifi-helper.h"
99#include "ns3/string.h"
100#include "ns3/wifi-net-device.h"
109 std::string sub = context.substr(10);
111 return std::stoi(sub.substr(0, pos));
122main(
int argc,
char* argv[])
124 double duration = 10.0;
128 double powSta1 = 10.0;
129 double powSta2 = 10.0;
130 double powAp1 = 21.0;
131 double powAp2 = 21.0;
132 double ccaEdTrSta1 = -62;
133 double ccaEdTrSta2 = -62;
134 double ccaEdTrAp1 = -62;
135 double ccaEdTrAp2 = -62;
136 double minimumRssi = -82;
137 int channelWidth = 20;
140 double interval = 0.001;
141 bool enableObssPd =
true;
142 double obssPdThreshold = -72.0;
145 cmd.AddValue(
"duration",
"Duration of simulation (s)", duration);
146 cmd.AddValue(
"interval",
"Inter packet interval (s)", interval);
147 cmd.AddValue(
"enableObssPd",
"Enable/disable OBSS_PD", enableObssPd);
148 cmd.AddValue(
"d1",
"Distance between STA1 and AP1 (m)", d1);
149 cmd.AddValue(
"d2",
"Distance between STA2 and AP2 (m)", d2);
150 cmd.AddValue(
"d3",
"Distance between AP1 and AP2 (m)", d3);
151 cmd.AddValue(
"powSta1",
"Power of STA1 (dBm)", powSta1);
152 cmd.AddValue(
"powSta2",
"Power of STA2 (dBm)", powSta2);
153 cmd.AddValue(
"powAp1",
"Power of AP1 (dBm)", powAp1);
154 cmd.AddValue(
"powAp2",
"Power of AP2 (dBm)", powAp2);
155 cmd.AddValue(
"ccaEdTrSta1",
"CCA-ED Threshold of STA1 (dBm)", ccaEdTrSta1);
156 cmd.AddValue(
"ccaEdTrSta2",
"CCA-ED Threshold of STA2 (dBm)", ccaEdTrSta2);
157 cmd.AddValue(
"ccaEdTrAp1",
"CCA-ED Threshold of AP1 (dBm)", ccaEdTrAp1);
158 cmd.AddValue(
"ccaEdTrAp2",
"CCA-ED Threshold of AP2 (dBm)", ccaEdTrAp2);
159 cmd.AddValue(
"minimumRssi",
160 "Minimum RSSI for the ThresholdPreambleDetectionModel",
162 cmd.AddValue(
"channelWidth",
"Bandwidth of the channel in MHz [20, 40, or 80]", channelWidth);
163 cmd.AddValue(
"obssPdThreshold",
"Threshold for the OBSS PD Algorithm", obssPdThreshold);
164 cmd.AddValue(
"mcs",
"The constant MCS value to transmit HE PPDUs", mcs);
165 cmd.Parse(argc, argv);
176 spectrumChannel->AddPropagationLossModel(lossModel);
178 CreateObject<ConstantSpeedPropagationDelayModel>();
179 spectrumChannel->SetPropagationDelayModel(delayModel);
183 switch (channelWidth)
186 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{36, 20, BAND_5GHZ, 0}"));
189 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{62, 40, BAND_5GHZ, 0}"));
192 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{171, 80, BAND_5GHZ, 0}"));
195 NS_ABORT_MSG(
"Unrecognized channel width: " << channelWidth);
206 wifi.SetObssPdAlgorithm(
"ns3::ConstantObssPdAlgorithm",
212 std::ostringstream oss;
213 oss <<
"HeMcs" << mcs;
214 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
226 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssidA));
234 mac.SetType(
"ns3::ApWifiMac",
"Ssid",
SsidValue(ssidA));
241 apDevice->GetHeConfiguration()->SetAttribute(
"BssColor",
UintegerValue(1));
250 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssidB));
258 mac.SetType(
"ns3::ApWifiMac",
"Ssid",
SsidValue(ssidB));
262 apWifiMac = ap2Device->GetMac()->GetObject<
ApWifiMac>();
265 ap2Device->GetHeConfiguration()->SetAttribute(
"BssColor",
UintegerValue(2));
270 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
271 positionAlloc->Add(Vector(d3, 0.0, 0.0));
272 positionAlloc->Add(Vector(0.0, d1, 0.0));
273 positionAlloc->Add(Vector(d3, d2, 0.0));
274 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
275 mobility.SetPositionAllocator(positionAlloc);
280 packetSocket.
Install(wifiApNodes);
281 packetSocket.
Install(wifiStaNodes);
291 client->SetRemote(socketAddr);
297 server->SetLocal(socketAddr);
308 client->SetRemote(socketAddr);
314 server->SetLocal(socketAddr);
318 Config::Connect(
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
328 double throughput =
static_cast<double>(
bytesReceived[2 + i]) * 8 / 1000 / 1000 / duration;
329 std::cout <<
"Throughput for BSS " << i + 1 <<
": " << throughput <<
" Mbit/s" << std::endl;
a polymophic address class
holds a vector of ns3::Application pointers.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Make it easy to create and manage PHY objects for the spectrum model.
void SetChannel(const Ptr< SpectrumChannel > channel)
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
AttributeValue implementation for Time.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
Hold together all Wifi-related objects.
void Set(std::string name, const AttributeValue &v)
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
void SetPreambleDetectionModel(std::string type, Args &&... args)
Helper function used to set the preamble detection model.
void Connect(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
uint32_t bytesReceived
Counter of the received bytes.
uint32_t ContextToNodeId(std::string context)
void SocketRx(std::string context, Ptr< const Packet > p, const Address &addr)