author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Fri, 14 Aug 2009 12:21:39 +0200 | |
changeset 4720 | 15221757964f |
parent 4687 | 02bf728f7e39 |
child 5524 | efed7493f2c1 |
permissions | -rw-r--r-- |
4408 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2006, 2009 INRIA |
|
4 |
* Copyright (c) 2009 MIRKO BANCHI |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License version 2 as |
|
8 |
* published by the Free Software Foundation; |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
* |
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
20 |
* Author: Mirko Banchi <mk.banchi@gmail.com> |
|
21 |
*/ |
|
22 |
#include "ns3/assert.h" |
|
23 |
#include "ns3/log.h" |
|
24 |
#include "ns3/simulator.h" |
|
25 |
#include "ns3/string.h" |
|
26 |
#include "ns3/pointer.h" |
|
27 |
||
28 |
#include "qos-tag.h" |
|
29 |
#include "qap-wifi-mac.h" |
|
30 |
#include "dca-txop.h" |
|
31 |
#include "edca-txop-n.h" |
|
32 |
#include "wifi-phy.h" |
|
33 |
#include "dcf-manager.h" |
|
34 |
#include "mac-rx-middle.h" |
|
35 |
#include "mac-tx-middle.h" |
|
36 |
#include "mgt-headers.h" |
|
37 |
#include "mac-low.h" |
|
38 |
#include "amsdu-subframe-header.h" |
|
39 |
#include "msdu-aggregator.h" |
|
40 |
||
41 |
NS_LOG_COMPONENT_DEFINE ("QapWifiMac"); |
|
42 |
||
43 |
namespace ns3 { |
|
44 |
||
45 |
NS_OBJECT_ENSURE_REGISTERED (QapWifiMac); |
|
46 |
||
47 |
TypeId |
|
48 |
QapWifiMac::GetTypeId (void) |
|
49 |
{ |
|
50 |
static TypeId tid = TypeId ("ns3::QapWifiMac") |
|
51 |
.SetParent<WifiMac> () |
|
52 |
.AddConstructor<QapWifiMac> () |
|
53 |
.AddAttribute ("BeaconInterval", "Delay between two beacons", |
|
54 |
TimeValue (Seconds (0.1)), |
|
55 |
MakeTimeAccessor (&QapWifiMac::GetBeaconInterval, |
|
56 |
&QapWifiMac::SetBeaconInterval), |
|
57 |
MakeTimeChecker ()) |
|
58 |
.AddAttribute ("BeaconGeneration", "Whether or not beacons are generated.", |
|
59 |
BooleanValue (true), |
|
60 |
MakeBooleanAccessor (&QapWifiMac::SetBeaconGeneration, |
|
61 |
&QapWifiMac::GetBeaconGeneration), |
|
62 |
MakeBooleanChecker ()) |
|
63 |
.AddAttribute ("VO_EdcaTxopN", |
|
64 |
"Queue that manages packets belonging to AC_VO access class", |
|
65 |
PointerValue (), |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
66 |
MakePointerAccessor(&QapWifiMac::GetVOQueue), |
4408 | 67 |
MakePointerChecker<EdcaTxopN> ()) |
68 |
.AddAttribute ("VI_EdcaTxopN", |
|
69 |
"Queue that manages packets belonging to AC_VI access class", |
|
70 |
PointerValue (), |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
71 |
MakePointerAccessor(&QapWifiMac::GetVIQueue), |
4408 | 72 |
MakePointerChecker<EdcaTxopN> ()) |
73 |
.AddAttribute ("BE_EdcaTxopN", |
|
74 |
"Queue that manages packets belonging to AC_BE access class", |
|
75 |
PointerValue (), |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
76 |
MakePointerAccessor(&QapWifiMac::GetBEQueue), |
4408 | 77 |
MakePointerChecker<EdcaTxopN> ()) |
78 |
.AddAttribute ("BK_EdcaTxopN", |
|
79 |
"Queue that manages packets belonging to AC_BK access class", |
|
80 |
PointerValue (), |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
81 |
MakePointerAccessor(&QapWifiMac::GetBKQueue), |
4408 | 82 |
MakePointerChecker<EdcaTxopN> ()) |
83 |
; |
|
84 |
return tid; |
|
85 |
} |
|
86 |
||
87 |
QapWifiMac::QapWifiMac () |
|
88 |
{ |
|
89 |
NS_LOG_FUNCTION (this); |
|
90 |
m_rxMiddle = new MacRxMiddle (); |
|
91 |
m_rxMiddle->SetForwardCallback (MakeCallback (&QapWifiMac::Receive, this)); |
|
92 |
||
93 |
m_txMiddle = new MacTxMiddle (); |
|
94 |
||
95 |
m_low = CreateObject<MacLow> (); |
|
96 |
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle)); |
|
97 |
||
98 |
m_dcfManager = new DcfManager (); |
|
99 |
m_dcfManager->SetupLowListener (m_low); |
|
100 |
||
101 |
m_beaconDca = CreateObject<DcaTxop> (); |
|
102 |
m_beaconDca->SetAifsn(1); |
|
103 |
m_beaconDca->SetMinCw(0); |
|
104 |
m_beaconDca->SetMaxCw(0); |
|
105 |
m_beaconDca->SetLow (m_low); |
|
106 |
m_beaconDca->SetManager (m_dcfManager); |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
107 |
|
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
108 |
SetQueue (AC_VO); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
109 |
SetQueue (AC_VI); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
110 |
SetQueue (AC_BE); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
111 |
SetQueue (AC_BK); |
4408 | 112 |
} |
113 |
||
114 |
QapWifiMac::~QapWifiMac () |
|
115 |
{ |
|
116 |
NS_LOG_FUNCTION (this); |
|
117 |
} |
|
118 |
||
119 |
void |
|
120 |
QapWifiMac::DoDispose () |
|
121 |
{ |
|
122 |
delete m_rxMiddle; |
|
4687
02bf728f7e39
bug 381: Wifi crashes on shutdown
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4461
diff
changeset
|
123 |
delete m_txMiddle; |
02bf728f7e39
bug 381: Wifi crashes on shutdown
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4461
diff
changeset
|
124 |
delete m_dcfManager; |
02bf728f7e39
bug 381: Wifi crashes on shutdown
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4461
diff
changeset
|
125 |
m_low->Dispose (); |
4408 | 126 |
m_rxMiddle = 0; |
127 |
m_txMiddle = 0; |
|
128 |
m_dcfManager = 0; |
|
129 |
m_low = 0; |
|
130 |
m_phy = 0; |
|
131 |
m_beaconDca = 0; |
|
132 |
m_beaconEvent.Cancel (); |
|
133 |
m_stationManager = 0; |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
134 |
for (Queues::iterator i = m_queues.begin (); i != m_queues.end (); ++i) |
4408 | 135 |
{ |
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
136 |
(*i).second = 0; |
4408 | 137 |
} |
138 |
WifiMac::DoDispose (); |
|
139 |
} |
|
140 |
||
141 |
void |
|
142 |
QapWifiMac::SetBeaconGeneration (bool enable) |
|
143 |
{ |
|
144 |
NS_LOG_FUNCTION (this << enable); |
|
145 |
if (enable) |
|
146 |
{ |
|
147 |
m_beaconEvent = Simulator::ScheduleNow (&QapWifiMac::SendOneBeacon, this); |
|
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
m_beaconEvent.Cancel (); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
bool |
|
156 |
QapWifiMac::GetBeaconGeneration (void) const |
|
157 |
{ |
|
158 |
return m_beaconEvent.IsRunning (); |
|
159 |
} |
|
160 |
||
161 |
Time |
|
162 |
QapWifiMac::GetBeaconInterval (void) const |
|
163 |
{ |
|
164 |
return m_beaconInterval; |
|
165 |
} |
|
166 |
||
167 |
void |
|
168 |
QapWifiMac::SetSlot (Time slotTime) |
|
169 |
{ |
|
170 |
NS_LOG_FUNCTION (this << slotTime); |
|
171 |
m_dcfManager->SetSlot (slotTime); |
|
172 |
m_low->SetSlotTime (slotTime); |
|
173 |
} |
|
174 |
||
175 |
void |
|
176 |
QapWifiMac::SetSifs (Time sifs) |
|
177 |
{ |
|
178 |
NS_LOG_FUNCTION (this << sifs); |
|
179 |
m_dcfManager->SetSifs (sifs); |
|
180 |
m_low->SetSifs (sifs); |
|
181 |
} |
|
182 |
||
183 |
void |
|
184 |
QapWifiMac::SetEifsNoDifs (Time eifsNoDifs) |
|
185 |
{ |
|
186 |
NS_LOG_FUNCTION (this << eifsNoDifs); |
|
187 |
m_dcfManager->SetEifsNoDifs (eifsNoDifs); |
|
188 |
} |
|
189 |
||
190 |
void |
|
191 |
QapWifiMac::SetAckTimeout (Time ackTimeout) |
|
192 |
{ |
|
193 |
m_low->SetAckTimeout (ackTimeout); |
|
194 |
} |
|
195 |
||
196 |
void |
|
197 |
QapWifiMac::SetCtsTimeout (Time ctsTimeout) |
|
198 |
{ |
|
199 |
m_low->SetCtsTimeout (ctsTimeout); |
|
200 |
} |
|
201 |
||
202 |
void |
|
203 |
QapWifiMac::SetPifs (Time pifs) |
|
204 |
{ |
|
205 |
m_low->SetPifs (pifs); |
|
206 |
} |
|
207 |
||
208 |
Time |
|
209 |
QapWifiMac::GetSlot (void) const |
|
210 |
{ |
|
211 |
return m_low->GetSlotTime (); |
|
212 |
} |
|
213 |
||
214 |
Time |
|
215 |
QapWifiMac::GetSifs (void) const |
|
216 |
{ |
|
217 |
return m_low->GetSifs (); |
|
218 |
} |
|
219 |
||
220 |
Time |
|
221 |
QapWifiMac::GetEifsNoDifs (void) const |
|
222 |
{ |
|
4461
ab9b58d664d7
move GetEifsNoDifs to DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4424
diff
changeset
|
223 |
return m_dcfManager->GetEifsNoDifs (); |
4408 | 224 |
} |
225 |
||
226 |
Time |
|
227 |
QapWifiMac::GetAckTimeout (void) const |
|
228 |
{ |
|
229 |
return m_low->GetAckTimeout (); |
|
230 |
} |
|
231 |
||
232 |
Time |
|
233 |
QapWifiMac::GetCtsTimeout (void) const |
|
234 |
{ |
|
235 |
return m_low->GetCtsTimeout (); |
|
236 |
} |
|
237 |
||
238 |
Time |
|
239 |
QapWifiMac::GetPifs (void) const |
|
240 |
{ |
|
241 |
return m_low->GetPifs (); |
|
242 |
} |
|
243 |
||
244 |
void |
|
245 |
QapWifiMac::SetWifiPhy (Ptr<WifiPhy> phy) |
|
246 |
{ |
|
247 |
NS_LOG_FUNCTION (this << phy); |
|
248 |
m_phy = phy; |
|
249 |
m_dcfManager->SetupPhyListener (phy); |
|
250 |
m_low->SetPhy (phy); |
|
251 |
} |
|
252 |
||
253 |
void |
|
254 |
QapWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) |
|
255 |
{ |
|
256 |
NS_LOG_FUNCTION (this << stationManager); |
|
257 |
m_stationManager = stationManager; |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
258 |
for (Queues::iterator i = m_queues.begin (); i != m_queues.end (); ++i) |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
259 |
{ |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
260 |
(*i).second->SetWifiRemoteStationManager (stationManager); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
261 |
} |
4408 | 262 |
m_beaconDca->SetWifiRemoteStationManager (stationManager); |
263 |
m_low->SetWifiRemoteStationManager (stationManager); |
|
264 |
} |
|
265 |
||
266 |
void |
|
267 |
QapWifiMac::SetForwardUpCallback (Callback<void, Ptr<Packet>, Mac48Address, Mac48Address> upCallback) |
|
268 |
{ |
|
269 |
NS_LOG_FUNCTION (this); |
|
270 |
m_forwardUp = upCallback; |
|
271 |
} |
|
272 |
||
273 |
void |
|
274 |
QapWifiMac::SetLinkUpCallback (Callback<void> linkUp) |
|
275 |
{ |
|
276 |
NS_LOG_FUNCTION (this); |
|
277 |
if (!linkUp.IsNull ()) |
|
278 |
{ |
|
279 |
linkUp (); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
void |
|
284 |
QapWifiMac::SetLinkDownCallback (Callback<void> linkDown) |
|
285 |
{ |
|
286 |
NS_LOG_FUNCTION (this); |
|
287 |
} |
|
288 |
||
289 |
Mac48Address |
|
290 |
QapWifiMac::GetAddress () const |
|
291 |
{ |
|
292 |
return m_low->GetAddress (); |
|
293 |
} |
|
294 |
||
295 |
Ssid |
|
296 |
QapWifiMac::GetSsid (void) const |
|
297 |
{ |
|
298 |
return m_ssid; |
|
299 |
} |
|
300 |
||
301 |
void |
|
302 |
QapWifiMac::SetAddress (Mac48Address address) |
|
303 |
{ |
|
304 |
NS_LOG_FUNCTION (address); |
|
305 |
m_low->SetAddress (address); |
|
306 |
m_low->SetBssid (address); |
|
307 |
} |
|
308 |
||
309 |
void |
|
310 |
QapWifiMac::SetSsid (Ssid ssid) |
|
311 |
{ |
|
312 |
NS_LOG_FUNCTION (this << ssid); |
|
313 |
m_ssid = ssid; |
|
314 |
} |
|
315 |
||
316 |
Mac48Address |
|
317 |
QapWifiMac::GetBssid (void) const |
|
318 |
{ |
|
319 |
return m_low->GetBssid (); |
|
320 |
} |
|
321 |
||
322 |
void |
|
323 |
QapWifiMac::SetBeaconInterval (Time interval) |
|
324 |
{ |
|
325 |
NS_LOG_FUNCTION (this << interval); |
|
326 |
m_beaconInterval = interval; |
|
327 |
} |
|
328 |
||
329 |
void |
|
330 |
QapWifiMac::StartBeaconing (void) |
|
331 |
{ |
|
332 |
NS_LOG_FUNCTION (this); |
|
333 |
SendOneBeacon (); |
|
334 |
} |
|
335 |
||
336 |
void |
|
337 |
QapWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to) |
|
338 |
{ |
|
339 |
NS_LOG_FUNCTION (this << packet << from); |
|
340 |
m_forwardUp (packet, from, to); |
|
341 |
} |
|
342 |
||
343 |
void |
|
344 |
QapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to) |
|
345 |
{ |
|
346 |
/* For now Qos AP sends only Qos frame. In the future it should be able to |
|
347 |
send frames also to Non-Qos Stas. |
|
348 |
*/ |
|
349 |
NS_LOG_FUNCTION (this << packet << from << to); |
|
350 |
WifiMacHeader hdr; |
|
351 |
hdr.SetType (WIFI_MAC_QOSDATA); |
|
352 |
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK); |
|
353 |
hdr.SetQosNoEosp (); |
|
354 |
hdr.SetQosNoAmsdu (); |
|
355 |
/* Transmission of multiple frames in the same |
|
356 |
Txop is not supported for now */ |
|
357 |
hdr.SetQosTxopLimit (0); |
|
358 |
||
359 |
hdr.SetAddr1 (to); |
|
360 |
hdr.SetAddr2 (GetAddress ()); |
|
361 |
hdr.SetAddr3 (from); |
|
362 |
hdr.SetDsFrom (); |
|
363 |
hdr.SetDsNotTo (); |
|
364 |
||
365 |
uint8_t tid = QosUtilsGetTidForPacket (packet); |
|
366 |
if (tid < 8) |
|
367 |
{ |
|
368 |
hdr.SetQosTid (tid); |
|
369 |
AccessClass ac = QosUtilsMapTidToAc (tid); |
|
370 |
m_queues[ac]->Queue (packet, hdr); |
|
371 |
} |
|
372 |
else |
|
373 |
{ |
|
374 |
//packet is considerated belonging to BestEffort AC |
|
375 |
hdr.SetQosTid (0); |
|
376 |
m_queues[AC_BE]->Queue (packet, hdr); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
void |
|
381 |
QapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to, |
|
382 |
WifiMacHeader const *oldHdr) |
|
383 |
{ |
|
384 |
/* For now Qos AP sends only Qos frame. In the future it should be able to |
|
385 |
send frames also to Non-Qos Stas. |
|
386 |
*/ |
|
387 |
NS_LOG_FUNCTION (this << packet << from << to); |
|
388 |
NS_ASSERT (oldHdr->IsQosData ()); |
|
389 |
WifiMacHeader hdr; |
|
390 |
hdr.SetType (WIFI_MAC_QOSDATA); |
|
391 |
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK); |
|
392 |
hdr.SetQosNoEosp (); |
|
393 |
hdr.SetQosNoAmsdu (); |
|
394 |
/* Transmission of multiple frames in the same |
|
395 |
Txop is not supported for now */ |
|
396 |
hdr.SetQosTxopLimit (0); |
|
397 |
hdr.SetQosTid (oldHdr->GetQosTid ()); |
|
398 |
||
399 |
hdr.SetAddr1 (to); |
|
400 |
hdr.SetAddr2 (GetAddress ()); |
|
401 |
hdr.SetAddr3 (from); |
|
402 |
hdr.SetDsFrom (); |
|
403 |
hdr.SetDsNotTo (); |
|
404 |
||
405 |
AccessClass ac = QosUtilsMapTidToAc (oldHdr->GetQosTid ()); |
|
406 |
m_queues[ac]->Queue (packet, hdr); |
|
407 |
} |
|
408 |
||
409 |
void |
|
410 |
QapWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from) |
|
411 |
{ |
|
412 |
NS_LOG_FUNCTION (this << packet << from << to); |
|
413 |
ForwardDown (packet, from, to); |
|
414 |
} |
|
415 |
||
416 |
void |
|
417 |
QapWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to) |
|
418 |
{ |
|
419 |
NS_LOG_FUNCTION (this << packet << to); |
|
420 |
ForwardDown (packet, m_low->GetAddress (), to); |
|
421 |
} |
|
422 |
||
423 |
bool |
|
424 |
QapWifiMac::SupportsSendFrom (void) const |
|
425 |
{ |
|
426 |
return true; |
|
427 |
} |
|
428 |
||
429 |
SupportedRates |
|
430 |
QapWifiMac::GetSupportedRates (void) const |
|
431 |
{ |
|
432 |
// send the set of supported rates and make sure that we indicate |
|
433 |
// the Basic Rate set in this set of supported rates. |
|
434 |
SupportedRates rates; |
|
435 |
for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
|
436 |
{ |
|
437 |
WifiMode mode = m_phy->GetMode (i); |
|
438 |
rates.AddSupportedRate (mode.GetDataRate ()); |
|
439 |
} |
|
440 |
// set the basic rates |
|
441 |
for (uint32_t j = 0; j < m_stationManager->GetNBasicModes (); j++) |
|
442 |
{ |
|
443 |
WifiMode mode = m_stationManager->GetBasicMode (j); |
|
444 |
rates.SetBasicRate (mode.GetDataRate ()); |
|
445 |
} |
|
446 |
return rates; |
|
447 |
} |
|
448 |
||
449 |
void |
|
450 |
QapWifiMac::SendProbeResp (Mac48Address to) |
|
451 |
{ |
|
452 |
NS_LOG_FUNCTION (this << to); |
|
453 |
WifiMacHeader hdr; |
|
454 |
hdr.SetProbeResp (); |
|
455 |
hdr.SetAddr1 (to); |
|
456 |
hdr.SetAddr2 (GetAddress ()); |
|
457 |
hdr.SetAddr3 (GetAddress ()); |
|
458 |
hdr.SetDsNotFrom (); |
|
459 |
hdr.SetDsNotTo (); |
|
460 |
Ptr<Packet> packet = Create<Packet> (); |
|
461 |
MgtProbeResponseHeader probe; |
|
462 |
probe.SetSsid (GetSsid ()); |
|
463 |
probe.SetSupportedRates (GetSupportedRates ()); |
|
464 |
probe.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ()); |
|
465 |
packet->AddHeader (probe); |
|
466 |
||
467 |
/* Which is correct queue for management frames ? */ |
|
468 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
469 |
} |
|
470 |
||
471 |
void |
|
472 |
QapWifiMac::SendAssocResp (Mac48Address to, bool success) |
|
473 |
{ |
|
474 |
NS_LOG_FUNCTION (this << to << success); |
|
475 |
WifiMacHeader hdr; |
|
476 |
hdr.SetAssocResp (); |
|
477 |
hdr.SetAddr1 (to); |
|
478 |
hdr.SetAddr2 (GetAddress ()); |
|
479 |
hdr.SetAddr3 (GetAddress ()); |
|
480 |
hdr.SetDsNotFrom (); |
|
481 |
hdr.SetDsNotTo (); |
|
482 |
Ptr<Packet> packet = Create<Packet> (); |
|
483 |
MgtAssocResponseHeader assoc; |
|
484 |
StatusCode code; |
|
485 |
if (success) |
|
486 |
{ |
|
487 |
code.SetSuccess (); |
|
488 |
} |
|
489 |
else |
|
490 |
{ |
|
491 |
code.SetFailure (); |
|
492 |
} |
|
493 |
assoc.SetSupportedRates (GetSupportedRates ()); |
|
494 |
assoc.SetStatusCode (code); |
|
495 |
packet->AddHeader (assoc); |
|
496 |
||
497 |
/* Which is correct queue for management frames ? */ |
|
498 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
499 |
} |
|
500 |
||
501 |
void |
|
502 |
QapWifiMac::SendOneBeacon (void) |
|
503 |
{ |
|
504 |
NS_LOG_FUNCTION (this); |
|
505 |
WifiMacHeader hdr; |
|
506 |
hdr.SetBeacon (); |
|
507 |
hdr.SetAddr1 (Mac48Address::GetBroadcast ()); |
|
508 |
hdr.SetAddr2 (GetAddress ()); |
|
509 |
hdr.SetAddr3 (GetAddress ()); |
|
510 |
hdr.SetDsNotFrom (); |
|
511 |
hdr.SetDsNotTo (); |
|
512 |
Ptr<Packet> packet = Create<Packet> (); |
|
513 |
MgtBeaconHeader beacon; |
|
514 |
beacon.SetSsid (GetSsid ()); |
|
515 |
beacon.SetSupportedRates (GetSupportedRates ()); |
|
516 |
beacon.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ()); |
|
517 |
||
518 |
packet->AddHeader (beacon); |
|
519 |
||
520 |
m_beaconDca->Queue (packet, hdr); |
|
521 |
m_beaconEvent = Simulator::Schedule (m_beaconInterval, &QapWifiMac::SendOneBeacon, this); |
|
522 |
} |
|
523 |
||
524 |
void |
|
525 |
QapWifiMac::TxOk (WifiMacHeader const &hdr) |
|
526 |
{ |
|
527 |
NS_LOG_FUNCTION (this); |
|
528 |
WifiRemoteStation *station = m_stationManager->Lookup (hdr.GetAddr1 ()); |
|
529 |
if (hdr.IsAssocResp () && |
|
530 |
station->IsWaitAssocTxOk ()) |
|
531 |
{ |
|
532 |
NS_LOG_DEBUG ("associated with sta="<<hdr.GetAddr1 ()); |
|
533 |
station->RecordGotAssocTxOk (); |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
void |
|
538 |
QapWifiMac::TxFailed (WifiMacHeader const &hdr) |
|
539 |
{ |
|
540 |
NS_LOG_FUNCTION (this); |
|
541 |
WifiRemoteStation *station = m_stationManager->Lookup (hdr.GetAddr1 ()); |
|
542 |
if (hdr.IsAssocResp () && |
|
543 |
station->IsWaitAssocTxOk ()) |
|
544 |
{ |
|
545 |
NS_LOG_DEBUG ("assoc failed with sta="<<hdr.GetAddr1 ()); |
|
546 |
station->RecordGotAssocTxFailed (); |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
void |
|
551 |
QapWifiMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr) |
|
552 |
{ |
|
553 |
NS_LOG_FUNCTION (this << packet << hdr); |
|
554 |
||
555 |
Mac48Address from = hdr->GetAddr2 (); |
|
556 |
WifiRemoteStation *fromStation = m_stationManager->Lookup (from); |
|
557 |
||
558 |
if (hdr->IsData ()) |
|
559 |
{ |
|
560 |
Mac48Address bssid = hdr->GetAddr1 (); |
|
561 |
if (!hdr->IsFromDs () && |
|
562 |
hdr->IsToDs () && |
|
563 |
bssid == GetAddress () && |
|
564 |
fromStation->IsAssociated ()) |
|
565 |
{ |
|
566 |
Mac48Address to = hdr->GetAddr3 (); |
|
567 |
WifiRemoteStation *toStation = m_stationManager->Lookup (to); |
|
568 |
||
569 |
if (to == GetAddress ()) |
|
570 |
{ |
|
571 |
NS_LOG_DEBUG ("frame for me (Qap) from="<<from); |
|
572 |
if (hdr->IsQosData ()) |
|
573 |
{ |
|
574 |
if (hdr->IsQosAmsdu ()) |
|
575 |
{ |
|
576 |
NS_LOG_DEBUG ("Received A-MSDU from="<<from<<", size="<<packet->GetSize ()); |
|
577 |
DeaggregateAmsduAndForward (packet, hdr); |
|
578 |
packet = 0; |
|
579 |
} |
|
580 |
else |
|
581 |
{ |
|
582 |
ForwardUp (packet, from, bssid); |
|
583 |
} |
|
584 |
} |
|
585 |
else |
|
586 |
{ |
|
587 |
ForwardUp (packet, from, bssid); |
|
588 |
} |
|
589 |
} |
|
4424
af26433b13bc
remove Mac48Address::IsMulticast
Fabian Mauchle <f1mauchl@hsr.ch>
parents:
4408
diff
changeset
|
590 |
else if (to.IsGroup () || |
4408 | 591 |
toStation->IsAssociated ()) |
592 |
{ |
|
593 |
NS_LOG_DEBUG ("forwarding frame from="<<from<<", to="<<to); |
|
594 |
Ptr<Packet> copy = packet->Copy (); |
|
595 |
ForwardDown (packet, from, to, hdr); |
|
596 |
ForwardUp (copy, from, to); |
|
597 |
} |
|
598 |
else |
|
599 |
{ |
|
600 |
ForwardUp (packet, from, to); |
|
601 |
} |
|
602 |
} |
|
603 |
else if (hdr->IsFromDs () && |
|
604 |
hdr->IsToDs ()) |
|
605 |
{ |
|
606 |
// this is an AP-to-AP frame |
|
607 |
// we ignore for now. |
|
608 |
} |
|
609 |
else |
|
610 |
{ |
|
611 |
// we can ignore these frames since |
|
612 |
// they are not targeted at the AP |
|
613 |
} |
|
614 |
} |
|
615 |
else if (hdr->IsMgt ()) |
|
616 |
{ |
|
617 |
if (hdr->IsProbeReq ()) |
|
618 |
{ |
|
619 |
NS_ASSERT (hdr->GetAddr1 ().IsBroadcast ()); |
|
620 |
SendProbeResp (hdr->GetAddr2 ()); |
|
621 |
} |
|
622 |
else if (hdr->GetAddr1 () == GetAddress ()) |
|
623 |
{ |
|
624 |
if (hdr->IsAssocReq ()) |
|
625 |
{ |
|
626 |
// first, verify that the the station's supported |
|
627 |
// rate set is compatible with our Basic Rate set |
|
628 |
MgtAssocRequestHeader assocReq; |
|
629 |
packet->RemoveHeader (assocReq); |
|
630 |
SupportedRates rates = assocReq.GetSupportedRates (); |
|
631 |
bool problem = false; |
|
632 |
for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++) |
|
633 |
{ |
|
634 |
WifiMode mode = m_stationManager->GetBasicMode (i); |
|
635 |
if (!rates.IsSupportedRate (mode.GetDataRate ())) |
|
636 |
{ |
|
637 |
problem = true; |
|
638 |
break; |
|
639 |
} |
|
640 |
} |
|
641 |
if (problem) |
|
642 |
{ |
|
643 |
// one of the Basic Rate set mode is not |
|
644 |
// supported by the station. So, we return an assoc |
|
645 |
// response with an error status. |
|
646 |
SendAssocResp (hdr->GetAddr2 (), false); |
|
647 |
} |
|
648 |
else |
|
649 |
{ |
|
650 |
// station supports all rates in Basic Rate Set. |
|
651 |
// record all its supported modes in its associated WifiRemoteStation |
|
652 |
for (uint32_t j = 0; j < m_phy->GetNModes (); j++) |
|
653 |
{ |
|
654 |
WifiMode mode = m_phy->GetMode (j); |
|
655 |
if (rates.IsSupportedRate (mode.GetDataRate ())) |
|
656 |
{ |
|
657 |
fromStation->AddSupportedMode (mode); |
|
658 |
} |
|
659 |
} |
|
660 |
fromStation->RecordWaitAssocTxOk (); |
|
661 |
// send assoc response with success status. |
|
662 |
SendAssocResp (hdr->GetAddr2 (), true); |
|
663 |
} |
|
664 |
} |
|
665 |
else if (hdr->IsDisassociation ()) |
|
666 |
{ |
|
667 |
fromStation->RecordDisassociated (); |
|
668 |
} |
|
669 |
else if (hdr->IsReassocReq ()) |
|
670 |
{ |
|
671 |
/* we don't support reassoc frames for now */ |
|
672 |
} |
|
673 |
else if (hdr->IsAuthentication () || |
|
674 |
hdr->IsDeauthentication ()) |
|
675 |
{ |
|
676 |
/* |
|
677 |
*/ |
|
678 |
} |
|
679 |
else |
|
680 |
{ |
|
681 |
/* unknown mgt frame |
|
682 |
*/ |
|
683 |
} |
|
684 |
} |
|
685 |
} |
|
686 |
} |
|
687 |
||
688 |
void |
|
689 |
QapWifiMac::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr) |
|
690 |
{ |
|
691 |
DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket); |
|
692 |
for (DeaggregatedMsdusCI i = packets.begin (); i != packets.end (); ++i) |
|
693 |
{ |
|
694 |
if ((*i).second.GetDestinationAddr () == GetAddress ()) |
|
695 |
{ |
|
696 |
ForwardUp ((*i).first, (*i).second.GetSourceAddr (), |
|
697 |
(*i).second.GetDestinationAddr ()); |
|
698 |
} |
|
699 |
else |
|
700 |
{ |
|
701 |
Mac48Address from = (*i).second.GetSourceAddr (); |
|
702 |
Mac48Address to = (*i).second.GetDestinationAddr (); |
|
703 |
NS_LOG_DEBUG ("forwarding QoS frame from="<<from<<", to="<<to); |
|
704 |
ForwardDown ((*i).first, from, to, hdr); |
|
705 |
} |
|
706 |
} |
|
707 |
} |
|
708 |
||
709 |
Ptr<EdcaTxopN> |
|
710 |
QapWifiMac::GetVOQueue (void) const |
|
711 |
{ |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
712 |
return m_queues.find (AC_VO)->second; |
4408 | 713 |
} |
714 |
||
715 |
Ptr<EdcaTxopN> |
|
716 |
QapWifiMac::GetVIQueue (void) const |
|
717 |
{ |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
718 |
return m_queues.find (AC_VI)->second; |
4408 | 719 |
} |
720 |
||
721 |
Ptr<EdcaTxopN> |
|
722 |
QapWifiMac::GetBEQueue (void) const |
|
723 |
{ |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
724 |
return m_queues.find (AC_BE)->second; |
4408 | 725 |
} |
726 |
||
727 |
Ptr<EdcaTxopN> |
|
728 |
QapWifiMac::GetBKQueue (void) const |
|
729 |
{ |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
730 |
return m_queues.find (AC_BK)->second; |
4408 | 731 |
} |
732 |
||
733 |
void |
|
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
734 |
QapWifiMac::SetQueue (enum AccessClass ac) |
4408 | 735 |
{ |
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
736 |
Ptr<EdcaTxopN> edca = CreateObject<EdcaTxopN> (); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
737 |
edca->SetLow (m_low); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
738 |
edca->SetManager (m_dcfManager); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
739 |
edca->SetTypeOfStation (AP); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
740 |
edca->SetTxMiddle (m_txMiddle); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
741 |
edca->SetTxOkCallback (MakeCallback (&QapWifiMac::TxOk, this)); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
742 |
edca->SetTxFailedCallback (MakeCallback (&QapWifiMac::TxFailed, this)); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
743 |
m_queues.insert (std::make_pair(ac, edca)); |
4408 | 744 |
} |
745 |
||
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
746 |
void |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
747 |
QapWifiMac::FinishConfigureStandard (enum WifiPhyStandard standard) |
4408 | 748 |
{ |
4720
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
749 |
switch (standard) |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
750 |
{ |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
751 |
case WIFI_PHY_STANDARD_holland: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
752 |
// fall through |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
753 |
case WIFI_PHY_STANDARD_80211a: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
754 |
// fall through |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
755 |
case WIFI_PHY_STANDARD_80211_10Mhz: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
756 |
// fall through |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
757 |
case WIFI_PHY_STANDARD_80211_5Mhz: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
758 |
ConfigureDcf (m_queues[AC_BK], 15, 1023, AC_BK); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
759 |
ConfigureDcf (m_queues[AC_BE], 15, 1023, AC_BE); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
760 |
ConfigureDcf (m_queues[AC_VI], 15, 1023, AC_VI); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
761 |
ConfigureDcf (m_queues[AC_VO], 15, 1023, AC_VO); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
762 |
break; |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
763 |
case WIFI_PHY_STANDARD_80211b: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
764 |
ConfigureDcf (m_queues[AC_BK], 31, 1023, AC_BK); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
765 |
ConfigureDcf (m_queues[AC_BE], 31, 1023, AC_BE); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
766 |
ConfigureDcf (m_queues[AC_VI], 31, 1023, AC_VI); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
767 |
ConfigureDcf (m_queues[AC_VO], 31, 1023, AC_VO); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
768 |
break; |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
769 |
default: |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
770 |
NS_ASSERT (false); |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
771 |
break; |
15221757964f
bug 641: CwMin setting for 802.11b
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4687
diff
changeset
|
772 |
} |
4408 | 773 |
} |
774 |
||
775 |
} //namespace ns3 |