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

(-)a/src/wifi/examples/frame-capture-model-validation.cc (+68 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) Crash Avoidance Metrics Partnership (CAMP) VSC3
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: Bin Cheng <cb3974@winlab.rutgers.edu>
19
 */
20
21
//
22
23
#include "ns3/core-module.h"
24
#include "ns3/frame-capture-model.h"
25
#include "ns3/gnuplot.h"
26
27
using namespace ns3;
28
29
int main (int argc, char *argv[])
30
{
31
  std::ofstream preambleCaptureFile ("preamble-capture-success-rate.plt");
32
  std::ofstream payloadCaptureFile ("payload-capture-success-rate.plt");
33
34
  Gnuplot preambleCapturePlot = Gnuplot ("preamble-capture-success-rate.eps");
35
  Gnuplot payloadCapturePlot = Gnuplot ("payload-capture-success-rate.eps");
36
37
  Ptr<FrameCaptureModel> captureModel = CreateObject<FrameCaptureModel> ();
38
  Gnuplot2dDataset preambleCaptureData ("Preamble-Capture");
39
  Gnuplot2dDataset payloadCaptureData ("Payload-Capture");
40
41
  for (double sinr = 0.0; sinr <= 15.0; sinr += 0.1)
42
    {
43
      double preambleRate = captureModel->CalculatePreambleCaptureProbability (std::pow (10.0, sinr / 10.0));
44
      preambleCaptureData.Add (sinr, preambleRate);
45
      double payloadRate = captureModel->CalculatePayloadCaptureProbability (std::pow (10.0, sinr / 10.0));
46
      payloadCaptureData.Add (sinr, payloadRate);
47
    }
48
49
  preambleCapturePlot.AddDataset (preambleCaptureData);
50
  payloadCapturePlot.AddDataset (payloadCaptureData);
51
52
  preambleCapturePlot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
53
  preambleCapturePlot.SetLegend ("SINR(dB)", "Preamble Capture Success Rate");
54
  preambleCapturePlot.SetExtra  ("set xrange [0:15]\n\
55
set yrange [0:1.1]\n\
56
set style line 1 linewidth 8"                                                                                                                                                                                                                                                                                                                                   );
57
  preambleCapturePlot.GenerateOutput (preambleCaptureFile);
58
  preambleCaptureFile.close ();
59
60
  payloadCapturePlot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
61
  payloadCapturePlot.SetLegend ("SNR(dB)", "Payload Capture Success Rate");
62
  payloadCapturePlot.SetExtra  ("set xrange [0:15]\n\
63
set yrange [0:1.1]\n\
64
set style line 1 linewidth 8"                                                                                                                                                                                                                                                                                                                                   );
65
66
  payloadCapturePlot.GenerateOutput (payloadCaptureFile);
67
  payloadCaptureFile.close ();
68
}
(-)a/src/wifi/examples/test-interference-helper.cc (-9 / +110 lines)
 Lines 54-59    Link Here 
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/yans-error-rate-model.h"
57
#include "ns3/nist-error-rate-model.h"
57
#include "ns3/constant-position-mobility-model.h"
58
#include "ns3/constant-position-mobility-model.h"
58
59
59
using namespace ns3;
60
using namespace ns3;
 Lines 71-80    Link Here 
71
    std::string txModeB;
72
    std::string txModeB;
72
    uint32_t txPowerLevelA;
73
    uint32_t txPowerLevelA;
73
    uint32_t txPowerLevelB;
74
    uint32_t txPowerLevelB;
75
    double txPowerA;
76
    double txPowerB;
74
    uint32_t packetSizeA;
77
    uint32_t packetSizeA;
75
    uint32_t packetSizeB;
78
    uint32_t packetSizeB;
76
    WifiPhyStandard standard;
79
    WifiPhyStandard standard;
77
    WifiPreamble preamble;
80
    WifiPreamble preamble;
81
    bool enableFrameCapture;
82
    int numSentPackets;
78
  };
83
  };
79
84
80
  InterferenceExperiment ();
85
  InterferenceExperiment ();
 Lines 96-101    Link Here 
96
  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
101
  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
97
  txVector.SetMode (WifiMode (m_input.txModeA));
102
  txVector.SetMode (WifiMode (m_input.txModeA));
98
  txVector.SetPreambleType (m_input.preamble);
103
  txVector.SetPreambleType (m_input.preamble);
104
  m_txA->SetTxPowerStart (m_input.txPowerA);
105
  m_txA->SetTxPowerEnd (m_input.txPowerA);
99
  m_txA->SendPacket (p, txVector);
106
  m_txA->SendPacket (p, txVector);
100
}
107
}
101
108
 Lines 107-112    Link Here 
107
  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
114
  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
108
  txVector.SetMode (WifiMode (m_input.txModeB));
115
  txVector.SetMode (WifiMode (m_input.txModeB));
109
  txVector.SetPreambleType (m_input.preamble);
116
  txVector.SetPreambleType (m_input.preamble);
117
  m_txB->SetTxPowerStart (m_input.txPowerB);
118
  m_txB->SetTxPowerEnd (m_input.txPowerB);
110
  m_txB->SendPacket (p, txVector);
119
  m_txB->SendPacket (p, txVector);
111
}
120
}
112
121
 Lines 121-130    Link Here 
121
    txModeB ("OfdmRate54Mbps"),
130
    txModeB ("OfdmRate54Mbps"),
122
    txPowerLevelA (0),
131
    txPowerLevelA (0),
123
    txPowerLevelB (0),
132
    txPowerLevelB (0),
133
    txPowerA (20),
134
    txPowerB (20),
124
    packetSizeA (1500),
135
    packetSizeA (1500),
125
    packetSizeB (1500),
136
    packetSizeB (1500),
126
    standard (WIFI_PHY_STANDARD_80211a),
137
    standard (WIFI_PHY_STANDARD_80211a),
127
    preamble (WIFI_PREAMBLE_LONG)
138
    preamble (WIFI_PREAMBLE_LONG),
139
    enableFrameCapture (false),
140
    numSentPackets (1)
128
{
141
{
129
}
142
}
130
143
 Lines 152-158    Link Here 
152
  m_txB = CreateObject<YansWifiPhy> ();
165
  m_txB = CreateObject<YansWifiPhy> ();
153
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
166
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
154
167
155
  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
168
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
156
  m_txA->SetErrorRateModel (error);
169
  m_txA->SetErrorRateModel (error);
157
  m_txB->SetErrorRateModel (error);
170
  m_txB->SetErrorRateModel (error);
158
  rx->SetErrorRateModel (error);
171
  rx->SetErrorRateModel (error);
 Lines 167-174    Link Here 
167
  m_txB->ConfigureStandard (input.standard);
180
  m_txB->ConfigureStandard (input.standard);
168
  rx->ConfigureStandard (input.standard);
181
  rx->ConfigureStandard (input.standard);
169
182
170
  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
183
  m_txA->SetAttribute ("PreambleCaptureEnabled", BooleanValue (input.enableFrameCapture));
171
  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
184
  m_txB->SetAttribute ("PreambleCaptureEnabled", BooleanValue (input.enableFrameCapture));
185
  rx->SetAttribute ("PreambleCaptureEnabled", BooleanValue (input.enableFrameCapture));
186
  m_txA->SetAttribute ("PayloadCaptureEnabled", BooleanValue (input.enableFrameCapture));
187
  m_txB->SetAttribute ("PayloadCaptureEnabled", BooleanValue (input.enableFrameCapture));
188
  rx->SetAttribute ("PayloadCaptureEnabled", BooleanValue (input.enableFrameCapture));
189
190
  for (int n = 0; n < input.numSentPackets; ++n)
191
    {
192
      double start = 0.1 * n;
193
      Simulator::Schedule (Seconds (start), &InterferenceExperiment::SendA, this);
194
      Simulator::Schedule (Seconds (start) + input.interval, &InterferenceExperiment::SendB, this);
195
    }
172
196
173
  Simulator::Run ();
197
  Simulator::Run ();
174
  Simulator::Destroy ();
198
  Simulator::Destroy ();
 Lines 181-186    Link Here 
181
  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
205
  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
182
  std::string str_preamble = "WIFI_PREAMBLE_LONG";
206
  std::string str_preamble = "WIFI_PREAMBLE_LONG";
183
  double delay = 0; //microseconds
207
  double delay = 0; //microseconds
208
  bool enableMultipleFrameCaptureTests = false; // If this is true, run tests for different frame capture cases
184
209
185
  CommandLine cmd;
210
  CommandLine cmd;
186
  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
211
  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
 Lines 188-202    Link Here 
188
  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
213
  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
189
  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
214
  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);
215
  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
191
  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
216
  cmd.AddValue ("txPowerLevelA", "TX power level of transmitter A", input.txPowerLevelA);
192
  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
217
  cmd.AddValue ("txPowerLevelB", "TX power level of transmitter B", input.txPowerLevelB);
218
  cmd.AddValue ("txPowerA", "Tx power of transmitter A", input.txPowerA);
219
  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);
220
  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);
221
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
195
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
222
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
196
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
223
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
224
  cmd.AddValue ("enableFrameCapture", "Enable frame capture capability", input.enableFrameCapture);
225
  cmd.AddValue ("enableMultipleFrameCaptureTests", "Enable test frame capture in difference scenarios", enableMultipleFrameCaptureTests);
197
  cmd.Parse (argc, argv);
226
  cmd.Parse (argc, argv);
198
227
199
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
228
  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
200
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
229
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
201
230
202
  input.interval = MicroSeconds (delay);
231
  input.interval = MicroSeconds (delay);
 Lines 258-265    Link Here 
258
      return 0;
287
      return 0;
259
    }
288
    }
260
289
261
  InterferenceExperiment experiment;
290
  input.enableFrameCapture = true;
262
  experiment.Run (input);
291
  enableMultipleFrameCaptureTests = true;
292
  if (input.enableFrameCapture && enableMultipleFrameCaptureTests)
293
    {
294
      InterferenceExperiment experiment;
263
295
296
      // There are two categories, 4 cases in the frame capture scenario. Two categories are the recovery
297
      // and the capture. The recovery means that the earlier arrived packet trends to be received. With
298
      // newly arrived packet as interference, a recovery probability is calculated, which determines whether
299
      // the reception of the packet can be continued. The capture means the later arrived packet tends to be
300
      // received. A capture probability is calculated to determine whether the receiver can switch to the new packet
301
      // For each category, two packets may collides at the preamble portion or the payload portion.
302
303
      // Note that different txPower of packet A and B can generate different SINR situations at the receiver
304
      int testIndex = 1;
305
      if (testIndex == 1)
306
        {
307
          // test 1: gradually increase the tx power of the first sent packet (packet A)
308
          // in order to check: with newly arrived interference, under what condition, the packet
309
          // can still be recovery at the receiver, collision at the preamble portion of the packet
310
          input.interval = MicroSeconds (10); // two packets collides at the preamble portion of the first packet
311
          input.numSentPackets = 1000;
312
          for (double powerGap = 0.0; powerGap <= 15.0; powerGap += 0.2)
313
            {
314
              input.txPowerA = input.txPowerB + powerGap;
315
              experiment.Run (input);
316
            }
317
318
        }
319
      else if (testIndex == 2)
320
        {
321
          // test 2: gradually increase the tx power of the first sent packet (packet A)
322
          // in order to check: with newly arrived interference, under what condition, the packet
323
          // can still be recovery at the receiver, collision at the payload portion of the packet
324
          input.interval = MicroSeconds (100); // two packets collides at the payload portion of the first packet
325
          input.numSentPackets = 1000;
326
          for (double powerGap = 0.0; powerGap <= 15.0; powerGap += 0.2)
327
            {
328
              input.txPowerA = input.txPowerB + powerGap;
329
              experiment.Run (input);
330
            }
331
        }
332
      else if (testIndex == 3)
333
        {
334
          // test 3: gradually increase the tx power of the late sent packet (packet B)
335
          // in order to check: under what condition, the receiver can switch to the new packet,
336
          // collision at preamble portion of the packet
337
          input.interval = MicroSeconds (10); // two packets collides at the preamble portion of the first packet
338
          input.numSentPackets = 1000;
339
          for (double powerGap = 0.0; powerGap <= 15.0; powerGap += 0.2)
340
            {
341
              input.txPowerB = input.txPowerA + powerGap;
342
              experiment.Run (input);
343
            }
344
        }
345
      else if (testIndex == 4)
346
        {
347
          // test 4 : gradually increase the tx power of the late sent packet (packet B)
348
          // in order to check: under what condition, the receiver can switch to the new packet
349
          // collision at payload portion of the packet
350
          input.interval = MicroSeconds (100); // two packets collides at the payload portion of the first packet
351
          input.numSentPackets = 1000;
352
          for (double powerGap = 0.0; powerGap <= 15.0; powerGap += 0.2)
353
            {
354
              input.txPowerB = input.txPowerA + powerGap;
355
              experiment.Run (input);
356
            }
357
        }
358
359
    }
360
  else
361
    {
362
      InterferenceExperiment experiment;
363
      experiment.Run (input);
364
    }
264
  return 0;
365
  return 0;
265
}
366
}
(-)a/src/wifi/examples/wscript (-1 / +6 lines)
 Lines 11-17    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'
 Lines 23-25    Link Here 
23
    obj = bld.create_ns3_program('wifi-phy-configuration',
23
    obj = bld.create_ns3_program('wifi-phy-configuration',
24
        ['core', 'network', 'config-store', 'wifi'])
24
        ['core', 'network', 'config-store', 'wifi'])
25
    obj.source = 'wifi-phy-configuration.cc'
25
    obj.source = 'wifi-phy-configuration.cc'
26
27
    obj = bld.create_ns3_program('frame-capture-model-validation',
28
        ['core', 'wifi'])
29
    obj.source = 'frame-capture-model-validation.cc'    
30
    
(-)a/src/wifi/model/frame-capture-model.cc (+88 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) Crash Avoidance Metrics Partnership (CAMP) VSC3
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: Bin Cheng <cb3974@winlab.rutgers.edu>
19
 */
20
21
22
#include "frame-capture-model.h"
23
#include <algorithm>
24
#include <cmath>
25
#include "wifi-utils.h"
26
27
namespace ns3 {
28
29
NS_OBJECT_ENSURE_REGISTERED (FrameCaptureModel);
30
31
TypeId
32
FrameCaptureModel::GetTypeId (void)
33
{
34
  static TypeId tid = TypeId ("ns3::FrameCaptureModel")
35
    .SetParent<Object> ()
36
    .SetGroupName ("Wifi")
37
    .AddConstructor<FrameCaptureModel> ()
38
  ;
39
  return tid;
40
}
41
42
FrameCaptureModel::FrameCaptureModel ()
43
{
44
}
45
46
double
47
FrameCaptureModel::CalculatePreambleCaptureProbability (double sinr)
48
{
49
  double z = std::sqrt (sinr / 4.0);
50
  double p = 0.5 * erfc (z);
51
  if (p == 0.0)
52
    {
53
      return 1.0;
54
    }
55
  double pe = CalculatePe (p);
56
  pe = std::min (pe, 1.0);
57
  double prob = std::pow (1 - pe, 240);
58
  return prob;
59
}
60
61
double
62
FrameCaptureModel::CalculatePayloadCaptureProbability (double sinr)
63
{
64
  double sinrDb = RatioToDb (sinr);
65
  double prob = 0.4989 * erf ((sinrDb - 9.356) / 0.8722) + 0.4989;
66
  prob = std::max (prob, 0.0);
67
  prob = std::min (prob, 1.0);
68
  return prob;
69
}
70
71
double
72
FrameCaptureModel::CalculatePe (double p)
73
{
74
  double D = std::sqrt (4.0 * p * (1.0 - p));
75
  double pe = 1.0;
76
  pe = 0.5 * (36.0 * std::pow (D, 10)
77
              + 211.0 * std::pow (D, 12)
78
              + 1404.0 * std::pow (D, 14)
79
              + 11633.0 * std::pow (D, 16)
80
              + 77433.0 * std::pow (D, 18)
81
              + 502690.0 * std::pow (D, 20)
82
              + 3322763.0 * std::pow (D, 22)
83
              + 21292910.0 * std::pow (D, 24)
84
              + 134365911.0 * std::pow (D, 26));
85
  return pe;
86
}
87
88
} // //namespace ns3
(-)a/src/wifi/model/frame-capture-model.h (+72 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) Crash Avoidance Metrics Partnership (CAMP) VSC3
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: Bin Cheng <cb3974@winlab.rutgers.edu>
19
 *
20
 */
21
22
23
#ifndef FRAME_CAPTURE_MODEL_H
24
#define FRAME_CAPTURE_MODEL_H
25
26
#include "ns3/object.h"
27
28
namespace ns3 {
29
30
/**
31
 * \ingroup wifi
32
 * \brief models for switching between two receptions
33
 */
34
class FrameCaptureModel : public Object
35
{
36
public:
37
  static TypeId GetTypeId (void);
38
  FrameCaptureModel ();
39
40
  /**
41
   * Given a sinr value, calculate the probability of a successful
42
   * reception switch at the preamble/header portion of a packet
43
   *
44
   * \param the current sinr value
45
   *
46
   * \return the successful probability of the reception switch
47
   */
48
  double CalculatePreambleCaptureProbability (double sinr);
49
50
  /**
51
   * Given a sinr value, calculate the probability of a successful
52
   * reception switch at the payload portion of a packet
53
   *
54
   * \param the current sinr value
55
   *
56
   * \return the successful probability of the reception switch
57
   */
58
  double CalculatePayloadCaptureProbability (double sinr);
59
private:
60
  /**
61
   * Calculate a coded bit error rate
62
   *
63
   * \param p
64
   *
65
   * \return BER
66
   */
67
  double CalculatePe (double p);
68
};
69
70
} //namespace ns3
71
72
#endif /* FRAME_CAPTURE_MODEL_H */
(-)a/src/wifi/model/interference-helper.cc (-4 / +22 lines)
 Lines 251-264    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 ())
257
        {
258
          noiseInterference += i->GetDelta ();
259
        }
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 ())
258
        {
265
        {
259
          break;
266
          break;
260
        }
267
        }
261
      ni->push_back (*i);
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    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 / +19 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    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
   * \return the probability of the successful preamble capture with the given sinr
216
   */
217
  double CalculatePreambleCaptureProbability (double sinr);
218
  /**
219
   * Calculate the successful probability for payload capture
220
   * \param sinr the sinr value at the current time
221
   *
222
   * \return the probability of the successful payload capture with the given sinr
223
   */
224
  double CalculatePayloadCaptureProbability (double sinr);
210
225
211
private:
226
private:
212
  /**
227
  /**
 Lines 322-327    Link Here 
322
  NiChanges m_niChanges;
337
  NiChanges m_niChanges;
323
  double m_firstPower;
338
  double m_firstPower;
324
  bool m_rxing;
339
  bool m_rxing;
340
  // following variables used for frame capture capability
341
  Ptr<FrameCaptureModel> m_frameCaptureModel;
342
325
  /// Returns an iterator to the first nichange, which is later than moment
343
  /// Returns an iterator to the first nichange, which is later than moment
326
  NiChanges::iterator GetPosition (Time moment);
344
  NiChanges::iterator GetPosition (Time moment);
327
  /**
345
  /**
(-)a/src/wifi/model/wifi-phy-state-helper.cc (+15 lines)
 Lines 541-544    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    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 (-39 / +222 lines)
 Lines 308-313    Link Here 
308
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
308
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
309
                                        &WifiPhy::SetShortPlcpPreambleSupported),
309
                                        &WifiPhy::SetShortPlcpPreambleSupported),
310
                   MakeBooleanChecker ())
310
                   MakeBooleanChecker ())
311
    .AddAttribute ("PreambleCaptureEnabled",
312
                   "Whether or not to enable capture at the preamble portion of the packet.",
313
                   BooleanValue (false),
314
                   MakeBooleanAccessor (&WifiPhy::m_doPreambleCapture),
315
                   MakeBooleanChecker ())
316
    .AddAttribute ("PayloadCaptureEnabled",
317
                   "Whether or not to enable capture at the payload portion of the packet",
318
                   BooleanValue (false),
319
                   MakeBooleanAccessor (&WifiPhy::m_doPayloadCapture),
320
                   MakeBooleanChecker ())
311
    .AddTraceSource ("PhyTxBegin",
321
    .AddTraceSource ("PhyTxBegin",
312
                     "Trace source indicating a packet "
322
                     "Trace source indicating a packet "
313
                     "has begun transmitting over the channel medium",
323
                     "has begun transmitting over the channel medium",
 Lines 883-891    Link Here 
883
    {
893
    {
884
      // erase all HtMcs modes from deviceMcsSet
894
      // erase all HtMcs modes from deviceMcsSet
885
      size_t index = m_deviceMcsSet.size () - 1;
895
      size_t index = m_deviceMcsSet.size () - 1;
886
      for (std::vector<WifiMode>::reverse_iterator rit = m_deviceMcsSet.rbegin (); rit != m_deviceMcsSet.rend(); ++rit, --index)
896
      for (std::vector<WifiMode>::reverse_iterator rit = m_deviceMcsSet.rbegin (); rit != m_deviceMcsSet.rend (); ++rit, --index)
887
        {
897
        {
888
          if (m_deviceMcsSet[index].GetModulationClass ()== WIFI_MOD_CLASS_HT)
898
          if (m_deviceMcsSet[index].GetModulationClass () == WIFI_MOD_CLASS_HT)
889
            {
899
            {
890
              m_deviceMcsSet.erase (m_deviceMcsSet.begin () + index);
900
              m_deviceMcsSet.erase (m_deviceMcsSet.begin () + index);
891
            }
901
            }
 Lines 999-1006    Link Here 
999
    {
1009
    {
1000
      if (it->second == f)
1010
      if (it->second == f)
1001
        {
1011
        {
1002
           found = true;
1012
          found = true;
1003
           break;
1013
          break;
1004
        }
1014
        }
1005
      ++it;
1015
      ++it;
1006
    }
1016
    }
 Lines 1945-1956    Link Here 
1945
        //check tables 20-35 and 20-36 in the .11n standard to get cases when nes = 2
1955
        //check tables 20-35 and 20-36 in the .11n standard to get cases when nes = 2
1946
        double Nes = 1;
1956
        double Nes = 1;
1947
        if (payloadMode.GetUniqueName () == "HtMcs21"
1957
        if (payloadMode.GetUniqueName () == "HtMcs21"
1948
           || payloadMode.GetUniqueName () == "HtMcs22"
1958
            || payloadMode.GetUniqueName () == "HtMcs22"
1949
           || payloadMode.GetUniqueName () == "HtMcs23"
1959
            || payloadMode.GetUniqueName () == "HtMcs23"
1950
           || payloadMode.GetUniqueName () == "HtMcs28"
1960
            || payloadMode.GetUniqueName () == "HtMcs28"
1951
           || payloadMode.GetUniqueName () == "HtMcs29"
1961
            || payloadMode.GetUniqueName () == "HtMcs29"
1952
           || payloadMode.GetUniqueName () == "HtMcs30"
1962
            || payloadMode.GetUniqueName () == "HtMcs30"
1953
           || payloadMode.GetUniqueName () == "HtMcs31")
1963
            || payloadMode.GetUniqueName () == "HtMcs31")
1954
          {
1964
          {
1955
            Nes = 2;
1965
            Nes = 2;
1956
          }
1966
          }
 Lines 2125-2131    Link Here 
2125
Time
2135
Time
2126
WifiPhy::CalculatePlcpPreambleAndHeaderDuration (WifiTxVector txVector)
2136
WifiPhy::CalculatePlcpPreambleAndHeaderDuration (WifiTxVector txVector)
2127
{
2137
{
2128
  WifiPreamble preamble = txVector.GetPreambleType();
2138
  WifiPreamble preamble = txVector.GetPreambleType ();
2129
  Time duration = GetPlcpPreambleDuration (txVector)
2139
  Time duration = GetPlcpPreambleDuration (txVector)
2130
    + GetPlcpHeaderDuration (txVector)
2140
    + GetPlcpHeaderDuration (txVector)
2131
    + GetPlcpHtSigHeaderDuration (preamble)
2141
    + GetPlcpHtSigHeaderDuration (preamble)
 Lines 2213-2219    Link Here 
2213
   *  - we are idle
2223
   *  - we are idle
2214
   */
2224
   */
2215
  NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ());
2225
  NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ());
2216
  
2226
2217
  if (txVector.GetNss () > GetMaxSupportedTxSpatialStreams ())
2227
  if (txVector.GetNss () > GetMaxSupportedTxSpatialStreams ())
2218
    {
2228
    {
2219
      NS_FATAL_ERROR ("Unsupported number of spatial streams!");
2229
      NS_FATAL_ERROR ("Unsupported number of spatial streams!");
 Lines 2252-2258    Link Here 
2252
  newPacket->RemovePacketTag (oldtag);
2262
  newPacket->RemovePacketTag (oldtag);
2253
  WifiPhyTag tag (txVector, mpdutype);
2263
  WifiPhyTag tag (txVector, mpdutype);
2254
  newPacket->AddPacketTag (tag);
2264
  newPacket->AddPacketTag (tag);
2255
  
2265
2256
  StartTx (newPacket, txVector, txDuration);
2266
  StartTx (newPacket, txVector, txDuration);
2257
}
2267
}
2258
2268
 Lines 2264-2270    Link Here 
2264
  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2274
  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2265
  AmpduTag ampduTag;
2275
  AmpduTag ampduTag;
2266
  Time endRx = Simulator::Now () + rxDuration;
2276
  Time endRx = Simulator::Now () + rxDuration;
2267
  
2277
2268
  WifiPhyTag tag;
2278
  WifiPhyTag tag;
2269
  bool found = packet->RemovePacketTag (tag);
2279
  bool found = packet->RemovePacketTag (tag);
2270
  if (!found)
2280
  if (!found)
 Lines 2274-2290    Link Here 
2274
    }
2284
    }
2275
2285
2276
  WifiTxVector txVector = tag.GetWifiTxVector ();
2286
  WifiTxVector txVector = tag.GetWifiTxVector ();
2277
  
2287
2278
  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT
2288
  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT
2279
      && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8))))
2289
      && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8))))
2280
    {
2290
    {
2281
      NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << (uint16_t)txVector.GetMode ().GetMcsValue () << ", NSS = " << (uint16_t)txVector.GetNss ());
2291
      NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << (uint16_t)txVector.GetMode ().GetMcsValue () << ", NSS = " << (uint16_t)txVector.GetNss ());
2282
    }
2292
    }
2283
  
2293
2284
  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2294
  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2285
     {
2295
    {
2286
      NS_FATAL_ERROR ("Reception ends in failure because of an unsupported number of spatial streams");
2296
      NS_FATAL_ERROR ("Reception ends in failure because of an unsupported number of spatial streams");
2287
     }
2297
    }
2288
2298
2289
  WifiPreamble preamble = txVector.GetPreambleType ();
2299
  WifiPreamble preamble = txVector.GetPreambleType ();
2290
  MpduType mpdutype = tag.GetMpduType ();
2300
  MpduType mpdutype = tag.GetMpduType ();
 Lines 2314-2333    Link Here 
2314
        {
2324
        {
2315
          //that packet will be noise _after_ the completion of the
2325
          //that packet will be noise _after_ the completion of the
2316
          //channel switching.
2326
          //channel switching.
2317
          goto maybeCcaBusy;
2327
          CalculateCcaBusyDuration ();
2318
        }
2328
        }
2319
      break;
2329
      break;
2320
    case WifiPhy::RX:
2330
    case WifiPhy::RX:
2321
      NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2331
      {
2322
                    rxPowerW << "W)");
2332
        NS_ASSERT (m_rxPacketEvent != NULL);
2323
      NotifyRxDrop (packet);
2333
        if (m_doPreambleCapture == false
2324
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2334
            || m_doPayloadCapture == false
2325
        {
2335
            || preamble == WIFI_PREAMBLE_NONE)
2326
          //that packet will be noise _after_ the reception of the
2336
          {
2327
          //currently-received packet.
2337
            NS_LOG_DEBUG ("cannot perform frame capture capture");
2328
          goto maybeCcaBusy;
2338
            NotifyRxDrop (packet);
2329
        }
2339
            if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2330
      break;
2340
              {
2341
                CalculateCcaBusyDuration ();
2342
              }
2343
            break;
2344
          }
2345
2346
        Time currentRxStage = Simulator::Now () - m_rxPacketEvent->GetStartTime ();
2347
        bool doReceptionSwitch = false;
2348
        if (m_rxPreambleType != WIFI_PREAMBLE_NONE
2349
            && currentRxStage < preambleAndHeaderDuration) // still receiving the preamble and plcp header portion of the old packet
2350
          {
2351
            doReceptionSwitch = CheckPreambleCapture (packet, event);
2352
          }
2353
        else
2354
          {
2355
            doReceptionSwitch = CheckPayloadCapture (packet, event);
2356
          }
2357
        if (doReceptionSwitch)
2358
          {
2359
            NS_LOG_INFO ("The receiver switches to the new packet (rxPowerDbm " << WToDbm (event->GetRxPowerW ()) << ")");
2360
            m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
2361
                                                    packet, txVector, mpdutype, event);
2362
            m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2363
                                                packet, preamble, mpdutype, event);
2364
            m_rxPreambleType = preamble;
2365
          }
2366
        break;
2367
      }
2331
    case WifiPhy::TX:
2368
    case WifiPhy::TX:
2332
      NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2369
      NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2333
                    rxPowerW << "W)");
2370
                    rxPowerW << "W)");
 Lines 2336-2342    Link Here 
2336
        {
2373
        {
2337
          //that packet will be noise _after_ the transmission of the
2374
          //that packet will be noise _after_ the transmission of the
2338
          //currently-transmitted packet.
2375
          //currently-transmitted packet.
2339
          goto maybeCcaBusy;
2376
          CalculateCcaBusyDuration ();
2340
        }
2377
        }
2341
      break;
2378
      break;
2342
    case WifiPhy::CCA_BUSY:
2379
    case WifiPhy::CCA_BUSY:
 Lines 2349-2355    Link Here 
2349
              m_mpdusNum = 0;
2386
              m_mpdusNum = 0;
2350
              NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
2387
              NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
2351
              NotifyRxDrop (packet);
2388
              NotifyRxDrop (packet);
2352
              goto maybeCcaBusy;
2389
              CalculateCcaBusyDuration ();
2353
            }
2390
            }
2354
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
2391
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
2355
            {
2392
            {
 Lines 2387-2392    Link Here 
2387
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2424
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2388
          NotifyRxBegin (packet);
2425
          NotifyRxBegin (packet);
2389
          m_interference.NotifyRxStart ();
2426
          m_interference.NotifyRxStart ();
2427
          m_rxPacket = packet;
2428
          m_rxPacketEvent = event;
2429
          m_rxPreambleType = preamble;
2390
2430
2391
          if (preamble != WIFI_PREAMBLE_NONE)
2431
          if (preamble != WIFI_PREAMBLE_NONE)
2392
            {
2432
            {
 Lines 2405-2411    Link Here 
2405
                        rxPowerW << "<" << GetEdThresholdW () << ")");
2445
                        rxPowerW << "<" << GetEdThresholdW () << ")");
2406
          NotifyRxDrop (packet);
2446
          NotifyRxDrop (packet);
2407
          m_plcpSuccess = false;
2447
          m_plcpSuccess = false;
2408
          goto maybeCcaBusy;
2448
          CalculateCcaBusyDuration ();
2409
        }
2449
        }
2410
      break;
2450
      break;
2411
    case WifiPhy::SLEEP:
2451
    case WifiPhy::SLEEP:
 Lines 2416-2427    Link Here 
2416
    }
2456
    }
2417
2457
2418
  return;
2458
  return;
2419
2459
}
2420
maybeCcaBusy:
2460
2421
  //We are here because we have received the first bit of a packet and we are
2461
void
2422
  //not going to be able to synchronize on it
2462
WifiPhy::CalculateCcaBusyDuration ()
2423
  //In this model, CCA becomes busy when the aggregation of all signals as
2463
{
2424
  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
2464
//  maybeCcaBusy:
2465
//We are here because we have received the first bit of a packet and we are
2466
//not going to be able to synchronize on it
2467
//In this model, CCA becomes busy when the aggregation of all signals as
2468
//tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
2425
2469
2426
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ()));
2470
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ()));
2427
  if (!delayUntilCcaEnd.IsZero ())
2471
  if (!delayUntilCcaEnd.IsZero ())
 Lines 2430-2435    Link Here 
2430
    }
2474
    }
2431
}
2475
}
2432
2476
2477
bool
2478
WifiPhy::CheckPreambleCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2479
{
2480
  NS_LOG_FUNCTION (this << packet << event);
2481
  NS_LOG_DEBUG (Simulator::Now () << ", preamble capture check: old reception event start at "
2482
                                  << m_rxPacketEvent->GetStartTime ()
2483
                                  << ", old preamble type " << m_rxPreambleType
2484
                                  << ", end at " << m_rxPacketEvent->GetEndTime ()
2485
                                  << ", old rxPower " << m_rxPacketEvent->GetRxPowerW ());
2486
  bool result = false;
2487
  Time endRx = event->GetEndTime ();
2488
  InterferenceHelper::SnrPer snrPer;
2489
  snrPer = m_interference.CalculatePlcpHeaderSnrPer (m_rxPacketEvent); // check whether the plcp header can still decoded
2490
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2491
  if (m_random->GetValue () > snrPer.per)  // the reception of the old packet can be continued
2492
    {
2493
      NS_ASSERT (m_endPlcpRxEvent.IsRunning ());
2494
      NS_LOG_INFO (Simulator::Now () << " preamble capture check: dropping newly arrived packet"
2495
                                     << ", because already sync to a stronger enough signal");
2496
      NotifyRxDrop (packet);
2497
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2498
        {
2499
          CalculateCcaBusyDuration ();
2500
        }
2501
    }
2502
  else // the reception of the old packet cannot be continued
2503
    {
2504
      NS_LOG_INFO (Simulator::Now () << " preamble capture check: dropping currently received packet");
2505
      AbortCurrentReception (m_rxPacket, snrPer.snr);
2506
2507
      NS_ASSERT (m_endPlcpRxEvent.IsExpired () && m_endRxEvent.IsExpired ());
2508
      NS_LOG_INFO (Simulator::Now () << " preamble capture check: switch to new packet");
2509
2510
      InterferenceHelper::SnrPer snrPerForNewPkt;
2511
      snrPerForNewPkt = m_interference.CalculatePlcpHeaderSnrPer (event);
2512
      double prob = m_interference.CalculatePreambleCaptureProbability (snrPerForNewPkt.snr);
2513
      if (m_random->GetValue () < prob)
2514
        {
2515
          SwitchReception (packet, event);
2516
          result = true;
2517
        }
2518
      else
2519
        {
2520
          NS_LOG_INFO (Simulator::Now () << " preamble capture: signal is too low for capture");
2521
          NotifyRxDrop (packet);
2522
          if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2523
            {
2524
              CalculateCcaBusyDuration ();
2525
            }
2526
        }
2527
    }
2528
  return result;
2529
}
2530
2531
bool
2532
WifiPhy::CheckPayloadCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2533
{
2534
  NS_LOG_FUNCTION (this << packet << event);
2535
  NS_LOG_DEBUG (Simulator::Now () << ", payload capture check: old reception event start at "
2536
                                  << m_rxPacketEvent->GetStartTime ()
2537
                                  << ", end at " << m_rxPacketEvent->GetEndTime ()
2538
                                  << ", old rxPower " << m_rxPacketEvent->GetRxPowerW ());
2539
  bool result = false;
2540
  Time endRx = event->GetEndTime ();
2541
  InterferenceHelper::SnrPer snrPer;
2542
  snrPer = m_interference.CalculatePlcpPayloadSnrPer (m_rxPacketEvent); // check whether the plcp header can still decoded
2543
  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2544
  if (m_random->GetValue () > snrPer.per)  // the reception of the old packet can be continued
2545
    {
2546
      NS_ASSERT (m_endRxEvent.IsRunning ());
2547
      NS_LOG_INFO (Simulator::Now () << " payload capture check: dropping newly arrived packet"
2548
                                     << ", because already sync to a stronger enough signal");
2549
      NotifyRxDrop (packet);
2550
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2551
        {
2552
          CalculateCcaBusyDuration ();
2553
        }
2554
    }
2555
  else // the reception of the old packet cannot be continued
2556
    {
2557
      NS_LOG_INFO (Simulator::Now () << " preamble capture check: dropping currently received packet");
2558
      AbortCurrentReception (m_rxPacket, snrPer.snr);
2559
2560
      NS_ASSERT (m_endPlcpRxEvent.IsExpired () && m_endRxEvent.IsExpired ());
2561
      NS_LOG_INFO (Simulator::Now () << " payload capture check: switch to new packet");
2562
2563
      InterferenceHelper::SnrPer snrPerForNewPkt;
2564
      snrPerForNewPkt = m_interference.CalculatePlcpPayloadSnrPer (event);
2565
      double prob = m_interference.CalculatePayloadCaptureProbability (snrPerForNewPkt.snr);
2566
      if (m_random->GetValue () < prob)
2567
        {
2568
          SwitchReception (packet, event);
2569
          result = true;
2570
        }
2571
      else
2572
        {
2573
          NS_LOG_INFO (Simulator::Now () << " payload capture: signal is too low for capture");
2574
          NotifyRxDrop (packet);
2575
          if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2576
            {
2577
              CalculateCcaBusyDuration ();
2578
            }
2579
        }
2580
    }
2581
  return result;
2582
}
2583
2584
void
2585
WifiPhy::AbortCurrentReception (Ptr<Packet> packet, double sinr)
2586
{
2587
  NS_LOG_FUNCTION (this << packet << sinr);
2588
  if (m_endPlcpRxEvent.IsRunning ())
2589
    {
2590
      m_endPlcpRxEvent.Cancel ();
2591
    }
2592
  if (m_endRxEvent.IsRunning ())
2593
    {
2594
      m_endRxEvent.Cancel ();
2595
    }
2596
  m_interference.NotifyRxEnd ();
2597
  m_state->SwitchFromRxAbort (packet, sinr);
2598
  m_rxPacket = NULL;
2599
  m_rxPacketEvent = NULL;
2600
  m_rxPreambleType = WIFI_PREAMBLE_NONE;
2601
}
2602
2603
void
2604
WifiPhy::SwitchReception (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event)
2605
{
2606
  NS_LOG_FUNCTION (this << packet << event);
2607
  m_rxPacket = packet;
2608
  m_rxPacketEvent = event;
2609
  m_state->SwitchToRx (event->GetDuration ());
2610
  NotifyRxBegin (packet);
2611
  m_interference.NotifyRxStart ();
2612
}
2613
2433
void
2614
void
2434
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
2615
WifiPhy::StartReceivePacket (Ptr<Packet> packet,
2435
                             WifiTxVector txVector,
2616
                             WifiTxVector txVector,
 Lines 2452-2457    Link Here 
2452
        {
2633
        {
2453
          NS_LOG_DEBUG ("receiving plcp payload"); //endReceive is already scheduled
2634
          NS_LOG_DEBUG ("receiving plcp payload"); //endReceive is already scheduled
2454
          m_plcpSuccess = true;
2635
          m_plcpSuccess = true;
2636
          NS_LOG_INFO ("decode plcp successfully (rxPowerDbm " << WToDbm (event->GetRxPowerW ()) << ")");
2455
        }
2637
        }
2456
      else //mode is not allowed
2638
      else //mode is not allowed
2457
        {
2639
        {
 Lines 2495-2500    Link Here 
2495
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
2677
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
2496
          NotifyMonitorSniffRx (packet, GetFrequency (), event->GetTxVector (), aMpdu, signalNoise);
2678
          NotifyMonitorSniffRx (packet, GetFrequency (), event->GetTxVector (), aMpdu, signalNoise);
2497
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector ());
2679
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector ());
2680
          NS_LOG_INFO ("decode payload successfully (rxPowerDbm " << WToDbm (event->GetRxPowerW ()) << ")");
2498
        }
2681
        }
2499
      else
2682
      else
2500
        {
2683
        {
 Lines 3311-3317    Link Here 
3311
WifiPhy::IsValidTxVector (WifiTxVector txVector)
3494
WifiPhy::IsValidTxVector (WifiTxVector txVector)
3312
{
3495
{
3313
  uint8_t chWidth = txVector.GetChannelWidth ();
3496
  uint8_t chWidth = txVector.GetChannelWidth ();
3314
  uint8_t nss = txVector.GetNss();
3497
  uint8_t nss = txVector.GetNss ();
3315
  std::string modeName = txVector.GetMode ().GetUniqueName ();
3498
  std::string modeName = txVector.GetMode ().GetUniqueName ();
3316
3499
3317
  if (chWidth == 20)
3500
  if (chWidth == 20)
(-)a/src/wifi/model/wifi-phy.h (-2 / +49 lines)
 Lines 1516-1522    Link Here 
1516
   */
1516
   */
1517
  virtual std::vector<uint8_t> GetSupportedChannelWidthSet (void) const;
1517
  virtual std::vector<uint8_t> GetSupportedChannelWidthSet (void) const;
1518
1518
1519
1520
protected:
1519
protected:
1521
  // Inherited
1520
  // Inherited
1522
  virtual void DoInitialize (void);
1521
  virtual void DoInitialize (void);
 Lines 1733-1739    Link Here 
1733
   * of its size.
1732
   * of its size.
1734
   */
1733
   */
1735
  TracedCallback<Ptr<const Packet>, uint16_t, WifiTxVector, MpduInfo> m_phyMonitorSniffTxTrace;
1734
  TracedCallback<Ptr<const Packet>, uint16_t, WifiTxVector, MpduInfo> m_phyMonitorSniffTxTrace;
1736
    
1735
1736
  /**
1737
   * Due to newly arrived signal, the old reception cannot be continued and has to be abort
1738
   *
1739
   * \param packet, the packet which has to be aborted
1740
   * \param sinr, the sinr of the aborted packet
1741
   */
1742
  void AbortCurrentReception (Ptr<Packet> packet, double sinr);
1743
1744
  /**
1745
   * Calculate the duration of CCA busy
1746
   */
1747
  void CalculateCcaBusyDuration (void);
1748
1749
  /**
1750
   * Check whether preamble capture can be triggered
1751
   *
1752
   * \param packet the newly arrived packet which needs to be check for capture
1753
   * \param event the receiving event associated with the receiving packet
1754
   *
1755
   * \return whether the capture, i.e., reception switching, has been successful
1756
   */
1757
  bool CheckPreambleCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1758
1759
  /**
1760
   * Check whether payload capture can be triggered
1761
   *
1762
   * \param packet the newly arrived packet which needs to be check for capture
1763
   * \param event the receiving event associated with the receiving packet
1764
   *
1765
   * \return whether the capture, i.e., reception switching, has been successful
1766
   */
1767
  bool CheckPayloadCapture (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1768
1769
  /**
1770
   * The new packet passes the check and the receiver is going to switch to the new packet
1771
   *
1772
   * \param packet the packet will be switched to
1773
   * \param event receiving event associated with the packet
1774
   */
1775
  void SwitchReception (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
1776
1737
  /**
1777
  /**
1738
   * This vector holds the set of transmission modes that this
1778
   * This vector holds the set of transmission modes that this
1739
   * WifiPhy(-derived class) can support. In conversation we call this
1779
   * WifiPhy(-derived class) can support. In conversation we call this
 Lines 1816-1821    Link Here 
1816
  
1856
  
1817
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1857
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1818
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1858
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1859
1860
  // following variables used to support frame capture capability
1861
  Ptr<Packet> m_rxPacket;                         // The packet that is currently being received by the receiver
1862
  Ptr<InterferenceHelper::Event> m_rxPacketEvent; // The event that indicates the current receiving event
1863
  bool m_doPreambleCapture;                       // The flag indicates whether the capture at the preamble portion of the packet is enabled or not
1864
  bool m_doPayloadCapture;                        // The flag indicates whether the capture at the payload(data) portion of the packet is enabled or not
1865
  WifiPreamble m_rxPreambleType;                  // The preamble type of the currently receiving frame
1819
};
1866
};
1820
1867
1821
/**
1868
/**
(-)a/src/wifi/wscript (+2 lines)
 Lines 82-87    Link Here 
82
        'model/vht-operation.cc',
82
        'model/vht-operation.cc',
83
        'model/dsss-parameter-set.cc',
83
        'model/dsss-parameter-set.cc',
84
        'model/edca-parameter-set.cc',
84
        'model/edca-parameter-set.cc',
85
        'model/frame-capture-model.cc',
85
        'helper/wifi-radio-energy-model-helper.cc',
86
        'helper/wifi-radio-energy-model-helper.cc',
86
        'helper/vht-wifi-mac-helper.cc',
87
        'helper/vht-wifi-mac-helper.cc',
87
        'helper/ht-wifi-mac-helper.cc',
88
        'helper/ht-wifi-mac-helper.cc',
 Lines 188-193    Link Here 
188
        'model/vht-operation.h',
189
        'model/vht-operation.h',
189
        'model/dsss-parameter-set.h',
190
        'model/dsss-parameter-set.h',
190
        'model/edca-parameter-set.h',
191
        'model/edca-parameter-set.h',
192
        'model/frame-capture-model.h',
191
        'helper/wifi-radio-energy-model-helper.h',
193
        'helper/wifi-radio-energy-model-helper.h',
192
        'helper/vht-wifi-mac-helper.h',
194
        'helper/vht-wifi-mac-helper.h',
193
        'helper/ht-wifi-mac-helper.h',
195
        'helper/ht-wifi-mac-helper.h',

Return to bug 2368