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