85 #include "ns3/abort.h"
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);
110 uint32_t pos = sub.find(
"/Device");
111 return std::stoi(sub.substr(0, pos));
122 main(
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 channelBandwidth = 20;
138 uint32_t payloadSize = 1500;
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(
"channelBandwidth",
163 "Bandwidth of the channel in MHz [20, 40, or 80]",
165 cmd.AddValue(
"obssPdThreshold",
"Threshold for the OBSS PD Algorithm", obssPdThreshold);
166 cmd.AddValue(
"mcs",
"The constant MCS value to transmit HE PPDUs", mcs);
167 cmd.Parse(argc, argv);
178 spectrumChannel->AddPropagationLossModel(lossModel);
180 CreateObject<ConstantSpeedPropagationDelayModel>();
181 spectrumChannel->SetPropagationDelayModel(delayModel);
185 switch (channelBandwidth)
188 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{36, 20, BAND_5GHZ, 0}"));
191 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{62, 40, BAND_5GHZ, 0}"));
194 spectrumPhy.
Set(
"ChannelSettings",
StringValue(
"{171, 80, BAND_5GHZ, 0}"));
197 NS_ABORT_MSG(
"Unrecognized channel bandwidth: " << channelBandwidth);
208 wifi.SetObssPdAlgorithm(
"ns3::ConstantObssPdAlgorithm",
214 std::ostringstream oss;
215 oss <<
"HeMcs" << mcs;
216 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
228 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssidA));
236 mac.SetType(
"ns3::ApWifiMac",
"Ssid",
SsidValue(ssidA));
252 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssidB));
260 mac.SetType(
"ns3::ApWifiMac",
"Ssid",
SsidValue(ssidB));
272 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
273 positionAlloc->Add(Vector(d3, 0.0, 0.0));
274 positionAlloc->Add(Vector(0.0, d1, 0.0));
275 positionAlloc->Add(Vector(d3, d2, 0.0));
276 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
277 mobility.SetPositionAllocator(positionAlloc);
282 packetSocket.
Install(wifiApNodes);
293 client->SetRemote(socketAddr);
295 client->SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
299 server->SetLocal(socketAddr);
310 client->SetRemote(socketAddr);
312 client->SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
316 server->SetLocal(socketAddr);
320 Config::Connect(
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
328 for (uint32_t i = 0; i < 2; i++)
330 double throughput =
static_cast<double>(
bytesReceived[2 + i]) * 8 / 1000 / 1000 / duration;
331 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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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.
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(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.
Ptr< WifiMac > GetMac() const
Ptr< HeConfiguration > GetHeConfiguration() const
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 ContextToNodeId(std::string context)
std::vector< uint32_t > bytesReceived(4)
void SocketRx(std::string context, Ptr< const Packet > p, const Address &addr)