9#include "ns3/boolean.h"
10#include "ns3/command-line.h"
11#include "ns3/config.h"
12#include "ns3/data-rate.h"
13#include "ns3/double.h"
15#include "ns3/error-model.h"
16#include "ns3/inet-socket-address.h"
17#include "ns3/internet-stack-helper.h"
18#include "ns3/ipv4-address-helper.h"
19#include "ns3/ipv4-l3-protocol.h"
20#include "ns3/ipv4-list-routing-helper.h"
21#include "ns3/ipv4-static-routing-helper.h"
22#include "ns3/ipv4-static-routing.h"
24#include "ns3/mobility-helper.h"
25#include "ns3/mobility-model.h"
28#include "ns3/on-off-helper.h"
29#include "ns3/packet-sink-helper.h"
30#include "ns3/packet-sink.h"
31#include "ns3/simulator.h"
32#include "ns3/socket.h"
34#include "ns3/string.h"
36#include "ns3/trace-helper.h"
37#include "ns3/udp-socket-factory.h"
38#include "ns3/udp-socket.h"
39#include "ns3/uinteger.h"
40#include "ns3/wifi-mac.h"
41#include "ns3/wifi-net-device.h"
42#include "ns3/wifi-psdu.h"
43#include "ns3/yans-wifi-channel.h"
44#include "ns3/yans-wifi-helper.h"
115 std::string sub = context.substr(10);
117 return std::stoi(sub.substr(0, pos));
168 auto psdu = psduMap.begin()->second;
169 if (psdu->GetHeader(0).GetAddr1().IsGroup() && !psdu->GetHeader(0).GetAddr1().IsBroadcast() &&
170 psdu->GetHeader(0).IsQosData())
172 NS_LOG_INFO(
"AP tx multicast: PSDU=" << *psdu <<
" TXVECTOR=" << txVector);
175 auto uid = psdu->GetPayload(0)->GetUid();
204 packet->RemoveHeader(
hdr);
205 if (
hdr.GetAddr1().IsGroup() && !
hdr.GetAddr1().IsBroadcast() &&
hdr.IsQosData())
207 std::stringstream
ss;
220 Time simulationTime{
"10s"};
224 uint32_t rtsThreshold{std::numeric_limits<uint16_t>::max()};
241 cmd.AddValue(
"logging",
"turn on example log components", logging);
242 cmd.AddValue(
"verbose",
"turn on all wifi log components",
verbose);
243 cmd.AddValue(
"pcap",
"turn on pcap file output", pcap);
244 cmd.AddValue(
"nStations",
"number of non-AP stations",
nStations);
245 cmd.AddValue(
"simulationTime",
"Simulation time", simulationTime);
246 cmd.AddValue(
"payloadSize",
"The application payload size in bytes", payloadSize);
249 "The maximum number of packets to be generated by the application (0 for no limit)",
251 cmd.AddValue(
"dataRate",
"The application data rate",
dataRate);
252 cmd.AddValue(
"rtsThreshold",
"RTS threshold", rtsThreshold);
253 cmd.AddValue(
"rateManager",
254 "The rate adaptation manager to use (Constant, Ideal, MinstrelHt)",
257 "The MCS to use if Constant rate adaptation manager is used",
259 cmd.AddValue(
"targetAddress",
"multicast target address",
targetAddr);
260 cmd.AddValue(
"accessCategory",
261 "select the multicast traffic access category (AC_BE, AC_BK, AC_VI, AC_VO)",
264 "gcrRetransmissionPolicy",
265 "GCR retransmission policy for groupcast frames (NoAckNoRetry, GcrUr, GcrBlockAck)",
267 cmd.AddValue(
"nRetriesGcrUr",
268 "number of retries per groupcast frame when GCR-UR retransmission policy is used",
270 cmd.AddValue(
"gcrProtection",
271 "protection to use for GCR (Rts-Cts or Cts-To-Self)",
273 cmd.AddValue(
"multicastFrameErrorRate",
274 "artificial error rate for multicast frame",
276 cmd.AddValue(
"maxAmpduLength",
"maximum length in bytes of an A-MPDU",
maxAmpduLength);
277 cmd.AddValue(
"minExpectedPackets",
278 "if set, simulation fails if the lowest amount of received packets is below this "
281 cmd.AddValue(
"maxExpectedPackets",
282 "if set, simulation fails if the highest amount of received packets is above this "
285 cmd.AddValue(
"minExpectedThroughput",
286 "if set, simulation fails if the throughput is below this value",
288 cmd.AddValue(
"maxExpectedThroughput",
289 "if set, simulation fails if the throughput is above this value",
317 wifiChannel.SetPropagationDelay(
"ns3::ConstantSpeedPropagationDelayModel");
323 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
331 wifi.SetRemoteStationManager(
"ns3::" +
rateManager +
"RateWifiManager",
349 std::cout <<
"Wrong retransmission policy!" << std::endl;
352 wifiMac.SetGcrManager(
"ns3::WifiDefaultGcrManager",
353 "RetransmissionPolicy",
355 "UnsolicitedRetryLimit",
374 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phys/0/PhyTxPsduBegin",
381 Config::Connect(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/State/RxOk",
393 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
404 internet.SetIpv6StackInstall(
false);
483 Config::Connect(
"/NodeList/*/$ns3::Node/ApplicationList/*/$ns3::OnOffApplication/Tx",
494 std::cout <<
"Node\t\t\tTX packets\t\tTX bytes\t\tRX packets\t\tRX bytes\t\tThroughput (Mbit/s)"
500 const auto txPackets =
g_txBytes / payloadSize;
502 <<
"\t\t\t" << txPackets <<
"\t\t\t" <<
g_txBytes <<
"\t\t\t0\t\t\t0\t\t\t" <<
txRate
506 const auto rxBytes =
sinks.Get(0)->GetObject<
PacketSink>()->GetTotalRx();
507 const auto rxPackets = rxBytes / payloadSize;
512 std::cout <<
"STA" <<
i + 1 <<
"\t\t\t0\t\t\t0\t\t\t" << rxPackets <<
"\t\t\t" << rxBytes
516 NS_LOG_ERROR(
"Obtained RX packets " << rxPackets <<
" is not expected!");
521 NS_LOG_ERROR(
"Obtained RX packets " << rxPackets <<
" is not expected!");
a polymophic address class
AttributeValue implementation for Boolean.
Parse command-line arguments.
Class for representing data rates.
AttributeValue implementation for DataRate.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
Helper class that adds ns3::Ipv4ListRouting objects.
Helper class that adds ns3::Ipv4StaticRouting objects.
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Receive and consume traffic generated to an IP address and port.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
static void EnableLogComponents(LogLevel logLevel=LOG_LEVEL_ALL)
Helper to enable all WifiNetDevice log components with one statement.
create MAC layers for a ns3::WifiNetDevice.
represent a single transmission mode
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
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.
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
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...
@ LOG_LEVEL_ALL
Print everything.
Time g_lastTx
Time at which last TX packet is generated.
void TxCallback(Ptr< ListErrorModel > rxErrorModel, Ptr< RandomVariableStream > ranVar, double errorRate, std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback when a frame is transmitted.
Time g_lastRx
Time at which last RX packet is received.
uint32_t ContextToNodeId(const std::string &context)
Parse context strings of the form "/NodeList/x/DeviceList/x/..." to extract the NodeId integer.
void RxCallback(std::string context, Ptr< const Packet > p, double snr, WifiMode mode, WifiPreamble preamble)
Callback when a frame is successfully received.
uint64_t g_txBytes
Number of generated bytes.
Time g_firstTx
Time at which first TX packet is generated.
void SocketRxPacket(std::string context, Ptr< const Packet > p, const Address &from)
void SocketTxPacket(std::string context, Ptr< const Packet > p)
Socket sent packet.