author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 16 Jul 2009 12:31:26 +0200 | |
changeset 4687 | 02bf728f7e39 |
parent 4609 | 6ec902d6af68 |
child 4720 | 15221757964f |
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/log.h" |
|
23 |
#include "ns3/simulator.h" |
|
24 |
#include "ns3/string.h" |
|
25 |
#include "ns3/pointer.h" |
|
26 |
||
27 |
#include "qos-tag.h" |
|
28 |
#include "edca-txop-n.h" |
|
29 |
#include "qsta-wifi-mac.h" |
|
30 |
#include "mac-low.h" |
|
31 |
#include "dcf-manager.h" |
|
32 |
#include "mac-rx-middle.h" |
|
33 |
#include "mac-tx-middle.h" |
|
34 |
#include "wifi-mac-header.h" |
|
35 |
#include "msdu-aggregator.h" |
|
36 |
#include "amsdu-subframe-header.h" |
|
37 |
#include "mgt-headers.h" |
|
38 |
||
39 |
NS_LOG_COMPONENT_DEFINE ("QstaWifiMac"); |
|
40 |
||
41 |
namespace ns3 { |
|
42 |
||
43 |
NS_OBJECT_ENSURE_REGISTERED (QstaWifiMac); |
|
44 |
||
45 |
TypeId |
|
46 |
QstaWifiMac::GetTypeId (void) |
|
47 |
{ |
|
48 |
static TypeId tid = TypeId ("ns3::QstaWifiMac") |
|
49 |
.SetParent<WifiMac> () |
|
50 |
.AddConstructor<QstaWifiMac> () |
|
51 |
.AddAttribute ("ProbeRequestTimeout", "The interval between two consecutive probe request attempts.", |
|
52 |
TimeValue (Seconds (0.05)), |
|
53 |
MakeTimeAccessor (&QstaWifiMac::m_probeRequestTimeout), |
|
54 |
MakeTimeChecker ()) |
|
55 |
.AddAttribute ("AssocRequestTimeout", "The interval between two consecutive assoc request attempts.", |
|
56 |
TimeValue (Seconds (0.5)), |
|
57 |
MakeTimeAccessor (&QstaWifiMac::m_assocRequestTimeout), |
|
58 |
MakeTimeChecker ()) |
|
59 |
.AddAttribute ("MaxMissedBeacons", |
|
60 |
"Number of beacons which much be consecutively missed before " |
|
61 |
"we attempt to restart association.", |
|
62 |
UintegerValue (10), |
|
63 |
MakeUintegerAccessor (&QstaWifiMac::m_maxMissedBeacons), |
|
64 |
MakeUintegerChecker<uint32_t> ()) |
|
65 |
.AddAttribute ("ActiveProbing", "If true, we send probe requests. If false, we don't.", |
|
66 |
BooleanValue (false), |
|
67 |
MakeBooleanAccessor (&QstaWifiMac::SetActiveProbing), |
|
68 |
MakeBooleanChecker ()) |
|
69 |
.AddAttribute ("VO_EdcaTxopN", |
|
70 |
"Queue that manages packets belonging to AC_VO access class", |
|
71 |
PointerValue (), |
|
72 |
MakePointerAccessor(&QstaWifiMac::GetVOQueue, |
|
73 |
&QstaWifiMac::SetVOQueue), |
|
74 |
MakePointerChecker<EdcaTxopN> ()) |
|
75 |
.AddAttribute ("VI_EdcaTxopN", |
|
76 |
"Queue that manages packets belonging to AC_VI access class", |
|
77 |
PointerValue (), |
|
78 |
MakePointerAccessor(&QstaWifiMac::GetVIQueue, |
|
79 |
&QstaWifiMac::SetVIQueue), |
|
80 |
MakePointerChecker<EdcaTxopN> ()) |
|
81 |
.AddAttribute ("BE_EdcaTxopN", |
|
82 |
"Queue that manages packets belonging to AC_BE access class", |
|
83 |
PointerValue (), |
|
84 |
MakePointerAccessor(&QstaWifiMac::GetBEQueue, |
|
85 |
&QstaWifiMac::SetBEQueue), |
|
86 |
MakePointerChecker<EdcaTxopN> ()) |
|
87 |
.AddAttribute ("BK_EdcaTxopN", |
|
88 |
"Queue that manages packets belonging to AC_BK access class", |
|
89 |
PointerValue (), |
|
90 |
MakePointerAccessor(&QstaWifiMac::GetBKQueue, |
|
91 |
&QstaWifiMac::SetBKQueue), |
|
92 |
MakePointerChecker<EdcaTxopN> ()) |
|
93 |
; |
|
94 |
return tid; |
|
95 |
} |
|
96 |
||
97 |
QstaWifiMac::QstaWifiMac () |
|
98 |
: m_state (BEACON_MISSED), |
|
99 |
m_probeRequestEvent (), |
|
100 |
m_assocRequestEvent (), |
|
101 |
m_beaconWatchdogEnd (Seconds (0.0)) |
|
102 |
{ |
|
103 |
NS_LOG_FUNCTION (this); |
|
104 |
m_rxMiddle = new MacRxMiddle (); |
|
105 |
m_rxMiddle->SetForwardCallback (MakeCallback (&QstaWifiMac::Receive, this)); |
|
106 |
/*TxMiddle can be shared between all queues */ |
|
107 |
m_txMiddle= new MacTxMiddle (); |
|
108 |
||
109 |
m_low = CreateObject<MacLow> (); |
|
110 |
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle)); |
|
111 |
||
112 |
m_dcfManager = new DcfManager (); |
|
113 |
m_dcfManager->SetupLowListener (m_low); |
|
114 |
} |
|
115 |
||
116 |
QstaWifiMac::~QstaWifiMac () |
|
117 |
{ |
|
118 |
NS_LOG_FUNCTION (this); |
|
119 |
} |
|
120 |
||
121 |
void |
|
122 |
QstaWifiMac::DoDispose () |
|
123 |
{ |
|
124 |
NS_LOG_FUNCTION (this); |
|
125 |
delete m_rxMiddle; |
|
126 |
delete m_txMiddle; |
|
127 |
delete m_dcfManager; |
|
4687
02bf728f7e39
bug 381: Wifi crashes on shutdown
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4609
diff
changeset
|
128 |
m_low->Dispose (); |
4408 | 129 |
m_rxMiddle = 0; |
130 |
m_txMiddle = 0; |
|
131 |
m_low = 0; |
|
132 |
m_phy = 0; |
|
133 |
m_dcfManager = 0; |
|
134 |
m_voEdca = 0; |
|
135 |
m_viEdca = 0; |
|
136 |
m_beEdca = 0; |
|
137 |
m_bkEdca = 0; |
|
138 |
m_stationManager = 0; |
|
139 |
std::map<AccessClass, Ptr<EdcaTxopN> >::iterator it = m_queues.begin (); |
|
140 |
for (;it != m_queues.end (); it++) |
|
141 |
{ |
|
142 |
it->second = 0; |
|
143 |
} |
|
144 |
WifiMac::DoDispose (); |
|
145 |
} |
|
146 |
||
147 |
void |
|
148 |
QstaWifiMac::SetSlot (Time slotTime) |
|
149 |
{ |
|
150 |
NS_LOG_FUNCTION (this << slotTime); |
|
151 |
m_dcfManager->SetSlot (slotTime); |
|
152 |
m_low->SetSlotTime (slotTime); |
|
153 |
} |
|
154 |
||
155 |
void |
|
156 |
QstaWifiMac::SetSifs (Time sifs) |
|
157 |
{ |
|
158 |
NS_LOG_FUNCTION (this << sifs); |
|
159 |
m_dcfManager->SetSifs (sifs); |
|
160 |
m_low->SetSifs (sifs); |
|
161 |
} |
|
162 |
||
163 |
void |
|
164 |
QstaWifiMac::SetEifsNoDifs (Time eifsNoDifs) |
|
165 |
{ |
|
166 |
NS_LOG_FUNCTION (this << eifsNoDifs); |
|
167 |
m_dcfManager->SetEifsNoDifs (eifsNoDifs); |
|
168 |
} |
|
169 |
||
170 |
void |
|
171 |
QstaWifiMac::SetAckTimeout (Time ackTimeout) |
|
172 |
{ |
|
173 |
m_low->SetAckTimeout (ackTimeout); |
|
174 |
} |
|
175 |
||
176 |
void |
|
177 |
QstaWifiMac::SetCtsTimeout (Time ctsTimeout) |
|
178 |
{ |
|
179 |
m_low->SetCtsTimeout (ctsTimeout); |
|
180 |
} |
|
181 |
||
182 |
void |
|
183 |
QstaWifiMac::SetPifs (Time pifs) |
|
184 |
{ |
|
185 |
m_low->SetPifs (pifs); |
|
186 |
} |
|
187 |
||
188 |
Time |
|
189 |
QstaWifiMac::GetSlot (void) const |
|
190 |
{ |
|
191 |
return m_low->GetSlotTime (); |
|
192 |
} |
|
193 |
||
194 |
Time |
|
195 |
QstaWifiMac::GetSifs (void) const |
|
196 |
{ |
|
197 |
return m_low->GetSifs (); |
|
198 |
} |
|
199 |
||
200 |
Time |
|
201 |
QstaWifiMac::GetEifsNoDifs (void) const |
|
202 |
{ |
|
4461
ab9b58d664d7
move GetEifsNoDifs to DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4408
diff
changeset
|
203 |
return m_dcfManager->GetEifsNoDifs (); |
4408 | 204 |
} |
205 |
||
206 |
Time |
|
207 |
QstaWifiMac::GetAckTimeout (void) const |
|
208 |
{ |
|
209 |
return m_low->GetAckTimeout (); |
|
210 |
} |
|
211 |
||
212 |
Time |
|
213 |
QstaWifiMac::GetCtsTimeout (void) const |
|
214 |
{ |
|
215 |
return m_low->GetCtsTimeout (); |
|
216 |
} |
|
217 |
||
218 |
Time |
|
219 |
QstaWifiMac::GetPifs (void) const |
|
220 |
{ |
|
221 |
return m_low->GetPifs (); |
|
222 |
} |
|
223 |
||
224 |
void |
|
225 |
QstaWifiMac::SetWifiPhy (Ptr<WifiPhy> phy) |
|
226 |
{ |
|
227 |
m_phy = phy; |
|
228 |
m_dcfManager->SetupPhyListener (phy); |
|
229 |
m_low->SetPhy (phy); |
|
230 |
} |
|
231 |
||
232 |
void |
|
233 |
QstaWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) |
|
234 |
{ |
|
235 |
m_stationManager = stationManager; |
|
236 |
m_queues[AC_VO]->SetWifiRemoteStationManager (stationManager); |
|
237 |
m_queues[AC_VI]->SetWifiRemoteStationManager (stationManager); |
|
238 |
m_queues[AC_BE]->SetWifiRemoteStationManager (stationManager); |
|
239 |
m_queues[AC_BK]->SetWifiRemoteStationManager (stationManager); |
|
240 |
m_low->SetWifiRemoteStationManager (stationManager); |
|
241 |
} |
|
242 |
||
243 |
void |
|
244 |
QstaWifiMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback) |
|
245 |
{ |
|
246 |
m_forwardUp = upCallback; |
|
247 |
} |
|
248 |
||
249 |
void |
|
250 |
QstaWifiMac::SetLinkUpCallback (Callback<void> linkUp) |
|
251 |
{ |
|
252 |
m_linkUp = linkUp; |
|
253 |
} |
|
254 |
||
255 |
void |
|
256 |
QstaWifiMac::SetLinkDownCallback (Callback<void> linkDown) |
|
257 |
{ |
|
258 |
m_linkDown = linkDown; |
|
259 |
} |
|
260 |
||
261 |
Mac48Address |
|
262 |
QstaWifiMac::GetAddress (void) const |
|
263 |
{ |
|
264 |
return m_low->GetAddress (); |
|
265 |
} |
|
266 |
||
267 |
Ssid |
|
268 |
QstaWifiMac::GetSsid (void) const |
|
269 |
{ |
|
270 |
return m_ssid; |
|
271 |
} |
|
272 |
||
273 |
Mac48Address |
|
274 |
QstaWifiMac::GetBssid () const |
|
275 |
{ |
|
276 |
return m_low->GetBssid (); |
|
277 |
} |
|
278 |
||
279 |
void |
|
280 |
QstaWifiMac::SetAddress (Mac48Address address) |
|
281 |
{ |
|
282 |
NS_LOG_FUNCTION (this << address); |
|
283 |
m_low->SetAddress (address); |
|
284 |
} |
|
285 |
||
286 |
void |
|
287 |
QstaWifiMac::SetSsid (Ssid ssid) |
|
288 |
{ |
|
289 |
NS_LOG_FUNCTION (this << ssid); |
|
290 |
m_ssid = ssid; |
|
291 |
} |
|
292 |
||
293 |
void |
|
294 |
QstaWifiMac::SetMaxMissedBeacons (uint32_t missed) |
|
295 |
{ |
|
296 |
NS_LOG_FUNCTION (this << missed); |
|
297 |
m_maxMissedBeacons = missed; |
|
298 |
} |
|
299 |
||
300 |
void |
|
301 |
QstaWifiMac::SetProbeRequestTimeout (Time timeout) |
|
302 |
{ |
|
303 |
NS_LOG_FUNCTION (this << timeout); |
|
304 |
m_probeRequestTimeout = timeout; |
|
305 |
} |
|
306 |
||
307 |
void |
|
308 |
QstaWifiMac::SetAssocRequestTimeout (Time timeout) |
|
309 |
{ |
|
310 |
NS_LOG_FUNCTION (this << timeout); |
|
311 |
m_assocRequestTimeout = timeout; |
|
312 |
} |
|
313 |
||
314 |
void |
|
315 |
QstaWifiMac::StartActiveAssociation (void) |
|
316 |
{ |
|
317 |
NS_LOG_FUNCTION (this); |
|
318 |
TryToEnsureAssociated (); |
|
319 |
} |
|
320 |
||
321 |
Mac48Address |
|
322 |
QstaWifiMac::GetBroadcastBssid (void) |
|
323 |
{ |
|
324 |
return Mac48Address::GetBroadcast (); |
|
325 |
} |
|
326 |
||
327 |
void |
|
328 |
QstaWifiMac::SetBssid (Mac48Address bssid) |
|
329 |
{ |
|
330 |
NS_LOG_FUNCTION (this << bssid); |
|
331 |
m_low->SetBssid (bssid); |
|
332 |
} |
|
333 |
||
334 |
void |
|
335 |
QstaWifiMac::SetActiveProbing (bool enable) |
|
336 |
{ |
|
337 |
NS_LOG_FUNCTION (this << enable); |
|
338 |
if (enable) |
|
339 |
{ |
|
340 |
TryToEnsureAssociated (); |
|
341 |
} |
|
342 |
else |
|
343 |
{ |
|
344 |
m_probeRequestEvent.Cancel (); |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
void |
|
349 |
QstaWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to) |
|
350 |
{ |
|
351 |
NS_LOG_FUNCTION (this << packet << from << to); |
|
352 |
m_forwardUp (packet, from, to); |
|
353 |
} |
|
354 |
||
355 |
void |
|
356 |
QstaWifiMac::SendProbeRequest (void) |
|
357 |
{ |
|
358 |
NS_LOG_FUNCTION (this); |
|
359 |
WifiMacHeader hdr; |
|
360 |
hdr.SetProbeReq (); |
|
361 |
hdr.SetAddr1 (GetBroadcastBssid ()); |
|
362 |
hdr.SetAddr2 (GetAddress ()); |
|
363 |
hdr.SetAddr3 (GetBroadcastBssid ()); |
|
364 |
hdr.SetDsNotFrom (); |
|
365 |
hdr.SetDsNotTo (); |
|
366 |
Ptr<Packet> packet = Create<Packet> (); |
|
367 |
MgtProbeRequestHeader probe; |
|
368 |
probe.SetSsid (GetSsid ()); |
|
369 |
probe.SetSupportedRates (GetSupportedRates ()); |
|
370 |
packet->AddHeader (probe); |
|
371 |
||
372 |
/* Which is correct queue for management frames ? */ |
|
373 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
374 |
||
375 |
m_probeRequestEvent = Simulator::Schedule (m_probeRequestTimeout, |
|
376 |
&QstaWifiMac::ProbeRequestTimeout, this); |
|
377 |
} |
|
378 |
||
379 |
void |
|
380 |
QstaWifiMac::SendAssociationRequest (void) |
|
381 |
{ |
|
382 |
NS_LOG_FUNCTION (this << GetBssid ()); |
|
383 |
WifiMacHeader hdr; |
|
384 |
hdr.SetAssocReq (); |
|
385 |
hdr.SetAddr1 (GetBssid ()); |
|
386 |
hdr.SetAddr2 (GetAddress ()); |
|
387 |
hdr.SetAddr3 (GetBssid ()); |
|
388 |
hdr.SetDsNotFrom (); |
|
389 |
hdr.SetDsNotTo (); |
|
390 |
Ptr<Packet> packet = Create<Packet> (); |
|
391 |
MgtAssocRequestHeader assoc; |
|
392 |
assoc.SetSsid (GetSsid ()); |
|
393 |
assoc.SetSupportedRates (GetSupportedRates ()); |
|
394 |
packet->AddHeader (assoc); |
|
395 |
||
396 |
/* Which is correct queue for management frames ? */ |
|
397 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
398 |
||
399 |
m_assocRequestEvent = Simulator::Schedule (m_assocRequestTimeout, |
|
400 |
&QstaWifiMac::AssocRequestTimeout, this); |
|
401 |
} |
|
402 |
||
403 |
void |
|
404 |
QstaWifiMac::TryToEnsureAssociated (void) |
|
405 |
{ |
|
406 |
NS_LOG_FUNCTION (this); |
|
407 |
switch (m_state) { |
|
408 |
case ASSOCIATED: |
|
409 |
return; |
|
410 |
break; |
|
411 |
case WAIT_PROBE_RESP: |
|
412 |
/* we have sent a probe request earlier so we |
|
413 |
do not need to re-send a probe request immediately. |
|
414 |
We just need to wait until probe-request-timeout |
|
415 |
or until we get a probe response |
|
416 |
*/ |
|
417 |
break; |
|
418 |
case BEACON_MISSED: |
|
419 |
/* we were associated but we missed a bunch of beacons |
|
420 |
* so we should assume we are not associated anymore. |
|
421 |
* We try to initiate a probe request now. |
|
422 |
*/ |
|
423 |
m_linkDown (); |
|
424 |
m_state = WAIT_PROBE_RESP; |
|
425 |
SendProbeRequest (); |
|
426 |
break; |
|
427 |
case WAIT_ASSOC_RESP: |
|
428 |
/* we have sent an assoc request so we do not need to |
|
429 |
re-send an assoc request right now. We just need to |
|
430 |
wait until either assoc-request-timeout or until |
|
431 |
we get an assoc response. |
|
432 |
*/ |
|
433 |
break; |
|
434 |
case REFUSED: |
|
435 |
/* we have sent an assoc request and received a negative |
|
436 |
assoc resp. We wait until someone restarts an |
|
437 |
association with a given ssid. |
|
438 |
*/ |
|
439 |
break; |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
void |
|
444 |
QstaWifiMac::AssocRequestTimeout (void) |
|
445 |
{ |
|
446 |
NS_LOG_FUNCTION (this); |
|
447 |
m_state = WAIT_ASSOC_RESP; |
|
448 |
SendAssociationRequest (); |
|
449 |
} |
|
450 |
||
451 |
void |
|
452 |
QstaWifiMac::ProbeRequestTimeout (void) |
|
453 |
{ |
|
454 |
NS_LOG_FUNCTION (this); |
|
455 |
m_state = WAIT_PROBE_RESP; |
|
456 |
SendProbeRequest (); |
|
457 |
} |
|
458 |
||
459 |
void |
|
460 |
QstaWifiMac::MissedBeacons (void) |
|
461 |
{ |
|
462 |
NS_LOG_FUNCTION (this); |
|
463 |
if (m_beaconWatchdogEnd > Simulator::Now ()) |
|
464 |
{ |
|
465 |
m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (), |
|
466 |
&QstaWifiMac::MissedBeacons, this); |
|
467 |
return; |
|
468 |
} |
|
469 |
NS_LOG_DEBUG ("beacon missed"); |
|
470 |
m_state = BEACON_MISSED; |
|
471 |
TryToEnsureAssociated (); |
|
472 |
} |
|
473 |
||
474 |
void |
|
475 |
QstaWifiMac::RestartBeaconWatchdog (Time delay) |
|
476 |
{ |
|
477 |
NS_LOG_FUNCTION (this << delay); |
|
478 |
m_beaconWatchdogEnd = std::max (Simulator::Now () + delay, m_beaconWatchdogEnd); |
|
479 |
if (Simulator::GetDelayLeft (m_beaconWatchdog) < delay && |
|
480 |
m_beaconWatchdog.IsExpired ()) |
|
481 |
{ |
|
482 |
NS_LOG_DEBUG ("really restart watchdog."); |
|
483 |
m_beaconWatchdog = Simulator::Schedule (delay, &QstaWifiMac::MissedBeacons, this); |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
bool |
|
4609
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
488 |
QstaWifiMac::IsAssociated (void) const |
4408 | 489 |
{ |
4609
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
490 |
return m_state == ASSOCIATED; |
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
491 |
} |
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
492 |
|
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
493 |
bool |
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
494 |
QstaWifiMac::IsWaitAssocResp (void) const |
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
495 |
{ |
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
496 |
return m_state == WAIT_ASSOC_RESP; |
4408 | 497 |
} |
498 |
||
499 |
void |
|
500 |
QstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to) |
|
501 |
{ |
|
502 |
NS_LOG_FUNCTION (this << packet << to); |
|
503 |
if (!IsAssociated ()) |
|
504 |
{ |
|
505 |
TryToEnsureAssociated (); |
|
506 |
return; |
|
507 |
} |
|
508 |
WifiMacHeader hdr; |
|
509 |
||
510 |
hdr.SetType (WIFI_MAC_QOSDATA); |
|
511 |
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK); |
|
512 |
hdr.SetQosNoAmsdu (); |
|
513 |
hdr.SetQosNoEosp (); |
|
514 |
/* Transmission of multiple frames in the same |
|
515 |
Txop is not supported for now */ |
|
516 |
hdr.SetQosTxopLimit (0); |
|
517 |
||
518 |
hdr.SetAddr1 (GetBssid ()); |
|
519 |
hdr.SetAddr2 (m_low->GetAddress ()); |
|
520 |
hdr.SetAddr3 (to); |
|
521 |
hdr.SetDsNotFrom (); |
|
522 |
hdr.SetDsTo (); |
|
523 |
||
524 |
uint8_t tid = QosUtilsGetTidForPacket (packet); |
|
525 |
if (tid < 8) |
|
526 |
{ |
|
527 |
hdr.SetQosTid (tid); |
|
528 |
AccessClass ac = QosUtilsMapTidToAc (tid); |
|
529 |
m_queues[ac]->Queue (packet, hdr); |
|
530 |
} |
|
531 |
else |
|
532 |
{ |
|
533 |
//packet is considerated belonging to BestEffort Access Class (AC_BE) |
|
534 |
hdr.SetQosTid (0); |
|
535 |
m_queues[AC_BE]->Queue (packet, hdr); |
|
536 |
} |
|
537 |
} |
|
538 |
||
539 |
bool |
|
540 |
QstaWifiMac::SupportsSendFrom (void) const |
|
541 |
{ |
|
542 |
return true; |
|
543 |
} |
|
544 |
||
545 |
void |
|
546 |
QstaWifiMac::Receive (Ptr<Packet> packet, const WifiMacHeader *hdr) |
|
547 |
{ |
|
548 |
NS_LOG_FUNCTION (this); |
|
549 |
NS_ASSERT (!hdr->IsCtl ()); |
|
550 |
if (hdr->GetAddr1 () != GetAddress () && |
|
551 |
!hdr->GetAddr1 ().IsBroadcast ()) |
|
552 |
{ |
|
553 |
NS_LOG_LOGIC ("packet is not for us"); |
|
554 |
} |
|
555 |
else if (hdr->IsData ()) |
|
556 |
{ |
|
557 |
if (!IsAssociated ()) |
|
558 |
{ |
|
559 |
NS_LOG_LOGIC ("Received data frame while not associated: ignore"); |
|
560 |
return; |
|
561 |
} |
|
562 |
if (!(hdr->IsFromDs () && !hdr->IsToDs ())) |
|
563 |
{ |
|
564 |
NS_LOG_LOGIC ("Received data frame not from the DS: ignore"); |
|
565 |
return; |
|
566 |
} |
|
567 |
if (hdr->GetAddr2 () != GetBssid ()) |
|
568 |
{ |
|
569 |
NS_LOG_LOGIC ("Received data frame not from the BSS we are associated with: ignore"); |
|
570 |
return; |
|
571 |
} |
|
572 |
if (hdr->GetAddr3 () != GetAddress ()) |
|
573 |
{ |
|
574 |
if (hdr->IsQosData ()) |
|
575 |
{ |
|
576 |
if (hdr->IsQosAmsdu ()) |
|
577 |
{ |
|
578 |
NS_ASSERT (hdr->GetAddr3 () == GetBssid ()); |
|
579 |
DeaggregateAmsduAndForward (packet, hdr); |
|
580 |
packet = 0; |
|
581 |
} |
|
582 |
else |
|
583 |
{ |
|
584 |
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ()); |
|
585 |
} |
|
586 |
} |
|
587 |
else |
|
588 |
{ |
|
589 |
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ()); |
|
590 |
} |
|
591 |
} |
|
592 |
} |
|
593 |
else if (hdr->IsBeacon ()) |
|
594 |
{ |
|
595 |
MgtBeaconHeader beacon; |
|
596 |
packet->RemoveHeader (beacon); |
|
597 |
bool goodBeacon = false; |
|
598 |
if (GetSsid ().IsBroadcast () || |
|
599 |
beacon.GetSsid ().IsEqual (GetSsid ())) |
|
600 |
{ |
|
601 |
goodBeacon = true; |
|
602 |
} |
|
4609
6ec902d6af68
bug 605: Nqsta MAC should ignore beacons SSIDs while waiting for association response
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4461
diff
changeset
|
603 |
if ((IsWaitAssocResp () || IsAssociated ()) && hdr->GetAddr3 () != GetBssid ()) |
4408 | 604 |
{ |
605 |
goodBeacon = false; |
|
606 |
} |
|
607 |
if (goodBeacon) |
|
608 |
{ |
|
609 |
Time delay = MicroSeconds (beacon.GetBeaconIntervalUs () * m_maxMissedBeacons); |
|
610 |
RestartBeaconWatchdog (delay); |
|
611 |
SetBssid (hdr->GetAddr3 ()); |
|
612 |
} |
|
613 |
if (goodBeacon && m_state == BEACON_MISSED) |
|
614 |
{ |
|
615 |
m_state = WAIT_ASSOC_RESP; |
|
616 |
SendAssociationRequest (); |
|
617 |
} |
|
618 |
} |
|
619 |
else if (hdr->IsProbeResp ()) |
|
620 |
{ |
|
621 |
if (m_state == WAIT_PROBE_RESP) |
|
622 |
{ |
|
623 |
MgtProbeResponseHeader probeResp; |
|
624 |
packet->RemoveHeader (probeResp); |
|
625 |
if (!probeResp.GetSsid ().IsEqual (GetSsid ())) |
|
626 |
{ |
|
627 |
//not a probe resp for our ssid. |
|
628 |
return; |
|
629 |
} |
|
630 |
SetBssid (hdr->GetAddr3 ()); |
|
631 |
Time delay = MicroSeconds (probeResp.GetBeaconIntervalUs () * m_maxMissedBeacons); |
|
632 |
RestartBeaconWatchdog (delay); |
|
633 |
if (m_probeRequestEvent.IsRunning ()) |
|
634 |
{ |
|
635 |
m_probeRequestEvent.Cancel (); |
|
636 |
} |
|
637 |
m_state = WAIT_ASSOC_RESP; |
|
638 |
SendAssociationRequest (); |
|
639 |
} |
|
640 |
} |
|
641 |
else if (hdr->IsAssocResp ()) |
|
642 |
{ |
|
643 |
if (m_state == WAIT_ASSOC_RESP) |
|
644 |
{ |
|
645 |
MgtAssocResponseHeader assocResp; |
|
646 |
packet->RemoveHeader (assocResp); |
|
647 |
if (m_assocRequestEvent.IsRunning ()) |
|
648 |
{ |
|
649 |
m_assocRequestEvent.Cancel (); |
|
650 |
} |
|
651 |
if (assocResp.GetStatusCode ().IsSuccess ()) |
|
652 |
{ |
|
653 |
m_state = ASSOCIATED; |
|
654 |
NS_LOG_DEBUG ("assoc completed"); |
|
655 |
SupportedRates rates = assocResp.GetSupportedRates (); |
|
656 |
WifiRemoteStation *ap = m_stationManager->Lookup (hdr->GetAddr2 ()); |
|
657 |
for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
|
658 |
{ |
|
659 |
WifiMode mode = m_phy->GetMode (i); |
|
660 |
if (rates.IsSupportedRate (mode.GetDataRate ())) |
|
661 |
{ |
|
662 |
ap->AddSupportedMode (mode); |
|
663 |
if (rates.IsBasicRate (mode.GetDataRate ())) |
|
664 |
{ |
|
665 |
m_stationManager->AddBasicMode (mode); |
|
666 |
} |
|
667 |
} |
|
668 |
} |
|
669 |
if (!m_linkUp.IsNull ()) |
|
670 |
{ |
|
671 |
m_linkUp (); |
|
672 |
} |
|
673 |
} |
|
674 |
else |
|
675 |
{ |
|
676 |
NS_LOG_DEBUG ("assoc refused"); |
|
677 |
m_state = REFUSED; |
|
678 |
} |
|
679 |
} |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
SupportedRates |
|
684 |
QstaWifiMac::GetSupportedRates (void) const |
|
685 |
{ |
|
686 |
SupportedRates rates; |
|
687 |
for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
|
688 |
{ |
|
689 |
WifiMode mode = m_phy->GetMode (i); |
|
690 |
rates.AddSupportedRate (mode.GetDataRate ()); |
|
691 |
} |
|
692 |
return rates; |
|
693 |
} |
|
694 |
||
695 |
void |
|
696 |
QstaWifiMac::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr) |
|
697 |
{ |
|
698 |
DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket); |
|
699 |
for (DeaggregatedMsdusCI i = packets.begin (); i != packets.end (); ++i) |
|
700 |
{ |
|
701 |
ForwardUp ((*i).first, (*i).second.GetSourceAddr (), |
|
702 |
(*i).second.GetDestinationAddr ()); |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
Ptr<EdcaTxopN> |
|
707 |
QstaWifiMac::GetVOQueue (void) const |
|
708 |
{ |
|
709 |
return m_voEdca; |
|
710 |
} |
|
711 |
||
712 |
Ptr<EdcaTxopN> |
|
713 |
QstaWifiMac::GetVIQueue (void) const |
|
714 |
{ |
|
715 |
return m_viEdca; |
|
716 |
} |
|
717 |
||
718 |
Ptr<EdcaTxopN> |
|
719 |
QstaWifiMac::GetBEQueue (void) const |
|
720 |
{ |
|
721 |
return m_beEdca; |
|
722 |
} |
|
723 |
||
724 |
Ptr<EdcaTxopN> |
|
725 |
QstaWifiMac::GetBKQueue (void) const |
|
726 |
{ |
|
727 |
return m_bkEdca; |
|
728 |
} |
|
729 |
||
730 |
void |
|
731 |
QstaWifiMac::SetVOQueue (Ptr<EdcaTxopN> voQueue) |
|
732 |
{ |
|
733 |
m_voEdca = voQueue; |
|
734 |
m_queues.insert (std::make_pair(AC_VO, m_voEdca)); |
|
735 |
m_queues[AC_VO]->SetLow (m_low); |
|
736 |
m_queues[AC_VO]->SetManager (m_dcfManager); |
|
737 |
m_queues[AC_VO]->SetTypeOfStation (STA); |
|
738 |
m_queues[AC_VO]->SetTxMiddle (m_txMiddle); |
|
739 |
} |
|
740 |
||
741 |
void |
|
742 |
QstaWifiMac::SetVIQueue (Ptr<EdcaTxopN> viQueue) |
|
743 |
{ |
|
744 |
m_viEdca = viQueue; |
|
745 |
m_queues.insert (std::make_pair(AC_VI, m_viEdca)); |
|
746 |
m_queues[AC_VI]->SetLow (m_low); |
|
747 |
m_queues[AC_VI]->SetManager (m_dcfManager); |
|
748 |
m_queues[AC_VI]->SetTypeOfStation (STA); |
|
749 |
m_queues[AC_VI]->SetTxMiddle (m_txMiddle); |
|
750 |
} |
|
751 |
||
752 |
void |
|
753 |
QstaWifiMac::SetBEQueue (Ptr<EdcaTxopN> beQueue) |
|
754 |
{ |
|
755 |
m_beEdca = beQueue; |
|
756 |
m_queues.insert (std::make_pair(AC_BE, m_beEdca)); |
|
757 |
m_queues[AC_BE]->SetLow (m_low); |
|
758 |
m_queues[AC_BE]->SetManager (m_dcfManager); |
|
759 |
m_queues[AC_BE]->SetTypeOfStation (STA); |
|
760 |
m_queues[AC_BE]->SetTxMiddle (m_txMiddle); |
|
761 |
} |
|
762 |
||
763 |
void |
|
764 |
QstaWifiMac::SetBKQueue (Ptr<EdcaTxopN> bkQueue) |
|
765 |
{ |
|
766 |
m_bkEdca = bkQueue; |
|
767 |
m_queues.insert (std::make_pair(AC_BK, m_bkEdca)); |
|
768 |
m_queues[AC_BK]->SetLow (m_low); |
|
769 |
m_queues[AC_BK]->SetManager (m_dcfManager); |
|
770 |
m_queues[AC_BK]->SetTypeOfStation (STA); |
|
771 |
m_queues[AC_BK]->SetTxMiddle (m_txMiddle); |
|
772 |
} |
|
773 |
||
774 |
} //namespace ns3 |