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