View | Details | Raw Unified | Return to bug 3020
Collapse All | Expand All

(-)a/src/wifi/model/interference-helper.cc (-5 / +16 lines)
 Lines 25-30    Link Here 
25
#include "interference-helper.h"
25
#include "interference-helper.h"
26
#include "wifi-phy.h"
26
#include "wifi-phy.h"
27
#include "error-rate-model.h"
27
#include "error-rate-model.h"
28
#include "wifi-utils.h"
28
29
29
namespace ns3 {
30
namespace ns3 {
30
31
 Lines 229-254   InterferenceHelper::CalculateSnr (double signal, double noiseInterference, uint1 Link Here 
229
  double noiseFloor = m_noiseFigure * Nt;
230
  double noiseFloor = m_noiseFigure * Nt;
230
  double noise = noiseFloor + noiseInterference;
231
  double noise = noiseFloor + noiseInterference;
231
  double snr = signal / noise; //linear scale
232
  double snr = signal / noise; //linear scale
232
  NS_LOG_DEBUG ("bandwidth(MHz)=" << channelWidth << ", signal(W)= " << signal << ", noise(W)=" << noiseFloor << ", interference(W)=" << noiseInterference << ", snr(linear)=" << snr);
233
  NS_LOG_DEBUG ("bandwidth(MHz)=" << channelWidth << ", signal(W)= " << signal << ", noise(W)=" << noiseFloor << ", interference(W)=" << noiseInterference << ", snr=" << RatioToDb(snr) << "dB");
233
  return snr;
234
  return snr;
234
}
235
}
235
236
236
double
237
double
237
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const
238
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const
238
{
239
{
239
  double noiseInterference = m_firstPower;
240
  double noiseInterferenceW = m_firstPower;
240
  auto it = m_niChanges.find (event->GetStartTime ());
241
  auto it = m_niChanges.find (event->GetStartTime ());
241
  for (; it != m_niChanges.end () && it->second.GetEvent () != event; ++it)
242
  for (; it != m_niChanges.end (); ++it)
242
    {
243
    {
243
      noiseInterference = it->second.GetPower ();
244
      if (it->second.GetEvent () == event)
245
        {
246
          continue;
247
        }
248
      if (it->first > Simulator::Now ())
249
        {
250
          break;
251
        }
252
      noiseInterferenceW = it->second.GetPower () - event->GetRxPowerW ();
244
    }
253
    }
254
  it = m_niChanges.find (event->GetStartTime ());
255
  for (; it != m_niChanges.end () && it->second.GetEvent () != event; ++it);
245
  ni->emplace (event->GetStartTime (), NiChange (0, event));
256
  ni->emplace (event->GetStartTime (), NiChange (0, event));
246
  while (++it != m_niChanges.end () && it->second.GetEvent () != event)
257
  while (++it != m_niChanges.end () && it->second.GetEvent () != event)
247
    {
258
    {
248
      ni->insert (*it);
259
      ni->insert (*it);
249
    }
260
    }
250
  ni->emplace (event->GetEndTime (), NiChange (0, event));
261
  ni->emplace (event->GetEndTime (), NiChange (0, event));
251
  return noiseInterference;
262
  return noiseInterferenceW;
252
}
263
}
253
264
254
double
265
double
(-)a/src/wifi/model/preamble-detection-model.cc (+36 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018 University of Washington
4
 *
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
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "preamble-detection-model.h"
22
23
namespace ns3 {
24
25
NS_OBJECT_ENSURE_REGISTERED (PreambleDetectionModel);
26
27
TypeId PreambleDetectionModel::GetTypeId (void)
28
{
29
  static TypeId tid = TypeId ("ns3::PreambleDetectionModel")
30
    .SetParent<Object> ()
31
    .SetGroupName ("Wifi")
32
  ;
33
  return tid;
34
}
35
36
} //namespace ns3
(-)a/src/wifi/model/preamble-detection-model.h (+58 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018 University of Washington
4
 *
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
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#ifndef PREAMBLE_DETECTION_MODEL_H
22
#define PREAMBLE_DETECTION_MODEL_H
23
24
#include "ns3/object.h"
25
26
namespace ns3 {
27
28
/**
29
 * \ingroup wifi
30
 * \brief the interface for Wifi's preamble detection models
31
 *
32
 */
33
class PreambleDetectionModel : public Object
34
{
35
public:
36
  /**
37
   * \brief Get the type ID.
38
   * \return the object TypeId
39
   */
40
  static TypeId GetTypeId (void);
41
42
  /**
43
   * A pure virtual method that must be implemented in the subclass.
44
   * This method returns whether the preamble detection was successful.
45
   *
46
   * \param snr the SNR of the received signal.
47
   * \param channelWidth the channel width of the received signal in MHz.
48
   *
49
   * \return true if the preamble has been detected,
50
   *         false otherwise
51
   */
52
  virtual bool IsPreambleDetected (double snr, double channelWidth) const = 0;
53
};
54
55
} //namespace ns3
56
57
#endif /* PREAMBLE_DETECTION_MODEL_H */
58
(-)a/src/wifi/model/spectrum-wifi-phy.cc (-1 / +1 lines)
 Lines 259-265   SpectrumWifiPhy::StartRx (Ptr<SpectrumSignalParameters> rxParams) Link Here 
259
259
260
  NS_LOG_INFO ("Received Wi-Fi signal");
260
  NS_LOG_INFO ("Received Wi-Fi signal");
261
  Ptr<Packet> packet = wifiRxParams->packet->Copy ();
261
  Ptr<Packet> packet = wifiRxParams->packet->Copy ();
262
  StartReceivePreambleAndHeader (packet, rxPowerW, rxDuration);
262
  StartReceivePreamble (packet, rxPowerW, rxDuration);
263
}
263
}
264
264
265
Ptr<AntennaModel>
265
Ptr<AntennaModel>
(-)a/src/wifi/model/threshold-preamble-detection-model.cc (+65 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018 University of Washington
4
 *
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
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "ns3/log.h"
22
#include "ns3/double.h"
23
#include "threshold-preamble-detection-model.h"
24
#include "wifi-utils.h"
25
26
namespace ns3 {
27
28
NS_LOG_COMPONENT_DEFINE ("ThresholdPreambleDetectionModel");
29
30
NS_OBJECT_ENSURE_REGISTERED (ThresholdPreambleDetectionModel);
31
32
TypeId
33
ThresholdPreambleDetectionModel::GetTypeId (void)
34
{
35
  static TypeId tid = TypeId ("ns3::ThresholdPreambleDetectionModel")
36
    .SetParent<PreambleDetectionModel> ()
37
    .SetGroupName ("Wifi")
38
    .AddConstructor<ThresholdPreambleDetectionModel> ()
39
    .AddAttribute ("Threshold",
40
                   "Preamble is successfully detection if the SNR is at or above this value (expressed in dB).",
41
                   DoubleValue (2),
42
                   MakeDoubleAccessor (&ThresholdPreambleDetectionModel::m_threshold),
43
                   MakeDoubleChecker<double> ())
44
  ;
45
  return tid;
46
}
47
48
ThresholdPreambleDetectionModel::ThresholdPreambleDetectionModel ()
49
{
50
  NS_LOG_FUNCTION (this);
51
}
52
53
ThresholdPreambleDetectionModel::~ThresholdPreambleDetectionModel ()
54
{
55
  NS_LOG_FUNCTION (this);
56
}
57
58
bool
59
ThresholdPreambleDetectionModel::IsPreambleDetected (double snr, double channelWidth) const
60
{
61
  NS_LOG_FUNCTION (this);
62
  return (RatioToDb (snr) >= m_threshold);
63
}
64
65
} //namespace ns3
(-)a/src/wifi/model/threshold-preamble-detection-model.h (+63 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018 University of Washington
4
 *
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
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#ifndef THRESHOLD_PREAMBLE_DETECTION_MODEL_H
22
#define THRESHOLD_PREAMBLE_DETECTION_MODEL_H
23
24
#include "preamble-detection-model.h"
25
26
namespace ns3 {
27
/**
28
 * \ingroup wifi
29
 *
30
 * A threshold-based model for detecting PHY preamble.
31
 * This model assumes that a preamble is successfully detected if SNR is at or above a given threshold. By default, this threshold is set to 2 dB.
32
 */
33
class ThresholdPreambleDetectionModel : public PreambleDetectionModel
34
{
35
public:
36
  /**
37
   * \brief Get the type ID.
38
   * \return the object TypeId
39
   */
40
  static TypeId GetTypeId (void);
41
42
  ThresholdPreambleDetectionModel ();
43
  ~ThresholdPreambleDetectionModel ();
44
45
  /**
46
   * This method returns whether the preamble detection was successful.
47
   *
48
   * \param snr the SNR ratio (not dB) of the received signal.
49
   * \param channelWidth the channel width of the received signal in MHz.
50
   *
51
   * \return true if the preamble has been detected,
52
   *         false otherwise
53
   */
54
  bool IsPreambleDetected (double snr, double channelWidth) const;
55
56
57
private:
58
  double m_threshold; ///< SNR threshold in dB used to decide whether a preamble is successfully received
59
};
60
61
} //namespace ns3
62
63
#endif /* THRESHOLD_PREAMBLE_DETECTION_MODEL_H */
(-)a/src/wifi/model/wifi-phy.cc (-38 / +113 lines)
 Lines 30-35    Link Here 
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 "
 Lines 363-368   WifiPhy::WifiPhy () Link Here 
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 392-397   void Link Here 
392
WifiPhy::DoDispose (void)
399
WifiPhy::DoDispose (void)
393
{
400
{
394
  NS_LOG_FUNCTION (this);
401
  NS_LOG_FUNCTION (this);
402
  m_endRxEvent.Cancel ();
403
  m_endPlcpRxEvent.Cancel ();
404
  m_endPreambleDetectionEvent.Cancel ();
395
  m_device = 0;
405
  m_device = 0;
396
  m_mobility = 0;
406
  m_mobility = 0;
397
  m_state = 0;
407
  m_state = 0;
 Lines 742-747   WifiPhy::SetFrameCaptureModel (const Ptr<FrameCaptureModel> model) Link Here 
742
}
752
}
743
753
744
void
754
void
755
WifiPhy::SetPreambleDetectionModel (const Ptr<PreambleDetectionModel> model)
756
{
757
  m_preambleDetectionModel = model;
758
}
759
760
void
745
WifiPhy::SetWifiRadioEnergyModel (const Ptr<WifiRadioEnergyModel> wifiRadioEnergyModel)
761
WifiPhy::SetWifiRadioEnergyModel (const Ptr<WifiRadioEnergyModel> wifiRadioEnergyModel)
746
{
762
{
747
  m_wifiRadioEnergyModel = wifiRadioEnergyModel;
763
  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");
1501
      NS_LOG_DEBUG ("drop packet because of channel switching while reception");
1486
      m_endPlcpRxEvent.Cancel ();
1502
      m_endPlcpRxEvent.Cancel ();
1487
      m_endRxEvent.Cancel ();
1503
      m_endRxEvent.Cancel ();
1504
      m_endPreambleDetectionEvent.Cancel ();
1488
      goto switchChannel;
1505
      goto switchChannel;
1489
      break;
1506
      break;
1490
    case WifiPhyState::TX:
1507
    case WifiPhyState::TX:
 Lines 1493-1498   WifiPhy::DoChannelSwitch (uint8_t nch) Link Here 
1493
      break;
1510
      break;
1494
    case WifiPhyState::CCA_BUSY:
1511
    case WifiPhyState::CCA_BUSY:
1495
    case WifiPhyState::IDLE:
1512
    case WifiPhyState::IDLE:
1513
      if (m_endPreambleDetectionEvent.IsRunning ())
1514
      {
1515
        m_endPreambleDetectionEvent.Cancel ();
1516
        m_endRxEvent.Cancel ();
1517
      }
1496
      goto switchChannel;
1518
      goto switchChannel;
1497
      break;
1519
      break;
1498
    case WifiPhyState::SLEEP:
1520
    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");
1559
      NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception");
1538
      m_endPlcpRxEvent.Cancel ();
1560
      m_endPlcpRxEvent.Cancel ();
1539
      m_endRxEvent.Cancel ();
1561
      m_endRxEvent.Cancel ();
1562
      m_endPreambleDetectionEvent.Cancel ();
1540
      goto switchFrequency;
1563
      goto switchFrequency;
1541
      break;
1564
      break;
1542
    case WifiPhyState::TX:
1565
    case WifiPhyState::TX:
 Lines 1545-1550   WifiPhy::DoFrequencySwitch (uint16_t frequency) Link Here 
1545
      break;
1568
      break;
1546
    case WifiPhyState::CCA_BUSY:
1569
    case WifiPhyState::CCA_BUSY:
1547
    case WifiPhyState::IDLE:
1570
    case WifiPhyState::IDLE:
1571
      if (m_endPreambleDetectionEvent.IsRunning ())
1572
      {
1573
        m_endPreambleDetectionEvent.Cancel ();
1574
        m_endRxEvent.Cancel ();
1575
      }
1548
      goto switchFrequency;
1576
      goto switchFrequency;
1549
      break;
1577
      break;
1550
    case WifiPhyState::SLEEP:
1578
    case WifiPhyState::SLEEP:
 Lines 1608-1629   void Link Here 
1608
WifiPhy::SetOffMode (void)
1636
WifiPhy::SetOffMode (void)
1609
{
1637
{
1610
  NS_LOG_FUNCTION (this);
1638
  NS_LOG_FUNCTION (this);
1611
  switch (m_state->GetState ())
1639
  m_endPlcpRxEvent.Cancel ();
1612
    {
1640
  m_endRxEvent.Cancel ();
1613
    case WifiPhyState::RX:
1641
  m_endPreambleDetectionEvent.Cancel ();
1614
      m_endPlcpRxEvent.Cancel ();
1642
  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
}
1643
}
1628
1644
1629
void
1645
void
 Lines 1706-1711   WifiPhy::GetHePlcpHeaderMode () Link Here 
1706
}
1722
}
1707
1723
1708
Time
1724
Time
1725
WifiPhy::GetPreambleDetectionDuration (void)
1726
{
1727
  return MicroSeconds (4);
1728
}
1729
1730
Time
1709
WifiPhy::GetPlcpTrainingSymbolDuration (WifiTxVector txVector)
1731
WifiPhy::GetPlcpTrainingSymbolDuration (WifiTxVector txVector)
1710
{
1732
{
1711
  uint8_t Ndltf, Neltf;
1733
  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);
2390
  Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1);
2369
  NS_ASSERT (txDuration.IsStrictlyPositive ());
2391
  NS_ASSERT (txDuration.IsStrictlyPositive ());
2370
2392
2371
  if (m_state->IsStateRx ())
2393
  if (m_endPreambleDetectionEvent.IsRunning ())
2394
    {
2395
      m_endPreambleDetectionEvent.Cancel ();
2396
    }
2397
  if (m_endPlcpRxEvent.IsRunning ())
2372
    {
2398
    {
2373
      m_endPlcpRxEvent.Cancel ();
2399
      m_endPlcpRxEvent.Cancel ();
2400
    }
2401
  if (m_endRxEvent.IsRunning ())
2402
    {
2374
      m_endRxEvent.Cancel ();
2403
      m_endRxEvent.Cancel ();
2404
    }
2405
  if (m_state->IsStateRx ())
2406
    {
2375
      m_interference.NotifyRxEnd ();
2407
      m_interference.NotifyRxEnd ();
2376
    }
2408
    }
2409
2377
  NotifyTxBegin (packet);
2410
  NotifyTxBegin (packet);
2378
  if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE))
2411
  if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE))
2379
    {
2412
    {
 Lines 2406-2412   WifiPhy::SendPacket (Ptr<const Packet> packet, WifiTxVector txVector, MpduType m Link Here 
2406
}
2439
}
2407
2440
2408
void
2441
void
2409
WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Time rxDuration)
2442
WifiPhy::StartReceiveHeader (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, Ptr<Event> event, Time rxDuration)
2443
{
2444
  NS_LOG_FUNCTION (this << packet << txVector.GetMode () << txVector.GetPreambleType () << +mpdutype);
2445
  NS_ASSERT (!IsStateRx ());
2446
  NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2447
2448
  InterferenceHelper::SnrPer snrPer = m_interference.CalculatePlcpHeaderSnrPer (event);
2449
  double snr = snrPer.snr;
2450
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2451
2452
  if (!m_preambleDetectionModel || (m_preambleDetectionModel->IsPreambleDetected (snr, m_channelWidth)))
2453
  {
2454
    m_state->SwitchToRx (rxDuration);
2455
    NotifyRxBegin (packet);
2456
2457
    Time remainingPreambleHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector) - GetPreambleDetectionDuration ();
2458
    m_endPlcpRxEvent = Simulator::Schedule (remainingPreambleHeaderDuration, &WifiPhy::StartReceivePacket, this,
2459
                                            packet, txVector, mpdutype, event);
2460
2461
    NS_ASSERT (m_endRxEvent.IsExpired ());
2462
    m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2463
                                        packet, txVector.GetPreambleType (), mpdutype, event);
2464
  }
2465
  else
2466
  {
2467
    NS_LOG_DEBUG ("Packet reception could not be started because PHY preamble detection failed");
2468
    m_plcpSuccess = false;
2469
    m_interference.NotifyRxEnd ();
2470
  }
2471
}
2472
2473
void
2474
WifiPhy::StartReceivePreamble (Ptr<Packet> packet, double rxPowerW, Time rxDuration)
2410
{
2475
{
2411
  WifiPhyTag tag;
2476
  WifiPhyTag tag;
2412
  bool found = packet->RemovePacketTag (tag);
2477
  bool found = packet->RemovePacketTag (tag);
 Lines 2435-2442   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2435
2500
2436
  if (tag.GetFrameComplete () == 0)
2501
  if (tag.GetFrameComplete () == 0)
2437
    {
2502
    {
2438
      NS_LOG_DEBUG ("drop packet because of incomplete frame");
2503
      NS_LOG_DEBUG ("Packet reception stopped because transmitter has been switched off");
2439
      NotifyRxDrop (packet);
2440
      m_plcpSuccess = false;
2504
      m_plcpSuccess = false;
2441
      return;
2505
      return;
2442
    }
2506
    }
 Lines 2450-2457   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2450
  Time endRx = Simulator::Now () + rxDuration;
2514
  Time endRx = Simulator::Now () + rxDuration;
2451
  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2515
  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2452
    {
2516
    {
2453
      NS_LOG_DEBUG ("drop packet because not enough RX antennas");
2517
      NS_LOG_DEBUG ("Packet reception could not be started because not enough RX antennas");
2454
      NotifyRxDrop (packet);
2455
      m_plcpSuccess = false;
2518
      m_plcpSuccess = false;
2456
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2519
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2457
        {
2520
        {
 Lines 2564-2571   WifiPhy::StartReceivePacket (Ptr<Packet> packet, Link Here 
2564
  InterferenceHelper::SnrPer snrPer;
2627
  InterferenceHelper::SnrPer snrPer;
2565
  snrPer = m_interference.CalculatePlcpHeaderSnrPer (event);
2628
  snrPer = m_interference.CalculatePlcpHeaderSnrPer (event);
2566
2629
2567
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2568
2569
  if (m_random->GetValue () > snrPer.per) //plcp reception succeeded
2630
  if (m_random->GetValue () > snrPer.per) //plcp reception succeeded
2570
    {
2631
    {
2571
      if (IsModeSupported (txMode) || IsMcsSupported (txMode))
2632
      if (IsModeSupported (txMode) || IsMcsSupported (txMode))
 Lines 2582-2588   WifiPhy::StartReceivePacket (Ptr<Packet> packet, Link Here 
2582
    }
2643
    }
2583
  else //plcp reception failed
2644
  else //plcp reception failed
2584
    {
2645
    {
2585
      NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed");
2646
      NS_LOG_DEBUG ("drop packet because PHY header reception failed");
2586
      NotifyRxDrop (packet);
2647
      NotifyRxDrop (packet);
2587
      m_plcpSuccess = false;
2648
      m_plcpSuccess = false;
2588
    }
2649
    }
 Lines 3658-3663   void Link Here 
3658
WifiPhy::AbortCurrentReception ()
3719
WifiPhy::AbortCurrentReception ()
3659
{
3720
{
3660
  NS_LOG_FUNCTION (this);
3721
  NS_LOG_FUNCTION (this);
3722
  if (m_endPreambleDetectionEvent.IsRunning ())
3723
    {
3724
      m_endPreambleDetectionEvent.Cancel ();
3725
    }
3661
  if (m_endPlcpRxEvent.IsRunning ())
3726
  if (m_endPlcpRxEvent.IsRunning ())
3662
    {
3727
    {
3663
      m_endPlcpRxEvent.Cancel ();
3728
      m_endPlcpRxEvent.Cancel ();
 Lines 3721-3742   WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, Link Here 
3721
3786
3722
      NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3787
      NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3723
      m_currentEvent = event;
3788
      m_currentEvent = event;
3724
      m_state->SwitchToRx (rxDuration);
3725
      NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3726
      NotifyRxBegin (packet);
3727
      m_interference.NotifyRxStart ();
3728
3789
3729
      if (preamble != WIFI_PREAMBLE_NONE)
3790
      m_interference.NotifyRxStart (); //We need to notify it now so that it starts recording events
3791
      if (preamble == WIFI_PREAMBLE_NONE)
3730
        {
3792
        {
3731
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3793
          m_state->SwitchToRx (rxDuration);
3732
          Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3794
          NotifyRxBegin (packet);
3733
          m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3795
          m_interference.NotifyRxStart ();
3734
                                                  packet, txVector, mpdutype, event);
3735
        }
3736
3796
3737
      NS_ASSERT (m_endRxEvent.IsExpired ());
3797
          NS_ASSERT (m_endRxEvent.IsExpired ());
3738
      m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3798
          m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3739
                                          packet, preamble, mpdutype, event);
3799
                                              packet, txVector.GetPreambleType (), mpdutype, event);
3800
        }
3801
      else
3802
        {
3803
          if (!m_endPreambleDetectionEvent.IsRunning ())
3804
            {
3805
              Time startOfPreambleDuration = GetPreambleDetectionDuration ();
3806
              Time remainingRxDuration = rxDuration - startOfPreambleDuration;
3807
              m_endPreambleDetectionEvent = Simulator::Schedule (startOfPreambleDuration, &WifiPhy::StartReceiveHeader, this,
3808
                                                                 packet, txVector, mpdutype, event, remainingRxDuration);
3809
            }
3810
          else
3811
            {
3812
              NS_LOG_DEBUG ("Ignore packet because RX is already decoding preamble");
3813
            }
3814
        }
3740
    }
3815
    }
3741
  else
3816
  else
3742
    {
3817
    {
(-)a/src/wifi/model/wifi-phy.h (-6 / +35 lines)
 Lines 40-45   class NetDevice; Link Here 
40
class MobilityModel;
40
class MobilityModel;
41
class WifiPhyStateHelper;
41
class WifiPhyStateHelper;
42
class FrameCaptureModel;
42
class FrameCaptureModel;
43
class PreambleDetectionModel;
43
class WifiRadioEnergyModel;
44
class WifiRadioEnergyModel;
44
class UniformRandomVariable;
45
class UniformRandomVariable;
45
46
 Lines 106-120   public: Link Here 
106
  void SetCapabilitiesChangedCallback (Callback<void> callback);
107
  void SetCapabilitiesChangedCallback (Callback<void> callback);
107
108
108
  /**
109
  /**
109
   * Starting receiving the plcp of a packet (i.e. the first bit of the preamble has arrived).
110
   * Starting receiving the PHY preamble of a packet (i.e. the first bit of the preamble has arrived).
110
   *
111
   *
111
   * \param packet the arriving packet
112
   * \param packet the arriving packet
112
   * \param rxPowerW the receive power in W
113
   * \param rxPowerW the receive power in W
113
   * \param rxDuration the duration needed for the reception of the packet
114
   * \param rxDuration the duration needed for the reception of the packet
114
   */
115
   */
115
  void StartReceivePreambleAndHeader (Ptr<Packet> packet,
116
  void StartReceivePreamble (Ptr<Packet> packet,
116
                                      double rxPowerW,
117
                             double rxPowerW,
117
                                      Time rxDuration);
118
                             Time rxDuration);
119
120
  /**
121
   * Starting receiving the PHY header of a packet (i.e. after the end of receiving the preamble).
122
   *
123
   * \param packet the arriving packet
124
   * \param txVector the TXVECTOR of the arriving packet
125
   * \param mpdutype the type of the MPDU as defined in WifiPhy::MpduType.
126
   * \param event the corresponding event of the first time the packet arrives
127
   */
128
  void StartReceiveHeader (Ptr<Packet> packet,
129
                           WifiTxVector txVector,
130
                           MpduType mpdutype,
131
                           Ptr<Event> event,
132
                           Time rxDuration);
118
133
119
  /**
134
  /**
120
   * Starting receiving the payload of a packet (i.e. the first bit of the packet has arrived).
135
   * Starting receiving the payload of a packet (i.e. the first bit of the packet has arrived).
 Lines 245-250   public: Link Here 
245
  static Time CalculatePlcpPreambleAndHeaderDuration (WifiTxVector txVector);
260
  static Time CalculatePlcpPreambleAndHeaderDuration (WifiTxVector txVector);
246
261
247
  /**
262
  /**
263
   *
264
   * \return the preamble detection duration, which is the time correletion needs to detect the start of an incoming frame.
265
   */
266
  Time GetPreambleDetectionDuration (void);
267
268
  /**
248
   * \param txVector the transmission parameters used for this packet
269
   * \param txVector the transmission parameters used for this packet
249
   *
270
   *
250
   * \return the training symbol duration
271
   * \return the training symbol duration
 Lines 1429-1434   public: Link Here 
1429
   */
1450
   */
1430
  void SetFrameCaptureModel (const Ptr<FrameCaptureModel> frameCaptureModel);
1451
  void SetFrameCaptureModel (const Ptr<FrameCaptureModel> frameCaptureModel);
1431
  /**
1452
  /**
1453
   * Sets the preamble detection model.
1454
   *
1455
   * \param preambleDetectionModel the preamble detection model
1456
   */
1457
  void SetPreambleDetectionModel (const Ptr<PreambleDetectionModel> preambleDetectionModel);
1458
  /**
1432
   * Sets the wifi radio energy model.
1459
   * Sets the wifi radio energy model.
1433
   *
1460
   *
1434
   * \param wifiRadioEnergyModel the wifi radio energy model
1461
   * \param wifiRadioEnergyModel the wifi radio energy model
 Lines 1506-1513   protected: Link Here 
1506
  uint32_t m_txMpduReferenceNumber;    //!< A-MPDU reference number to identify all transmitted subframes belonging to the same received A-MPDU
1533
  uint32_t m_txMpduReferenceNumber;    //!< A-MPDU reference number to identify all transmitted subframes belonging to the same received A-MPDU
1507
  uint32_t m_rxMpduReferenceNumber;    //!< A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU
1534
  uint32_t m_rxMpduReferenceNumber;    //!< A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU
1508
1535
1509
  EventId m_endRxEvent;                //!< the end reeive event
1536
  EventId m_endRxEvent;                //!< the end of receive event
1510
  EventId m_endPlcpRxEvent;            //!< the end PLCP receive event
1537
  EventId m_endPlcpRxEvent;            //!< the end of PLCP receive event
1538
  EventId m_endPreambleDetectionEvent;   //!< the end of preamble detection event
1511
1539
1512
private:
1540
private:
1513
  /**
1541
  /**
 Lines 1789-1794   private: Link Here 
1789
1817
1790
  Ptr<Event> m_currentEvent; //!< Hold the current event
1818
  Ptr<Event> m_currentEvent; //!< Hold the current event
1791
  Ptr<FrameCaptureModel> m_frameCaptureModel; //!< Frame capture model
1819
  Ptr<FrameCaptureModel> m_frameCaptureModel; //!< Frame capture model
1820
  Ptr<PreambleDetectionModel> m_preambleDetectionModel; //!< Preamble detection model
1792
  Ptr<WifiRadioEnergyModel> m_wifiRadioEnergyModel; //!< Wifi radio energy model
1821
  Ptr<WifiRadioEnergyModel> m_wifiRadioEnergyModel; //!< Wifi radio energy model
1793
  Ptr<ErrorModel> m_postReceptionErrorModel; //!< Error model for receive packet events
1822
  Ptr<ErrorModel> m_postReceptionErrorModel; //!< Error model for receive packet events
1794
1823
(-)a/src/wifi/model/yans-wifi-channel.cc (-1 / +1 lines)
 Lines 125-131   void Link Here 
125
YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
125
YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
126
{
126
{
127
  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
127
  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
128
  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
128
  phy->StartReceivePreamble (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
129
}
129
}
130
130
131
std::size_t
131
std::size_t
(-)a/src/wifi/test/preamble-detection-test.cc (+255 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018 University of Washington
4
 *
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
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "ns3/log.h"
22
#include "ns3/test.h"
23
#include "ns3/pointer.h"
24
#include "ns3/spectrum-wifi-helper.h"
25
#include "ns3/wifi-spectrum-value-helper.h"
26
#include "ns3/spectrum-wifi-phy.h"
27
#include "ns3/nist-error-rate-model.h"
28
#include "ns3/wifi-mac-header.h"
29
#include "ns3/wifi-mac-trailer.h"
30
#include "ns3/wifi-phy-tag.h"
31
#include "ns3/wifi-spectrum-signal-parameters.h"
32
#include "ns3/wifi-utils.h"
33
#include "ns3/threshold-preamble-detection-model.h"
34
35
using namespace ns3;
36
37
NS_LOG_COMPONENT_DEFINE ("TestThresholdPreambleDetectionWithoutFrameCapture");
38
39
static const uint8_t CHANNEL_NUMBER = 36;
40
static const uint32_t FREQUENCY = 5180; // MHz
41
static const uint16_t CHANNEL_WIDTH = 20; // MHz
42
static const uint16_t GUARD_WIDTH = CHANNEL_WIDTH; // MHz (expanded to channel width to model spectrum mask)
43
44
/**
45
 * \ingroup wifi-test
46
 * \ingroup tests
47
 *
48
 * \brief Wifi Preamble Detection Test
49
 */
50
class TestThresholdPreambleDetectionWithoutFrameCapture : public TestCase
51
{
52
public:
53
  TestThresholdPreambleDetectionWithoutFrameCapture ();
54
  virtual ~TestThresholdPreambleDetectionWithoutFrameCapture ();
55
56
protected:
57
  virtual void DoSetup (void);
58
  Ptr<SpectrumWifiPhy> m_phy; ///< Phy
59
  /**
60
   * Send packet function
61
   * \param txPowerDbm the transmit power in dBm
62
   */
63
  void SendPacket (double txPowerDbm);
64
  /**
65
   * Spectrum wifi receive success function
66
   * \param p the packet
67
   * \param snr the SNR
68
   * \param txVector the transmit vector
69
   */
70
  void SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector);
71
  /**
72
   * Spectrum wifi receive failure function
73
   */
74
  void SpectrumWifiPhyRxFailure (void);
75
  uint32_t m_countRxSuccess; ///< count RX success
76
  uint32_t m_countRxFailure; ///< count RX failure
77
78
private:
79
  virtual void DoRun (void);
80
81
  /**
82
   * Check the PHY state
83
   * \param expectedState the expected PHY state
84
   */
85
  void CheckPhyState (WifiPhyState expectedState);
86
  /**
87
   * Check the number of received packets
88
   * \param expectedSuccessCount the number of successfully received packets
89
   * \param expectedFailureCount the number of unsuccessfully received packets
90
   */
91
  void CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount);
92
};
93
94
TestThresholdPreambleDetectionWithoutFrameCapture::TestThresholdPreambleDetectionWithoutFrameCapture ()
95
  : TestCase ("Threshold preamble detection model test when no frame capture model is applied"),
96
    m_countRxSuccess (0),
97
    m_countRxFailure (0)
98
{
99
}
100
101
void
102
TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket (double txPowerDbm)
103
{
104
  WifiTxVector txVector = WifiTxVector (WifiPhy::GetHeMcs11 (), 0, WIFI_PREAMBLE_HE_SU, 800, 1, 1, 0, 20, false, false);
105
  MpduType mpdutype = NORMAL_MPDU;
106
107
  Ptr<Packet> pkt = Create<Packet> (1000);
108
  WifiMacHeader hdr;
109
  WifiMacTrailer trailer;
110
111
  hdr.SetType (WIFI_MAC_QOSDATA);
112
  hdr.SetQosTid (0);
113
  uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize ();
114
  Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFrequency (), mpdutype, 0);
115
  hdr.SetDuration (txDuration);
116
117
  pkt->AddHeader (hdr);
118
  pkt->AddTrailer (trailer);
119
  WifiPhyTag tag (txVector, mpdutype, 1);
120
  pkt->AddPacketTag (tag);
121
  Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, DbmToW (txPowerDbm), GUARD_WIDTH);
122
  Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> ();
123
  txParams->psd = txPowerSpectrum;
124
  txParams->txPhy = 0;
125
  txParams->duration = txDuration;
126
  txParams->packet = pkt;
127
128
  m_phy->StartRx (txParams);
129
}
130
131
void
132
TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState (WifiPhyState expectedState)
133
{
134
  WifiPhyState currentState;
135
  PointerValue ptr;
136
  m_phy->GetAttribute ("State", ptr);
137
  Ptr <WifiPhyStateHelper> state = DynamicCast <WifiPhyStateHelper> (ptr.Get<WifiPhyStateHelper> ());
138
  currentState = state->GetState ();
139
  NS_TEST_ASSERT_MSG_EQ (currentState, expectedState, "PHY State " << currentState << " does not match expected state " << expectedState << " at " << Simulator::Now ());
140
}
141
142
void
143
TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount)
144
{
145
  NS_TEST_ASSERT_MSG_EQ (m_countRxSuccess, expectedSuccessCount, "Didn't receive right number of successful packets");
146
  NS_TEST_ASSERT_MSG_EQ (m_countRxFailure, expectedFailureCount, "Didn't receive right number of unsuccessful packets");
147
}
148
149
void
150
TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector)
151
{
152
  NS_LOG_FUNCTION (this << p << snr << txVector);
153
  m_countRxSuccess++;
154
}
155
156
void
157
TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxFailure (void)
158
{
159
  NS_LOG_FUNCTION (this);
160
  m_countRxFailure++;
161
}
162
163
TestThresholdPreambleDetectionWithoutFrameCapture::~TestThresholdPreambleDetectionWithoutFrameCapture ()
164
{
165
}
166
167
void
168
TestThresholdPreambleDetectionWithoutFrameCapture::DoSetup (void)
169
{
170
  m_phy = CreateObject<SpectrumWifiPhy> ();
171
  m_phy->ConfigureStandard (WIFI_PHY_STANDARD_80211ax_5GHZ);
172
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
173
  m_phy->SetErrorRateModel (error);
174
  m_phy->SetChannelNumber (CHANNEL_NUMBER);
175
  m_phy->SetFrequency (FREQUENCY);
176
  m_phy->SetReceiveOkCallback (MakeCallback (&TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxSuccess, this));
177
  m_phy->SetReceiveErrorCallback (MakeCallback (&TestThresholdPreambleDetectionWithoutFrameCapture::SpectrumWifiPhyRxFailure, this));
178
  m_phy->SetCcaMode1Threshold (-62.0); //to be removed once merged!
179
180
  Ptr<ThresholdPreambleDetectionModel> preambleDetectionModel = CreateObject<ThresholdPreambleDetectionModel> ();
181
  m_phy->SetPreambleDetectionModel (preambleDetectionModel);
182
}
183
184
// Test that the expected number of packet receptions occur.
185
void
186
TestThresholdPreambleDetectionWithoutFrameCapture::DoRun (void)
187
{
188
  double txPowerDbm = -30;
189
190
  //CASE 1: send one packet and check PHY state: packet reception should succeed
191
192
  Simulator::Schedule (Seconds (1.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
193
  // At 4us, STA PHY STATE should be IDLE
194
  Simulator::Schedule (Seconds (1.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
195
  // At 5us, STA PHY STATE should be RX
196
  Simulator::Schedule (Seconds (1.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX);
197
  // Packet should have been successfully received
198
  Simulator::Schedule (Seconds (1.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 0);
199
200
  //CASE 2: send two packets with same power within the 4us window and check PHY state: PHY preamble detection should fail
201
202
  Simulator::Schedule (Seconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
203
  Simulator::Schedule (Seconds (2.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
204
  Simulator::Schedule (Seconds (2.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
205
  Simulator::Schedule (Seconds (2.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
206
  // No more packet should have been successfully received, and since preamble detection did not pass the packet should not have been counted as a failure
207
  Simulator::Schedule (Seconds (2.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 0);
208
209
  //CASE 3: send two packets with second one 3 dB weaker within the 4us window and check PHY state: PHY preamble detection should succeed and packet reception should fail
210
211
  Simulator::Schedule (Seconds (3.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
212
  Simulator::Schedule (Seconds (3.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm - 3);
213
  Simulator::Schedule (Seconds (3.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
214
  Simulator::Schedule (Seconds (3.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX);
215
  // In this case, the first packet should be marked as a failure
216
  Simulator::Schedule (Seconds (3.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 1);
217
218
  //CASE 4: send two packets with second one 3 dB higher within the 4us window and check PHY state: PHY preamble detection should fail and no packets should enter the reception stage
219
  Simulator::Schedule (Seconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
220
  Simulator::Schedule (Seconds (4.0) + MicroSeconds (2.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm + 3);
221
  Simulator::Schedule (Seconds (4.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
222
  Simulator::Schedule (Seconds (4.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
223
  Simulator::Schedule (Seconds (4.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 1);
224
225
  //CASE 5: idem but send the second packet after the 4us window: PHY preamble detection should succeed and packet reception should fail
226
227
  Simulator::Schedule (Seconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm);
228
  Simulator::Schedule (Seconds (5.0) + MicroSeconds (6.0), &TestThresholdPreambleDetectionWithoutFrameCapture::SendPacket, this, txPowerDbm + 3);
229
  Simulator::Schedule (Seconds (5.0) + MicroSeconds (4.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::IDLE);
230
  Simulator::Schedule (Seconds (5.0) + MicroSeconds (5.0), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckPhyState, this, WifiPhyState::RX);
231
  Simulator::Schedule (Seconds (5.1), &TestThresholdPreambleDetectionWithoutFrameCapture::CheckRxPacketCount, this, 1, 2);
232
233
  Simulator::Run ();
234
  Simulator::Destroy ();
235
}
236
237
/**
238
 * \ingroup wifi-test
239
 * \ingroup tests
240
 *
241
 * \brief Preamble Detection Test Suite
242
 */
243
class PreambleDetectionTestSuite : public TestSuite
244
{
245
public:
246
  PreambleDetectionTestSuite ();
247
};
248
249
PreambleDetectionTestSuite::PreambleDetectionTestSuite ()
250
  : TestSuite ("wifi-preamble-detection", UNIT)
251
{
252
  AddTestCase (new TestThresholdPreambleDetectionWithoutFrameCapture, TestCase::QUICK);
253
}
254
255
static PreambleDetectionTestSuite preambleDetectionTestSuite; ///< the test suite
(-)a/src/wifi/test/wifi-test.cc (-1 / +9 lines)
 Lines 1025-1031   SetChannelFrequencyTest::DoRun () Link Here 
1025
  }
1025
  }
1026
1026
1027
  Simulator::Destroy ();
1027
  Simulator::Destroy ();
1028
1029
}
1028
}
1030
1029
1031
//-----------------------------------------------------------------------------
1030
//-----------------------------------------------------------------------------
 Lines 1657-1662   void Link Here 
1657
StaWifiMacScanningTestCase::DoRun (void)
1656
StaWifiMacScanningTestCase::DoRun (void)
1658
{
1657
{
1659
  {
1658
  {
1659
    RngSeedManager::SetSeed (1);
1660
    RngSeedManager::SetRun (1);
1661
  
1660
    NodeContainer nodes = Setup (false, false);
1662
    NodeContainer nodes = Setup (false, false);
1661
    Ptr<Node> nearestAp = nodes.Get (2);
1663
    Ptr<Node> nearestAp = nodes.Get (2);
1662
    Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1664
    Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
 Lines 1671-1676   StaWifiMacScanningTestCase::DoRun (void) Link Here 
1671
  }
1673
  }
1672
  m_associatedApBssid = Mac48Address ();
1674
  m_associatedApBssid = Mac48Address ();
1673
  {
1675
  {
1676
    RngSeedManager::SetSeed (1);
1677
    RngSeedManager::SetRun (1);
1678
1674
    NodeContainer nodes = Setup (true, true);
1679
    NodeContainer nodes = Setup (true, true);
1675
    Ptr<Node> nearestAp = nodes.Get (2);
1680
    Ptr<Node> nearestAp = nodes.Get (2);
1676
    Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1681
    Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
 Lines 1683-1688   StaWifiMacScanningTestCase::DoRun (void) Link Here 
1683
  }
1688
  }
1684
  m_associatedApBssid = Mac48Address ();
1689
  m_associatedApBssid = Mac48Address ();
1685
  {
1690
  {
1691
    RngSeedManager::SetSeed (1);
1692
    RngSeedManager::SetRun (1);
1693
1686
    NodeContainer nodes = Setup (true, false);
1694
    NodeContainer nodes = Setup (true, false);
1687
    Ptr<Node> nearestAp = nodes.Get (2);
1695
    Ptr<Node> nearestAp = nodes.Get (2);
1688
    Mac48Address secondNearestApAddr = DynamicCast<WifiNetDevice> (nodes.Get (1)->GetDevice (0))->GetMac ()->GetAddress ();
1696
    Mac48Address secondNearestApAddr = DynamicCast<WifiNetDevice> (nodes.Get (1)->GetDevice (0))->GetMac ()->GetAddress ();
(-)a/src/wifi/wscript (+5 lines)
 Lines 85-90   def build(bld): Link Here 
85
        'model/he-capabilities.cc',
85
        'model/he-capabilities.cc',
86
        'model/frame-capture-model.cc',
86
        'model/frame-capture-model.cc',
87
        'model/simple-frame-capture-model.cc',
87
        'model/simple-frame-capture-model.cc',
88
        'model/preamble-detection-model.cc',
89
        'model/threshold-preamble-detection-model.cc',
88
        'model/he-operation.cc',
90
        'model/he-operation.cc',
89
        'model/he-configuration.cc',
91
        'model/he-configuration.cc',
90
        'model/extended-capabilities.cc',
92
        'model/extended-capabilities.cc',
 Lines 111-116   def build(bld): Link Here 
111
        'test/wifi-aggregation-test.cc',
113
        'test/wifi-aggregation-test.cc',
112
        'test/wifi-error-rate-models-test.cc',
114
        'test/wifi-error-rate-models-test.cc',
113
        'test/wifi-transmit-mask-test.cc',
115
        'test/wifi-transmit-mask-test.cc',
116
        'test/preamble-detection-test.cc',
114
        ]
117
        ]
115
118
116
    headers = bld(features='ns3header')
119
    headers = bld(features='ns3header')
 Lines 199-204   def build(bld): Link Here 
199
        'model/he-capabilities.h',
202
        'model/he-capabilities.h',
200
        'model/frame-capture-model.h',
203
        'model/frame-capture-model.h',
201
        'model/simple-frame-capture-model.h',
204
        'model/simple-frame-capture-model.h',
205
        'model/preamble-detection-model.h',
206
        'model/threshold-preamble-detection-model.h',
202
        'model/qos-blocked-destinations.h',
207
        'model/qos-blocked-destinations.h',
203
        'model/he-operation.h',
208
        'model/he-operation.h',
204
        'model/he-configuration.h',
209
        'model/he-configuration.h',

Return to bug 3020