|
|
| 30 |
#include "ampdu-tag.h" |
30 |
#include "ampdu-tag.h" |
| 31 |
#include "wifi-utils.h" |
31 |
#include "wifi-utils.h" |
| 32 |
#include "frame-capture-model.h" |
32 |
#include "frame-capture-model.h" |
|
|
33 |
#include "preamble-detection-model.h" |
| 33 |
#include "wifi-radio-energy-model.h" |
34 |
#include "wifi-radio-energy-model.h" |
| 34 |
#include "error-rate-model.h" |
35 |
#include "error-rate-model.h" |
| 35 |
#include "wifi-net-device.h" |
36 |
#include "wifi-net-device.h" |
|
Lines 299-304
WifiPhy::GetTypeId (void)
|
Link Here
|
|---|
|
| 299 |
PointerValue (), |
300 |
PointerValue (), |
| 300 |
MakePointerAccessor (&WifiPhy::m_frameCaptureModel), |
301 |
MakePointerAccessor (&WifiPhy::m_frameCaptureModel), |
| 301 |
MakePointerChecker <FrameCaptureModel> ()) |
302 |
MakePointerChecker <FrameCaptureModel> ()) |
|
|
303 |
.AddAttribute ("PreambleDetectionModel", |
| 304 |
"Ptr to an object that implements the preamble detection model", |
| 305 |
PointerValue (), |
| 306 |
MakePointerAccessor (&WifiPhy::m_preambleDetectionModel), |
| 307 |
MakePointerChecker <PreambleDetectionModel> ()) |
| 302 |
.AddAttribute ("PostReceptionErrorModel", |
308 |
.AddAttribute ("PostReceptionErrorModel", |
| 303 |
"An optional packet error model can be added to the receive " |
309 |
"An optional packet error model can be added to the receive " |
| 304 |
"packet process after any propagation-based (SNR-based) error " |
310 |
"packet process after any propagation-based (SNR-based) error " |
|
|
| 363 |
m_rxMpduReferenceNumber (0xffffffff), |
369 |
m_rxMpduReferenceNumber (0xffffffff), |
| 364 |
m_endRxEvent (), |
370 |
m_endRxEvent (), |
| 365 |
m_endPlcpRxEvent (), |
371 |
m_endPlcpRxEvent (), |
|
|
372 |
m_endPreambleDetectionEvent (), |
| 366 |
m_standard (WIFI_PHY_STANDARD_UNSPECIFIED), |
373 |
m_standard (WIFI_PHY_STANDARD_UNSPECIFIED), |
| 367 |
m_isConstructed (false), |
374 |
m_isConstructed (false), |
| 368 |
m_channelCenterFrequency (0), |
375 |
m_channelCenterFrequency (0), |
|
Lines 742-747
WifiPhy::SetFrameCaptureModel (const Ptr<FrameCaptureModel> model)
|
Link Here
|
|---|
|
| 742 |
} |
749 |
} |
| 743 |
|
750 |
|
| 744 |
void |
751 |
void |
|
|
752 |
WifiPhy::SetPreambleDetectionModel (const Ptr<PreambleDetectionModel> model) |
| 753 |
{ |
| 754 |
m_preambleDetectionModel = model; |
| 755 |
} |
| 756 |
|
| 757 |
void |
| 745 |
WifiPhy::SetWifiRadioEnergyModel (const Ptr<WifiRadioEnergyModel> wifiRadioEnergyModel) |
758 |
WifiPhy::SetWifiRadioEnergyModel (const Ptr<WifiRadioEnergyModel> wifiRadioEnergyModel) |
| 746 |
{ |
759 |
{ |
| 747 |
m_wifiRadioEnergyModel = wifiRadioEnergyModel; |
760 |
m_wifiRadioEnergyModel = wifiRadioEnergyModel; |
|
Lines 1485-1490
WifiPhy::DoChannelSwitch (uint8_t nch)
|
Link Here
|
|---|
|
| 1485 |
NS_LOG_DEBUG ("drop packet because of channel switching while reception"); |
1498 |
NS_LOG_DEBUG ("drop packet because of channel switching while reception"); |
| 1486 |
m_endPlcpRxEvent.Cancel (); |
1499 |
m_endPlcpRxEvent.Cancel (); |
| 1487 |
m_endRxEvent.Cancel (); |
1500 |
m_endRxEvent.Cancel (); |
|
|
1501 |
m_endPreambleDetectionEvent.Cancel (); |
| 1488 |
goto switchChannel; |
1502 |
goto switchChannel; |
| 1489 |
break; |
1503 |
break; |
| 1490 |
case WifiPhyState::TX: |
1504 |
case WifiPhyState::TX: |
|
Lines 1493-1498
WifiPhy::DoChannelSwitch (uint8_t nch)
|
Link Here
|
|---|
|
| 1493 |
break; |
1507 |
break; |
| 1494 |
case WifiPhyState::CCA_BUSY: |
1508 |
case WifiPhyState::CCA_BUSY: |
| 1495 |
case WifiPhyState::IDLE: |
1509 |
case WifiPhyState::IDLE: |
|
|
1510 |
if (m_endPreambleDetectionEvent.IsRunning ()) |
| 1511 |
{ |
| 1512 |
m_endPreambleDetectionEvent.Cancel (); |
| 1513 |
m_endRxEvent.Cancel (); |
| 1514 |
} |
| 1496 |
goto switchChannel; |
1515 |
goto switchChannel; |
| 1497 |
break; |
1516 |
break; |
| 1498 |
case WifiPhyState::SLEEP: |
1517 |
case WifiPhyState::SLEEP: |
|
Lines 1537-1542
WifiPhy::DoFrequencySwitch (uint16_t frequency)
|
Link Here
|
|---|
|
| 1537 |
NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception"); |
1556 |
NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception"); |
| 1538 |
m_endPlcpRxEvent.Cancel (); |
1557 |
m_endPlcpRxEvent.Cancel (); |
| 1539 |
m_endRxEvent.Cancel (); |
1558 |
m_endRxEvent.Cancel (); |
|
|
1559 |
m_endPreambleDetectionEvent.Cancel (); |
| 1540 |
goto switchFrequency; |
1560 |
goto switchFrequency; |
| 1541 |
break; |
1561 |
break; |
| 1542 |
case WifiPhyState::TX: |
1562 |
case WifiPhyState::TX: |
|
Lines 1545-1550
WifiPhy::DoFrequencySwitch (uint16_t frequency)
|
Link Here
|
|---|
|
| 1545 |
break; |
1565 |
break; |
| 1546 |
case WifiPhyState::CCA_BUSY: |
1566 |
case WifiPhyState::CCA_BUSY: |
| 1547 |
case WifiPhyState::IDLE: |
1567 |
case WifiPhyState::IDLE: |
|
|
1568 |
if (m_endPreambleDetectionEvent.IsRunning ()) |
| 1569 |
{ |
| 1570 |
m_endPreambleDetectionEvent.Cancel (); |
| 1571 |
m_endRxEvent.Cancel (); |
| 1572 |
} |
| 1548 |
goto switchFrequency; |
1573 |
goto switchFrequency; |
| 1549 |
break; |
1574 |
break; |
| 1550 |
case WifiPhyState::SLEEP: |
1575 |
case WifiPhyState::SLEEP: |
|
|
| 1608 |
WifiPhy::SetOffMode (void) |
1633 |
WifiPhy::SetOffMode (void) |
| 1609 |
{ |
1634 |
{ |
| 1610 |
NS_LOG_FUNCTION (this); |
1635 |
NS_LOG_FUNCTION (this); |
| 1611 |
switch (m_state->GetState ()) |
1636 |
m_endPlcpRxEvent.Cancel (); |
| 1612 |
{ |
1637 |
m_endRxEvent.Cancel (); |
| 1613 |
case WifiPhyState::RX: |
1638 |
m_endPreambleDetectionEvent.Cancel (); |
| 1614 |
m_endPlcpRxEvent.Cancel (); |
1639 |
m_state->SwitchToOff (); |
| 1615 |
m_endRxEvent.Cancel (); |
|
|
| 1616 |
case WifiPhyState::TX: |
| 1617 |
case WifiPhyState::SWITCHING: |
| 1618 |
case WifiPhyState::CCA_BUSY: |
| 1619 |
case WifiPhyState::IDLE: |
| 1620 |
case WifiPhyState::SLEEP: |
| 1621 |
m_state->SwitchToOff (); |
| 1622 |
break; |
| 1623 |
default: |
| 1624 |
NS_ASSERT (false); |
| 1625 |
break; |
| 1626 |
} |
| 1627 |
} |
1640 |
} |
| 1628 |
|
1641 |
|
| 1629 |
void |
1642 |
void |
|
Lines 1706-1711
WifiPhy::GetHePlcpHeaderMode ()
|
Link Here
|
|---|
|
| 1706 |
} |
1719 |
} |
| 1707 |
|
1720 |
|
| 1708 |
Time |
1721 |
Time |
|
|
1722 |
WifiPhy::GetPreambleDetectionDuration (void) |
| 1723 |
{ |
| 1724 |
return MicroSeconds (4); |
| 1725 |
} |
| 1726 |
|
| 1727 |
Time |
| 1709 |
WifiPhy::GetPlcpTrainingSymbolDuration (WifiTxVector txVector) |
1728 |
WifiPhy::GetPlcpTrainingSymbolDuration (WifiTxVector txVector) |
| 1710 |
{ |
1729 |
{ |
| 1711 |
uint8_t Ndltf, Neltf; |
1730 |
uint8_t Ndltf, Neltf; |
|
Lines 2368-2379
WifiPhy::SendPacket (Ptr<const Packet> packet, WifiTxVector txVector, MpduType m
|
Link Here
|
|---|
|
| 2368 |
Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1); |
2387 |
Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1); |
| 2369 |
NS_ASSERT (txDuration.IsStrictlyPositive ()); |
2388 |
NS_ASSERT (txDuration.IsStrictlyPositive ()); |
| 2370 |
|
2389 |
|
| 2371 |
if (m_state->IsStateRx ()) |
2390 |
if (m_endPreambleDetectionEvent.IsRunning ()) |
|
|
2391 |
{ |
| 2392 |
m_endPreambleDetectionEvent.Cancel (); |
| 2393 |
} |
| 2394 |
if (m_endPlcpRxEvent.IsRunning ()) |
| 2372 |
{ |
2395 |
{ |
| 2373 |
m_endPlcpRxEvent.Cancel (); |
2396 |
m_endPlcpRxEvent.Cancel (); |
|
|
2397 |
} |
| 2398 |
if (m_endRxEvent.IsRunning ()) |
| 2399 |
{ |
| 2374 |
m_endRxEvent.Cancel (); |
2400 |
m_endRxEvent.Cancel (); |
|
|
2401 |
} |
| 2402 |
if (m_state->IsStateRx ()) |
| 2403 |
{ |
| 2375 |
m_interference.NotifyRxEnd (); |
2404 |
m_interference.NotifyRxEnd (); |
| 2376 |
} |
2405 |
} |
|
|
2406 |
|
| 2377 |
NotifyTxBegin (packet); |
2407 |
NotifyTxBegin (packet); |
| 2378 |
if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE)) |
2408 |
if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE)) |
| 2379 |
{ |
2409 |
{ |
|
Lines 2406-2412
WifiPhy::SendPacket (Ptr<const Packet> packet, WifiTxVector txVector, MpduType m
|
Link Here
|
|---|
|
| 2406 |
} |
2436 |
} |
| 2407 |
|
2437 |
|
| 2408 |
void |
2438 |
void |
| 2409 |
WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Time rxDuration) |
2439 |
WifiPhy::StartReceiveHeader (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, Ptr<Event> event, Time rxDuration) |
|
|
2440 |
{ |
| 2441 |
NS_LOG_FUNCTION (this << packet << txVector.GetMode () << txVector.GetPreambleType () << +mpdutype); |
| 2442 |
NS_ASSERT (!IsStateRx ()); |
| 2443 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
| 2444 |
|
| 2445 |
InterferenceHelper::SnrPer snrPer = m_interference.CalculatePlcpHeaderSnrPer (event); |
| 2446 |
double snr = snrPer.snr; |
| 2447 |
NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per); |
| 2448 |
|
| 2449 |
if (!m_preambleDetectionModel || (m_preambleDetectionModel->IsPreambleDetected (snr, m_channelWidth))) |
| 2450 |
{ |
| 2451 |
// switch to RX after successful preamble detection |
| 2452 |
m_state->SwitchToRx (rxDuration); |
| 2453 |
Time remainingPreambleHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector) - GetPreambleDetectionDuration (); |
| 2454 |
m_endPlcpRxEvent = Simulator::Schedule (remainingPreambleHeaderDuration, &WifiPhy::StartReceivePacket, this, |
| 2455 |
packet, txVector, mpdutype, event); |
| 2456 |
} |
| 2457 |
else |
| 2458 |
{ |
| 2459 |
NS_LOG_DEBUG ("drop packet because PHY preamble detection failed"); |
| 2460 |
NotifyRxDrop (packet); |
| 2461 |
m_plcpSuccess = false; |
| 2462 |
} |
| 2463 |
} |
| 2464 |
|
| 2465 |
void |
| 2466 |
WifiPhy::StartReceivePreamble (Ptr<Packet> packet, double rxPowerW, Time rxDuration) |
| 2410 |
{ |
2467 |
{ |
| 2411 |
WifiPhyTag tag; |
2468 |
WifiPhyTag tag; |
| 2412 |
bool found = packet->RemovePacketTag (tag); |
2469 |
bool found = packet->RemovePacketTag (tag); |
|
Lines 2564-2571
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 2564 |
InterferenceHelper::SnrPer snrPer; |
2621 |
InterferenceHelper::SnrPer snrPer; |
| 2565 |
snrPer = m_interference.CalculatePlcpHeaderSnrPer (event); |
2622 |
snrPer = m_interference.CalculatePlcpHeaderSnrPer (event); |
| 2566 |
|
2623 |
|
| 2567 |
NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per); |
|
|
| 2568 |
|
| 2569 |
if (m_random->GetValue () > snrPer.per) //plcp reception succeeded |
2624 |
if (m_random->GetValue () > snrPer.per) //plcp reception succeeded |
| 2570 |
{ |
2625 |
{ |
| 2571 |
if (IsModeSupported (txMode) || IsMcsSupported (txMode)) |
2626 |
if (IsModeSupported (txMode) || IsMcsSupported (txMode)) |
|
Lines 2582-2588
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
|
Link Here
|
|---|
|
| 2582 |
} |
2637 |
} |
| 2583 |
else //plcp reception failed |
2638 |
else //plcp reception failed |
| 2584 |
{ |
2639 |
{ |
| 2585 |
NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed"); |
2640 |
NS_LOG_DEBUG ("drop packet because PHY header reception failed"); |
| 2586 |
NotifyRxDrop (packet); |
2641 |
NotifyRxDrop (packet); |
| 2587 |
m_plcpSuccess = false; |
2642 |
m_plcpSuccess = false; |
| 2588 |
} |
2643 |
} |
|
|
| 3658 |
WifiPhy::AbortCurrentReception () |
3713 |
WifiPhy::AbortCurrentReception () |
| 3659 |
{ |
3714 |
{ |
| 3660 |
NS_LOG_FUNCTION (this); |
3715 |
NS_LOG_FUNCTION (this); |
|
|
3716 |
if (m_endPreambleDetectionEvent.IsRunning ()) |
| 3717 |
{ |
| 3718 |
m_endPreambleDetectionEvent.Cancel (); |
| 3719 |
} |
| 3661 |
if (m_endPlcpRxEvent.IsRunning ()) |
3720 |
if (m_endPlcpRxEvent.IsRunning ()) |
| 3662 |
{ |
3721 |
{ |
| 3663 |
m_endPlcpRxEvent.Cancel (); |
3722 |
m_endPlcpRxEvent.Cancel (); |
|
Lines 3721-3737
WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype,
|
Link Here
|
|---|
|
| 3721 |
|
3780 |
|
| 3722 |
NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)"); |
3781 |
NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)"); |
| 3723 |
m_currentEvent = event; |
3782 |
m_currentEvent = event; |
| 3724 |
m_state->SwitchToRx (rxDuration); |
3783 |
|
| 3725 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
3784 |
if (preamble == WIFI_PREAMBLE_NONE) |
|
|
3785 |
{ |
| 3786 |
m_state->SwitchToRx (rxDuration); |
| 3787 |
} |
| 3726 |
NotifyRxBegin (packet); |
3788 |
NotifyRxBegin (packet); |
| 3727 |
m_interference.NotifyRxStart (); |
3789 |
m_interference.NotifyRxStart (); |
| 3728 |
|
3790 |
|
| 3729 |
if (preamble != WIFI_PREAMBLE_NONE) |
3791 |
if (preamble != WIFI_PREAMBLE_NONE) |
| 3730 |
{ |
3792 |
{ |
| 3731 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
3793 |
if (m_endPreambleDetectionEvent.IsRunning ()) |
| 3732 |
Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector); |
3794 |
{ |
| 3733 |
m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this, |
3795 |
m_endPreambleDetectionEvent.Cancel (); |
| 3734 |
packet, txVector, mpdutype, event); |
3796 |
} |
|
|
3797 |
|
| 3798 |
Time startOfPreambleDuration = GetPreambleDetectionDuration (); |
| 3799 |
Time remainingRxDuration = rxDuration - startOfPreambleDuration; |
| 3800 |
m_endPreambleDetectionEvent = Simulator::Schedule (startOfPreambleDuration, &WifiPhy::StartReceiveHeader, this, |
| 3801 |
packet, txVector, mpdutype, event, remainingRxDuration); |
| 3802 |
if (m_endRxEvent.IsRunning ()) |
| 3803 |
{ |
| 3804 |
m_endRxEvent.Cancel (); |
| 3805 |
} |
| 3735 |
} |
3806 |
} |
| 3736 |
|
3807 |
|
| 3737 |
NS_ASSERT (m_endRxEvent.IsExpired ()); |
3808 |
NS_ASSERT (m_endRxEvent.IsExpired ()); |