A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-phy-rx-trace-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef WIFI_PHY_RX_TRACE_HELPER_H
19#define WIFI_PHY_RX_TRACE_HELPER_H
20
21#include "ns3/nstime.h"
22#include "ns3/object.h"
23#include "ns3/phy-entity.h"
24#include "ns3/ptr.h"
25#include "ns3/wifi-phy-common.h"
26#include "ns3/wifi-phy-state.h"
27#include "ns3/wifi-ppdu.h"
28
29#include <functional>
30#include <map>
31#include <optional>
32#include <set>
33#include <string>
34#include <vector>
35
36// Forward declare some friend test classes that access private methods
40
41namespace ns3
42{
43
44class Mac48Address;
45class NetDeviceContainer;
46class Node;
47class NodeContainer;
48struct SpectrumSignalParameters;
49class WifiPhyRxTraceSink;
50class WifiTxVector;
51
52/**
53 * @struct WifiPhyTraceStatistics
54 * @brief Keeps track of PHY layer trace statistics.
55 *
56 * This structure stores various statistics related to the Physical Layer (PHY) of the Wi-Fi
57 * communication, including the number of successful and failed PPDUs containing unicast data,
58 * and unicast data MPDU receptions.
59 */
61{
63 0}; ///< Number of PPDUs that overlapped in time with at least one other PPDU.
65 0}; ///< Number of PPDUs that did not overlap in time with any other PPDU.
66 uint64_t m_receivedPpdus{0}; ///< Number of successfully received PPDUs (with unicast data).
67 uint64_t m_failedPpdus{0}; ///< Number of failed PPDU receptions (with unicast data).
68 uint64_t m_receivedMpdus{0}; ///< Number of successfully received unicast data MPDUs.
69 uint64_t m_failedMpdus{0}; ///< Number of failed unicast data MPDU receptions.
70 std::map<WifiPhyRxfailureReason, uint64_t> m_ppduDropReasons; ///< Counts of the drop reasons
71};
72
73/**
74 * @struct WifiPpduRxRecord
75 * @brief Structure recording a received PPDU (Physical Protocol Data Unit) in a Wi-Fi network.
76 *
77 * This structure contains various details about the received PPDU, such as signal strength,
78 * identifiers for the sender and receiver, timing information, and reception status.
79 */
81{
82 Ptr<const WifiPpdu> m_ppdu{nullptr}; ///< Pointer to the received PPDU.
83 double m_rssi{0}; ///< Received Signal Strength Indicator (RSSI) in dBm.
84 uint64_t m_rxTag{
85 std::numeric_limits<uint64_t>::max()}; ///< Unique tag for the reception of this PPDU.
86 uint32_t m_receiverId{std::numeric_limits<uint32_t>::max()}; ///< Node ID of the receiver.
87 Time m_startTime; ///< Start time of the PPDU reception.
88 Time m_endTime; ///< End time of the PPDU reception.
90 WifiPhyRxfailureReason::UNKNOWN}; ///< Reason for reception failure, if any.
91 std::vector<WifiPpduRxRecord>
92 m_overlappingPpdu; ///< List of PPDUs that overlapped in time with this reception.
93 std::vector<bool> m_statusPerMpdu; ///< Reception status for each MPDU within the PPDU.
94 uint8_t m_linkId{std::numeric_limits<uint8_t>::max()}; ///< The link ID belonging to this record
95 uint32_t m_senderId{std::numeric_limits<uint32_t>::max()}; ///< Node ID of the sender.
96 uint32_t m_senderDeviceId{std::numeric_limits<uint32_t>::max()}; ///< Device ID of Sender
97};
98
99/**
100 * @class WifiPhyRxTraceHelper
101 * @brief Assists in tracing and analyzing Wi-Fi Physical Layer (PHY) receptions.
102 *
103 * The WifiPhyRxTraceHelper class can be used to instrument Wi-Fi nodes (or devices, or
104 * links) to keep track of the reception of Wi-Fi signals, and in particular, whether they overlap
105 * (collide) with one another. The implementation maintains reception records within internal
106 * data structures, and statistics or full reception records can be queried.
107 *
108 * The class provides functionality to connect traces to all nodes and WifiNetDevices within scope,
109 * enabling the capture of all Physical Protocol Data Units (PPDUs) received. It also
110 * allows for the collection and retrieval of statistics related to successful and failed receptions
111 * of PPDUs containing unicast data, and their corresponding MAC Protocol Data Units (MPDUs).
112 *
113 * Key features include:
114 * - Enabling trace connections to capture reception data.
115 * - Starting and stopping the collection of statistics at specified times.
116 * - Resetting the collected data for fresh starts in data collection.
117 * - Accessing detailed reception records for further analysis.
118 *
119 * Usage involves connecting to desired nodes or devices, (optionally) managing the
120 * collection period with start, stop, and reset methods, and finally, accessing the collected
121 * statistics or reception records.
122 *
123 * Statistics are only compiled for unicast data (WIFI_MAC_DATA and WIFI_MAC_QOSDATA), although
124 * PPDU records are kept for all frame types because it is possible for non-data frames to
125 * collide with data frames.
126 */
128{
129 friend class ::TestWifiPhyRxTraceHelper;
130 friend class ::TestWifiPhyRxTraceHelperMloStr;
131 friend class ::TestWifiPhyRxTraceHelperYans;
132
133 public:
134 /**
135 * Constructor.
136 */
138
139 /**
140 * Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
141 * @param nodes The NodeContainer to which traces are to be connected.
142 */
144
145 /**
146 * Enables trace collection for all nodes corresponding to the devices in the specified
147 * NetDeviceContainer.
148 * @param devices The NetDeviceContainer containing nodes to which traces are to be connected.
149 */
150 void Enable(NetDeviceContainer devices);
151
152 /**
153 * Retrieves current statistics of successful and failed data PPDUs and MPDUs receptions,
154 * for all nodes, devices, and links that have been enabled.
155 *
156 * Statistics are compiled for the current observation window, which extends to the
157 * trace helper start time or last reset time (whichever is later) until the last
158 * stop time or the current time (whichever is earlier).
159 *
160 * @return A WifiPhyTraceStatistics object containing current reception statistics.
161 */
163
164 /**
165 * Retrieves reception statistics for a given node, device, and link.
166 * @param node Ptr to Node.
167 * @param deviceId Device identifier (optional, defaults to 0).
168 * @param linkId Link identifier (optional, defaults to 0).
169 * @return WifiPhyTraceStatistics object with current reception stats.
170 */
172 uint32_t deviceId = 0,
173 uint8_t linkId = 0) const;
174
175 /**
176 * Retrieves reception statistics for a given node, device, and link.
177 * @param nodeId Node identifier.
178 * @param deviceId Device identifier (optional, defaults to 0).
179 * @param linkId Link identifier (optional, defaults to 0).
180 * @return WifiPhyTraceStatistics object with current reception stats.
181 */
183 uint32_t deviceId = 0,
184 uint8_t linkId = 0) const;
185
186 /**
187 * Starts the collection of statistics from a specified start time.
188 * @param startTime The time to start collecting statistics.
189 */
190 void Start(Time startTime);
191
192 /**
193 * Stops the collection of statistics at a specified time.
194 * @param stopTime The time to stop collecting statistics.
195 */
196 void Stop(Time stopTime);
197
198 /**
199 * Resets the current statistics, clearing all counts and PPDU records.
200 */
201 void Reset();
202
203 /**
204 * Accesses a vector of saved and completed PPDU reception records.
205 * @return A constant reference to a vector of WifiPpduRxRecord instances.
206 */
207 const std::vector<WifiPpduRxRecord>& GetPpduRecords() const;
208
209 /**
210 * Accesses PPDU reception records for a specific node, device, and link.
211 *
212 * Because the return value could be null if the specified node/device/link do not have any
213 * records, this method returns a std::optional object, and because we are passing the
214 * underlying vector by const reference to avoid a copy, it must be wrapped by
215 * std::reference_wrapper. See the example program wifi-phy-reception-trace-example.cc for an
216 * example of how to use the value returned.
217 *
218 * @param nodeId The ID of the node.
219 * @param deviceId The ID of the WifiNetDevice (optional, defaults to 0).
220 * @param linkId The ID of the link (optional, defaults to 0).
221 * @return A reference to a vector of WifiPpduRxRecord instances.
222 */
223 std::optional<std::reference_wrapper<const std::vector<WifiPpduRxRecord>>> GetPpduRecords(
224 uint32_t nodeId,
225 uint32_t deviceId = 0,
226 uint8_t linkId = 0) const;
227
228 /**
229 * Print statistics for all nodes, devices, and links during the collection period.
230 */
231 void PrintStatistics() const;
232
233 /**
234 * Prints statistics collected in the period for a specific node, device, and link.
235 * @param node Ptr to Node.
236 * @param deviceId Device identifier (optional, defaults to 0).
237 * @param linkId Link identifier (optional, defaults to 0).
238 */
239 void PrintStatistics(Ptr<Node> node, uint32_t deviceId = 0, uint8_t linkId = 0) const;
240
241 /**
242 * Prints statistics collected in the period for a specific node, device, and link.
243 * @param nodeId Node identifier.
244 * @param deviceId Device identifier (optional, defaults to 0).
245 * @param linkId Link identifier (optional, defaults to 0).
246 */
247 void PrintStatistics(uint32_t nodeId, uint32_t deviceId = 0, uint8_t linkId = 0) const;
248
249 private:
250 /**
251 * Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
252 * @param nodes The NodeContainer to which traces are to be connected.
253 * @param MacToNodeMap A mapping from MAC address to node ID.
254 */
255 void Enable(NodeContainer nodes, const std::map<Mac48Address, uint32_t>& MacToNodeMap);
256
257 /**
258 * Populates the mapping of MAC addresses to node IDs for a given set of nodes.
259 * @param nodes The container of nodes for which to populate the MAC address to node ID mapping.
260 * @return a copy of the std::map container
261 */
262 std::map<Mac48Address, uint32_t> MapMacAddressesToNodeIds(NodeContainer nodes) const;
263
264 Ptr<WifiPhyRxTraceSink> m_traceSink; ///< Pointer to the current trace sink object.
265};
266
267/**
268 * @class WifiPhyRxTraceSink
269 * @brief Sink class for capturing and analyzing PHY layer reception events in Wi-Fi networks.
270 *
271 * The WifiPhyRxTraceSink class acts as a comprehensive sink for events related to the
272 * reception of signals at the Physical Layer (PHY) of Wi-Fi networks. It is designed to facilitate
273 * the detailed analysis and tracing of reception activities, and the management of reception data
274 * across nodes, devices, and links. This class supports the capture and analysis of detailed
275 * reception records, including successful and failed receptions, and offers capabilities to
276 * manage the collection of reception statistics.
277 *
278 * Features include:
279 * - Unique tag generation for tracking individual reception events.
280 * - Access to detailed PPDU reception records for analysis.
281 * - Management of reception statistics collection through start, stop, and reset operations.
282 * - Mapping of MAC addresses to node IDs for network element identification.
283 * - Handling of PHY signal transmission and reception events for detailed outcome logging.
284 * - Tracking and analysis of overlapping reception events for interference assessment.
285 */
287{
288 public:
289 /**
290 * Constructor.
291 */
293
294 /**
295 * Retrieves the TypeId of the class.
296 * @return The TypeId of the WifiPhyRxTraceSink class.
297 */
298 static TypeId GetTypeId();
299
300 /**
301 * @brief Generating unique tags for more than one instance of a WifiPpdu object
302 *
303 * This class is responsible for generating unique identifiers for each received
304 * WifiPpdu. The WifiPpdu UID is not sufficient because there can be more than one
305 * record per WifiPpdu.
306 */
308 {
309 public:
310 /**
311 * Generates a unique tag for a WifiPpdu. Uses an internal counter and a set of
312 * previously used tags to ensure that each generated tag is unique, allowing accurate
313 * tracking of received frames.
314 * @param ppduUid The PPDU UID to generate a unique tag for.
315 * @return uint64_t The generated unique tag.
316 */
317 uint64_t GenerateUniqueTag(uint64_t ppduUid);
318
319 private:
320 uint64_t counter{0}; ///< Counter to help generate unique tags.
321 std::set<uint64_t> usedTags; ///< Set of already used tags.
322 };
323
324 UniqueTagGenerator m_tagGenerator; ///< Instance of UniqueTagGenerator used for generating
325 ///< unique reception tags.
326
327 /**
328 * Provides access to all saved and completed PPDU reception records across all nodes,
329 * WifiNetDevices, and links.
330 * @return A constant reference to a vector of WifiPpduRxRecord instances.
331 */
332 const std::vector<WifiPpduRxRecord>& GetPpduRecords() const;
333
334 /**
335 * Provides access to PPDU reception records for a specific node, device, and link.
336 * @param nodeId The ID of the node.
337 * @param deviceId The ID of the WifiNetDevice (optional, defaults to 0).
338 * @param linkId The ID of the link (optional, defaults to 0).
339 * @return A constant reference to a vector of WifiPpduRxRecord instances.
340 */
341 std::optional<std::reference_wrapper<const std::vector<WifiPpduRxRecord>>> GetPpduRecords(
342 uint32_t nodeId,
343 uint32_t deviceId = 0,
344 uint8_t linkId = 0) const;
345
346 /**
347 * Creates a vector with all completed WiFi reception records to be returned by the
348 * GetPpduRecords(). This is only called if no specific node, device or link is
349 * provided.
350 */
352
353 /**
354 * Provides a custom mapping of MAC addresses to intended receiver node IDs. This mapping is
355 * crucial for identifying the nodes involved in reception events based on their MAC addresses,
356 * facilitating the analysis of network dynamics at the PHY layer.
357 * @param MacAddressToNodeIdMap A mapping from MAC addresses to node IDs.
358 */
359 void SetMapMacAddressToNodeId(const std::map<Mac48Address, uint32_t>& MacAddressToNodeIdMap);
360
361 /**
362 * Retrieves the frequency and channel number used by a specific link.
363 * @param node The node ID.
364 * @param deviceId The device ID of the WifiNetDevice.
365 * @param link The link ID.
366 * @return A pair containing the channel number (uint8_t) and frequency (uint16_t).
367 */
368 std::optional<std::pair<uint8_t, uint16_t>> GetChannelInfo(uint32_t node,
369 uint32_t deviceId,
370 int link) const;
371
372 /**
373 * Starts the statistics collection period from a specified start time. Ongoing PPDUs when this
374 * method is called will be counted towards this statistics collection period.
375 */
376 void Start();
377
378 /**
379 * Stops the statistics collection period at a specified time. This method ensures that
380 * incomplete PPDUs at the end of the collection period are not included in the current
381 * statistics count.
382 */
383 void Stop();
384
385 /**
386 * Resets the statistics collection, clearing all counts and discarding all fully completed PPDU
387 * records. This allows for a fresh start in data collection and analysis.
388 */
389 void Reset();
390
391 /**
392 * Translates a context string to a link ID, facilitating the association of events with
393 * specific links in the network.
394 * @param context The context string.
395 * @return The link ID associated with the context.
396 */
397 int ContextToLinkId(std::string context) const;
398
399 /**
400 * Translates a context string to a device ID, enabling the identification of devices involved
401 * in reception events based on context information.
402 * @param context The context string.
403 * @return The device ID associated with the context.
404 */
405 int ContextToDeviceId(std::string context) const;
406
407 /**
408 * Translates a context string to a node ID.
409 * @param context The context string to translate.
410 * @return The corresponding node ID, facilitating the identification of the node involved in a
411 * reception event.
412 */
413 uint32_t ContextToNodeId(std::string context) const;
414
415 /**
416 * Translate a context string to a colon-delimited tuple "0:0:0" where the first element
417 * is a node ID, second is a device ID, third is a link ID
418 * @param context The context string to translate.
419 * @return The tuple of node, device, and link IDs
420 */
421 std::string ContextToTuple(std::string context) const;
422
423 /**
424 * Handles the event of a PHY signal transmission.
425 * @param context The context string, providing situational information about the transmission.
426 * @param ppdu The Wi-Fi PPDU being transmitted.
427 * @param txVector The transmission vector, detailing the parameters of the transmission.
428 */
429 void PhySignalTransmission(std::string context,
431 const WifiTxVector& txVector);
432
433 /**
434 * @brief Handles the event of a Wi-Fi PPDU arrival.
435 *
436 * @param context The context string, offering contextual information about the signal
437 * reception.
438 * @param ppdu The received WifiPpdu
439 * @param rxPower The power level at which the signal was received, indicating the signal's
440 * strength.
441 * @param duration The duration of the signal, offering temporal information about the reception
442 * event.
443 */
444 void PhySignalArrival(std::string context,
446 double rxPower,
447 Time duration);
448
449 /**
450 * @brief Handles the event of a PHY signal arrival from a SpectrumChannel.
451 *
452 * @param context The context string, offering contextual information about the signal
453 * reception.
454 * @param signal The received signal parameters, detailing the characteristics of the arriving
455 * signal.
456 * @param senderNodeId The ID of the node sending the signal, providing insight into the source
457 * of the signal.
458 * @param rxPower The power level at which the signal was received, indicating the signal's
459 * strength.
460 * @param duration The duration of the signal, offering temporal information about the reception
461 * event.
462 */
463 void SpectrumPhySignalArrival(std::string context,
465 uint32_t senderNodeId,
466 double rxPower,
467 Time duration);
468
469 /**
470 * Maps nodes to links and channels, creating a structured association between network
471 * elements and their communication channels. This mapping is essential for understanding
472 * what frequency and channel number is used for a given link.
473 * @param nodes NodeContainer of all nodes whose MAC address is going to be link to their
474 * NodeID.
475 */
477
478 /**
479 * Returns statistics on the count of successful and failed PPDUs with unicast data, and their
480 * MPDUs, across all nodes, devices, and links.
481 * @return A WifiPhyTraceStatistics object containing the current statistics. This method does
482 * not reset the collected statistics, allowing for continuous accumulation of data over time.
483 */
485
486 /**
487 * Returns statistics on the count of successful and failed PPDUs with unicast data, and their
488 * MPDUs, for a specific node, device, and link.
489 * @param nodeId The node ID from which to get the statistics.
490 * @param deviceId The device ID from which to get the statistics.
491 * @param linkId The link ID from which to get the statistics.
492 * @return A WifiPhyTraceStatistics object containing the current statistics. This method does
493 * not reset the collected statistics, allowing for continuous accumulation of data over time.
494 */
495 WifiPhyTraceStatistics GetStatistics(uint32_t nodeId, uint32_t deviceId, uint8_t linkId) const;
496
497 /**
498 * Updates the information for signals currently being received by a node.
499 * @param nodeId The node ID for which to update the reception information.
500 * @param deviceId The device ID on the node for which to update the information.
501 * @param linkId The link ID associated with the ongoing reception.
502 */
503 void UpdateCurrentlyReceivedSignal(uint32_t nodeId, uint32_t deviceId, uint8_t linkId);
504
505 /**
506 * Records the outcome of a PPDU transmission, including the signal info, and the success or
507 * failure status of each MPDU within the PPDU.
508 * @param context Descriptive context for the PPDU outcome.
509 * @param ppdu Pointer to the PPDU whose outcome is being recorded.
510 * @param signal Information about the received signal.
511 * @param txVector The transmission vector used for the PPDU.
512 * @param statusPerMpdu A vector indicating the success (true) or failure (false) of each MPDU.
513 */
514 void PpduOutcome(std::string context,
516 RxSignalInfo signal,
517 const WifiTxVector& txVector,
518 const std::vector<bool>& statusPerMpdu);
519
520 /**
521 * Logs the drop of a PPDU at the PHY layer, detailing the context and reason for the drop.
522 * @param context Descriptive context for the PPDU drop.
523 * @param ppdu Pointer to the PPDU that was dropped.
524 * @param reason The reason for the PPDU drop, represented as a WifiPhyRxfailureReason.
525 */
526 void PhyPpduDrop(std::string context, Ptr<const WifiPpdu> ppdu, WifiPhyRxfailureReason reason);
527
528 /**
529 * Handles the end of a PHY reception event, logging the conclusion of a reception and its
530 * associated details.
531 * @param nodeId The node ID where the reception ended.
532 * @param deviceId The device ID on the node where the reception took place.
533 * @param rxTag The unique reception tag associated with the reception event.
534 * @param ppduUid The PPDU UID of the received WifiPpdu
535 */
536 void PhyRxEnd(uint32_t nodeId, uint32_t deviceId, uint64_t rxTag, uint64_t ppduUid);
537
538 /**
539 * Handles the conclusion of a transmission event, facilitating the logging of transmission
540 * outcomes.
541 * @param nodeId The node ID from which the transmission originated.
542 * @param deviceId The device ID on the node that performed the transmission.
543 * @param ppduRecord The WifiPpduRxRecord representing the concluded transmission.
544 */
545 void EndTx(uint32_t nodeId, uint32_t deviceId, WifiPpduRxRecord ppduRecord);
546
547 /**
548 * Counts and aggregates PHY layer statistics including receptions, transmissions, and
549 * performance metrics (Success, Failure, Overlap) of unicast data PPDUs and MPDUs across all
550 * nodes.
551 * @return WifiPhyTraceStatistics object containing aggregated statistics for all nodes.
552 */
554
555 /**
556 * Counts statistics related to PHY layer receptions, transmissions, and performance metrics
557 * such as Success, Failure or Overlap of a PPDU containing unicast data, and the MPDUs within,
558 * for the specific node,
559 * device and link.
560 * @param nodeId Node identifier.
561 * @param deviceId Device identifier.
562 * @param linkId Link identifier.
563 * @return WifiPhyTraceStatistics object with current reception stats.
564 */
566 uint32_t deviceId,
567 uint8_t linkId) const;
568
569 /**
570 * Prints a summary of the statistics collected, offering a concise overview of PHY layer
571 * performance and reception outcomes for all nodes, devices and links.
572 */
573 void PrintStatistics() const;
574
575 /**
576 * Prints statistics collected in the period for a node, device, and link.
577 * @param nodeId Node identifier.
578 * @param deviceId Device identifier.
579 * @param linkId Link identifier.
580 */
581 void PrintStatistics(uint32_t nodeId, uint32_t deviceId, uint8_t linkId) const;
582
583 /**
584 * @brief Returns whether the collection period is active
585 * @return Whether the collection period is active
586 */
587 bool IsCollectionPeriodActive() const;
588
589 /**
590 * @brief Maps a reception tag to the corresponding WifiPpduRxRecord.
591 *
592 * This map links each unique reception tag generated upon receiving a
593 * frame to the corresponding detailed reception record (WifiPpduRxRecord). It is
594 * refreshed every time a new reception record is created.
595 */
596 std::map<uint64_t, WifiPpduRxRecord> m_rxTagToPpduRecord;
597
598 /**
599 * @brief Stores records of PPDUs that have completed reception, organized by node, device, and
600 * link.
601 *
602 * This nested map structure is updated each time a WifiPpduRxRecord is finalized,
603 * keeping a history of all completed packet receptions across different nodes,
604 * devices, and links.
605 */
606 std::map<uint32_t, std::map<uint32_t, std::map<uint8_t, std::vector<WifiPpduRxRecord>>>>
608
609 /**
610 * @brief Stores a flat vector of all records of PPDUs that have completed reception.
611 *
612 * This vector is updated upon the request of GetPpduRecords(),
613 * maintaining all packet receptions.
614 */
615 std::vector<WifiPpduRxRecord> m_records;
616
617 /**
618 * @brief Tracks ongoing frames being transmitted or received per node, device, and link.
619 *
620 * This map associates each node (by its ID) with nested maps keyed by device and link IDs, each
621 * containing vectors of WifiPpduRxRecords. It enables the tracking of current packet
622 * transmissions and receptions.
623 */
624 std::map<uint32_t, std::map<uint32_t, std::map<uint32_t, std::vector<WifiPpduRxRecord>>>>
626
627 /**
628 * @brief Maps each reception tag to a list of overlapping WifiPpduRxRecords.
629 *
630 * For each unique reception tag, this map stores a vector of WifiPpduRxRecords that
631 * overlap with the record corresponding to the tag.
632 */
633 std::map<uint64_t, std::vector<WifiPpduRxRecord>> m_rxTagToListOfOverlappingPpduRecords;
634
635 /**
636 * @brief Aids in correlating PHY reception drops and outcomes with specific reception tags.
637 *
638 * This complex map structure is used to navigate from node and device IDs, and link and packet
639 * IDs (PIDs), to the corresponding reception tag.
640 */
641 std::map<uint64_t, std::map<uint64_t, std::map<uint64_t, std::map<uint64_t, uint64_t>>>>
643
644 /**
645 * @brief Maps WifiPpdu UIDs to WifiPpduRxRecord tags stored by transmitter.
646 *
647 * This map allows a transmit-side PPDU record to be fetched based on the WifiPpdu UID.
648 */
649 std::map<uint64_t, uint64_t> m_ppduUidToTxTag;
650
651 /**
652 * @brief Maps MAC addresses to node IDs.
653 *
654 * This mapping facilitates the identification of nodes within the network based on the MAC
655 * addresses observed in reception events. By translating MAC addresses to node IDs, this map
656 * enables the association of reception data with specific network nodes.
657 */
658 std::map<Mac48Address, uint32_t> m_macAddressToNodeId;
659
660 /**
661 * Maps node IDs to device IDs and further to link IDs, associating each with a pair consisting
662 * of the channel number and frequency. This structure is vital for understanding the channel
663 * and frequency utilization across different links.
664 */
665 std::map<uint32_t, std::map<uint32_t, std::map<int, std::pair<uint8_t, uint16_t>>>>
667
668 private:
669 /**
670 * Flag indicating whether to keep a record of certain statistics or events for analysis. This
671 * boolean flag can be toggled to control the granularity and scope of data collection, enabling
672 * customization of the analysis to focus on specific times of interest.
673 */
675
676 /**
677 * Update the passed-in statistics object with statistics from the passed-in record.
678 * \param statistics The WifiPhyTraceStatistics object to modify
679 * \param record The WifiPpduRxRecord to examine
680 */
682 const WifiPpduRxRecord& record) const;
683
684}; // class WifiPhyRxTraceSink
685
686// Non-member function declarations
687
688/**
689 * @brief Checks if two WifiPpduRxRecord objects are equal.
690 *
691 * Compares two WifiPpduRxRecord objects to determine if they are equal. Two objects
692 * are considered equal if all their corresponding counts have the same values.
693 *
694 * @param lhs The left-hand side WifiPpduRxRecord object in the comparison.
695 * @param rhs The right-hand side WifiPpduRxRecord object in the comparison.
696 * @return true if the objects are equal, false otherwise.
697 */
698bool operator==(const WifiPpduRxRecord& lhs, const WifiPpduRxRecord& rhs);
699
700/**
701 * @brief Checks if two WifiPpduRxRecord objects are not equal.
702 *
703 * Compares two WifiPpduRxRecord objects to determine if they are not equal. Two objects
704 * are considered not equal if at least one of their corresponding counts have different values.
705 *
706 * @param lhs The left-hand side WifiPpduRxRecord object in the comparison.
707 * @param rhs The right-hand side WifiPpduRxRecord object in the comparison.
708 * @return true if the objects are not equal, false otherwise.
709 */
710bool operator!=(const WifiPpduRxRecord& lhs, const WifiPpduRxRecord& rhs);
711
712/**
713 * @brief Determines if one WifiPpduRxRecord object is less than another.
714 *
715 * Compares two WifiPpduRxRecord objects to determine if the left-hand side object is
716 * considered less than the right-hand side object based on a specific criteria of comparison,
717 * such as a key property value.
718 *
719 * @note The specific criteria for comparison should be defined and consistent.
720 *
721 * @param lhs The left-hand side WifiPpduRxRecord object in the comparison.
722 * @param rhs The right-hand side WifiPpduRxRecord object in the comparison.
723 * @return true if lhs is considered less than rhs, false otherwise.
724 */
725bool operator<(const WifiPpduRxRecord& lhs, const WifiPpduRxRecord& rhs);
726
727/**
728 * @brief Checks if two WifiPhyTraceStatistics objects are equal.
729 *
730 * Determines if two WifiPhyTraceStatistics objects are equal by comparing their counts.
731 * Equality is based on the values of all relevant statistical counts being identical.
732 *
733 * @param lhs The left-hand side WifiPhyTraceStatistics object in the comparison.
734 * @param rhs The right-hand side WifiPhyTraceStatistics object in the comparison.
735 * @return true if all counts are equal, false otherwise.
736 */
737bool operator==(const WifiPhyTraceStatistics& lhs, const WifiPhyTraceStatistics& rhs);
738
739/**
740 * @brief Checks if two WifiPhyTraceStatistics objects are not equal.
741 *
742 * Determines if two WifiPhyTraceStatistics objects are not equal by comparing their counts.
743 * Non-equality is based on any of the relevant statistical counts having different values.
744 *
745 * @param lhs The left-hand side WifiPhyTraceStatistics object in the comparison.
746 * @param rhs The right-hand side WifiPhyTraceStatistics object in the comparison.
747 * @return true if any property is different, false otherwise.
748 */
749bool operator!=(const WifiPhyTraceStatistics& lhs, const WifiPhyTraceStatistics& rhs);
750
751/**
752 * @brief Adds two WifiPhyTraceStatistics objects.
753 *
754 * Combines two WifiPhyTraceStatistics objects by summing their counts.
755 * This can be useful for aggregating statistics from multiple sources or time periods.
756 *
757 * @param lhs The left-hand side WifiPhyTraceStatistics object to be added.
758 * @param rhs The right-hand side WifiPhyTraceStatistics object to be added.
759 * @return A new WifiPhyTraceStatistics object that is the result of the addition.
760 */
762 const WifiPhyTraceStatistics& rhs);
763
764} // namespace ns3
765
766#endif /* WIFI_PHY_RX_TRACE_HELPER_H */
Implements a test case to evaluate the reception process of WiFi Physical Layer (PHY) frames (PPDU) w...
Implements a test case to evaluate the reception process of WiFi Physical Layer (PHY) frames (PPDU) c...
Implements a test case to evaluate the reception process of WiFi Physical Layer (PHY) frames (PPDU) w...
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
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 Reset()
Resets the current statistics, clearing all counts and PPDU records.
Ptr< WifiPhyRxTraceSink > m_traceSink
Pointer to the current trace sink object.
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.
std::map< Mac48Address, uint32_t > MapMacAddressesToNodeIds(NodeContainer nodes) const
Populates the mapping of MAC addresses to node IDs for a given set of nodes.
void Start(Time startTime)
Starts the collection of statistics from a specified start time.
Generating unique tags for more than one instance of a WifiPpdu object.
std::set< uint64_t > usedTags
Set of already used tags.
uint64_t GenerateUniqueTag(uint64_t ppduUid)
Generates a unique tag for a WifiPpdu.
uint64_t counter
Counter to help generate unique tags.
Sink class for capturing and analyzing PHY layer reception events in Wi-Fi networks.
std::map< uint64_t, std::map< uint64_t, std::map< uint64_t, std::map< uint64_t, uint64_t > > > > m_nodeDeviceLinkPidToRxId
Aids in correlating PHY reception drops and outcomes with specific reception tags.
void Reset()
Resets the statistics collection, clearing all counts and discarding all fully completed PPDU records...
std::map< uint32_t, std::map< uint32_t, std::map< uint8_t, std::vector< WifiPpduRxRecord > > > > m_completedRecords
Stores records of PPDUs that have completed reception, organized by node, device, and link.
void CreateVectorFromRecords()
Creates a vector with all completed WiFi reception records to be returned by the GetPpduRecords().
void SpectrumPhySignalArrival(std::string context, Ptr< const SpectrumSignalParameters > signal, uint32_t senderNodeId, double rxPower, Time duration)
Handles the event of a PHY signal arrival from a SpectrumChannel.
const std::vector< WifiPpduRxRecord > & GetPpduRecords() const
Provides access to all saved and completed PPDU reception records across all nodes,...
bool m_statisticsCollectionPeriodStarted
Flag indicating whether to keep a record of certain statistics or events for analysis.
void Stop()
Stops the statistics collection period at a specified time.
WifiPhyTraceStatistics CountStatistics() const
Counts and aggregates PHY layer statistics including receptions, transmissions, and performance metri...
void PhyRxEnd(uint32_t nodeId, uint32_t deviceId, uint64_t rxTag, uint64_t ppduUid)
Handles the end of a PHY reception event, logging the conclusion of a reception and its associated de...
bool IsCollectionPeriodActive() const
Returns whether the collection period is active.
std::map< uint64_t, WifiPpduRxRecord > m_rxTagToPpduRecord
Maps a reception tag to the corresponding WifiPpduRxRecord.
std::map< Mac48Address, uint32_t > m_macAddressToNodeId
Maps MAC addresses to node IDs.
void PhyPpduDrop(std::string context, Ptr< const WifiPpdu > ppdu, WifiPhyRxfailureReason reason)
Logs the drop of a PPDU at the PHY layer, detailing the context and reason for the drop.
std::optional< std::pair< uint8_t, uint16_t > > GetChannelInfo(uint32_t node, uint32_t deviceId, int link) const
Retrieves the frequency and channel number used by a specific link.
std::vector< WifiPpduRxRecord > m_records
Stores a flat vector of all records of PPDUs that have completed reception.
void PhySignalTransmission(std::string context, Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector)
Handles the event of a PHY signal transmission.
void PrintStatistics() const
Prints a summary of the statistics collected, offering a concise overview of PHY layer performance an...
WifiPhyTraceStatistics GetStatistics() const
Returns statistics on the count of successful and failed PPDUs with unicast data, and their MPDUs,...
std::map< uint64_t, std::vector< WifiPpduRxRecord > > m_rxTagToListOfOverlappingPpduRecords
Maps each reception tag to a list of overlapping WifiPpduRxRecords.
std::string ContextToTuple(std::string context) const
Translate a context string to a colon-delimited tuple "0:0:0" where the first element is a node ID,...
void Start()
Starts the statistics collection period from a specified start time.
void PpduOutcome(std::string context, Ptr< const WifiPpdu > ppdu, RxSignalInfo signal, const WifiTxVector &txVector, const std::vector< bool > &statusPerMpdu)
Records the outcome of a PPDU transmission, including the signal info, and the success or failure sta...
std::map< uint32_t, std::map< uint32_t, std::map< uint32_t, std::vector< WifiPpduRxRecord > > > > m_nodeDeviceLinkRxRecords
Tracks ongoing frames being transmitted or received per node, device, and link.
void EndTx(uint32_t nodeId, uint32_t deviceId, WifiPpduRxRecord ppduRecord)
Handles the conclusion of a transmission event, facilitating the logging of transmission outcomes.
int ContextToDeviceId(std::string context) const
Translates a context string to a device ID, enabling the identification of devices involved in recept...
void CountStatisticsForRecord(WifiPhyTraceStatistics &statistics, const WifiPpduRxRecord &record) const
Update the passed-in statistics object with statistics from the passed-in record.
void PhySignalArrival(std::string context, Ptr< const WifiPpdu > ppdu, double rxPower, Time duration)
Handles the event of a Wi-Fi PPDU arrival.
UniqueTagGenerator m_tagGenerator
Instance of UniqueTagGenerator used for generating unique reception tags.
void SetMapMacAddressToNodeId(const std::map< Mac48Address, uint32_t > &MacAddressToNodeIdMap)
Provides a custom mapping of MAC addresses to intended receiver node IDs.
void UpdateCurrentlyReceivedSignal(uint32_t nodeId, uint32_t deviceId, uint8_t linkId)
Updates the information for signals currently being received by a node.
uint32_t ContextToNodeId(std::string context) const
Translates a context string to a node ID.
int ContextToLinkId(std::string context) const
Translates a context string to a link ID, facilitating the association of events with specific links ...
void MapNodeToLinkToChannel(NodeContainer nodes)
Maps nodes to links and channels, creating a structured association between network elements and thei...
std::map< uint32_t, std::map< uint32_t, std::map< int, std::pair< uint8_t, uint16_t > > > > m_nodeToDeviceToLinkToChannelInfo
Maps node IDs to device IDs and further to link IDs, associating each with a pair consisting of the c...
std::map< uint64_t, uint64_t > m_ppduUidToTxTag
Maps WifiPpdu UIDs to WifiPpduRxRecord tags stored by transmitter.
static TypeId GetTypeId()
Retrieves the TypeId of the class.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time stopTime
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition: int64x64.h:88
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:674
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:166
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:179
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
Keeps track of PHY layer trace statistics.
std::map< WifiPhyRxfailureReason, uint64_t > m_ppduDropReasons
Counts of the drop reasons.
uint64_t m_failedMpdus
Number of failed unicast data MPDU receptions.
uint64_t m_failedPpdus
Number of failed PPDU receptions (with unicast data).
uint64_t m_receivedPpdus
Number of successfully received PPDUs (with unicast data).
uint64_t m_receivedMpdus
Number of successfully received unicast data MPDUs.
uint64_t m_overlappingPpdus
Number of PPDUs that overlapped in time with at least one other PPDU.
uint64_t m_nonOverlappingPpdus
Number of PPDUs that did not overlap in time with any other PPDU.
Structure recording a received PPDU (Physical Protocol Data Unit) in a Wi-Fi network.
Ptr< const WifiPpdu > m_ppdu
Pointer to the received PPDU.
double m_rssi
Received Signal Strength Indicator (RSSI) in dBm.
Time m_endTime
End time of the PPDU reception.
Time m_startTime
Start time of the PPDU reception.
uint8_t m_linkId
The link ID belonging to this record.
WifiPhyRxfailureReason m_reason
Reason for reception failure, if any.
uint32_t m_senderDeviceId
Device ID of Sender.
uint32_t m_senderId
Node ID of the sender.
std::vector< bool > m_statusPerMpdu
Reception status for each MPDU within the PPDU.
std::vector< WifiPpduRxRecord > m_overlappingPpdu
List of PPDUs that overlapped in time with this reception.
uint32_t m_receiverId
Node ID of the receiver.
uint64_t m_rxTag
Unique tag for the reception of this PPDU.