50#include "ns3/command-line.h"
51#include "ns3/config.h"
52#include "ns3/double.h"
53#include "ns3/internet-stack-helper.h"
54#include "ns3/ipv4-address-helper.h"
56#include "ns3/mobility-helper.h"
57#include "ns3/mobility-model.h"
58#include "ns3/neighbor-cache-helper.h"
60#include "ns3/string.h"
61#include "ns3/wifi-phy-rx-trace-helper.h"
62#include "ns3/yans-wifi-channel.h"
63#include "ns3/yans-wifi-helper.h"
78 while ((p = socket->Recv()))
80 NS_LOG_INFO(
"Received packet with size " << p->GetSize());
88 while ((p = socket->Recv()))
90 NS_LOG_INFO(
"Received packet on OBSS network with size " << p->GetSize());
130main(
int argc,
char* argv[])
135 bool enableTwoBss =
false;
136 double distanceTwoBss = 10;
139 bool logging =
false;
142 cmd.AddValue(
"packetSize",
"size of application packet sent",
packetSize);
143 cmd.AddValue(
"numPackets",
"number of packets generated", numPackets);
144 cmd.AddValue(
"interval",
"interval between packets", interval);
145 cmd.AddValue(
"distance",
"distance between AP and STA", distance);
146 cmd.AddValue(
"enableTwoBss",
"enable a second BSS (not traced)", enableTwoBss);
147 cmd.AddValue(
"distanceTwoBss",
"distance between BSS (meters)", distanceTwoBss);
148 cmd.AddValue(
"logging",
"enable all wifi module log components", logging);
149 cmd.AddValue(
"verbose",
"enable this program's log components",
verbose);
150 cmd.Parse(argc, argv);
154 std::cout <<
"No packets configured to be sent; exiting" << std::endl;
169 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
170 positionAlloc->Add(Vector(distance, 0.0, 0.0));
171 mobility.SetPositionAllocator(positionAlloc);
172 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
179 obssPositionAlloc->Add(Vector(0.0, distanceTwoBss, 0.0));
180 obssPositionAlloc->Add(Vector(distance, distanceTwoBss, 0.0));
199 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
212 wifiMac.
SetType(
"ns3::ApWifiMac",
226 obssDevices = obssStaDevice;
227 wifiMac.
SetType(
"ns3::ApWifiMac",
233 obssDevices.
Add(obssApDevice);
240 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
246 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
247 ipv4.Assign(obssDevices);
253 recvSink->Bind(local);
258 source->Connect(remote);
266 obssRecvSink->Bind(obssLocal);
271 obssSource->Connect(obssRemote);
281 wifiPhy.
EnablePcap(
"wifi-phy-rx-trace-example", devices);
293 "WifiPhyRxTraceExample",
329 std::cout <<
"*** Print statistics for all nodes using built-in print method:" << std::endl;
331 std::cout << std::endl;
333 std::cout <<
"*** Print statistics for the STA only using built-in print method:" << std::endl;
335 std::cout << std::endl;
337 std::cout <<
"*** Print statistics for the AP only using built-in print method:" << std::endl;
339 std::cout << std::endl;
341 std::cout <<
"*** Get statistics object and print the fields one-by-one:" << std::endl;
344 std::cout <<
" nonOverlapppingPpdu: " << stats.m_nonOverlappingPpdus << std::endl;
345 std::cout <<
" receivedPpdus: " << stats.m_receivedPpdus << std::endl;
346 std::cout <<
" failedPpdus: " << stats.m_failedPpdus << std::endl;
347 std::cout <<
" receivedMpdus: " << stats.m_receivedMpdus << std::endl;
348 std::cout <<
" failedMpdus: " << stats.m_failedMpdus << std::endl;
349 std::cout << std::endl;
351 std::cout <<
"*** Get vector of reception records and print out some fields:" << std::endl;
353 if (optionalRecords.has_value())
355 auto records = optionalRecords->get();
356 std::cout <<
"*** Records vector has size of " << records.size() << std::endl;
357 if (!records.empty())
360 std::cout <<
" First record:" << std::endl;
361 std::cout <<
" first PPDU's RSSI (dBm): " << records[0].m_rssi << std::endl;
362 std::cout <<
" first PPDU's receiver ID: " << records[0].m_receiverId << std::endl;
363 std::cout <<
" first PPDU's sender ID: " << records[0].m_senderId << std::endl;
364 std::cout <<
" first PPDU's start time: " << records[0].m_startTime.GetSeconds()
366 std::cout <<
" first PPDU's end time: " << records[0].m_endTime.GetSeconds()
368 std::cout <<
" first PPDU's number of MPDUs: " << records[0].m_statusPerMpdu.size()
370 std::cout <<
" first PPDU's sender device ID: " << records[0].m_senderDeviceId
373 if (records.size() > 1)
376 std::cout <<
" Second record:" << std::endl;
377 std::cout <<
" second PPDU's RSSI (dBm): " << records[1].m_rssi << std::endl;
378 std::cout <<
" second PPDU's receiver ID: " << records[1].m_receiverId << std::endl;
379 std::cout <<
" second PPDU's sender ID: " << records[1].m_senderId << std::endl;
380 std::cout <<
" second PPDU's start time: " << records[1].m_startTime.GetSeconds()
382 std::cout <<
" second PPDU's end time: " << records[1].m_endTime.GetSeconds()
384 std::cout <<
" second PPDU's number of MPDUs: " << records[1].m_statusPerMpdu.size()
386 std::cout <<
" second PPDU's sender device ID: " << records[1].m_senderDeviceId
389 if (records.size() > 2)
392 std::cout <<
" Third record:" << std::endl;
393 std::cout <<
" third PPDU's RSSI (dBm): " << records[2].m_rssi << std::endl;
394 std::cout <<
" third PPDU's receiver ID: " << records[2].m_receiverId << std::endl;
395 std::cout <<
" third PPDU's sender ID: " << records[2].m_senderId << std::endl;
396 std::cout <<
" third PPDU's start time: " << records[2].m_startTime.GetSeconds()
398 std::cout <<
" third PPDU's end time: " << records[2].m_endTime.GetSeconds()
400 std::cout <<
" third PPDU's number of MPDUs: " << records[2].m_statusPerMpdu.size()
402 std::cout <<
" third PPDU's sender device ID: " << records[2].m_senderDeviceId
405 std::cout << std::endl;
409 std::cout <<
"*** Records vector is empty" << std::endl;
410 std::cout << std::endl;
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Manage ASCII trace files for device models.
Parse command-line arguments.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
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.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
The IEEE 802.11 SSID Information Element.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
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.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Assists in tracing and analyzing Wi-Fi Physical Layer (PHY) receptions.
const std::vector< WifiPpduRxRecord > & GetPpduRecords() const
Accesses a vector of saved and completed PPDU reception records.
void PrintStatistics() const
Print statistics for all nodes, devices, and links during the collection period.
void Stop(Time stopTime)
Stops the collection of statistics at a specified time.
WifiPhyTraceStatistics GetStatistics() const
Retrieves current statistics of successful and failed data PPDUs and MPDUs receptions,...
void Enable(NodeContainer nodes)
Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
void Start(Time startTime)
Starts the collection of statistics from a specified start time.
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, Ts &&... args)
void AddPropagationLoss(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
#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 > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
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.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
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...
LogLevel
Logging severity classes and levels.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
@ LOG_LEVEL_INFO
LOG_INFO and above.
uint64_t m_overlappingPpdus
Number of PPDUs that overlapped in time with at least one other PPDU.
uint32_t pktSize
packet size used for the simulation (in bytes)
void ReceiveObssPacket(Ptr< Socket > socket)
static void GeneratePacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Generate traffic.
void ReceivePacket(Ptr< Socket > socket)
Function called when a packet is received.
void PopulateNeighborCache()
static const uint32_t packetSize
Packet size generated at the AP.