author | Pavel Boyko <boyko@iitp.ru> |
Tue, 16 Jun 2009 17:58:16 +0400 | |
changeset 5074 | 355de6af8ea9 |
parent 4461 | ab9b58d664d7 |
child 4609 | 6ec902d6af68 |
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; |
|
128 |
m_rxMiddle = 0; |
|
129 |
m_txMiddle = 0; |
|
130 |
m_low = 0; |
|
131 |
m_phy = 0; |
|
132 |
m_dcfManager = 0; |
|
133 |
m_voEdca = 0; |
|
134 |
m_viEdca = 0; |
|
135 |
m_beEdca = 0; |
|
136 |
m_bkEdca = 0; |
|
137 |
m_stationManager = 0; |
|
138 |
std::map<AccessClass, Ptr<EdcaTxopN> >::iterator it = m_queues.begin (); |
|
139 |
for (;it != m_queues.end (); it++) |
|
140 |
{ |
|
141 |
it->second = 0; |
|
142 |
} |
|
143 |
WifiMac::DoDispose (); |
|
144 |
} |
|
145 |
||
146 |
void |
|
147 |
QstaWifiMac::SetSlot (Time slotTime) |
|
148 |
{ |
|
149 |
NS_LOG_FUNCTION (this << slotTime); |
|
150 |
m_dcfManager->SetSlot (slotTime); |
|
151 |
m_low->SetSlotTime (slotTime); |
|
152 |
} |
|
153 |
||
154 |
void |
|
155 |
QstaWifiMac::SetSifs (Time sifs) |
|
156 |
{ |
|
157 |
NS_LOG_FUNCTION (this << sifs); |
|
158 |
m_dcfManager->SetSifs (sifs); |
|
159 |
m_low->SetSifs (sifs); |
|
160 |
} |
|
161 |
||
162 |
void |
|
163 |
QstaWifiMac::SetEifsNoDifs (Time eifsNoDifs) |
|
164 |
{ |
|
165 |
NS_LOG_FUNCTION (this << eifsNoDifs); |
|
166 |
m_dcfManager->SetEifsNoDifs (eifsNoDifs); |
|
167 |
} |
|
168 |
||
169 |
void |
|
170 |
QstaWifiMac::SetAckTimeout (Time ackTimeout) |
|
171 |
{ |
|
172 |
m_low->SetAckTimeout (ackTimeout); |
|
173 |
} |
|
174 |
||
175 |
void |
|
176 |
QstaWifiMac::SetCtsTimeout (Time ctsTimeout) |
|
177 |
{ |
|
178 |
m_low->SetCtsTimeout (ctsTimeout); |
|
179 |
} |
|
180 |
||
181 |
void |
|
182 |
QstaWifiMac::SetPifs (Time pifs) |
|
183 |
{ |
|
184 |
m_low->SetPifs (pifs); |
|
185 |
} |
|
186 |
||
187 |
Time |
|
188 |
QstaWifiMac::GetSlot (void) const |
|
189 |
{ |
|
190 |
return m_low->GetSlotTime (); |
|
191 |
} |
|
192 |
||
193 |
Time |
|
194 |
QstaWifiMac::GetSifs (void) const |
|
195 |
{ |
|
196 |
return m_low->GetSifs (); |
|
197 |
} |
|
198 |
||
199 |
Time |
|
200 |
QstaWifiMac::GetEifsNoDifs (void) const |
|
201 |
{ |
|
4461
ab9b58d664d7
move GetEifsNoDifs to DcfManager
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4408
diff
changeset
|
202 |
return m_dcfManager->GetEifsNoDifs (); |
4408 | 203 |
} |
204 |
||
205 |
Time |
|
206 |
QstaWifiMac::GetAckTimeout (void) const |
|
207 |
{ |
|
208 |
return m_low->GetAckTimeout (); |
|
209 |
} |
|
210 |
||
211 |
Time |
|
212 |
QstaWifiMac::GetCtsTimeout (void) const |
|
213 |
{ |
|
214 |
return m_low->GetCtsTimeout (); |
|
215 |
} |
|
216 |
||
217 |
Time |
|
218 |
QstaWifiMac::GetPifs (void) const |
|
219 |
{ |
|
220 |
return m_low->GetPifs (); |
|
221 |
} |
|
222 |
||
223 |
void |
|
224 |
QstaWifiMac::SetWifiPhy (Ptr<WifiPhy> phy) |
|
225 |
{ |
|
226 |
m_phy = phy; |
|
227 |
m_dcfManager->SetupPhyListener (phy); |
|
228 |
m_low->SetPhy (phy); |
|
229 |
} |
|
230 |
||
231 |
void |
|
232 |
QstaWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) |
|
233 |
{ |
|
234 |
m_stationManager = stationManager; |
|
235 |
m_queues[AC_VO]->SetWifiRemoteStationManager (stationManager); |
|
236 |
m_queues[AC_VI]->SetWifiRemoteStationManager (stationManager); |
|
237 |
m_queues[AC_BE]->SetWifiRemoteStationManager (stationManager); |
|
238 |
m_queues[AC_BK]->SetWifiRemoteStationManager (stationManager); |
|
239 |
m_low->SetWifiRemoteStationManager (stationManager); |
|
240 |
} |
|
241 |
||
242 |
void |
|
243 |
QstaWifiMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback) |
|
244 |
{ |
|
245 |
m_forwardUp = upCallback; |
|
246 |
} |
|
247 |
||
248 |
void |
|
249 |
QstaWifiMac::SetLinkUpCallback (Callback<void> linkUp) |
|
250 |
{ |
|
251 |
m_linkUp = linkUp; |
|
252 |
} |
|
253 |
||
254 |
void |
|
255 |
QstaWifiMac::SetLinkDownCallback (Callback<void> linkDown) |
|
256 |
{ |
|
257 |
m_linkDown = linkDown; |
|
258 |
} |
|
259 |
||
260 |
Mac48Address |
|
261 |
QstaWifiMac::GetAddress (void) const |
|
262 |
{ |
|
263 |
return m_low->GetAddress (); |
|
264 |
} |
|
265 |
||
266 |
Ssid |
|
267 |
QstaWifiMac::GetSsid (void) const |
|
268 |
{ |
|
269 |
return m_ssid; |
|
270 |
} |
|
271 |
||
272 |
Mac48Address |
|
273 |
QstaWifiMac::GetBssid () const |
|
274 |
{ |
|
275 |
return m_low->GetBssid (); |
|
276 |
} |
|
277 |
||
278 |
void |
|
279 |
QstaWifiMac::SetAddress (Mac48Address address) |
|
280 |
{ |
|
281 |
NS_LOG_FUNCTION (this << address); |
|
282 |
m_low->SetAddress (address); |
|
283 |
} |
|
284 |
||
285 |
void |
|
286 |
QstaWifiMac::SetSsid (Ssid ssid) |
|
287 |
{ |
|
288 |
NS_LOG_FUNCTION (this << ssid); |
|
289 |
m_ssid = ssid; |
|
290 |
} |
|
291 |
||
292 |
void |
|
293 |
QstaWifiMac::SetMaxMissedBeacons (uint32_t missed) |
|
294 |
{ |
|
295 |
NS_LOG_FUNCTION (this << missed); |
|
296 |
m_maxMissedBeacons = missed; |
|
297 |
} |
|
298 |
||
299 |
void |
|
300 |
QstaWifiMac::SetProbeRequestTimeout (Time timeout) |
|
301 |
{ |
|
302 |
NS_LOG_FUNCTION (this << timeout); |
|
303 |
m_probeRequestTimeout = timeout; |
|
304 |
} |
|
305 |
||
306 |
void |
|
307 |
QstaWifiMac::SetAssocRequestTimeout (Time timeout) |
|
308 |
{ |
|
309 |
NS_LOG_FUNCTION (this << timeout); |
|
310 |
m_assocRequestTimeout = timeout; |
|
311 |
} |
|
312 |
||
313 |
void |
|
314 |
QstaWifiMac::StartActiveAssociation (void) |
|
315 |
{ |
|
316 |
NS_LOG_FUNCTION (this); |
|
317 |
TryToEnsureAssociated (); |
|
318 |
} |
|
319 |
||
320 |
Mac48Address |
|
321 |
QstaWifiMac::GetBroadcastBssid (void) |
|
322 |
{ |
|
323 |
return Mac48Address::GetBroadcast (); |
|
324 |
} |
|
325 |
||
326 |
void |
|
327 |
QstaWifiMac::SetBssid (Mac48Address bssid) |
|
328 |
{ |
|
329 |
NS_LOG_FUNCTION (this << bssid); |
|
330 |
m_low->SetBssid (bssid); |
|
331 |
} |
|
332 |
||
333 |
void |
|
334 |
QstaWifiMac::SetActiveProbing (bool enable) |
|
335 |
{ |
|
336 |
NS_LOG_FUNCTION (this << enable); |
|
337 |
if (enable) |
|
338 |
{ |
|
339 |
TryToEnsureAssociated (); |
|
340 |
} |
|
341 |
else |
|
342 |
{ |
|
343 |
m_probeRequestEvent.Cancel (); |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
void |
|
348 |
QstaWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to) |
|
349 |
{ |
|
350 |
NS_LOG_FUNCTION (this << packet << from << to); |
|
351 |
m_forwardUp (packet, from, to); |
|
352 |
} |
|
353 |
||
354 |
void |
|
355 |
QstaWifiMac::SendProbeRequest (void) |
|
356 |
{ |
|
357 |
NS_LOG_FUNCTION (this); |
|
358 |
WifiMacHeader hdr; |
|
359 |
hdr.SetProbeReq (); |
|
360 |
hdr.SetAddr1 (GetBroadcastBssid ()); |
|
361 |
hdr.SetAddr2 (GetAddress ()); |
|
362 |
hdr.SetAddr3 (GetBroadcastBssid ()); |
|
363 |
hdr.SetDsNotFrom (); |
|
364 |
hdr.SetDsNotTo (); |
|
365 |
Ptr<Packet> packet = Create<Packet> (); |
|
366 |
MgtProbeRequestHeader probe; |
|
367 |
probe.SetSsid (GetSsid ()); |
|
368 |
probe.SetSupportedRates (GetSupportedRates ()); |
|
369 |
packet->AddHeader (probe); |
|
370 |
||
371 |
/* Which is correct queue for management frames ? */ |
|
372 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
373 |
||
374 |
m_probeRequestEvent = Simulator::Schedule (m_probeRequestTimeout, |
|
375 |
&QstaWifiMac::ProbeRequestTimeout, this); |
|
376 |
} |
|
377 |
||
378 |
void |
|
379 |
QstaWifiMac::SendAssociationRequest (void) |
|
380 |
{ |
|
381 |
NS_LOG_FUNCTION (this << GetBssid ()); |
|
382 |
WifiMacHeader hdr; |
|
383 |
hdr.SetAssocReq (); |
|
384 |
hdr.SetAddr1 (GetBssid ()); |
|
385 |
hdr.SetAddr2 (GetAddress ()); |
|
386 |
hdr.SetAddr3 (GetBssid ()); |
|
387 |
hdr.SetDsNotFrom (); |
|
388 |
hdr.SetDsNotTo (); |
|
389 |
Ptr<Packet> packet = Create<Packet> (); |
|
390 |
MgtAssocRequestHeader assoc; |
|
391 |
assoc.SetSsid (GetSsid ()); |
|
392 |
assoc.SetSupportedRates (GetSupportedRates ()); |
|
393 |
packet->AddHeader (assoc); |
|
394 |
||
395 |
/* Which is correct queue for management frames ? */ |
|
396 |
m_queues[AC_VO]->Queue (packet, hdr); |
|
397 |
||
398 |
m_assocRequestEvent = Simulator::Schedule (m_assocRequestTimeout, |
|
399 |
&QstaWifiMac::AssocRequestTimeout, this); |
|
400 |
} |
|
401 |
||
402 |
void |
|
403 |
QstaWifiMac::TryToEnsureAssociated (void) |
|
404 |
{ |
|
405 |
NS_LOG_FUNCTION (this); |
|
406 |
switch (m_state) { |
|
407 |
case ASSOCIATED: |
|
408 |
return; |
|
409 |
break; |
|
410 |
case WAIT_PROBE_RESP: |
|
411 |
/* we have sent a probe request earlier so we |
|
412 |
do not need to re-send a probe request immediately. |
|
413 |
We just need to wait until probe-request-timeout |
|
414 |
or until we get a probe response |
|
415 |
*/ |
|
416 |
break; |
|
417 |
case BEACON_MISSED: |
|
418 |
/* we were associated but we missed a bunch of beacons |
|
419 |
* so we should assume we are not associated anymore. |
|
420 |
* We try to initiate a probe request now. |
|
421 |
*/ |
|
422 |
m_linkDown (); |
|
423 |
m_state = WAIT_PROBE_RESP; |
|
424 |
SendProbeRequest (); |
|
425 |
break; |
|
426 |
case WAIT_ASSOC_RESP: |
|
427 |
/* we have sent an assoc request so we do not need to |
|
428 |
re-send an assoc request right now. We just need to |
|
429 |
wait until either assoc-request-timeout or until |
|
430 |
we get an assoc response. |
|
431 |
*/ |
|
432 |
break; |
|
433 |
case REFUSED: |
|
434 |
/* we have sent an assoc request and received a negative |
|
435 |
assoc resp. We wait until someone restarts an |
|
436 |
association with a given ssid. |
|
437 |
*/ |
|
438 |
break; |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
void |
|
443 |
QstaWifiMac::AssocRequestTimeout (void) |
|
444 |
{ |
|
445 |
NS_LOG_FUNCTION (this); |
|
446 |
m_state = WAIT_ASSOC_RESP; |
|
447 |
SendAssociationRequest (); |
|
448 |
} |
|
449 |
||
450 |
void |
|
451 |
QstaWifiMac::ProbeRequestTimeout (void) |
|
452 |
{ |
|
453 |
NS_LOG_FUNCTION (this); |
|
454 |
m_state = WAIT_PROBE_RESP; |
|
455 |
SendProbeRequest (); |
|
456 |
} |
|
457 |
||
458 |
void |
|
459 |
QstaWifiMac::MissedBeacons (void) |
|
460 |
{ |
|
461 |
NS_LOG_FUNCTION (this); |
|
462 |
if (m_beaconWatchdogEnd > Simulator::Now ()) |
|
463 |
{ |
|
464 |
m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (), |
|
465 |
&QstaWifiMac::MissedBeacons, this); |
|
466 |
return; |
|
467 |
} |
|
468 |
NS_LOG_DEBUG ("beacon missed"); |
|
469 |
m_state = BEACON_MISSED; |
|
470 |
TryToEnsureAssociated (); |
|
471 |
} |
|
472 |
||
473 |
void |
|
474 |
QstaWifiMac::RestartBeaconWatchdog (Time delay) |
|
475 |
{ |
|
476 |
NS_LOG_FUNCTION (this << delay); |
|
477 |
m_beaconWatchdogEnd = std::max (Simulator::Now () + delay, m_beaconWatchdogEnd); |
|
478 |
if (Simulator::GetDelayLeft (m_beaconWatchdog) < delay && |
|
479 |
m_beaconWatchdog.IsExpired ()) |
|
480 |
{ |
|
481 |
NS_LOG_DEBUG ("really restart watchdog."); |
|
482 |
m_beaconWatchdog = Simulator::Schedule (delay, &QstaWifiMac::MissedBeacons, this); |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
bool |
|
487 |
QstaWifiMac::IsAssociated () |
|
488 |
{ |
|
489 |
return (m_state == ASSOCIATED)?true:false; |
|
490 |
} |
|
491 |
||
492 |
void |
|
493 |
QstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to) |
|
494 |
{ |
|
495 |
NS_LOG_FUNCTION (this << packet << to); |
|
496 |
if (!IsAssociated ()) |
|
497 |
{ |
|
498 |
TryToEnsureAssociated (); |
|
499 |
return; |
|
500 |
} |
|
501 |
WifiMacHeader hdr; |
|
502 |
||
503 |
hdr.SetType (WIFI_MAC_QOSDATA); |
|
504 |
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK); |
|
505 |
hdr.SetQosNoAmsdu (); |
|
506 |
hdr.SetQosNoEosp (); |
|
507 |
/* Transmission of multiple frames in the same |
|
508 |
Txop is not supported for now */ |
|
509 |
hdr.SetQosTxopLimit (0); |
|
510 |
||
511 |
hdr.SetAddr1 (GetBssid ()); |
|
512 |
hdr.SetAddr2 (m_low->GetAddress ()); |
|
513 |
hdr.SetAddr3 (to); |
|
514 |
hdr.SetDsNotFrom (); |
|
515 |
hdr.SetDsTo (); |
|
516 |
||
517 |
uint8_t tid = QosUtilsGetTidForPacket (packet); |
|
518 |
if (tid < 8) |
|
519 |
{ |
|
520 |
hdr.SetQosTid (tid); |
|
521 |
AccessClass ac = QosUtilsMapTidToAc (tid); |
|
522 |
m_queues[ac]->Queue (packet, hdr); |
|
523 |
} |
|
524 |
else |
|
525 |
{ |
|
526 |
//packet is considerated belonging to BestEffort Access Class (AC_BE) |
|
527 |
hdr.SetQosTid (0); |
|
528 |
m_queues[AC_BE]->Queue (packet, hdr); |
|
529 |
} |
|
530 |
} |
|
531 |
||
532 |
bool |
|
533 |
QstaWifiMac::SupportsSendFrom (void) const |
|
534 |
{ |
|
535 |
return true; |
|
536 |
} |
|
537 |
||
538 |
void |
|
539 |
QstaWifiMac::Receive (Ptr<Packet> packet, const WifiMacHeader *hdr) |
|
540 |
{ |
|
541 |
NS_LOG_FUNCTION (this); |
|
542 |
NS_ASSERT (!hdr->IsCtl ()); |
|
543 |
if (hdr->GetAddr1 () != GetAddress () && |
|
544 |
!hdr->GetAddr1 ().IsBroadcast ()) |
|
545 |
{ |
|
546 |
NS_LOG_LOGIC ("packet is not for us"); |
|
547 |
} |
|
548 |
else if (hdr->IsData ()) |
|
549 |
{ |
|
550 |
if (!IsAssociated ()) |
|
551 |
{ |
|
552 |
NS_LOG_LOGIC ("Received data frame while not associated: ignore"); |
|
553 |
return; |
|
554 |
} |
|
555 |
if (!(hdr->IsFromDs () && !hdr->IsToDs ())) |
|
556 |
{ |
|
557 |
NS_LOG_LOGIC ("Received data frame not from the DS: ignore"); |
|
558 |
return; |
|
559 |
} |
|
560 |
if (hdr->GetAddr2 () != GetBssid ()) |
|
561 |
{ |
|
562 |
NS_LOG_LOGIC ("Received data frame not from the BSS we are associated with: ignore"); |
|
563 |
return; |
|
564 |
} |
|
565 |
if (hdr->GetAddr3 () != GetAddress ()) |
|
566 |
{ |
|
567 |
if (hdr->IsQosData ()) |
|
568 |
{ |
|
569 |
if (hdr->IsQosAmsdu ()) |
|
570 |
{ |
|
571 |
NS_ASSERT (hdr->GetAddr3 () == GetBssid ()); |
|
572 |
DeaggregateAmsduAndForward (packet, hdr); |
|
573 |
packet = 0; |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ()); |
|
578 |
} |
|
579 |
} |
|
580 |
else |
|
581 |
{ |
|
582 |
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ()); |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
else if (hdr->IsBeacon ()) |
|
587 |
{ |
|
588 |
MgtBeaconHeader beacon; |
|
589 |
packet->RemoveHeader (beacon); |
|
590 |
bool goodBeacon = false; |
|
591 |
if (GetSsid ().IsBroadcast () || |
|
592 |
beacon.GetSsid ().IsEqual (GetSsid ())) |
|
593 |
{ |
|
594 |
goodBeacon = true; |
|
595 |
} |
|
596 |
if (IsAssociated () && hdr->GetAddr3 () != GetBssid ()) |
|
597 |
{ |
|
598 |
goodBeacon = false; |
|
599 |
} |
|
600 |
if (goodBeacon) |
|
601 |
{ |
|
602 |
Time delay = MicroSeconds (beacon.GetBeaconIntervalUs () * m_maxMissedBeacons); |
|
603 |
RestartBeaconWatchdog (delay); |
|
604 |
SetBssid (hdr->GetAddr3 ()); |
|
605 |
} |
|
606 |
if (goodBeacon && m_state == BEACON_MISSED) |
|
607 |
{ |
|
608 |
m_state = WAIT_ASSOC_RESP; |
|
609 |
SendAssociationRequest (); |
|
610 |
} |
|
611 |
} |
|
612 |
else if (hdr->IsProbeResp ()) |
|
613 |
{ |
|
614 |
if (m_state == WAIT_PROBE_RESP) |
|
615 |
{ |
|
616 |
MgtProbeResponseHeader probeResp; |
|
617 |
packet->RemoveHeader (probeResp); |
|
618 |
if (!probeResp.GetSsid ().IsEqual (GetSsid ())) |
|
619 |
{ |
|
620 |
//not a probe resp for our ssid. |
|
621 |
return; |
|
622 |
} |
|
623 |
SetBssid (hdr->GetAddr3 ()); |
|
624 |
Time delay = MicroSeconds (probeResp.GetBeaconIntervalUs () * m_maxMissedBeacons); |
|
625 |
RestartBeaconWatchdog (delay); |
|
626 |
if (m_probeRequestEvent.IsRunning ()) |
|
627 |
{ |
|
628 |
m_probeRequestEvent.Cancel (); |
|
629 |
} |
|
630 |
m_state = WAIT_ASSOC_RESP; |
|
631 |
SendAssociationRequest (); |
|
632 |
} |
|
633 |
} |
|
634 |
else if (hdr->IsAssocResp ()) |
|
635 |
{ |
|
636 |
if (m_state == WAIT_ASSOC_RESP) |
|
637 |
{ |
|
638 |
MgtAssocResponseHeader assocResp; |
|
639 |
packet->RemoveHeader (assocResp); |
|
640 |
if (m_assocRequestEvent.IsRunning ()) |
|
641 |
{ |
|
642 |
m_assocRequestEvent.Cancel (); |
|
643 |
} |
|
644 |
if (assocResp.GetStatusCode ().IsSuccess ()) |
|
645 |
{ |
|
646 |
m_state = ASSOCIATED; |
|
647 |
NS_LOG_DEBUG ("assoc completed"); |
|
648 |
SupportedRates rates = assocResp.GetSupportedRates (); |
|
649 |
WifiRemoteStation *ap = m_stationManager->Lookup (hdr->GetAddr2 ()); |
|
650 |
for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
|
651 |
{ |
|
652 |
WifiMode mode = m_phy->GetMode (i); |
|
653 |
if (rates.IsSupportedRate (mode.GetDataRate ())) |
|
654 |
{ |
|
655 |
ap->AddSupportedMode (mode); |
|
656 |
if (rates.IsBasicRate (mode.GetDataRate ())) |
|
657 |
{ |
|
658 |
m_stationManager->AddBasicMode (mode); |
|
659 |
} |
|
660 |
} |
|
661 |
} |
|
662 |
if (!m_linkUp.IsNull ()) |
|
663 |
{ |
|
664 |
m_linkUp (); |
|
665 |
} |
|
666 |
} |
|
667 |
else |
|
668 |
{ |
|
669 |
NS_LOG_DEBUG ("assoc refused"); |
|
670 |
m_state = REFUSED; |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
SupportedRates |
|
677 |
QstaWifiMac::GetSupportedRates (void) const |
|
678 |
{ |
|
679 |
SupportedRates rates; |
|
680 |
for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
|
681 |
{ |
|
682 |
WifiMode mode = m_phy->GetMode (i); |
|
683 |
rates.AddSupportedRate (mode.GetDataRate ()); |
|
684 |
} |
|
685 |
return rates; |
|
686 |
} |
|
687 |
||
688 |
void |
|
689 |
QstaWifiMac::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 |
ForwardUp ((*i).first, (*i).second.GetSourceAddr (), |
|
695 |
(*i).second.GetDestinationAddr ()); |
|
696 |
} |
|
697 |
} |
|
698 |
||
699 |
Ptr<EdcaTxopN> |
|
700 |
QstaWifiMac::GetVOQueue (void) const |
|
701 |
{ |
|
702 |
return m_voEdca; |
|
703 |
} |
|
704 |
||
705 |
Ptr<EdcaTxopN> |
|
706 |
QstaWifiMac::GetVIQueue (void) const |
|
707 |
{ |
|
708 |
return m_viEdca; |
|
709 |
} |
|
710 |
||
711 |
Ptr<EdcaTxopN> |
|
712 |
QstaWifiMac::GetBEQueue (void) const |
|
713 |
{ |
|
714 |
return m_beEdca; |
|
715 |
} |
|
716 |
||
717 |
Ptr<EdcaTxopN> |
|
718 |
QstaWifiMac::GetBKQueue (void) const |
|
719 |
{ |
|
720 |
return m_bkEdca; |
|
721 |
} |
|
722 |
||
723 |
void |
|
724 |
QstaWifiMac::SetVOQueue (Ptr<EdcaTxopN> voQueue) |
|
725 |
{ |
|
726 |
m_voEdca = voQueue; |
|
727 |
m_queues.insert (std::make_pair(AC_VO, m_voEdca)); |
|
728 |
m_queues[AC_VO]->SetLow (m_low); |
|
729 |
m_queues[AC_VO]->SetManager (m_dcfManager); |
|
730 |
m_queues[AC_VO]->SetTypeOfStation (STA); |
|
731 |
m_queues[AC_VO]->SetTxMiddle (m_txMiddle); |
|
732 |
} |
|
733 |
||
734 |
void |
|
735 |
QstaWifiMac::SetVIQueue (Ptr<EdcaTxopN> viQueue) |
|
736 |
{ |
|
737 |
m_viEdca = viQueue; |
|
738 |
m_queues.insert (std::make_pair(AC_VI, m_viEdca)); |
|
739 |
m_queues[AC_VI]->SetLow (m_low); |
|
740 |
m_queues[AC_VI]->SetManager (m_dcfManager); |
|
741 |
m_queues[AC_VI]->SetTypeOfStation (STA); |
|
742 |
m_queues[AC_VI]->SetTxMiddle (m_txMiddle); |
|
743 |
} |
|
744 |
||
745 |
void |
|
746 |
QstaWifiMac::SetBEQueue (Ptr<EdcaTxopN> beQueue) |
|
747 |
{ |
|
748 |
m_beEdca = beQueue; |
|
749 |
m_queues.insert (std::make_pair(AC_BE, m_beEdca)); |
|
750 |
m_queues[AC_BE]->SetLow (m_low); |
|
751 |
m_queues[AC_BE]->SetManager (m_dcfManager); |
|
752 |
m_queues[AC_BE]->SetTypeOfStation (STA); |
|
753 |
m_queues[AC_BE]->SetTxMiddle (m_txMiddle); |
|
754 |
} |
|
755 |
||
756 |
void |
|
757 |
QstaWifiMac::SetBKQueue (Ptr<EdcaTxopN> bkQueue) |
|
758 |
{ |
|
759 |
m_bkEdca = bkQueue; |
|
760 |
m_queues.insert (std::make_pair(AC_BK, m_bkEdca)); |
|
761 |
m_queues[AC_BK]->SetLow (m_low); |
|
762 |
m_queues[AC_BK]->SetManager (m_dcfManager); |
|
763 |
m_queues[AC_BK]->SetTypeOfStation (STA); |
|
764 |
m_queues[AC_BK]->SetTxMiddle (m_txMiddle); |
|
765 |
} |
|
766 |
||
767 |
} //namespace ns3 |