LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2005,2006 INRIA | 3 * Copyright (c) 2005,2006 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ns3/simulator.h" | 24 #include "ns3/simulator.h" |
25 #include "ns3/log.h" | 25 #include "ns3/log.h" |
26 #include "ns3/boolean.h" | 26 #include "ns3/boolean.h" |
27 #include "ns3/double.h" | 27 #include "ns3/double.h" |
28 #include "ns3/uinteger.h" | 28 #include "ns3/uinteger.h" |
29 #include "ns3/pointer.h" | 29 #include "ns3/pointer.h" |
30 #include "wifi-phy-tag.h" | 30 #include "wifi-phy-tag.h" |
31 #include "ampdu-tag.h" | 31 #include "ampdu-tag.h" |
32 #include "wifi-utils.h" | 32 #include "wifi-utils.h" |
33 #include "frame-capture-model.h" | 33 #include "frame-capture-model.h" |
| 34 #include "wifi-radio-energy-model.h" |
34 | 35 |
35 namespace ns3 { | 36 namespace ns3 { |
36 | 37 |
37 NS_LOG_COMPONENT_DEFINE ("WifiPhy"); | 38 NS_LOG_COMPONENT_DEFINE ("WifiPhy"); |
38 | 39 |
39 /**************************************************************** | 40 /**************************************************************** |
40 * This destructor is needed. | 41 * This destructor is needed. |
41 ****************************************************************/ | 42 ****************************************************************/ |
42 | 43 |
43 WifiPhyListener::~WifiPhyListener () | 44 WifiPhyListener::~WifiPhyListener () |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 m_endPlcpRxEvent (), | 366 m_endPlcpRxEvent (), |
366 m_standard (WIFI_PHY_STANDARD_UNSPECIFIED), | 367 m_standard (WIFI_PHY_STANDARD_UNSPECIFIED), |
367 m_isConstructed (false), | 368 m_isConstructed (false), |
368 m_channelCenterFrequency (0), | 369 m_channelCenterFrequency (0), |
369 m_initialFrequency (0), | 370 m_initialFrequency (0), |
370 m_frequencyChannelNumberInitialized (false), | 371 m_frequencyChannelNumberInitialized (false), |
371 m_channelNumber (0), | 372 m_channelNumber (0), |
372 m_initialChannelNumber (0), | 373 m_initialChannelNumber (0), |
373 m_totalAmpduSize (0), | 374 m_totalAmpduSize (0), |
374 m_totalAmpduNumSymbols (0), | 375 m_totalAmpduNumSymbols (0), |
375 m_currentEvent (0) | 376 m_currentEvent (0), |
| 377 m_wifiRadioEnergyModel (0) |
376 { | 378 { |
377 NS_LOG_FUNCTION (this); | 379 NS_LOG_FUNCTION (this); |
378 m_random = CreateObject<UniformRandomVariable> (); | 380 m_random = CreateObject<UniformRandomVariable> (); |
379 m_state = CreateObject<WifiPhyStateHelper> (); | 381 m_state = CreateObject<WifiPhyStateHelper> (); |
380 } | 382 } |
381 | 383 |
382 WifiPhy::~WifiPhy () | 384 WifiPhy::~WifiPhy () |
383 { | 385 { |
384 NS_LOG_FUNCTION (this); | 386 NS_LOG_FUNCTION (this); |
385 } | 387 } |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 void | 699 void |
698 WifiPhy::SetFrameCaptureModel (const Ptr<FrameCaptureModel> model) | 700 WifiPhy::SetFrameCaptureModel (const Ptr<FrameCaptureModel> model) |
699 { | 701 { |
700 m_frameCaptureModel = model; | 702 m_frameCaptureModel = model; |
701 } | 703 } |
702 | 704 |
703 Ptr<FrameCaptureModel> | 705 Ptr<FrameCaptureModel> |
704 WifiPhy::GetFrameCaptureModel (void) const | 706 WifiPhy::GetFrameCaptureModel (void) const |
705 { | 707 { |
706 return m_frameCaptureModel; | 708 return m_frameCaptureModel; |
| 709 } |
| 710 ···· |
| 711 void |
| 712 WifiPhy::SetWifiRadioEnergyModel (const Ptr<WifiRadioEnergyModel> wifiRadioEnerg
yModel) |
| 713 { |
| 714 m_wifiRadioEnergyModel = wifiRadioEnergyModel; |
707 } | 715 } |
708 | 716 |
709 double | 717 double |
710 WifiPhy::GetPowerDbm (uint8_t power) const | 718 WifiPhy::GetPowerDbm (uint8_t power) const |
711 { | 719 { |
712 NS_ASSERT (m_txPowerBaseDbm <= m_txPowerEndDbm); | 720 NS_ASSERT (m_txPowerBaseDbm <= m_txPowerEndDbm); |
713 NS_ASSERT (m_nTxPower > 0); | 721 NS_ASSERT (m_nTxPower > 0); |
714 double dbm; | 722 double dbm; |
715 if (m_nTxPower > 1) | 723 if (m_nTxPower > 1) |
716 { | 724 { |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching
"); | 1592 NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching
"); |
1585 Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetSleepMode, this); | 1593 Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetSleepMode, this); |
1586 break; | 1594 break; |
1587 case WifiPhy::CCA_BUSY: | 1595 case WifiPhy::CCA_BUSY: |
1588 case WifiPhy::IDLE: | 1596 case WifiPhy::IDLE: |
1589 NS_LOG_DEBUG ("setting sleep mode"); | 1597 NS_LOG_DEBUG ("setting sleep mode"); |
1590 m_state->SwitchToSleep (); | 1598 m_state->SwitchToSleep (); |
1591 break; | 1599 break; |
1592 case WifiPhy::SLEEP: | 1600 case WifiPhy::SLEEP: |
1593 NS_LOG_DEBUG ("already in sleep mode"); | 1601 NS_LOG_DEBUG ("already in sleep mode"); |
| 1602 break; |
| 1603 default: |
| 1604 NS_ASSERT (false); |
| 1605 break; |
| 1606 } |
| 1607 } |
| 1608 |
| 1609 void |
| 1610 WifiPhy::SetOffMode (void) |
| 1611 { |
| 1612 NS_LOG_FUNCTION (this); |
| 1613 switch (m_state->GetState ()) |
| 1614 { |
| 1615 case WifiPhy::RX: |
| 1616 m_endPlcpRxEvent.Cancel (); |
| 1617 m_endRxEvent.Cancel (); |
| 1618 case WifiPhy::TX: |
| 1619 case WifiPhy::SWITCHING: |
| 1620 case WifiPhy::CCA_BUSY: |
| 1621 case WifiPhy::IDLE: |
| 1622 case WifiPhy::SLEEP: |
| 1623 m_state->SwitchToOff (); |
1594 break; | 1624 break; |
1595 default: | 1625 default: |
1596 NS_ASSERT (false); | 1626 NS_ASSERT (false); |
1597 break; | 1627 break; |
1598 } | 1628 } |
1599 } | 1629 } |
1600 | 1630 |
1601 void | 1631 void |
1602 WifiPhy::ResumeFromSleep (void) | 1632 WifiPhy::ResumeFromSleep (void) |
1603 { | 1633 { |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 } | 2351 } |
2322 MpduInfo aMpdu; | 2352 MpduInfo aMpdu; |
2323 aMpdu.type = mpdutype; | 2353 aMpdu.type = mpdutype; |
2324 aMpdu.mpduRefNumber = m_txMpduReferenceNumber; | 2354 aMpdu.mpduRefNumber = m_txMpduReferenceNumber; |
2325 NotifyMonitorSniffTx (packet, GetFrequency (), txVector, aMpdu); | 2355 NotifyMonitorSniffTx (packet, GetFrequency (), txVector, aMpdu); |
2326 m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel
()), txVector); | 2356 m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel
()), txVector); |
2327 | 2357 |
2328 Ptr<Packet> newPacket = packet->Copy (); // obtain non-const Packet | 2358 Ptr<Packet> newPacket = packet->Copy (); // obtain non-const Packet |
2329 WifiPhyTag oldtag; | 2359 WifiPhyTag oldtag; |
2330 newPacket->RemovePacketTag (oldtag); | 2360 newPacket->RemovePacketTag (oldtag); |
2331 WifiPhyTag tag (txVector, mpdutype); | 2361 if (m_state->GetState () == WifiPhy::OFF) |
| 2362 { |
| 2363 NS_LOG_DEBUG ("Transmission canceled because device is OFF"); |
| 2364 return; |
| 2365 } |
| 2366 uint8_t isFrameComplete = 1; |
| 2367 if (m_wifiRadioEnergyModel != 0 && m_wifiRadioEnergyModel->GetMaximumTimeInSta
te (WifiPhy::TX) < txDuration) |
| 2368 { |
| 2369 isFrameComplete = 0; |
| 2370 } |
| 2371 WifiPhyTag tag (txVector, mpdutype, isFrameComplete); |
2332 newPacket->AddPacketTag (tag); | 2372 newPacket->AddPacketTag (tag); |
2333 | 2373 |
2334 StartTx (newPacket, txVector, txDuration); | 2374 StartTx (newPacket, txVector, txDuration); |
2335 } | 2375 } |
2336 | 2376 |
2337 void | 2377 void |
2338 WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim
e rxDuration) | 2378 WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim
e rxDuration) |
2339 { | 2379 { |
2340 //This function should be later split to check separately whether plcp preambl
e and plcp header can be successfully received. | 2380 //This function should be later split to check separately whether plcp preambl
e and plcp header can be successfully received. |
2341 //Note: plcp preamble reception is not yet modeled. | 2381 //Note: plcp preamble reception is not yet modeled. |
| 2382 if (m_state->GetState () == WifiPhy::OFF) |
| 2383 { |
| 2384 NS_LOG_DEBUG ("Cannot start RX because device is OFF"); |
| 2385 return; |
| 2386 } |
| 2387 |
2342 NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration); | 2388 NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration); |
2343 Time endRx = Simulator::Now () + rxDuration; | 2389 Time endRx = Simulator::Now () + rxDuration; |
2344 | 2390 |
2345 WifiPhyTag tag; | 2391 WifiPhyTag tag; |
2346 bool found = packet->RemovePacketTag (tag); | 2392 bool found = packet->RemovePacketTag (tag); |
2347 if (!found) | 2393 if (!found) |
2348 { | 2394 { |
2349 NS_FATAL_ERROR ("Received Wi-Fi Signal with no WifiPhyTag"); | 2395 NS_FATAL_ERROR ("Received Wi-Fi Signal with no WifiPhyTag"); |
2350 return; | 2396 return; |
| 2397 } |
| 2398 |
| 2399 if (tag.GetFrameComplete () == 0) |
| 2400 { |
| 2401 NS_LOG_DEBUG ("drop packet because of incomplete frame"); |
| 2402 NotifyRxDrop (packet); |
| 2403 m_plcpSuccess = false; |
| 2404 return; |
2351 } | 2405 } |
2352 | 2406 |
2353 WifiTxVector txVector = tag.GetWifiTxVector (); | 2407 WifiTxVector txVector = tag.GetWifiTxVector (); |
2354 | 2408 |
2355 if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT | 2409 if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT |
2356 && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8)))) | 2410 && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8)))) |
2357 { | 2411 { |
2358 NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << static_cas
t<uint16_t> (txVector.GetMode ().GetMcsValue ()) << ", NSS = " << static_cast<ui
nt16_t> (txVector.GetNss ())); | 2412 NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << static_cas
t<uint16_t> (txVector.GetMode ().GetMcsValue ()) << ", NSS = " << static_cast<ui
nt16_t> (txVector.GetNss ())); |
2359 } | 2413 } |
2360 | 2414 |
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3486 return static_cast<uint8_t>(m_deviceMcsSet.size ()); | 3540 return static_cast<uint8_t>(m_deviceMcsSet.size ()); |
3487 } | 3541 } |
3488 | 3542 |
3489 WifiMode | 3543 WifiMode |
3490 WifiPhy::GetMcs (uint8_t mcs) const | 3544 WifiPhy::GetMcs (uint8_t mcs) const |
3491 { | 3545 { |
3492 return m_deviceMcsSet[mcs]; | 3546 return m_deviceMcsSet[mcs]; |
3493 } | 3547 } |
3494 | 3548 |
3495 bool | 3549 bool |
3496 WifiPhy::IsStateCcaBusy (void) | 3550 WifiPhy::IsStateCcaBusy (void) const |
3497 { | 3551 { |
3498 return m_state->IsStateCcaBusy (); | 3552 return m_state->IsStateCcaBusy (); |
3499 } | 3553 } |
3500 | 3554 |
3501 bool | 3555 bool |
3502 WifiPhy::IsStateIdle (void) | 3556 WifiPhy::IsStateIdle (void) const |
3503 { | 3557 { |
3504 return m_state->IsStateIdle (); | 3558 return m_state->IsStateIdle (); |
3505 } | 3559 } |
3506 | 3560 |
3507 bool | 3561 bool |
3508 WifiPhy::IsStateBusy (void) | 3562 WifiPhy::IsStateBusy (void) const |
3509 { | 3563 { |
3510 return m_state->IsStateBusy (); | 3564 return m_state->IsStateBusy (); |
3511 } | 3565 } |
3512 | 3566 |
3513 bool | 3567 bool |
3514 WifiPhy::IsStateRx (void) | 3568 WifiPhy::IsStateRx (void) const |
3515 { | 3569 { |
3516 return m_state->IsStateRx (); | 3570 return m_state->IsStateRx (); |
3517 } | 3571 } |
3518 | 3572 |
3519 bool | 3573 bool |
3520 WifiPhy::IsStateTx (void) | 3574 WifiPhy::IsStateTx (void) const |
3521 { | 3575 { |
3522 return m_state->IsStateTx (); | 3576 return m_state->IsStateTx (); |
3523 } | 3577 } |
3524 | 3578 |
3525 bool | 3579 bool |
3526 WifiPhy::IsStateSwitching (void) | 3580 WifiPhy::IsStateSwitching (void) const |
3527 { | 3581 { |
3528 return m_state->IsStateSwitching (); | 3582 return m_state->IsStateSwitching (); |
3529 } | 3583 } |
3530 | 3584 |
3531 bool | 3585 bool |
3532 WifiPhy::IsStateSleep (void) | 3586 WifiPhy::IsStateSleep (void) const |
3533 { | 3587 { |
3534 return m_state->IsStateSleep (); | 3588 return m_state->IsStateSleep (); |
| 3589 } |
| 3590 |
| 3591 bool |
| 3592 WifiPhy::IsStateOff (void) const |
| 3593 { |
| 3594 return m_state->IsStateOff (); |
3535 } | 3595 } |
3536 | 3596 |
3537 Time | 3597 Time |
3538 WifiPhy::GetStateDuration (void) | 3598 WifiPhy::GetStateDuration (void) |
3539 { | 3599 { |
3540 return m_state->GetStateDuration (); | 3600 return m_state->GetStateDuration (); |
3541 } | 3601 } |
3542 | 3602 |
3543 Time | 3603 Time |
3544 WifiPhy::GetDelayUntilIdle (void) | 3604 WifiPhy::GetDelayUntilIdle (void) |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3794 ns3::WifiPhy::GetHeMcs6 (); | 3854 ns3::WifiPhy::GetHeMcs6 (); |
3795 ns3::WifiPhy::GetHeMcs7 (); | 3855 ns3::WifiPhy::GetHeMcs7 (); |
3796 ns3::WifiPhy::GetHeMcs8 (); | 3856 ns3::WifiPhy::GetHeMcs8 (); |
3797 ns3::WifiPhy::GetHeMcs9 (); | 3857 ns3::WifiPhy::GetHeMcs9 (); |
3798 ns3::WifiPhy::GetHeMcs10 (); | 3858 ns3::WifiPhy::GetHeMcs10 (); |
3799 ns3::WifiPhy::GetHeMcs11 (); | 3859 ns3::WifiPhy::GetHeMcs11 (); |
3800 } | 3860 } |
3801 } g_constructor; ///< the constructor | 3861 } g_constructor; ///< the constructor |
3802 | 3862 |
3803 } | 3863 } |
LEFT | RIGHT |