61#include "ns3/command-line.h"
62#include "ns3/config.h"
63#include "ns3/double.h"
64#include "ns3/internet-stack-helper.h"
65#include "ns3/ipv4-address-helper.h"
67#include "ns3/mobility-helper.h"
68#include "ns3/mobility-model.h"
69#include "ns3/neighbor-cache-helper.h"
71#include "ns3/string.h"
72#include "ns3/wifi-phy-rx-trace-helper.h"
73#include "ns3/yans-wifi-channel.h"
74#include "ns3/yans-wifi-helper.h"
89 while ((p = socket->Recv()))
91 NS_LOG_INFO(
"Received packet with size " << p->GetSize());
99 while ((p = socket->Recv()))
101 NS_LOG_INFO(
"Received packet on OBSS network with size " << p->GetSize());
119 socket->Send(Create<Packet>(
pktSize));
141main(
int argc,
char* argv[])
146 bool enableTwoBss =
false;
147 double distanceTwoBss = 10;
150 bool logging =
false;
153 cmd.AddValue(
"packetSize",
"size of application packet sent",
packetSize);
154 cmd.AddValue(
"numPackets",
"number of packets generated", numPackets);
155 cmd.AddValue(
"interval",
"interval between packets", interval);
156 cmd.AddValue(
"distance",
"distance between AP and STA", distance);
157 cmd.AddValue(
"enableTwoBss",
"enable a second BSS (not traced)", enableTwoBss);
158 cmd.AddValue(
"distanceTwoBss",
"distance between BSS (meters)", distanceTwoBss);
159 cmd.AddValue(
"logging",
"enable all wifi module log components", logging);
160 cmd.AddValue(
"verbose",
"enable this program's log components",
verbose);
161 cmd.Parse(argc, argv);
165 std::cout <<
"No packets configured to be sent; exiting" << std::endl;
180 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
181 positionAlloc->Add(Vector(distance, 0.0, 0.0));
182 mobility.SetPositionAllocator(positionAlloc);
183 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
190 obssPositionAlloc->Add(Vector(0.0, distanceTwoBss, 0.0));
191 obssPositionAlloc->Add(Vector(distance, distanceTwoBss, 0.0));
210 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
223 wifiMac.
SetType(
"ns3::ApWifiMac",
237 obssDevices = obssStaDevice;
238 wifiMac.
SetType(
"ns3::ApWifiMac",
244 obssDevices.
Add(obssApDevice);
251 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
257 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
258 ipv4.Assign(obssDevices);
264 recvSink->Bind(local);
269 source->Connect(remote);
277 obssRecvSink->Bind(obssLocal);
282 obssSource->Connect(obssRemote);
292 wifiPhy.
EnablePcap(
"wifi-phy-rx-trace-example", devices);
304 "WifiPhyRxTraceExample",
340 std::cout <<
"*** Print statistics for all nodes using built-in print method:" << std::endl;
342 std::cout << std::endl;
344 std::cout <<
"*** Print statistics for the STA only using built-in print method:" << std::endl;
346 std::cout << std::endl;
348 std::cout <<
"*** Print statistics for the AP only using built-in print method:" << std::endl;
350 std::cout << std::endl;
352 std::cout <<
"*** Get statistics object and print the fields one-by-one:" << std::endl;
355 std::cout <<
" nonOverlapppingPpdu: " << stats.m_nonOverlappingPpdus << std::endl;
356 std::cout <<
" receivedPpdus: " << stats.m_receivedPpdus << std::endl;
357 std::cout <<
" failedPpdus: " << stats.m_failedPpdus << std::endl;
358 std::cout <<
" receivedMpdus: " << stats.m_receivedMpdus << std::endl;
359 std::cout <<
" failedMpdus: " << stats.m_failedMpdus << std::endl;
360 std::cout << std::endl;
362 std::cout <<
"*** Get vector of reception records and print out some fields:" << std::endl;
364 if (optionalRecords.has_value())
366 auto records = optionalRecords->get();
367 std::cout <<
"*** Records vector has size of " << records.size() << std::endl;
368 if (!records.empty())
371 std::cout <<
" First record:" << std::endl;
372 std::cout <<
" first PPDU's RSSI (dBm): " << records[0].m_rssi << std::endl;
373 std::cout <<
" first PPDU's receiver ID: " << records[0].m_receiverId << std::endl;
374 std::cout <<
" first PPDU's sender ID: " << records[0].m_senderId << std::endl;
375 std::cout <<
" first PPDU's start time: " << records[0].m_startTime.GetSeconds()
377 std::cout <<
" first PPDU's end time: " << records[0].m_endTime.GetSeconds()
379 std::cout <<
" first PPDU's number of MPDUs: " << records[0].m_statusPerMpdu.size()
381 std::cout <<
" first PPDU's sender device ID: " << records[0].m_senderDeviceId
384 if (records.size() > 1)
387 std::cout <<
" Second record:" << std::endl;
388 std::cout <<
" second PPDU's RSSI (dBm): " << records[1].m_rssi << std::endl;
389 std::cout <<
" second PPDU's receiver ID: " << records[1].m_receiverId << std::endl;
390 std::cout <<
" second PPDU's sender ID: " << records[1].m_senderId << std::endl;
391 std::cout <<
" second PPDU's start time: " << records[1].m_startTime.GetSeconds()
393 std::cout <<
" second PPDU's end time: " << records[1].m_endTime.GetSeconds()
395 std::cout <<
" second PPDU's number of MPDUs: " << records[1].m_statusPerMpdu.size()
397 std::cout <<
" second PPDU's sender device ID: " << records[1].m_senderDeviceId
400 if (records.size() > 2)
403 std::cout <<
" Third record:" << std::endl;
404 std::cout <<
" third PPDU's RSSI (dBm): " << records[2].m_rssi << std::endl;
405 std::cout <<
" third PPDU's receiver ID: " << records[2].m_receiverId << std::endl;
406 std::cout <<
" third PPDU's sender ID: " << records[2].m_senderId << std::endl;
407 std::cout <<
" third PPDU's start time: " << records[2].m_startTime.GetSeconds()
409 std::cout <<
" third PPDU's end time: " << records[2].m_endTime.GetSeconds()
411 std::cout <<
" third PPDU's number of MPDUs: " << records[2].m_statusPerMpdu.size()
413 std::cout <<
" third PPDU's sender device ID: " << records[2].m_senderDeviceId
416 std::cout << std::endl;
420 std::cout <<
"*** Records vector is empty" << std::endl;
421 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.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
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.
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.