A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
athstats-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#ifndef ATHSTATS_HELPER_H
10#define ATHSTATS_HELPER_H
11
12#include "ns3/nstime.h"
13#include "ns3/object.h"
14#include "ns3/ptr.h"
15#include "ns3/type-id.h"
16#include "ns3/wifi-phy-common.h"
17#include "ns3/wifi-phy-state.h"
18
19#include <iosfwd>
20#include <stdint.h>
21#include <string>
22
23namespace ns3
24{
25
26class NetDevice;
27class NodeContainer;
28class NetDeviceContainer;
29class Packet;
30class Mac48Address;
31class WifiMode;
32
33/**
34 * @brief create AthstatsWifiTraceSink instances and connect them to wifi devices
35 *
36 *
37 */
39{
40 public:
42 /**
43 * Enable athstats
44 * \param filename the file name
45 * \param nodeid the node ID
46 * \param deviceid the device ID
47 */
48 void EnableAthstats(std::string filename, uint32_t nodeid, uint32_t deviceid);
49 /**
50 * Enable athstats
51 * \param filename the file name
52 * \param nd the device
53 */
54 void EnableAthstats(std::string filename, Ptr<NetDevice> nd);
55 /**
56 * Enable athstats
57 * \param filename the file name
58 * \param d the collection of devices
59 */
60 void EnableAthstats(std::string filename, NetDeviceContainer d);
61 /**
62 * Enable athstats
63 * \param filename the file name
64 * \param n the collection of nodes
65 */
66 void EnableAthstats(std::string filename, NodeContainer n);
67
68 private:
69 Time m_interval; ///< interval
70};
71
72/**
73 * @brief trace sink for wifi device that mimics madwifi's athstats tool.
74 *
75 * The AthstatsWifiTraceSink class is a trace sink to be connected to several of the traces
76 * available within a wifi device. The purpose of AthstatsWifiTraceSink is to
77 * mimic the behavior of the athstats tool distributed with the madwifi
78 * driver. In particular, the reproduced behavior is that obtained
79 * when executing athstats without parameters: a report written in
80 * text format is produced every fixed interval, based on the events
81 * observed by the wifi device.
82 *
83 * Differences with the "real" athstats:
84 *
85 * - AthstatsWifiTraceSink is expected to write its output to a file
86 * (not to stdout).
87 *
88 * - only a subset of the metrics supported by athstats is supported
89 * by AthstatsWifiTraceSink
90 *
91 * - AthstatsWifiTraceSink does never produce a cumulative report.
92 */
94{
95 public:
96 /**
97 * \brief Get the type ID.
98 * \return the object TypeId
99 */
100 static TypeId GetTypeId();
102 ~AthstatsWifiTraceSink() override;
103
104 /**
105 * function to be called when the net device transmits a packet
106 *
107 * @param context the calling context
108 * @param p the packet being transmitted
109 */
110 void DevTxTrace(std::string context, Ptr<const Packet> p);
111
112 /**
113 * function to be called when the net device receives a packet
114 *
115 * @param context the calling context
116 * @param p the packet being received
117 */
118 void DevRxTrace(std::string context, Ptr<const Packet> p);
119
120 /**
121 * Function to be called when a RTS frame transmission by the considered
122 * device has failed
123 *
124 * @param context the calling context
125 * @param address the MAC address of the remote station
126 */
127 void TxRtsFailedTrace(std::string context, Mac48Address address);
128
129 /**
130 * Function to be called when a data frame transmission by the considered
131 * device has failed
132 *
133 * @param context the calling context
134 * @param address the MAC address of the remote station
135 */
136 void TxDataFailedTrace(std::string context, Mac48Address address);
137
138 /**
139 * Function to be called when the transmission of a RTS frame has
140 * exceeded the retry limit
141 *
142 * @param context the calling context
143 * @param address the MAC address of the remote station
144 */
145 void TxFinalRtsFailedTrace(std::string context, Mac48Address address);
146
147 /**
148 * Function to be called when the transmission of a data frame has
149 * exceeded the retry limit
150 *
151 * @param context the calling context
152 * @param address the MAC address of the remote station
153 */
154 void TxFinalDataFailedTrace(std::string context, Mac48Address address);
155
156 /**
157 * Function to be called when the PHY layer of the considered
158 * device receives a frame
159 *
160 * @param context the calling context
161 * @param packet the packet
162 * @param snr the SNR in linear scale
163 * @param mode the WifiMode
164 * @param preamble the wifi preamble
165 */
166 void PhyRxOkTrace(std::string context,
167 Ptr<const Packet> packet,
168 double snr,
169 WifiMode mode,
170 WifiPreamble preamble);
171
172 /**
173 * Function to be called when a frame reception by the PHY
174 * layer of the considered device resulted in an error due to a failure in the CRC check of
175 * the frame
176 *
177 * @param context the calling context
178 * @param packet the packet
179 * @param snr the SNR in linear scale
180 */
181 void PhyRxErrorTrace(std::string context, Ptr<const Packet> packet, double snr);
182
183 /**
184 * Function to be called when a frame is being transmitted by the
185 * PHY layer of the considered device
186 *
187 * @param context the calling context
188 * @param packet the packet
189 * @param mode the WifiMode
190 * @param preamble the wifi preamble
191 * @param txPower the transmit power level
192 */
193 void PhyTxTrace(std::string context,
194 Ptr<const Packet> packet,
195 WifiMode mode,
196 WifiPreamble preamble,
197 uint8_t txPower);
198
199 /**
200 * Function to be called when the PHY layer of the considered device
201 * changes state
202 *
203 * @param context the calling context
204 * @param start the time at which the state changed
205 * @param duration the duration of the state
206 * @param state the PHY layer state
207 */
208 void PhyStateTrace(std::string context, Time start, Time duration, WifiPhyState state);
209
210 /**
211 * Open a file for output
212 *
213 * @param name the name of the file to be opened.
214 */
215 void Open(const std::string& name);
216
217 private:
218 /// Write status function
219 void WriteStats();
220 /// Reset counters function
221 void ResetCounters();
222
223 uint32_t m_txCount; ///< transmit count
224 uint32_t m_rxCount; ///< receive count
225 uint32_t m_shortRetryCount; ///< short retry count
226 uint32_t m_longRetryCount; ///< long retry count
227 uint32_t m_exceededRetryCount; ///< exceeded retry count
228 uint32_t m_phyRxOkCount; ///< PHY receive OK count
229 uint32_t m_phyRxErrorCount; ///< PHY receive error count
230 uint32_t m_phyTxCount; ///< PHY transmit count
231
232 std::ofstream* m_writer; ///< output stream
233
234 Time m_interval; ///< interval
235
236}; // class AthstatsWifiTraceSink
237
238} // namespace ns3
239
240#endif /* ATHSTATS_HELPER_H */
create AthstatsWifiTraceSink instances and connect them to wifi devices
Time m_interval
interval
void EnableAthstats(std::string filename, uint32_t nodeid, uint32_t deviceid)
Enable athstats.
trace sink for wifi device that mimics madwifi's athstats tool.
void TxFinalRtsFailedTrace(std::string context, Mac48Address address)
Function to be called when the transmission of a RTS frame has exceeded the retry limit.
void Open(const std::string &name)
Open a file for output.
static TypeId GetTypeId()
Get the type ID.
void TxFinalDataFailedTrace(std::string context, Mac48Address address)
Function to be called when the transmission of a data frame has exceeded the retry limit.
void PhyRxOkTrace(std::string context, Ptr< const Packet > packet, double snr, WifiMode mode, WifiPreamble preamble)
Function to be called when the PHY layer of the considered device receives a frame.
uint32_t m_txCount
transmit count
void DevRxTrace(std::string context, Ptr< const Packet > p)
function to be called when the net device receives a packet
std::ofstream * m_writer
output stream
uint32_t m_rxCount
receive count
uint32_t m_shortRetryCount
short retry count
void WriteStats()
Write status function.
void TxRtsFailedTrace(std::string context, Mac48Address address)
Function to be called when a RTS frame transmission by the considered device has failed.
void PhyStateTrace(std::string context, Time start, Time duration, WifiPhyState state)
Function to be called when the PHY layer of the considered device changes state.
void PhyRxErrorTrace(std::string context, Ptr< const Packet > packet, double snr)
Function to be called when a frame reception by the PHY layer of the considered device resulted in an...
void DevTxTrace(std::string context, Ptr< const Packet > p)
function to be called when the net device transmits a packet
uint32_t m_longRetryCount
long retry count
void PhyTxTrace(std::string context, Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
Function to be called when a frame is being transmitted by the PHY layer of the considered device.
uint32_t m_phyTxCount
PHY transmit count.
void TxDataFailedTrace(std::string context, Mac48Address address)
Function to be called when a data frame transmission by the considered device has failed.
uint32_t m_phyRxOkCount
PHY receive OK count.
uint32_t m_phyRxErrorCount
PHY receive error count.
void ResetCounters()
Reset counters function.
uint32_t m_exceededRetryCount
exceeded retry count
an EUI-48 address
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:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
represent a single transmission mode
Definition wifi-mode.h:40
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.
WifiPhyState
The state of the PHY layer.