A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mesh-wifi-interface-mac.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Kirill Andreev <andreev@iitp.ru>
7 * Pavel Boyko <boyko@iitp.ru>
8 */
9
10#ifndef MESH_WIFI_INTERFACE_MAC_H
11#define MESH_WIFI_INTERFACE_MAC_H
12
14
15#include "ns3/callback.h"
16#include "ns3/event-id.h"
17#include "ns3/mac48-address.h"
18#include "ns3/mgt-headers.h"
19#include "ns3/nstime.h"
20#include "ns3/packet.h"
21#include "ns3/wifi-mac.h"
22
23#include <map>
24#include <stdint.h>
25
26namespace ns3
27{
28
29class UniformRandomVariable;
30
31/**
32 * @ingroup mesh
33 *
34 * @brief Basic MAC of mesh point Wi-Fi interface. Its function is extendable through plugins
35 * mechanism.
36 *
37 * Now only three output queues are used:
38 * - beacons (PIFS and no backoff),
39 * - background traffic,
40 * - management and priority traffic.
41 *
42 */
44{
45 public:
46 /**
47 * @brief Get the type ID.
48 * @return the object TypeId
49 */
50 static TypeId GetTypeId();
51 /// C-tor
53 /// D-tor
54 ~MeshWifiInterfaceMac() override;
55
56 // Inherited from WifiMac
57 bool SupportsSendFrom() const override;
58 void SetLinkUpCallback(Callback<void> linkUp) override;
59 bool CanForwardPacketsTo(Mac48Address to) const override;
60
61 /// @name Each mesh point interface must know the mesh point address
62 ///@{
63 /**
64 * Set the mesh point address
65 * @param addr the mesh point address
66 */
68 /**
69 * Get the mesh point address
70 * @return The mesh point address
71 */
73 ///@}
74
75 /// @name Beacons
76 ///@{
77 /**
78 * Set maximum initial random delay before first beacon
79 * @param interval maximum random interval
80 */
81 void SetRandomStartDelay(Time interval);
82 /**
83 * Set interval between two successive beacons
84 * @param interval beacon interval
85 */
86 void SetBeaconInterval(Time interval);
87 /**
88 * Get beacon interval.
89 * @return interval between two beacons
90 */
91 Time GetBeaconInterval() const;
92 /**
93 * @brief Next beacon frame time
94 * @return TBTT time
95 *
96 * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer
97 * management protocol in 802.11s)
98 */
99 Time GetTbtt() const;
100 /**
101 * @brief Shift TBTT.
102 * @param shift Shift
103 *
104 * This is supposed to be used by any entity managing beacon collision avoidance (e.g. Peer
105 * management protocol in 802.11s)
106 *
107 * @attention User of ShiftTbtt () must take care to not shift it to the past.
108 */
109 void ShiftTbtt(Time shift);
110 ///@}
111
112 /**
113 * Install plugin.
114 *
115 * @param plugin Plugin
116 *
117 * @todo return unique ID to allow user to unregister plugins
118 */
120
121 /*
122 * Channel center frequency = Channel starting frequency + 5 * channel_id (MHz),
123 * where Starting channel frequency is standard-dependent as defined in IEEE
124 * 802.11-2007 17.3.8.3.2.
125 *
126 * Number of channels to use must be limited elsewhere.
127 */
128
129 /**
130 * Current channel Id
131 * @returns the frequency channel
132 */
133 uint16_t GetFrequencyChannel() const;
134 /**
135 * Switch frequency channel.
136 *
137 * @param new_id New ID.
138 */
139 void SwitchFrequencyChannel(uint16_t new_id);
140
141 /**
142 * To be used by plugins sending management frames.
143 *
144 * @param frame the management frame
145 * @param hdr the wifi MAC header
146 */
147 void SendManagementFrame(Ptr<Packet> frame, const WifiMacHeader& hdr);
148 /**
149 * Check supported rates.
150 *
151 * @param rates Rates.
152 * @return true if rates are supported
153 */
154 bool CheckSupportedRates(AllSupportedRates rates) const;
155
156 /**
157 * Get supported rates.
158 * @return list of supported bitrates
159 */
161
162 /// @name Metric Calculation routines:
163 ///@{
164 /**
165 * Set the link metric callback
166 * @param cb the callback
167 */
169 /**
170 * Get the link metric
171 * @param peerAddress the peer address
172 * @return The metric
173 */
175 ///@}
176
177 /**
178 * @brief Report statistics
179 * @param os the output stream
180 */
181 void Report(std::ostream& os) const;
182
183 /**
184 * Reset statistics function
185 */
186 void ResetStats();
187
188 /**
189 * Enable/disable beacons
190 *
191 * @param enable enable / disable flag
192 */
193 void SetBeaconGeneration(bool enable);
194 /**
195 * @param cwMin the minimum contention window size
196 * @param cwMax the maximum contention window size
197 *
198 * This method is called to set the minimum and the maximum
199 * contention window size.
200 */
201 void ConfigureContentionWindow(uint32_t cwMin, uint32_t cwMax) override;
202
203 /**
204 * Assign a fixed random variable stream number to the random variables
205 * used by this model. Return the number of streams (possibly zero) that
206 * have been assigned.
207 *
208 * @param stream first stream index to use
209 * @return the number of stream indices assigned by this model
210 */
211 int64_t AssignStreams(int64_t stream) override;
212
213 private:
214 void DoCompleteConfig() override;
215
216 /**
217 * Frame receive handler
218 *
219 * @param mpdu the received MPDU
220 * @param linkId the ID of the link the frame was received over
221 */
222 void Receive(Ptr<const WifiMpdu> mpdu, uint8_t linkId) override;
223 /**
224 * Send beacon.
225 */
226 void SendBeacon();
227 /**
228 * Schedule next beacon.
229 */
230 void ScheduleNextBeacon();
231 /**
232 * Get current beaconing status
233 *
234 * @returns true if beacon active
235 */
236 bool GetBeaconGeneration() const;
237 /**
238 * Real d-tor.
239 */
240 void DoDispose() override;
241
242 private:
243 typedef std::vector<Ptr<MeshWifiInterfaceMacPlugin>> PluginList; ///< PluginList typedef
244
245 void DoInitialize() override;
246 void Enqueue(Ptr<WifiMpdu> mpdu, Mac48Address to, Mac48Address from) override;
247
248 /// @name Mesh timing intervals
249 ///@{
250 /// Whether beaconing is enabled
252 /// Beaconing interval.
254 /// Maximum delay before first beacon
256 /// Time for the next frame
258 ///@}
259
260 /// Mesh point address
262
263 /// "Timer" for the next beacon
265 /// List of all installed plugins
268 m_linkMetricCallback; ///< linkMetricCallback
269
270 /// Statistics:
272 {
273 uint16_t recvBeacons; ///< receive beacons
274 uint32_t sentFrames; ///< sent frames
275 uint32_t sentBytes; ///< sent bytes
276 uint32_t recvFrames; ///< receive frames
277 uint32_t recvBytes; ///< receive bytes
278 /**
279 * Print statistics.
280 *
281 * @param os Output stream
282 */
283 void Print(std::ostream& os) const;
284 /**
285 * Constructor.
286 */
287 Statistics();
288 };
289
290 Statistics m_stats; ///< statistics
291
292 /// Add randomness to beacon generation
294};
295
296} // namespace ns3
297
298#endif /* MESH_WIFI_INTERFACE_MAC_H */
Callback template class.
Definition callback.h:422
An identifier for simulation events.
Definition event-id.h:45
an EUI-48 address
Basic MAC of mesh point Wi-Fi interface.
bool SupportsSendFrom() const override
Time m_beaconInterval
Beaconing interval.
void SetLinkMetricCallback(Callback< uint32_t, Mac48Address, Ptr< MeshWifiInterfaceMac > > cb)
Set the link metric callback.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Mac48Address m_mpAddress
Mesh point address.
void SetBeaconInterval(Time interval)
Set interval between two successive beacons.
void SwitchFrequencyChannel(uint16_t new_id)
Switch frequency channel.
void ShiftTbtt(Time shift)
Shift TBTT.
Time GetTbtt() const
Next beacon frame time.
void SetRandomStartDelay(Time interval)
Set maximum initial random delay before first beacon.
bool CanForwardPacketsTo(Mac48Address to) const override
Return true if packets can be forwarded to the given destination, false otherwise.
void ResetStats()
Reset statistics function.
void DoCompleteConfig() override
Allow subclasses to complete the configuration of the MAC layer components.
void ConfigureContentionWindow(uint32_t cwMin, uint32_t cwMax) override
void SendManagementFrame(Ptr< Packet > frame, const WifiMacHeader &hdr)
To be used by plugins sending management frames.
Callback< uint32_t, Mac48Address, Ptr< MeshWifiInterfaceMac > > m_linkMetricCallback
linkMetricCallback
EventId m_beaconSendEvent
"Timer" for the next beacon
void InstallPlugin(Ptr< MeshWifiInterfaceMacPlugin > plugin)
Install plugin.
void ScheduleNextBeacon()
Schedule next beacon.
uint32_t GetLinkMetric(Mac48Address peerAddress)
Get the link metric.
uint16_t GetFrequencyChannel() const
Current channel Id.
void SetBeaconGeneration(bool enable)
Enable/disable beacons.
void DoInitialize() override
Initialize() implementation.
bool GetBeaconGeneration() const
Get current beaconing status.
AllSupportedRates GetSupportedRates() const
Get supported rates.
void SetMeshPointAddress(Mac48Address addr)
Set the mesh point address.
Mac48Address GetMeshPointAddress() const
Get the mesh point address.
void Report(std::ostream &os) const
Report statistics.
Time GetBeaconInterval() const
Get beacon interval.
void Receive(Ptr< const WifiMpdu > mpdu, uint8_t linkId) override
Frame receive handler.
void SetLinkUpCallback(Callback< void > linkUp) override
void Enqueue(Ptr< WifiMpdu > mpdu, Mac48Address to, Mac48Address from) override
Time m_randomStart
Maximum delay before first beacon.
static TypeId GetTypeId()
Get the type ID.
PluginList m_plugins
List of all installed plugins.
bool CheckSupportedRates(AllSupportedRates rates) const
Check supported rates.
std::vector< Ptr< MeshWifiInterfaceMacPlugin > > PluginList
PluginList typedef.
Ptr< UniformRandomVariable > m_coefficient
Add randomness to beacon generation.
Time m_tbtt
Time for the next frame.
void DoDispose() override
Real d-tor.
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
Implements the IEEE 802.11 MAC header.
base class for all MAC-level wifi objects.
Definition wifi-mac.h:89
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Struct containing all supported rates.
void Print(std::ostream &os) const
Print statistics.