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

(-)a/src/wifi/examples/test-interference-helper.cc (-8 / +29 lines)
 Lines 53-59    Link Here 
53
#include "ns3/yans-wifi-channel.h"
53
#include "ns3/yans-wifi-channel.h"
54
#include "ns3/propagation-loss-model.h"
54
#include "ns3/propagation-loss-model.h"
55
#include "ns3/propagation-delay-model.h"
55
#include "ns3/propagation-delay-model.h"
56
#include "ns3/yans-error-rate-model.h"
56
#include "ns3/nist-error-rate-model.h"
57
#include "ns3/constant-position-mobility-model.h"
57
#include "ns3/constant-position-mobility-model.h"
58
58
59
using namespace ns3;
59
using namespace ns3;
 Lines 71-80   public: Link Here 
71
    std::string txModeB;
71
    std::string txModeB;
72
    uint32_t txPowerLevelA;
72
    uint32_t txPowerLevelA;
73
    uint32_t txPowerLevelB;
73
    uint32_t txPowerLevelB;
74
    double txPowerA;
75
    double txPowerB;
74
    uint32_t packetSizeA;
76
    uint32_t packetSizeA;
75
    uint32_t packetSizeB;
77
    uint32_t packetSizeB;
76
    WifiPhyStandard standard;
78
    WifiPhyStandard standard;
77
    WifiPreamble preamble;
79
    WifiPreamble preamble;
80
    bool enableFrameCapture;
78
  };
81
  };
79
82
80
  InterferenceExperiment ();
83
  InterferenceExperiment ();
 Lines 96-101   InterferenceExperiment::SendA (void) const Link Here 
96
  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
99
  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
97
  txVector.SetMode (WifiMode (m_input.txModeA));
100
  txVector.SetMode (WifiMode (m_input.txModeA));
98
  txVector.SetPreambleType (m_input.preamble);
101
  txVector.SetPreambleType (m_input.preamble);
102
  m_txA->SetTxPowerStart (m_input.txPowerA);
103
  m_txA->SetTxPowerEnd (m_input.txPowerA);
99
  m_txA->SendPacket (p, txVector);
104
  m_txA->SendPacket (p, txVector);
100
}
105
}
101
106
 Lines 107-112   InterferenceExperiment::SendB (void) const Link Here 
107
  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
112
  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
108
  txVector.SetMode (WifiMode (m_input.txModeB));
113
  txVector.SetMode (WifiMode (m_input.txModeB));
109
  txVector.SetPreambleType (m_input.preamble);
114
  txVector.SetPreambleType (m_input.preamble);
115
  m_txB->SetTxPowerStart (m_input.txPowerB);
116
  m_txB->SetTxPowerEnd (m_input.txPowerB);
110
  m_txB->SendPacket (p, txVector);
117
  m_txB->SendPacket (p, txVector);
111
}
118
}
112
119
 Lines 117-130   InterferenceExperiment::Input::Input () Link Here 
117
  : interval (MicroSeconds (0)),
124
  : interval (MicroSeconds (0)),
118
    xA (-5),
125
    xA (-5),
119
    xB (5),
126
    xB (5),
120
    txModeA ("OfdmRate54Mbps"),
127
    txModeA ("OfdmRate12Mbps"),
121
    txModeB ("OfdmRate54Mbps"),
128
    txModeB ("OfdmRate12Mbps"),
122
    txPowerLevelA (0),
129
    txPowerLevelA (0),
123
    txPowerLevelB (0),
130
    txPowerLevelB (0),
131
    txPowerA (20),
132
    txPowerB (20),
124
    packetSizeA (1500),
133
    packetSizeA (1500),
125
    packetSizeB (1500),
134
    packetSizeB (1500),
126
    standard (WIFI_PHY_STANDARD_80211a),
135
    standard (WIFI_PHY_STANDARD_80211a),
127
    preamble (WIFI_PREAMBLE_LONG)
136
    preamble (WIFI_PREAMBLE_LONG),
137
    enableFrameCapture (false)
128
{
138
{
129
}
139
}
130
140
 Lines 152-158   InterferenceExperiment::Run (struct InterferenceExperiment::Input input) Link Here 
152
  m_txB = CreateObject<YansWifiPhy> ();
162
  m_txB = CreateObject<YansWifiPhy> ();
153
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
163
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
154
164
155
  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
165
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
156
  m_txA->SetErrorRateModel (error);
166
  m_txA->SetErrorRateModel (error);
157
  m_txB->SetErrorRateModel (error);
167
  m_txB->SetErrorRateModel (error);
158
  rx->SetErrorRateModel (error);
168
  rx->SetErrorRateModel (error);
 Lines 167-172   InterferenceExperiment::Run (struct InterferenceExperiment::Input input) Link Here 
167
  m_txB->ConfigureStandard (input.standard);
177
  m_txB->ConfigureStandard (input.standard);
168
  rx->ConfigureStandard (input.standard);
178
  rx->ConfigureStandard (input.standard);
169
179
180
  m_txA->SetPreambleCapture(input.enableFrameCapture);
181
  m_txB->SetPreambleCapture(input.enableFrameCapture);
182
  rx->SetPreambleCapture(input.enableFrameCapture);
183
  m_txA->SetPayloadCapture(input.enableFrameCapture);
184
  m_txB->SetPayloadCapture(input.enableFrameCapture);
185
  rx->SetPayloadCapture(input.enableFrameCapture);
186
187
170
  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
188
  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
171
  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
189
  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
172
190
 Lines 188-202   int main (int argc, char *argv[]) Link Here 
188
  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
206
  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
189
  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
207
  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
190
  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
208
  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
191
  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
209
  cmd.AddValue ("txPowerLevelA", "TX power level of transmitter A", input.txPowerLevelA);
192
  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
210
  cmd.AddValue ("txPowerLevelB", "TX power level of transmitter B", input.txPowerLevelB);
211
  cmd.AddValue ("txPowerA", "Tx power of transmitter A", input.txPowerA);
212
  cmd.AddValue ("txPowerB", "Tx power of transmitter B", input.txPowerB);
193
  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
213
  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
194
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
214
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
195
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
215
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
196
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
216
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
217
  cmd.AddValue ("enableFrameCapture", "Enable frame capture capability", input.enableFrameCapture);
197
  cmd.Parse (argc, argv);
218
  cmd.Parse (argc, argv);
198
219
199
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
220
  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
200
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
221
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
201
222
202
  input.interval = MicroSeconds (delay);
223
  input.interval = MicroSeconds (delay);
(-)a/src/wifi/examples/wscript (-1 / +1 lines)
 Lines 11-17   def build(bld): Link Here 
11
    obj = bld.create_ns3_program('test-interference-helper',
11
    obj = bld.create_ns3_program('test-interference-helper',
12
        ['core', 'mobility', 'network', 'wifi'])
12
        ['core', 'mobility', 'network', 'wifi'])
13
    obj.source = 'test-interference-helper.cc'
13
    obj.source = 'test-interference-helper.cc'
14
14
    
15
    obj = bld.create_ns3_program('ideal-wifi-manager-example',
15
    obj = bld.create_ns3_program('ideal-wifi-manager-example',
16
        ['core', 'network', 'wifi', 'stats', 'mobility', 'propagation'])
16
        ['core', 'network', 'wifi', 'stats', 'mobility', 'propagation'])
17
    obj.source = 'ideal-wifi-manager-example.cc'
17
    obj.source = 'ideal-wifi-manager-example.cc'
(-)a/src/wifi/model/frame-capture-model.cc (+67 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
#include "frame-capture-model.h"
3
#include <algorithm>
4
#include <cmath>
5
6
namespace ns3 {
7
8
NS_OBJECT_ENSURE_REGISTERED (FrameCaptureModel);
9
10
TypeId
11
FrameCaptureModel::GetTypeId (void)
12
{
13
  static TypeId tid = TypeId ("ns3::FrameCaptureModel")
14
    .SetParent<Object> ()
15
    .SetGroupName ("Wifi")
16
    .AddConstructor<FrameCaptureModel> ()
17
  ;
18
  return tid;
19
}
20
21
FrameCaptureModel::FrameCaptureModel()
22
{
23
}
24
25
double
26
FrameCaptureModel::CalculatePreambleCaptureProbability (double sinr)
27
{
28
  double z = std::sqrt (sinr / 4.0);
29
  double p = 0.5 * erfc(z);
30
  if (p == 0.0)
31
    {
32
      return 1.0;
33
    }
34
  double pe = CalculatePe (p);
35
  pe = std::min(pe, 1.0);
36
  double prob = std::pow (1 - pe, 240);
37
  return prob;
38
}
39
40
double
41
FrameCaptureModel::CalculatePayloadCaptureProbability (double sinr)
42
{
43
  double sinrDb = 10 * std::log10(sinr);
44
  double prob = 0.4989 * erf((sinrDb - 9.356) / 0.8722) + 0.4989;
45
  prob = std::max(prob, 0.0);
46
  prob = std::min(prob, 1.0);
47
  return prob;
48
}
49
50
double
51
FrameCaptureModel::CalculatePe(double p)
52
{
53
  double D = std::sqrt (4.0 * p * (1.0 - p));
54
  double pe = 1.0;
55
  pe = 0.5 * (36.0 * std::pow (D, 10)
56
	      + 211.0 * std::pow (D, 12)
57
	      + 1404.0 * std::pow (D, 14)
58
	      + 11633.0 * std::pow (D, 16)
59
	      + 77433.0 * std::pow (D, 18)
60
	      + 502690.0 * std::pow (D, 20)
61
	      + 3322763.0 * std::pow (D, 22)
62
	      + 21292910.0 * std::pow (D, 24)
63
	      + 134365911.0 * std::pow (D, 26));
64
  return pe;
65
}
66
67
} // //namespace ns3
(-)a/src/wifi/model/frame-capture-model.h (+23 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
3
#ifndef FRAME_CAPTURE_MODEL_H
4
#define FRAME_CAPTURE_MODEL_H
5
6
#include "ns3/object.h"
7
8
namespace ns3 {
9
10
class FrameCaptureModel : public Object
11
{
12
public:
13
  static TypeId GetTypeId (void);
14
  FrameCaptureModel ();
15
  double CalculatePreambleCaptureProbability (double sinr);
16
  double CalculatePayloadCaptureProbability (double sinr);
17
private:
18
  double CalculatePe (double p);
19
};
20
21
} //namespace ns3
22
23
#endif /* FRAME_CAPTURE_MODEL_H */
(-)a/src/wifi/model/interference-helper.cc (-7 / +25 lines)
 Lines 251-264   double Link Here 
251
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
251
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
252
{
252
{
253
  double noiseInterference = m_firstPower;
253
  double noiseInterference = m_firstPower;
254
  NS_ASSERT (m_rxing);
254
  for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); ++i)
255
  for (NiChanges::const_iterator i = m_niChanges.begin () + 1; i != m_niChanges.end (); i++)
256
    {
255
    {
257
      if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
256
      if (i->GetTime () < event->GetStartTime ())
258
        {
257
	{
259
          break;
258
	  noiseInterference += i->GetDelta ();
260
        }
259
	}
261
      ni->push_back (*i);
260
      else if (i->GetTime () > event->GetStartTime () && i->GetTime () < event->GetEndTime ())
261
	{
262
	  ni->push_back(*i);
263
	}
264
      else if (event->GetEndTime () == i->GetTime () && event->GetRxPowerW () == -i->GetDelta ())
265
	{
266
	  break;
267
	}
262
    }
268
    }
263
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference));
269
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference));
264
  ni->push_back (NiChange (event->GetEndTime (), 0));
270
  ni->push_back (NiChange (event->GetEndTime (), 0));
 Lines 865-868   InterferenceHelper::NotifyRxEnd () Link Here 
865
  m_rxing = false;
871
  m_rxing = false;
866
}
872
}
867
873
874
double
875
InterferenceHelper::CalculatePreambleCaptureProbability (double sinr)
876
{
877
  return m_frameCaptureModel->CalculatePreambleCaptureProbability(sinr);
878
}
879
880
double
881
InterferenceHelper::CalculatePayloadCaptureProbability (double sinr)
882
{
883
  return m_frameCaptureModel->CalculatePayloadCaptureProbability(sinr);
884
}
885
868
} //namespace ns3
886
} //namespace ns3
(-)a/src/wifi/model/interference-helper.h (-1 / +15 lines)
 Lines 24-29    Link Here 
24
#include "ns3/nstime.h"
24
#include "ns3/nstime.h"
25
#include "wifi-tx-vector.h"
25
#include "wifi-tx-vector.h"
26
#include "error-rate-model.h"
26
#include "error-rate-model.h"
27
#include "frame-capture-model.h"
27
28
28
namespace ns3 {
29
namespace ns3 {
29
30
 Lines 206-212   private: Link Here 
206
   * Erase all events.
207
   * Erase all events.
207
   */
208
   */
208
  void EraseEvents (void);
209
  void EraseEvents (void);
209
210
  // following methods used to support frame capture capability
211
  /**
212
   * Calculate the successful probability for preamble capture
213
   * \param sinr the sinr value at the current time
214
   */
215
  double CalculatePreambleCaptureProbability (double sinr);
216
  /**
217
   * Calculate the successful probability for payload capture
218
   * \param sinr the sinr value at the current time
219
   */
220
  double CalculatePayloadCaptureProbability (double sinr);
210
221
211
private:
222
private:
212
  /**
223
  /**
 Lines 322-327   private: Link Here 
322
  NiChanges m_niChanges;
333
  NiChanges m_niChanges;
323
  double m_firstPower;
334
  double m_firstPower;
324
  bool m_rxing;
335
  bool m_rxing;
336
  // following variables used for frame capture capability
337
  Ptr<FrameCaptureModel> m_frameCaptureModel;
338
325
  /// Returns an iterator to the first nichange, which is later than moment
339
  /// Returns an iterator to the first nichange, which is later than moment
326
  NiChanges::iterator GetPosition (Time moment);
340
  NiChanges::iterator GetPosition (Time moment);
327
  /**
341
  /**
(-)a/src/wifi/model/wifi-phy-state-helper.cc (+15 lines)
 Lines 541-544   WifiPhyStateHelper::SwitchFromSleep (Time duration) Link Here 
541
    }
541
    }
542
}
542
}
543
543
544
void
545
WifiPhyStateHelper::SwitchFromRxAbort (Ptr<Packet> packet, double snr)
546
{
547
  NS_ASSERT (IsStateRx ());
548
  NS_ASSERT (m_rxing);
549
  m_rxErrorTrace (packet, snr);
550
  NotifyRxEndError ();
551
  m_endRx = Simulator::Now ();
552
  DoSwitchFromRx ();
553
  NS_ASSERT (!IsStateRx ());
554
  if (!m_rxErrorCallback.IsNull ())
555
    {
556
      m_rxErrorCallback (packet, snr);
557
    }
558
}
544
} //namespace ns3
559
} //namespace ns3
(-)a/src/wifi/model/wifi-phy-state-helper.h (-1 / +4 lines)
 Lines 181-187   public: Link Here 
181
   * \param duration the duration of CCA busy state
181
   * \param duration the duration of CCA busy state
182
   */
182
   */
183
  void SwitchFromSleep (Time duration);
183
  void SwitchFromSleep (Time duration);
184
184
  /**
185
   * Abort current reception
186
   */
187
  void SwitchFromRxAbort (Ptr<Packet> packet, double snr);
185
  /** \todo Why is this public? */
188
  /** \todo Why is this public? */
186
  TracedCallback<Time, Time, WifiPhy::State> m_stateLogger;
189
  TracedCallback<Time, Time, WifiPhy::State> m_stateLogger;
187
190
(-)a/src/wifi/model/wifi-phy.cc (-19 / +254 lines)
 Lines 29-34    Link Here 
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-phy-tag.h"
32
#include "wifi-utils.h"
33
#include "wifi-utils.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
 Lines 191-203   WifiPhy::GetTypeId (void) Link Here 
191
                   MakeDoubleChecker<double> ())
192
                   MakeDoubleChecker<double> ())
192
    .AddAttribute ("TxGain",
193
    .AddAttribute ("TxGain",
193
                   "Transmission gain (dB).",
194
                   "Transmission gain (dB).",
194
                   DoubleValue (1.0),
195
                   DoubleValue (0.0),
195
                   MakeDoubleAccessor (&WifiPhy::SetTxGain,
196
                   MakeDoubleAccessor (&WifiPhy::SetTxGain,
196
                                       &WifiPhy::GetTxGain),
197
                                       &WifiPhy::GetTxGain),
197
                   MakeDoubleChecker<double> ())
198
                   MakeDoubleChecker<double> ())
198
    .AddAttribute ("RxGain",
199
    .AddAttribute ("RxGain",
199
                   "Reception gain (dB).",
200
                   "Reception gain (dB).",
200
                   DoubleValue (1.0),
201
                   DoubleValue (0.0),
201
                   MakeDoubleAccessor (&WifiPhy::SetRxGain,
202
                   MakeDoubleAccessor (&WifiPhy::SetRxGain,
202
                                       &WifiPhy::GetRxGain),
203
                                       &WifiPhy::GetRxGain),
203
                   MakeDoubleChecker<double> ())
204
                   MakeDoubleChecker<double> ())
 Lines 308-313   WifiPhy::GetTypeId (void) Link Here 
308
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
309
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
309
                                        &WifiPhy::SetShortPlcpPreambleSupported),
310
                                        &WifiPhy::SetShortPlcpPreambleSupported),
310
                   MakeBooleanChecker ())
311
                   MakeBooleanChecker ())
312
    .AddAttribute ("PreambleCaptureEnabled",
313
		   "Whether or not to enable capture at the preamble portion of the packet.",
314
		   BooleanValue (false),
315
		   MakeBooleanAccessor (&WifiPhy::GetPreambleCapture,
316
					&WifiPhy::SetPreambleCapture),
317
		   MakeBooleanChecker ())
318
    .AddAttribute ("PayloadCaptureEnabled",
319
		   "Whether or not to enable cautpure at the payload(data) portion of the packet",
320
		   BooleanValue (false),
321
		   MakeBooleanAccessor (&WifiPhy::GetPayloadCapture,
322
					&WifiPhy::SetPayloadCapture),
323
		   MakeBooleanChecker ())
311
    .AddTraceSource ("PhyTxBegin",
324
    .AddTraceSource ("PhyTxBegin",
312
                     "Trace source indicating a packet "
325
                     "Trace source indicating a packet "
313
                     "has begun transmitting over the channel medium",
326
                     "has begun transmitting over the channel medium",
 Lines 372-378   WifiPhy::WifiPhy () Link Here 
372
    m_channelNumber (0),
385
    m_channelNumber (0),
373
    m_initialChannelNumber (0),
386
    m_initialChannelNumber (0),
374
    m_totalAmpduSize (0),
387
    m_totalAmpduSize (0),
375
    m_totalAmpduNumSymbols (0)
388
    m_totalAmpduNumSymbols (0),
389
    m_doPreambleCapture (false),
390
    m_doPayloadCapture (false)
376
{
391
{
377
  NS_LOG_FUNCTION (this);
392
  NS_LOG_FUNCTION (this);
378
  NS_UNUSED (m_numberOfTransmitters);
393
  NS_UNUSED (m_numberOfTransmitters);
 Lines 706-711   WifiPhy::GetChannelSwitchDelay (void) const Link Here 
706
  return m_channelSwitchDelay;
721
  return m_channelSwitchDelay;
707
}
722
}
708
723
724
void
725
WifiPhy::SetPreambleCapture (bool enable)
726
{
727
  NS_LOG_FUNCTION (this << enable);
728
  m_doPreambleCapture = enable;
729
}
730
731
bool
732
WifiPhy::GetPreambleCapture (void) const
733
{
734
  return m_doPreambleCapture;
735
}
736
737
void
738
WifiPhy::SetPayloadCapture (bool enable)
739
{
740
  NS_LOG_FUNCTION (this << enable);
741
  m_doPayloadCapture = enable;
742
}
743
744
bool
745
WifiPhy::GetPayloadCapture (void) const
746
{
747
  return m_doPayloadCapture;
748
}
749
709
double
750
double
710
WifiPhy::CalculateSnr (WifiTxVector txVector, double ber) const
751
WifiPhy::CalculateSnr (WifiTxVector txVector, double ber) const
711
{
752
{
 Lines 2296-2301   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2296
                              txVector,
2337
                              txVector,
2297
                              rxDuration,
2338
                              rxDuration,
2298
                              rxPowerW);
2339
                              rxPowerW);
2340
  Time currentRxStage = Seconds (0);
2299
2341
2300
  switch (m_state->GetState ())
2342
  switch (m_state->GetState ())
2301
    {
2343
    {
 Lines 2315-2334   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2315
        {
2357
        {
2316
          //that packet will be noise _after_ the completion of the
2358
          //that packet will be noise _after_ the completion of the
2317
          //channel switching.
2359
          //channel switching.
2318
          goto maybeCcaBusy;
2360
	  CalculateCcaBusyDuration ();
2319
        }
2361
        }
2320
      break;
2362
      break;
2321
    case WifiPhy::RX:
2363
    case WifiPhy::RX:
2322
      NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2364
      {
2323
                    rxPowerW << "W)");
2365
	NS_ASSERT (m_rxPacketEvent != NULL);
2324
      NotifyRxDrop (packet);
2366
	if (preamble == WIFI_PREAMBLE_NONE)
2325
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2367
	  {
2326
        {
2368
	    NS_LOG_DEBUG ("New packet does not contains preamble/plcp header");
2327
          //that packet will be noise _after_ the reception of the
2369
            NotifyRxDrop (packet);
2328
          //currently-received packet.
2370
            if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2329
          goto maybeCcaBusy;
2371
              {
2330
        }
2372
                CalculateCcaBusyDuration ();
2331
      break;
2373
              }
2374
            break;
2375
	  }
2376
2377
	currentRxStage = Simulator::Now() - m_rxPacketEvent->GetStartTime();
2378
	bool doReceptionSwitch = false;
2379
	if (m_rxPreambleType != WIFI_PREAMBLE_NONE
2380
	    && currentRxStage < preambleAndHeaderDuration) // still receiving the preamble and plcp header portion of the old packet
2381
	  {
2382
	    NS_LOG_DEBUG ("old preamble type "<<m_rxPreambleType
2383
			 <<", new preamble type "<<preamble
2384
			 <<", rxStage "<<currentRxStage);
2385
	    doReceptionSwitch = CheckPreambleCapture (packet, event);
2386
	  }
2387
	else
2388
	  {
2389
	    doReceptionSwitch = CheckPayloadCapture (packet, event);
2390
	  }
2391
	if (doReceptionSwitch)
2392
	  {
2393
	    m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
2394
						    packet, txVector, mpdutype, event);
2395
	    m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2396
						packet, preamble, mpdutype, event);
2397
	    m_rxPreambleType = preamble;
2398
	  }
2399
	break;
2400
      }
2332
    case WifiPhy::TX:
2401
    case WifiPhy::TX:
2333
      NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2402
      NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2334
                    rxPowerW << "W)");
2403
                    rxPowerW << "W)");
 Lines 2337-2343   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2337
        {
2406
        {
2338
          //that packet will be noise _after_ the transmission of the
2407
          //that packet will be noise _after_ the transmission of the
2339
          //currently-transmitted packet.
2408
          //currently-transmitted packet.
2340
          goto maybeCcaBusy;
2409
	  CalculateCcaBusyDuration ();
2341
        }
2410
        }
2342
      break;
2411
      break;
2343
    case WifiPhy::CCA_BUSY:
2412
    case WifiPhy::CCA_BUSY:
 Lines 2350-2356   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2350
              m_mpdusNum = 0;
2419
              m_mpdusNum = 0;
2351
              NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
2420
              NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
2352
              NotifyRxDrop (packet);
2421
              NotifyRxDrop (packet);
2353
              goto maybeCcaBusy;
2422
              CalculateCcaBusyDuration ();
2354
            }
2423
            }
2355
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
2424
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
2356
            {
2425
            {
 Lines 2388-2393   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2388
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2457
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2389
          NotifyRxBegin (packet);
2458
          NotifyRxBegin (packet);
2390
          m_interference.NotifyRxStart ();
2459
          m_interference.NotifyRxStart ();
2460
          m_rxPacket = packet;
2461
          m_rxPacketEvent = event;
2462
          m_rxPreambleType = preamble;
2391
2463
2392
          if (preamble != WIFI_PREAMBLE_NONE)
2464
          if (preamble != WIFI_PREAMBLE_NONE)
2393
            {
2465
            {
 Lines 2398-2404   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2398
2470
2399
          NS_ASSERT (m_endRxEvent.IsExpired ());
2471
          NS_ASSERT (m_endRxEvent.IsExpired ());
2400
          m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2472
          m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2401
                                              packet, preamble, mpdutype, event);
2473
					      packet, preamble, mpdutype, event);
2402
        }
2474
        }
2403
      else
2475
      else
2404
        {
2476
        {
 Lines 2406-2412   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2406
                        rxPowerW << "<" << GetEdThresholdW () << ")");
2478
                        rxPowerW << "<" << GetEdThresholdW () << ")");
2407
          NotifyRxDrop (packet);
2479
          NotifyRxDrop (packet);
2408
          m_plcpSuccess = false;
2480
          m_plcpSuccess = false;
2409
          goto maybeCcaBusy;
2481
          CalculateCcaBusyDuration ();
2410
        }
2482
        }
2411
      break;
2483
      break;
2412
    case WifiPhy::SLEEP:
2484
    case WifiPhy::SLEEP:
 Lines 2417-2424   WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Tim Link Here 
2417
    }
2489
    }
2418
2490
2419
  return;
2491
  return;
2492
}
2420
2493
2421
maybeCcaBusy:
2494
void
2495
WifiPhy::CalculateCcaBusyDuration ()
2496
{
2497
//  maybeCcaBusy:
2422
  //We are here because we have received the first bit of a packet and we are
2498
  //We are here because we have received the first bit of a packet and we are
2423
  //not going to be able to synchronize on it
2499
  //not going to be able to synchronize on it
2424
  //In this model, CCA becomes busy when the aggregation of all signals as
2500
  //In this model, CCA becomes busy when the aggregation of all signals as
 Lines 2431-2436   maybeCcaBusy: Link Here 
2431
    }
2507
    }
2432
}
2508
}
2433
2509
2510
bool
2511
WifiPhy::CheckPreambleCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2512
{
2513
  NS_LOG_DEBUG (Simulator::Now() << ", preamble capture check: old reception event start at "
2514
		  << m_rxPacketEvent->GetStartTime()
2515
		  << ", old preamble type "<<m_rxPreambleType
2516
		  << ", end at " << m_rxPacketEvent->GetEndTime()
2517
		  << ", old rxPower "<< m_rxPacketEvent->GetRxPowerW());
2518
  bool result = false;
2519
  Time endRx = event->GetEndTime();
2520
  InterferenceHelper::SnrPer snrPer;
2521
  snrPer = m_interference.CalculatePlcpHeaderSnrPer (m_rxPacketEvent); // check whether the plcp header can still decoded
2522
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2523
  if (m_random->GetValue () > snrPer.per)  // the reception of the old packet can be continued
2524
    {
2525
      NS_ASSERT (m_endPlcpRxEvent.IsRunning());
2526
      NS_LOG_INFO (Simulator::Now() << " preamble capture check: dropping newly arrived packet"
2527
		   << ", because already sync to a stronger enough signal");
2528
      NotifyRxDrop (packet);
2529
      if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2530
	{
2531
	  CalculateCcaBusyDuration ();
2532
	}
2533
    }
2534
  else // the reception of the old packet cannot be continued
2535
    {
2536
      NS_LOG_INFO (Simulator::Now() << " preamble capture check: dropping currently received packet");
2537
      AbortCurrentReception (m_rxPacket, snrPer.snr);
2538
      if (m_doPreambleCapture) // if the frame capture capability at preamble is enabled, check whether can
2539
			       // switch to the new packet
2540
	{
2541
	  NS_ASSERT (m_endPlcpRxEvent.IsExpired() && m_endRxEvent.IsExpired());
2542
	  NS_LOG_INFO (Simulator::Now()<< " preamble capture check: switch to new packet");
2543
	  InterferenceHelper::SnrPer snrPerForNewPkt;
2544
	  snrPerForNewPkt = m_interference.CalculatePlcpHeaderSnrPer (event);
2545
	  double prob = m_interference.CalculatePreambleCaptureProbability(snrPerForNewPkt.snr);
2546
	  if (m_random->GetValue () < prob)
2547
	    {
2548
	      SwitchReception (packet, event);
2549
	      result = true;
2550
	    }
2551
	  else
2552
	    {
2553
	      NS_LOG_INFO (Simulator::Now()<<" preamble capture: signal is too low for capture");
2554
	      NotifyRxDrop (packet);
2555
	      if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2556
		{
2557
		  CalculateCcaBusyDuration ();
2558
		}
2559
	    }
2560
	}
2561
      else // if the frame capture is not enabled, drop the packet
2562
	{
2563
	  NS_LOG_INFO (Simulator::Now()<<" preamble capture check: drop packet because already receiving");
2564
	  NotifyRxDrop (packet);
2565
	  if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2566
	    {
2567
	      CalculateCcaBusyDuration ();
2568
	    }
2569
	}
2570
    }
2571
  return result;
2572
}
2573
2574
bool
2575
WifiPhy::CheckPayloadCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2576
{
2577
  NS_LOG_DEBUG (Simulator::Now() << ", payload capture check: old reception event start at "
2578
		  << m_rxPacketEvent->GetStartTime()
2579
		  << ", end at " << m_rxPacketEvent->GetEndTime()
2580
		  << ", old rxPower "<< m_rxPacketEvent->GetRxPowerW());
2581
  bool result = false;
2582
  Time endRx = event->GetEndTime();
2583
  InterferenceHelper::SnrPer snrPer;
2584
  snrPer = m_interference.CalculatePlcpPayloadSnrPer(m_rxPacketEvent); // check whether the plcp header can still decoded
2585
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2586
  if (m_random->GetValue () > snrPer.per)  // the reception of the old packet can be continued
2587
    {
2588
      NS_ASSERT (m_endRxEvent.IsRunning());
2589
      NS_LOG_INFO (Simulator::Now() << " payload capture check: dropping newly arrived packet"
2590
		   << ", because already sync to a stronger enough signal");
2591
      NotifyRxDrop (packet);
2592
      if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2593
	{
2594
	  CalculateCcaBusyDuration ();
2595
	}
2596
    }
2597
  else // the reception of the old packet cannot be continued
2598
    {
2599
      NS_LOG_INFO (Simulator::Now() << " preamble capture check: dropping currently received packet");
2600
      AbortCurrentReception (m_rxPacket, snrPer.snr);
2601
      if (m_doPayloadCapture) // if the frame capture capability at preamble is enabled, check whether can
2602
			       // switch to the new packet
2603
	{
2604
	  NS_ASSERT (m_endPlcpRxEvent.IsExpired() && m_endRxEvent.IsExpired());
2605
	  NS_LOG_INFO (Simulator::Now()<< " payload capture check: switch to new packet");
2606
	  InterferenceHelper::SnrPer snrPerForNewPkt;
2607
	  snrPerForNewPkt = m_interference.CalculatePlcpPayloadSnrPer (event);
2608
	  double prob = m_interference.CalculatePayloadCaptureProbability (snrPerForNewPkt.snr);
2609
	  if (m_random->GetValue () < prob)
2610
	    {
2611
	      SwitchReception (packet, event);
2612
	      result = true;
2613
	    }
2614
	  else
2615
	    {
2616
	      NS_LOG_INFO (Simulator::Now()<<" payload capture: signal is too low for capture");
2617
	      NotifyRxDrop (packet);
2618
	      if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2619
		{
2620
		  CalculateCcaBusyDuration ();
2621
		}
2622
	    }
2623
	}
2624
      else // if the frame capture is not enabled, drop the packet
2625
	{
2626
	  NS_LOG_INFO (Simulator::Now()<<" payload capture check: drop packet because already receiving");
2627
	  NotifyRxDrop (packet);
2628
	  if (endRx > Simulator::Now() + m_state->GetDelayUntilIdle())
2629
	    {
2630
	      CalculateCcaBusyDuration ();
2631
	    }
2632
	}
2633
    }
2634
  return result;
2635
}
2636
2637
void
2638
WifiPhy::AbortCurrentReception (Ptr<Packet> packet, double snr)
2639
{
2640
  if (m_endPlcpRxEvent.IsRunning())
2641
    {
2642
      m_endPlcpRxEvent.Cancel();
2643
    }
2644
  if (m_endRxEvent.IsRunning())
2645
    {
2646
      m_endRxEvent.Cancel();
2647
    }
2648
  m_interference.NotifyRxEnd();
2649
  m_state->SwitchFromRxAbort(packet, snr);
2650
  m_rxPacket = NULL;
2651
  m_rxPacketEvent = NULL;
2652
  m_rxPreambleType = WIFI_PREAMBLE_NONE;
2653
}
2654
2655
void
2656
WifiPhy::SwitchReception (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2657
{
2658
  m_rxPacket = packet;
2659
  m_rxPacketEvent = event;
2660
  m_state->SwitchToRx (event->GetDuration());
2661
  NotifyRxBegin (packet);
2662
  m_interference.NotifyRxStart();
2663
}
2664
2434
void
2665
void
2435
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
2666
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
2436
                             WifiTxVector txVector,
2667
                             WifiTxVector txVector,
 Lines 2459-2464   WifiPhy::StartReceivePacket (Ptr<Packet> packet, Link Here 
2459
          NS_LOG_DEBUG ("drop packet because it was sent using an unsupported mode (" << txMode << ")");
2690
          NS_LOG_DEBUG ("drop packet because it was sent using an unsupported mode (" << txMode << ")");
2460
          NotifyRxDrop (packet);
2691
          NotifyRxDrop (packet);
2461
          m_plcpSuccess = false;
2692
          m_plcpSuccess = false;
2693
          AbortCurrentReception (packet, snrPer.snr);
2694
          CalculateCcaBusyDuration ();
2462
        }
2695
        }
2463
    }
2696
    }
2464
  else //plcp reception failed
2697
  else //plcp reception failed
 Lines 2466-2471   WifiPhy::StartReceivePacket (Ptr<Packet> packet, Link Here 
2466
      NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed");
2699
      NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed");
2467
      NotifyRxDrop (packet);
2700
      NotifyRxDrop (packet);
2468
      m_plcpSuccess = false;
2701
      m_plcpSuccess = false;
2702
      AbortCurrentReception (packet, snrPer.snr);
2703
      CalculateCcaBusyDuration ();
2469
    }
2704
    }
2470
}
2705
}
2471
2706
(-)a/src/wifi/model/wifi-phy.h (-1 / +55 lines)
 Lines 1524-1529   public: Link Here 
1524
   */
1524
   */
1525
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const;
1525
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const;
1526
1526
1527
// following method is used to support frame capture capability
1528
1529
  /**
1530
   * \param enable boolean value to indicate whether preamble capture is enabled or not
1531
   */
1532
  void SetPreambleCapture (bool enable);
1533
  /**
1534
   * \return boolean value to indicate whether preamble capture is enable or not
1535
   */
1536
  bool GetPreambleCapture (void) const;
1537
  /**
1538
   * \param enable boolean value to indicate whether payload capture is enabled or not
1539
   */
1540
  void SetPayloadCapture (bool enable);
1541
  /**
1542
   * \return boolean value to indicate whether payload capture is enable or not
1543
   */
1544
  bool GetPayloadCapture (void) const;
1545
1527
1546
1528
protected:
1547
protected:
1529
  // Inherited
1548
  // Inherited
 Lines 1741-1747   private: Link Here 
1741
   * of its size.
1760
   * of its size.
1742
   */
1761
   */
1743
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, WifiTxVector, MpduInfo> m_phyMonitorSniffTxTrace;
1762
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, WifiTxVector, MpduInfo> m_phyMonitorSniffTxTrace;
1744
    
1763
1764
  // following methods used to support frame capture capability
1765
  /**
1766
   * Due to newly arrived signal, the old reception cannot be continued and has to be abort
1767
   */
1768
  void AbortCurrentReception (Ptr<Packet> packet, double snr);
1769
  /**
1770
   * Calculate the duration of CCA busy
1771
   */
1772
  void CalculateCcaBusyDuration (void);
1773
  /**
1774
   * Check whether preamble capture can be triggered
1775
   * \param packet the newly arrived packet which needs to be check for capture
1776
   * \param event the receiving event associated with the receiving packet
1777
   * \param txVector
1778
   * \param mpdutype
1779
   */
1780
  bool CheckPreambleCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1781
  /**
1782
   * Check whether payload capture can be triggered
1783
   * \param packet the newly arrived packet which needs to be check for capture
1784
   * \param event the receiving event associated with the receiving packet
1785
   * \param tag
1786
   */
1787
  bool CheckPayloadCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1788
  /**
1789
   * The new packet passes the check and the receiver is going to switch to the new packet
1790
   */
1791
  void SwitchReception (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1745
  /**
1792
  /**
1746
   * This vector holds the set of transmission modes that this
1793
   * This vector holds the set of transmission modes that this
1747
   * WifiPhy(-derived class) can support. In conversation we call this
1794
   * WifiPhy(-derived class) can support. In conversation we call this
 Lines 1824-1829   private: Link Here 
1824
  
1871
  
1825
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1872
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1826
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1873
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1874
1875
  // following variables used to support frame capture capability
1876
  Ptr<Packet> m_rxPacket;                         // The packet that is currently being received by the receiver
1877
  Ptr<InterferenceHelper::Event> m_rxPacketEvent; // The event that indicates the current receiving event
1878
  bool m_doPreambleCapture;                       // The flag indicates whether the capture at the preamble portion of the packet is enabled or not
1879
  bool m_doPayloadCapture;                        // The flag indicates whether the capture at the payload(data) portion of the packet is enabled or not
1880
  WifiPreamble m_rxPreambleType;                  // The preamble type of the currently receiving frame
1827
};
1881
};
1828
1882
1829
/**
1883
/**
(-)a/src/wifi/wscript (+2 lines)
 Lines 81-86   def build(bld): Link Here 
81
        'model/ht-operations.cc',
81
        'model/ht-operations.cc',
82
        'model/dsss-parameter-set.cc',
82
        'model/dsss-parameter-set.cc',
83
        'model/edca-parameter-set.cc',
83
        'model/edca-parameter-set.cc',
84
        'model/frame-capture-model.cc',
84
        'helper/wifi-radio-energy-model-helper.cc',
85
        'helper/wifi-radio-energy-model-helper.cc',
85
        'helper/vht-wifi-mac-helper.cc',
86
        'helper/vht-wifi-mac-helper.cc',
86
        'helper/ht-wifi-mac-helper.cc',
87
        'helper/ht-wifi-mac-helper.cc',
 Lines 186-191   def build(bld): Link Here 
186
        'model/ht-operations.h',
187
        'model/ht-operations.h',
187
        'model/dsss-parameter-set.h',
188
        'model/dsss-parameter-set.h',
188
        'model/edca-parameter-set.h',
189
        'model/edca-parameter-set.h',
190
        'model/frame-capture-model.h',
189
        'helper/wifi-radio-energy-model-helper.h',
191
        'helper/wifi-radio-energy-model-helper.h',
190
        'helper/vht-wifi-mac-helper.h',
192
        'helper/vht-wifi-mac-helper.h',
191
        'helper/ht-wifi-mac-helper.h',
193
        'helper/ht-wifi-mac-helper.h',

Return to bug 2368