31 #include "ns3/simulator.h" |
31 #include "ns3/simulator.h" |
32 #include "ns3/yans-wifi-phy.h" |
32 #include "ns3/yans-wifi-phy.h" |
33 #include "ns3/pointer.h" |
33 #include "ns3/pointer.h" |
34 #include "ns3/qos-tag.h" |
34 #include "ns3/qos-tag.h" |
35 |
35 |
36 |
|
37 NS_LOG_COMPONENT_DEFINE ("MeshWifiInterfaceMac"); |
36 NS_LOG_COMPONENT_DEFINE ("MeshWifiInterfaceMac"); |
38 |
37 |
39 namespace ns3 { |
38 namespace ns3 |
40 |
39 { |
41 NS_OBJECT_ENSURE_REGISTERED (MeshWifiInterfaceMac); |
40 |
|
41 NS_OBJECT_ENSURE_REGISTERED ( MeshWifiInterfaceMac); |
42 |
42 |
43 TypeId |
43 TypeId |
44 MeshWifiInterfaceMac::GetTypeId () |
44 MeshWifiInterfaceMac::GetTypeId () |
45 { |
45 { |
46 static TypeId tid = TypeId ("ns3::MeshWifiInterfaceMac") |
46 static TypeId tid = TypeId ("ns3::MeshWifiInterfaceMac") |
47 .SetParent<WifiMac> () |
47 .SetParent<WifiMac> () |
48 .AddConstructor<MeshWifiInterfaceMac> () |
48 .AddConstructor<MeshWifiInterfaceMac> () |
49 .AddAttribute ("BeaconInterval", "Beacon Interval", |
49 .AddAttribute ( "BeaconInterval", |
50 TimeValue (Seconds (0.5)), |
50 "Beacon Interval", |
51 MakeTimeAccessor (&MeshWifiInterfaceMac::m_beaconInterval), |
51 TimeValue (Seconds (0.5)), |
52 MakeTimeChecker () |
52 |
53 ) |
53 MakeTimeAccessor ( |
54 .AddAttribute ("RandomStart", "Window when beacon generating starts (uniform random) in seconds", |
54 &MeshWifiInterfaceMac::m_beaconInterval), |
55 TimeValue (Seconds (0.5)), |
55 MakeTimeChecker () |
56 MakeTimeAccessor (&MeshWifiInterfaceMac::m_randomStart), |
56 ) |
57 MakeTimeChecker () |
57 .AddAttribute ( "RandomStart", |
58 ) |
58 "Window when beacon generating starts (uniform random) in seconds", |
59 .AddAttribute ("BeaconGeneration", "Enable/Disable Beaconing.", |
59 TimeValue (Seconds (0.5)), |
60 BooleanValue (true), |
60 MakeTimeAccessor ( |
61 MakeBooleanAccessor ( |
61 &MeshWifiInterfaceMac::m_randomStart), |
62 &MeshWifiInterfaceMac::SetBeaconGeneration, |
62 MakeTimeChecker () |
63 &MeshWifiInterfaceMac::GetBeaconGeneration |
63 ) |
64 ), |
64 .AddAttribute ( "BeaconGeneration", |
65 MakeBooleanChecker () |
65 "Enable/Disable Beaconing.", |
66 ); |
66 BooleanValue (true), |
|
67 MakeBooleanAccessor ( |
|
68 &MeshWifiInterfaceMac::SetBeaconGeneration, &MeshWifiInterfaceMac::GetBeaconGeneration), |
|
69 MakeBooleanChecker () |
|
70 ); |
67 return tid; |
71 return tid; |
68 } |
72 } |
69 |
|
70 MeshWifiInterfaceMac::MeshWifiInterfaceMac () |
73 MeshWifiInterfaceMac::MeshWifiInterfaceMac () |
71 { |
74 { |
72 NS_LOG_FUNCTION (this); |
75 NS_LOG_FUNCTION (this); |
73 |
76 |
74 m_rxMiddle = new MacRxMiddle (); |
77 m_rxMiddle = new MacRxMiddle (); |
136 { |
134 { |
137 NS_LOG_FUNCTION (this << eifsNoDifs); |
135 NS_LOG_FUNCTION (this << eifsNoDifs); |
138 m_dcfManager->SetEifsNoDifs (eifsNoDifs); |
136 m_dcfManager->SetEifsNoDifs (eifsNoDifs); |
139 m_eifsNoDifs = eifsNoDifs; |
137 m_eifsNoDifs = eifsNoDifs; |
140 } |
138 } |
141 |
|
142 Time |
139 Time |
143 MeshWifiInterfaceMac::GetSlot () const |
140 MeshWifiInterfaceMac::GetSlot () const |
144 { |
141 { |
145 return m_slot; |
142 return m_slot; |
146 } |
143 } |
147 |
|
148 Time |
144 Time |
149 MeshWifiInterfaceMac::GetSifs () const |
145 MeshWifiInterfaceMac::GetSifs () const |
150 { |
146 { |
151 return m_sifs; |
147 return m_sifs; |
152 } |
148 } |
153 |
|
154 Time |
149 Time |
155 MeshWifiInterfaceMac::GetEifsNoDifs () const |
150 MeshWifiInterfaceMac::GetEifsNoDifs () const |
156 { |
151 { |
157 return m_eifsNoDifs; |
152 return m_eifsNoDifs; |
158 } |
153 } |
159 |
|
160 Time |
154 Time |
161 MeshWifiInterfaceMac::GetAckTimeout () const |
155 MeshWifiInterfaceMac::GetAckTimeout () const |
162 { |
156 { |
163 return m_low->GetAckTimeout (); |
157 return m_low->GetAckTimeout (); |
164 } |
158 } |
165 |
|
166 Time |
159 Time |
167 MeshWifiInterfaceMac::GetCtsTimeout () const |
160 MeshWifiInterfaceMac::GetCtsTimeout () const |
168 { |
161 { |
169 return m_low->GetCtsTimeout (); |
162 return m_low->GetCtsTimeout (); |
170 } |
163 } |
171 |
|
172 Time |
164 Time |
173 MeshWifiInterfaceMac::GetPifs () const |
165 MeshWifiInterfaceMac::GetPifs () const |
174 { |
166 { |
175 return m_low->GetPifs (); |
167 return m_low->GetPifs (); |
176 } |
168 } |
177 |
|
178 void |
169 void |
179 MeshWifiInterfaceMac::SetWifiPhy (Ptr<WifiPhy> phy) |
170 MeshWifiInterfaceMac::SetWifiPhy (Ptr<WifiPhy> phy) |
180 { |
171 { |
181 NS_LOG_FUNCTION (this << phy); |
172 NS_LOG_FUNCTION (this << phy); |
182 m_phy = phy; |
173 m_phy = phy; |
183 m_dcfManager->SetupPhyListener (phy); |
174 m_dcfManager->SetupPhyListener (phy); |
184 m_low->SetPhy (phy); |
175 m_low->SetPhy (phy); |
185 } |
176 } |
186 |
|
187 void |
177 void |
188 MeshWifiInterfaceMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) |
178 MeshWifiInterfaceMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) |
189 { |
179 { |
190 NS_LOG_FUNCTION (this << stationManager); |
180 NS_LOG_FUNCTION (this << stationManager); |
191 m_stationManager = stationManager; |
181 m_stationManager = stationManager; |
192 for (Queues::const_iterator i = m_queues.begin (); i != m_queues.end (); i ++) |
182 for (Queues::const_iterator i = m_queues.begin (); i != m_queues.end (); i++) |
193 { |
183 { |
194 i->second->SetWifiRemoteStationManager (stationManager); |
184 i->second->SetWifiRemoteStationManager (stationManager); |
195 } |
185 } |
196 m_beaconDca->SetWifiRemoteStationManager (stationManager); |
186 m_beaconDca->SetWifiRemoteStationManager (stationManager); |
197 m_low->SetWifiRemoteStationManager (stationManager); |
187 m_low->SetWifiRemoteStationManager (stationManager); |
198 } |
188 } |
199 |
|
200 void |
189 void |
201 MeshWifiInterfaceMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from) |
190 MeshWifiInterfaceMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from) |
202 { |
191 { |
203 NS_LOG_FUNCTION (this << packet << to << from); |
192 NS_LOG_FUNCTION (this << packet << to << from); |
204 ForwardDown (packet, from, to); |
193 ForwardDown (packet, from, to); |
205 } |
194 } |
206 |
|
207 void |
195 void |
208 MeshWifiInterfaceMac::Enqueue (Ptr<const Packet> packet, Mac48Address to) |
196 MeshWifiInterfaceMac::Enqueue (Ptr<const Packet> packet, Mac48Address to) |
209 { |
197 { |
210 NS_LOG_FUNCTION (this << packet << to); |
198 NS_LOG_FUNCTION (this << packet << to); |
211 ForwardDown (packet, m_low->GetAddress (), to); |
199 ForwardDown (packet, m_low->GetAddress (), to); |
212 } |
200 } |
213 |
|
214 bool |
201 bool |
215 MeshWifiInterfaceMac::SupportsSendFrom () const |
202 MeshWifiInterfaceMac::SupportsSendFrom () const |
216 { |
203 { |
217 return true; |
204 return true; |
218 } |
205 } |
219 |
206 void |
220 void |
207 MeshWifiInterfaceMac::SetForwardUpCallback ( |
221 MeshWifiInterfaceMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback) |
208 Callback<void, Ptr<Packet> , Mac48Address, Mac48Address> upCallback) |
222 { |
209 { |
223 NS_LOG_FUNCTION (this); |
210 NS_LOG_FUNCTION (this); |
224 m_upCallback = upCallback; |
211 m_upCallback = upCallback; |
225 } |
212 } |
226 |
|
227 void |
213 void |
228 MeshWifiInterfaceMac::SetLinkUpCallback (Callback<void> linkUp) |
214 MeshWifiInterfaceMac::SetLinkUpCallback (Callback<void> linkUp) |
229 { |
215 { |
230 NS_LOG_FUNCTION (this); |
216 NS_LOG_FUNCTION (this); |
231 if (!linkUp.IsNull ()) |
217 if (!linkUp.IsNull ()) |
232 { |
218 { |
233 linkUp (); |
219 linkUp (); |
234 } |
220 } |
235 } |
221 } |
236 |
|
237 void |
222 void |
238 MeshWifiInterfaceMac::SetLinkDownCallback (Callback<void> linkDown) |
223 MeshWifiInterfaceMac::SetLinkDownCallback (Callback<void> linkDown) |
239 { |
224 { |
240 NS_LOG_FUNCTION (this); |
225 NS_LOG_FUNCTION (this); |
241 } |
226 } |
242 |
|
243 Mac48Address |
227 Mac48Address |
244 MeshWifiInterfaceMac::GetAddress () const |
228 MeshWifiInterfaceMac::GetAddress () const |
245 { |
229 { |
246 return m_address; |
230 return m_address; |
247 } |
231 } |
248 Mac48Address |
232 Mac48Address |
249 MeshWifiInterfaceMac::GetBssid () const |
233 MeshWifiInterfaceMac::GetBssid () const |
250 { |
234 { |
251 return m_address; |
235 return m_address; |
252 } |
236 } |
253 |
|
254 Ssid |
237 Ssid |
255 MeshWifiInterfaceMac::GetSsid () const |
238 MeshWifiInterfaceMac::GetSsid () const |
256 { |
239 { |
257 return m_meshId; |
240 return m_meshId; |
258 } |
241 } |
259 |
|
260 void |
242 void |
261 MeshWifiInterfaceMac::SetAddress (Mac48Address address) |
243 MeshWifiInterfaceMac::SetAddress (Mac48Address address) |
262 { |
244 { |
263 NS_LOG_FUNCTION (address); |
245 NS_LOG_FUNCTION (address); |
264 m_low->SetAddress (address); |
246 m_low->SetAddress (address); |
265 m_address = address; |
247 m_address = address; |
266 } |
248 } |
267 |
|
268 void |
249 void |
269 MeshWifiInterfaceMac::SetSsid (Ssid ssid) |
250 MeshWifiInterfaceMac::SetSsid (Ssid ssid) |
270 { |
251 { |
271 NS_LOG_FUNCTION (ssid); |
252 NS_LOG_FUNCTION (ssid); |
272 m_meshId = ssid; |
253 m_meshId = ssid; |
273 } |
254 } |
274 |
|
275 void |
255 void |
276 MeshWifiInterfaceMac::DoDispose () |
256 MeshWifiInterfaceMac::DoDispose () |
277 { |
257 { |
278 NS_LOG_FUNCTION (this); |
258 NS_LOG_FUNCTION (this); |
279 delete m_rxMiddle; |
259 delete m_rxMiddle; |
405 QosTag tag; |
378 QosTag tag; |
406 if (packet->RemovePacketTag (tag)) |
379 if (packet->RemovePacketTag (tag)) |
407 { |
380 { |
408 ac = QosUtilsMapTidToAc (tag.Get ()); |
381 ac = QosUtilsMapTidToAc (tag.Get ()); |
409 } |
382 } |
410 m_stats.sentFrames ++; |
383 m_stats.sentFrames++; |
411 m_stats.sentBytes += packet->GetSize (); |
384 m_stats.sentBytes += packet->GetSize (); |
412 NS_ASSERT(m_queues.find(ac) != m_queues.end ()); |
385 NS_ASSERT (m_queues.find (ac) != m_queues.end ()); |
413 m_queues[ac]->Queue (packet, hdr); |
386 m_queues[ac]->Queue (packet, hdr); |
414 } |
387 } |
415 |
|
416 void |
388 void |
417 MeshWifiInterfaceMac::SendManagementFrame (Ptr<Packet> packet, const WifiMacHeader& hdr) |
389 MeshWifiInterfaceMac::SendManagementFrame (Ptr<Packet> packet, const WifiMacHeader& hdr) |
418 { |
390 { |
419 //Filter management frames: |
391 //Filter management frames: |
420 WifiMacHeader header = hdr; |
392 WifiMacHeader header = hdr; |
421 for (PluginList::const_iterator i = m_plugins.end()-1; i != m_plugins.begin()-1; i--) |
393 for (PluginList::const_iterator i = m_plugins.end () - 1; i != m_plugins.begin () - 1; i--) |
422 { |
394 { |
423 bool drop = ! ((*i)->UpdateOutcomingFrame(packet, header, Mac48Address (), Mac48Address ())); |
395 bool drop = !((*i)->UpdateOutcomingFrame (packet, header, Mac48Address (), Mac48Address ())); |
424 if (drop) |
396 if (drop) |
425 { |
397 { |
426 return; // plugin drops frame |
398 return; // plugin drops frame |
427 } |
399 } |
428 } |
400 } |
429 m_stats.sentFrames ++; |
401 m_stats.sentFrames++; |
430 m_stats.sentBytes += packet->GetSize (); |
402 m_stats.sentBytes += packet->GetSize (); |
431 Queues::iterator i = m_queues.find (AC_VO); |
403 Queues::iterator i = m_queues.find (AC_VO); |
432 if (i == m_queues.end ()) |
404 if (i == m_queues.end ()) |
433 { |
405 { |
434 NS_FATAL_ERROR("Voice queue is not set up!"); |
406 NS_FATAL_ERROR ("Voice queue is not set up!"); |
435 } |
407 } |
436 m_queues[AC_VO]->Queue (packet, header); |
408 m_queues[AC_VO]->Queue (packet, header); |
437 } |
409 } |
438 |
|
439 SupportedRates |
410 SupportedRates |
440 MeshWifiInterfaceMac::GetSupportedRates () const |
411 MeshWifiInterfaceMac::GetSupportedRates () const |
441 { |
412 { |
442 // set the set of supported rates and make sure that we indicate |
413 // set the set of supported rates and make sure that we indicate |
443 // the Basic Rate set in this set of supported rates. |
414 // the Basic Rate set in this set of supported rates. |
454 rates.SetBasicRate (mode.GetDataRate ()); |
425 rates.SetBasicRate (mode.GetDataRate ()); |
455 } |
426 } |
456 return rates; |
427 return rates; |
457 } |
428 } |
458 bool |
429 bool |
459 MeshWifiInterfaceMac::CheckSupportedRates(SupportedRates rates) const |
430 MeshWifiInterfaceMac::CheckSupportedRates (SupportedRates rates) const |
460 { |
431 { |
461 for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++) |
432 for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++) |
462 { |
433 { |
463 WifiMode mode = m_stationManager->GetBasicMode (i); |
434 WifiMode mode = m_stationManager->GetBasicMode (i); |
464 if (!rates.IsSupportedRate (mode.GetDataRate ())) |
435 if (!rates.IsSupportedRate (mode.GetDataRate ())) |
465 { |
436 { |
466 return false; |
437 return false; |
467 } |
438 } |
468 } |
439 } |
469 return true; |
440 return true; |
470 } |
441 } |
471 |
|
472 //----------------------------------------------------------------------------- |
442 //----------------------------------------------------------------------------- |
473 // Beacons |
443 // Beacons |
474 //----------------------------------------------------------------------------- |
444 //----------------------------------------------------------------------------- |
475 void |
445 void |
476 MeshWifiInterfaceMac::SetRandomStartDelay (Time interval) |
446 MeshWifiInterfaceMac::SetRandomStartDelay (Time interval) |
477 { |
447 { |
478 NS_LOG_FUNCTION (this << interval); |
448 NS_LOG_FUNCTION (this << interval); |
479 m_randomStart = interval; |
449 m_randomStart = interval; |
480 } |
450 } |
481 |
|
482 void |
451 void |
483 MeshWifiInterfaceMac::SetBeaconInterval (Time interval) |
452 MeshWifiInterfaceMac::SetBeaconInterval (Time interval) |
484 { |
453 { |
485 NS_LOG_FUNCTION (this << interval); |
454 NS_LOG_FUNCTION (this << interval); |
486 m_beaconInterval = interval; |
455 m_beaconInterval = interval; |
487 } |
456 } |
488 |
|
489 Time |
457 Time |
490 MeshWifiInterfaceMac::GetBeaconInterval () const |
458 MeshWifiInterfaceMac::GetBeaconInterval () const |
491 { |
459 { |
492 return m_beaconInterval; |
460 return m_beaconInterval; |
493 } |
461 } |
494 |
|
495 void |
462 void |
496 MeshWifiInterfaceMac::SetBeaconGeneration (bool enable) |
463 MeshWifiInterfaceMac::SetBeaconGeneration (bool enable) |
497 { |
464 { |
498 NS_LOG_FUNCTION (this << enable); |
465 NS_LOG_FUNCTION (this << enable); |
499 if (enable) |
466 if (enable) |
500 { |
467 { |
501 // Now start sending beacons after some random delay (to avoid collisions) |
468 // Now start sending beacons after some random delay (to avoid collisions) |
502 UniformVariable coefficient (0.0, m_randomStart.GetSeconds()); |
469 UniformVariable coefficient (0.0, m_randomStart.GetSeconds ()); |
503 Time randomStart = Seconds (coefficient.GetValue()); |
470 Time randomStart = Seconds (coefficient.GetValue ()); |
504 |
471 |
505 m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this); |
472 m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this); |
506 m_tbtt = Simulator::Now() + randomStart; |
473 m_tbtt = Simulator::Now () + randomStart; |
507 } |
474 } |
508 else |
475 else |
509 { |
476 { |
510 // stop sending beacons |
477 // stop sending beacons |
511 m_beaconSendEvent.Cancel (); |
478 m_beaconSendEvent.Cancel (); |
512 } |
479 } |
513 } |
480 } |
514 |
|
515 bool |
481 bool |
516 MeshWifiInterfaceMac::GetBeaconGeneration () const |
482 MeshWifiInterfaceMac::GetBeaconGeneration () const |
517 { |
483 { |
518 return m_beaconSendEvent.IsRunning (); |
484 return m_beaconSendEvent.IsRunning (); |
519 } |
485 } |
520 |
|
521 Time |
486 Time |
522 MeshWifiInterfaceMac::GetTbtt () const |
487 MeshWifiInterfaceMac::GetTbtt () const |
523 { |
488 { |
524 return m_tbtt; |
489 return m_tbtt; |
525 } |
490 } |
526 |
491 void |
527 void MeshWifiInterfaceMac::ShiftTbtt (Time shift) |
492 MeshWifiInterfaceMac::ShiftTbtt (Time shift) |
528 { |
493 { |
529 // User of ShiftTbtt () must take care don't shift it to the past |
494 // User of ShiftTbtt () must take care don't shift it to the past |
530 NS_ASSERT (GetTbtt() + shift > Simulator::Now()); |
495 NS_ASSERT (GetTbtt () + shift > Simulator::Now ()); |
531 |
496 |
532 m_tbtt += shift; |
497 m_tbtt += shift; |
533 // Shift scheduled event |
498 // Shift scheduled event |
534 Simulator::Cancel (m_beaconSendEvent); |
499 Simulator::Cancel (m_beaconSendEvent); |
535 m_beaconSendEvent = Simulator::Schedule (GetTbtt () - Simulator::Now(), &MeshWifiInterfaceMac::SendBeacon, this); |
500 m_beaconSendEvent = Simulator::Schedule (GetTbtt () - Simulator::Now (), &MeshWifiInterfaceMac::SendBeacon, |
536 } |
501 this); |
537 |
502 } |
538 void |
503 void |
539 MeshWifiInterfaceMac::ScheduleNextBeacon () |
504 MeshWifiInterfaceMac::ScheduleNextBeacon () |
540 { |
505 { |
541 m_tbtt += GetBeaconInterval (); |
506 m_tbtt += GetBeaconInterval (); |
542 m_beaconSendEvent = Simulator::Schedule (GetBeaconInterval(), &MeshWifiInterfaceMac::SendBeacon, this); |
507 m_beaconSendEvent = Simulator::Schedule (GetBeaconInterval (), &MeshWifiInterfaceMac::SendBeacon, this); |
543 } |
508 } |
544 |
|
545 void |
509 void |
546 MeshWifiInterfaceMac::SendBeacon () |
510 MeshWifiInterfaceMac::SendBeacon () |
547 { |
511 { |
548 NS_LOG_FUNCTION (this); |
512 NS_LOG_FUNCTION (this); |
549 NS_LOG_DEBUG (GetAddress() <<" is sending beacon"); |
513 NS_LOG_DEBUG (GetAddress () << " is sending beacon"); |
550 |
514 |
551 NS_ASSERT (! m_beaconSendEvent.IsRunning()); |
515 NS_ASSERT (!m_beaconSendEvent.IsRunning ()); |
552 NS_ASSERT (Simulator::Now().GetMicroSeconds() == GetTbtt().GetMicroSeconds()); // assert that beacon is just on time |
516 NS_ASSERT (Simulator::Now ().GetMicroSeconds () == GetTbtt ().GetMicroSeconds ()); // assert that beacon is just on time |
553 |
517 |
554 // Form & send beacon |
518 // Form & send beacon |
555 MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ()); |
519 MeshWifiBeacon beacon (GetSsid (), GetSupportedRates (), m_beaconInterval.GetMicroSeconds ()); |
556 |
520 |
557 // Ask all plugins to add their specific information elements to beacon |
521 // Ask all plugins to add their specific information elements to beacon |
558 for (PluginList::const_iterator i = m_plugins.begin(); i != m_plugins.end(); ++i) |
522 for (PluginList::const_iterator i = m_plugins.begin (); i != m_plugins.end (); ++i) |
559 { |
523 { |
560 (*i)->UpdateBeacon (beacon); |
524 (*i)->UpdateBeacon (beacon); |
561 } |
525 } |
562 m_beaconDca->Queue (beacon.CreatePacket(), beacon.CreateHeader(GetAddress (), GetMeshPointAddress ())); |
526 m_beaconDca->Queue (beacon.CreatePacket (), beacon.CreateHeader (GetAddress (), GetMeshPointAddress ())); |
563 |
527 |
564 ScheduleNextBeacon (); |
528 ScheduleNextBeacon (); |
565 } |
529 } |
566 |
|
567 void |
530 void |
568 MeshWifiInterfaceMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr) |
531 MeshWifiInterfaceMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr) |
569 { |
532 { |
570 // Process beacon |
533 // Process beacon |
571 if ((hdr->GetAddr1() != GetAddress()) && (hdr->GetAddr1() != Mac48Address::GetBroadcast())) |
534 if ((hdr->GetAddr1 () != GetAddress ()) && (hdr->GetAddr1 () != Mac48Address::GetBroadcast ())) |
572 { |
535 { |
573 return; |
536 return; |
574 } |
537 } |
575 if (hdr->IsBeacon ()) |
538 if (hdr->IsBeacon ()) |
576 { |
539 { |
577 m_stats.recvBeacons ++; |
540 m_stats.recvBeacons++; |
578 MgtBeaconHeader beacon_hdr; |
541 MgtBeaconHeader beacon_hdr; |
579 Mac48Address from = hdr->GetAddr2 (); |
542 Mac48Address from = hdr->GetAddr2 (); |
580 |
543 |
581 packet->PeekHeader (beacon_hdr); |
544 packet->PeekHeader (beacon_hdr); |
582 |
545 |
583 NS_LOG_DEBUG ("Beacon received from "<<hdr->GetAddr2()<< |
546 NS_LOG_DEBUG ("Beacon received from " << hdr->GetAddr2 () << " I am " << GetAddress () << " at " |
584 " I am "<<GetAddress ()<< |
547 << Simulator::Now ().GetMicroSeconds () << " microseconds"); |
585 " at "<<Simulator::Now ().GetMicroSeconds ()<< |
|
586 " microseconds"); |
|
587 |
548 |
588 // update supported rates |
549 // update supported rates |
589 if (beacon_hdr.GetSsid ().IsEqual (GetSsid())) |
550 if (beacon_hdr.GetSsid ().IsEqual (GetSsid ())) |
590 { |
551 { |
591 SupportedRates rates = beacon_hdr.GetSupportedRates (); |
552 SupportedRates rates = beacon_hdr.GetSupportedRates (); |
592 WifiRemoteStation * peerSta = m_stationManager->Lookup (hdr->GetAddr2 ()); |
553 WifiRemoteStation * peerSta = m_stationManager->Lookup (hdr->GetAddr2 ()); |
593 |
554 |
594 for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
555 for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
595 { |
556 { |
596 WifiMode mode = m_phy->GetMode (i); |
557 WifiMode mode = m_phy->GetMode (i); |
597 if (rates.IsSupportedRate (mode.GetDataRate ())) |
558 if (rates.IsSupportedRate (mode.GetDataRate ())) |
598 { |
559 { |
599 peerSta->AddSupportedMode (mode); |
560 peerSta->AddSupportedMode (mode); |
600 if (rates.IsBasicRate (mode.GetDataRate ())) |
561 if (rates.IsBasicRate (mode.GetDataRate ())) |
601 { |
562 { |
602 m_stationManager->AddBasicMode (mode); |
563 m_stationManager->AddBasicMode (mode); |
603 } |
564 } |
604 } |
565 } |
605 } |
566 } |
606 } |
567 } |
607 } |
568 } |
608 else |
569 else |
609 { |
570 { |
610 m_stats.recvBytes += packet->GetSize (); |
571 m_stats.recvBytes += packet->GetSize (); |
611 m_stats.recvFrames ++; |
572 m_stats.recvFrames++; |
612 } |
573 } |
613 // Filter frame through all installed plugins |
574 // Filter frame through all installed plugins |
614 for (PluginList::iterator i = m_plugins.begin (); i != m_plugins.end(); ++i) |
575 for (PluginList::iterator i = m_plugins.begin (); i != m_plugins.end (); ++i) |
615 { |
576 { |
616 bool drop = ! ((*i)->Receive(packet, *hdr)); |
577 bool drop = !((*i)->Receive (packet, *hdr)); |
617 if (drop) |
578 if (drop) |
618 { |
579 { |
619 return; // plugin drops frame |
580 return; // plugin drops frame |
620 } |
581 } |
621 } |
582 } |
622 |
|
623 // Check if QoS tag exists and add it: |
583 // Check if QoS tag exists and add it: |
624 if (hdr->IsQosData ()) |
584 if (hdr->IsQosData ()) |
625 { |
585 { |
626 packet->AddPacketTag (QosTag (hdr->GetQosTid ())); |
586 packet->AddPacketTag (QosTag (hdr->GetQosTid ())); |
627 } |
587 } |
628 // Forward data up |
588 // Forward data up |
629 if (hdr->IsData ()) |
589 if (hdr->IsData ()) |
630 { |
590 { |
631 ForwardUp (packet, hdr->GetAddr4(), hdr->GetAddr3()); |
591 ForwardUp (packet, hdr->GetAddr4 (), hdr->GetAddr3 ()); |
632 } |
592 } |
633 } |
593 } |
634 |
|
635 uint32_t |
594 uint32_t |
636 MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress) |
595 MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress) |
637 { |
596 { |
638 uint32_t metric = 1; |
597 uint32_t metric = 1; |
639 if (!m_linkMetricCallback.IsNull ()) |
598 if (!m_linkMetricCallback.IsNull ()) |
640 { |
599 { |
641 metric = m_linkMetricCallback(peerAddress, this); |
600 metric = m_linkMetricCallback (peerAddress, this); |
642 } |
601 } |
643 return metric; |
602 return metric; |
644 } |
603 } |
645 |
|
646 void |
604 void |
647 MeshWifiInterfaceMac::SetLinkMetricCallback (Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb) |
605 MeshWifiInterfaceMac::SetLinkMetricCallback (Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb) |
648 { |
606 { |
649 m_linkMetricCallback = cb; |
607 m_linkMetricCallback = cb; |
650 } |
608 } |
651 |
|
652 Ptr<WifiRemoteStationManager> |
609 Ptr<WifiRemoteStationManager> |
653 MeshWifiInterfaceMac::GetStationManager() |
610 MeshWifiInterfaceMac::GetStationManager () |
654 { |
611 { |
655 return m_stationManager; |
612 return m_stationManager; |
656 } |
613 } |
657 |
|
658 void |
614 void |
659 MeshWifiInterfaceMac::SetMeshPointAddress (Mac48Address a) |
615 MeshWifiInterfaceMac::SetMeshPointAddress (Mac48Address a) |
660 { |
616 { |
661 m_mpAddress = a; |
617 m_mpAddress = a; |
662 } |
618 } |
663 |
619 Mac48Address |
664 Mac48Address |
|
665 MeshWifiInterfaceMac::GetMeshPointAddress () const |
620 MeshWifiInterfaceMac::GetMeshPointAddress () const |
666 { |
621 { |
667 return m_mpAddress; |
622 return m_mpAddress; |
668 } |
623 } |
669 //Statistics: |
624 //Statistics: |
670 MeshWifiInterfaceMac::Statistics::Statistics () : |
625 MeshWifiInterfaceMac::Statistics::Statistics () : |
671 recvBeacons (0), |
626 recvBeacons (0), sentFrames (0), sentBytes (0), recvFrames (0), recvBytes (0) |
672 sentFrames (0), |
627 { |
673 sentBytes (0), |
628 } |
674 recvFrames (0), |
|
675 recvBytes (0) |
|
676 {} |
|
677 void |
629 void |
678 MeshWifiInterfaceMac::Statistics::Print (std::ostream & os) const |
630 MeshWifiInterfaceMac::Statistics::Print (std::ostream & os) const |
679 { |
631 { |
680 os << "<Statistics " |
632 os << "<Statistics " |
681 // TODO txBeacons |
633 // TODO txBeacons |
682 "rxBeacons=\"" << recvBeacons << "\" " |
634 "rxBeacons=\"" << recvBeacons << "\" " |
683 "txFrames=\"" << sentFrames << "\" " |
635 "txFrames=\"" << sentFrames << "\" " |
684 "txBytes=\"" << sentBytes << "\" " |
636 "txBytes=\"" << sentBytes << "\" " |
685 "rxFrames=\"" << recvFrames << "\" " |
637 "rxFrames=\"" << recvFrames << "\" " |
686 "rxBytes=\"" << recvBytes << "\"/>\n"; |
638 "rxBytes=\"" << recvBytes << "\"/>\n"; |
687 } |
639 } |
688 void |
640 void |
689 MeshWifiInterfaceMac::Report (std::ostream & os) const |
641 MeshWifiInterfaceMac::Report (std::ostream & os) const |
690 { |
642 { |
691 os << "<Interface " |
643 os << "<Interface " |
692 "BeaconInterval=\"" << GetBeaconInterval ().GetSeconds() << "\" " |
644 "BeaconInterval=\"" << GetBeaconInterval ().GetSeconds () << "\" " |
693 "Channel=\"" << GetFrequencyChannel () << "\" " |
645 "Channel=\"" << GetFrequencyChannel () << "\" " |
694 "Address = \"" << GetAddress () << "\">\n"; |
646 "Address = \"" << GetAddress () << "\">\n"; |
695 m_stats.Print (os); |
647 m_stats.Print (os); |
696 os << "</Interface>\n"; |
648 os << "</Interface>\n"; |
697 } |
649 } |