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

(-)a/src/wifi/examples/test-interference-helper.cc (-5 / +23 lines)
 Lines 55-60    Link Here 
55
#include "ns3/propagation-delay-model.h"
55
#include "ns3/propagation-delay-model.h"
56
#include "ns3/nist-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
#include "ns3/simple-frame-capture-model.h"
58
59
59
using namespace ns3;
60
using namespace ns3;
60
61
 Lines 71-82    Link Here 
71
    double xB; ///< x B
72
    double xB; ///< x B
72
    std::string txModeA; ///< transmit mode A
73
    std::string txModeA; ///< transmit mode A
73
    std::string txModeB; ///< transmit mode B
74
    std::string txModeB; ///< transmit mode B
74
    uint32_t txPowerLevelA; ///< transmit power level A
75
    double txPowerLevelA; ///< transmit power level A
75
    uint32_t txPowerLevelB; ///< transmit power level B
76
    double txPowerLevelB; ///< transmit power level B
76
    uint32_t packetSizeA; ///< packet size A
77
    uint32_t packetSizeA; ///< packet size A
77
    uint32_t packetSizeB; ///< packet size B
78
    uint32_t packetSizeB; ///< packet size B
78
    WifiPhyStandard standard; ///< standard
79
    WifiPhyStandard standard; ///< standard
79
    WifiPreamble preamble; ///< preamble
80
    WifiPreamble preamble; ///< preamble
81
    bool captureEnabled; ///< whether physical layer capture is enabled
82
    double captureMargin; ///< margin used for physical layer capture
80
  };
83
  };
81
84
82
  InterferenceExperiment ();
85
  InterferenceExperiment ();
 Lines 127-138    Link Here 
127
    xB (5),
130
    xB (5),
128
    txModeA ("OfdmRate54Mbps"),
131
    txModeA ("OfdmRate54Mbps"),
129
    txModeB ("OfdmRate54Mbps"),
132
    txModeB ("OfdmRate54Mbps"),
130
    txPowerLevelA (0),
133
    txPowerLevelA (16.0206),
131
    txPowerLevelB (0),
134
    txPowerLevelB (16.0206),
132
    packetSizeA (1500),
135
    packetSizeA (1500),
133
    packetSizeB (1500),
136
    packetSizeB (1500),
134
    standard (WIFI_PHY_STANDARD_80211a),
137
    standard (WIFI_PHY_STANDARD_80211a),
135
    preamble (WIFI_PREAMBLE_LONG)
138
    preamble (WIFI_PREAMBLE_LONG),
139
    captureEnabled (false),
140
    captureMargin (0)
136
{
141
{
137
}
142
}
138
143
 Lines 157-163    Link Here 
157
  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
162
  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
158
163
159
  m_txA = CreateObject<YansWifiPhy> ();
164
  m_txA = CreateObject<YansWifiPhy> ();
165
  m_txA->SetTxPowerStart (input.txPowerLevelA);
166
  m_txA->SetTxPowerEnd (input.txPowerLevelA);
160
  m_txB = CreateObject<YansWifiPhy> ();
167
  m_txB = CreateObject<YansWifiPhy> ();
168
  m_txB->SetTxPowerStart (input.txPowerLevelB);
169
  m_txB->SetTxPowerEnd (input.txPowerLevelB);
161
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
170
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
162
171
163
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
172
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
 Lines 170-175    Link Here 
170
  m_txA->SetMobility (posTxA);
179
  m_txA->SetMobility (posTxA);
171
  m_txB->SetMobility (posTxB);
180
  m_txB->SetMobility (posTxB);
172
  rx->SetMobility (posRx);
181
  rx->SetMobility (posRx);
182
  if (input.captureEnabled)
183
    {
184
      Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel> ();
185
      frameCaptureModel->SetMargin (input.captureMargin);
186
      rx->SetFrameCaptureModel (frameCaptureModel);
187
    }
173
188
174
  m_txA->ConfigureStandard (input.standard);
189
  m_txA->ConfigureStandard (input.standard);
175
  m_txB->ConfigureStandard (input.standard);
190
  m_txB->ConfigureStandard (input.standard);
 Lines 202-209    Link Here 
202
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
217
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
203
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
218
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
204
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
219
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
220
  cmd.AddValue ("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
221
  cmd.AddValue ("captureMargin", "Margin used for physical layer capture", input.captureMargin);
205
  cmd.Parse (argc, argv);
222
  cmd.Parse (argc, argv);
206
223
224
  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
207
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
225
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
208
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
226
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
209
227
(-)8154ca19d840 (+36 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2017
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "frame-capture-model.h"
22
23
namespace ns3 {
24
25
NS_OBJECT_ENSURE_REGISTERED (FrameCaptureModel);
26
27
TypeId FrameCaptureModel::GetTypeId (void)
28
{
29
  static TypeId tid = TypeId ("ns3::FrameCaptureModel")
30
    .SetParent<Object> ()
31
    .SetGroupName ("Wifi")
32
  ;
33
  return tid;
34
}
35
36
} //namespace ns3
(-)8154ca19d840 (+60 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2017
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#ifndef FRAME_CAPTURE_MODEL_H
22
#define FRAME_CAPTURE_MODEL_H
23
24
#include "ns3/object.h"
25
#include "interference-helper.h"
26
27
namespace ns3 {
28
29
/**
30
 * \ingroup wifi
31
 * \brief the interface for Wifi's frame capture models
32
 *
33
 */
34
class FrameCaptureModel : public Object
35
{
36
public:
37
  /**
38
   * \brief Get the type ID.
39
   * \return the object TypeId
40
   */
41
  static TypeId GetTypeId (void);
42
43
  /**
44
   * A pure virtual method that must be implemented in the subclass.
45
   * This method returns whether the reception should be switch to a
46
   * new incoming frame.
47
   *
48
   * \param currentEvent the event of the current frame
49
   * \param newEvent the event of the new incoming frame
50
   *
51
   * \return true if the reception should be switch to a new incoming frame,
52
   *         false otherwise
53
   */
54
  virtual bool CalculateFrameCapture (Ptr<InterferenceHelper::Event> currentEvent, Ptr<InterferenceHelper::Event> newEvent) const = 0;
55
};
56
57
} //namespace ns3
58
59
#endif /* FRAME_CAPTURE_MODEL_H */
60
(-)a/src/wifi/model/interference-helper.cc (-11 / +42 lines)
 Lines 94-102    Link Here 
94
 *       short period of time.
94
 *       short period of time.
95
 ****************************************************************/
95
 ****************************************************************/
96
96
97
InterferenceHelper::NiChange::NiChange (Time time, double delta)
97
InterferenceHelper::NiChange::NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event)
98
  : m_time (time),
98
  : m_time (time),
99
    m_delta (delta)
99
    m_delta (delta),
100
    m_event (event)
100
{
101
{
101
}
102
}
102
103
 Lines 112-117    Link Here 
112
  return m_delta;
113
  return m_delta;
113
}
114
}
114
115
116
Ptr<InterferenceHelper::Event>
117
InterferenceHelper::NiChange::GetEvent (void) const
118
{
119
  return m_event;
120
}
121
115
bool
122
bool
116
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const
123
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const
117
{
124
{
 Lines 221-233    Link Here 
221
          m_firstPower += i->GetDelta ();
228
          m_firstPower += i->GetDelta ();
222
        }
229
        }
223
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
230
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
224
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW ()));
231
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
225
    }
232
    }
226
  else
233
  else
227
    {
234
    {
228
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW ()));
235
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
229
    }
236
    }
230
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW ()));
237
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
231
238
232
}
239
}
233
240
 Lines 251-267    Link Here 
251
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
258
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
252
{
259
{
253
  double noiseInterference = m_firstPower;
260
  double noiseInterference = m_firstPower;
254
  NS_ASSERT (m_rxing);
261
  NiChanges::const_iterator eventIterator = m_niChanges.begin ();
255
  for (NiChanges::const_iterator i = m_niChanges.begin () + 1; i != m_niChanges.end (); i++)
262
  while (eventIterator != m_niChanges.end ())
256
    {
263
    {
257
      if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
264
      // Iterate the NI change list from the beginning to the end
265
      // until find the position of the event in the NI change list
266
      // The reason of using the event that causes the NI change to identify
267
      // different NI changes is because in some special cases
268
      // different NI changes happen at the same time with the same delta
269
      // value. Therefore, it may be impossible to identify a NI change that belongs
270
      // to which event based on just the NI time and NI delta value
271
      if (eventIterator->GetEvent () != event)
272
        {
273
          // The NI changes which happen before the event should be considered
274
          // as the interference. This considers the case that the receiving event
275
          // arrives while another receiving event is going on. The SINR of
276
          // the newly arrived event is calculated for checking the possibility of frame capture
277
          noiseInterference += eventIterator->GetDelta ();
278
        }
279
      else
280
        {
281
          break;
282
        }
283
      ++eventIterator;
284
    }
285
286
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
287
    {
288
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
258
        {
289
        {
259
          break;
290
          break;
260
        }
291
        }
261
      ni->push_back (*i);
292
      ni->push_back (*i);
262
    }
293
    }
263
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference));
294
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
264
  ni->push_back (NiChange (event->GetEndTime (), 0));
295
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
265
  return noiseInterference;
296
  return noiseInterference;
266
}
297
}
267
298
 Lines 846-852    Link Here 
846
InterferenceHelper::NiChanges::iterator
877
InterferenceHelper::NiChanges::iterator
847
InterferenceHelper::GetPosition (Time moment)
878
InterferenceHelper::GetPosition (Time moment)
848
{
879
{
849
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0));
880
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
850
}
881
}
851
882
852
void
883
void
(-)a/src/wifi/model/interference-helper.h (-1 / +10 lines)
 Lines 220-227    Link Here 
220
     *
220
     *
221
     * \param time time of the event
221
     * \param time time of the event
222
     * \param delta the power
222
     * \param delta the power
223
     * \param event causes this NI change
223
     */
224
     */
224
    NiChange (Time time, double delta);
225
    NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event);
225
    /**
226
    /**
226
     * Return the event time.
227
     * Return the event time.
227
     *
228
     *
 Lines 235-240    Link Here 
235
     */
236
     */
236
    double GetDelta (void) const;
237
    double GetDelta (void) const;
237
    /**
238
    /**
239
     * Return the event causes the corresponding NI change
240
     *
241
     * \return the event
242
     */
243
    Ptr<InterferenceHelper::Event> GetEvent (void) const;
244
    /**
238
     * Compare the event time of two NiChange objects (a < o).
245
     * Compare the event time of two NiChange objects (a < o).
239
     *
246
     *
240
     * \param o
247
     * \param o
 Lines 246-251    Link Here 
246
private:
253
private:
247
    Time m_time; ///< time
254
    Time m_time; ///< time
248
    double m_delta; ///< delta
255
    double m_delta; ///< delta
256
    Ptr<InterferenceHelper::Event> m_event;
249
  };
257
  };
250
  /**
258
  /**
251
   * typedef for a vector of NiChanges
259
   * typedef for a vector of NiChanges
 Lines 322-327    Link Here 
322
  NiChanges m_niChanges;
330
  NiChanges m_niChanges;
323
  double m_firstPower; ///< first power
331
  double m_firstPower; ///< first power
324
  bool m_rxing; ///< flag whether it is in receiving state
332
  bool m_rxing; ///< flag whether it is in receiving state
333
325
  /// Returns an iterator to the first nichange, which is later than moment
334
  /// Returns an iterator to the first nichange, which is later than moment
326
  NiChanges::iterator GetPosition (Time moment);
335
  NiChanges::iterator GetPosition (Time moment);
327
  /**
336
  /**
(-)8154ca19d840 (+87 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2017
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "simple-frame-capture-model.h"
22
#include "ns3/simulator.h"
23
#include "ns3/log.h"
24
#include "ns3/double.h"
25
#include "wifi-utils.h"
26
#include "wifi-phy.h"
27
28
namespace ns3 {
29
30
NS_LOG_COMPONENT_DEFINE ("SimpleFrameCaptureModel");
31
32
NS_OBJECT_ENSURE_REGISTERED (SimpleFrameCaptureModel);
33
34
TypeId
35
SimpleFrameCaptureModel::GetTypeId (void)
36
{
37
  static TypeId tid = TypeId ("ns3::SimpleFrameCaptureModel")
38
    .SetParent<FrameCaptureModel> ()
39
    .SetGroupName ("Wifi")
40
    .AddConstructor<SimpleFrameCaptureModel> ()
41
    .AddAttribute ("Margin",
42
                   "Reception is switched if the newly arrived frame has a power higher than "
43
                   "this value above the frame currently being received (expressed in dB).",
44
                   DoubleValue (10),
45
                   MakeDoubleAccessor (&SimpleFrameCaptureModel::GetMargin,
46
                                       &SimpleFrameCaptureModel::SetMargin),
47
                   MakeDoubleChecker<double> ())
48
  ;
49
  return tid;
50
}
51
52
SimpleFrameCaptureModel::SimpleFrameCaptureModel ()
53
{
54
  NS_LOG_FUNCTION (this);
55
}
56
57
SimpleFrameCaptureModel::~SimpleFrameCaptureModel ()
58
{
59
  NS_LOG_FUNCTION (this);
60
}
61
62
void
63
SimpleFrameCaptureModel::SetMargin (double margin)
64
{
65
  NS_LOG_FUNCTION (this << margin);
66
  m_margin = margin;
67
}
68
69
double
70
SimpleFrameCaptureModel::GetMargin (void) const
71
{
72
  return m_margin;
73
}
74
75
bool
76
SimpleFrameCaptureModel::CalculateFrameCapture (Ptr<InterferenceHelper::Event> currentEvent, Ptr<InterferenceHelper::Event> newEvent) const
77
{
78
  if (newEvent->GetTxVector ().GetPreambleType () != WIFI_PREAMBLE_NONE
79
      && (WToDbm (currentEvent->GetRxPowerW ()) + m_margin) < WToDbm (newEvent->GetRxPowerW ())
80
      && ((currentEvent->GetStartTime () + WifiPhy::GetPlcpPreambleDuration (currentEvent->GetTxVector ())) < Simulator::Now ()))
81
    {
82
      return true;
83
    }
84
  return false;
85
}
86
87
} //namespace ns3
(-)8154ca19d840 (+77 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2017
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#ifndef SIMPLE_FRAME_CAPTURE_MODEL_H
22
#define SIMPLE_FRAME_CAPTURE_MODEL_H
23
24
#include "frame-capture-model.h"
25
26
namespace ns3 {
27
/**
28
 * \ingroup wifi
29
 *
30
 * A simple model for frame capture effect.
31
 */
32
class SimpleFrameCaptureModel : public FrameCaptureModel
33
{
34
public:
35
  /**
36
   * \brief Get the type ID.
37
   * \return the object TypeId
38
   */
39
  static TypeId GetTypeId (void);
40
41
  SimpleFrameCaptureModel ();
42
  ~SimpleFrameCaptureModel ();
43
44
  /**
45
   * Sets the frame capture margin (dB).
46
   *
47
   * \param margin the frame capture margin in dB
48
   */
49
  void SetMargin (double margin);
50
  /**
51
   * Return the frame capture margin (dB).
52
   *
53
   * \return the frame capture margin in dB
54
   */
55
  double GetMargin (void) const;
56
57
  /**
58
   * This method returns whether the reception should be switch to a
59
   * new incoming frame.
60
   *
61
   * \param currentEvent the event of the current frame
62
   * \param newEvent the event of the new incoming frame
63
   *
64
   * \return true if the reception should be switch to a new incoming frame,
65
   *         false otherwise
66
   */
67
  bool CalculateFrameCapture (Ptr<InterferenceHelper::Event> currentEvent, Ptr<InterferenceHelper::Event> newEvent) const;
68
69
70
private:
71
  double m_margin;
72
};
73
74
} //namespace ns3
75
76
#endif /* SIMPLE_FRAME_CAPTURE_MODEL_H */
77
(-)a/src/wifi/model/wifi-phy-state-helper.cc (+29 lines)
 Lines 221-226    Link Here 
221
void
221
void
222
WifiPhyStateHelper::NotifyTxStart (Time duration, double txPowerDbm)
222
WifiPhyStateHelper::NotifyTxStart (Time duration, double txPowerDbm)
223
{
223
{
224
  NS_LOG_FUNCTION (this);
224
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
225
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
225
    {
226
    {
226
      (*i)->NotifyTxStart (duration, txPowerDbm);
227
      (*i)->NotifyTxStart (duration, txPowerDbm);
 Lines 230-235    Link Here 
230
void
231
void
231
WifiPhyStateHelper::NotifyRxStart (Time duration)
232
WifiPhyStateHelper::NotifyRxStart (Time duration)
232
{
233
{
234
  NS_LOG_FUNCTION (this);
233
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
235
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
234
    {
236
    {
235
      (*i)->NotifyRxStart (duration);
237
      (*i)->NotifyRxStart (duration);
 Lines 239-244    Link Here 
239
void
241
void
240
WifiPhyStateHelper::NotifyRxEndOk (void)
242
WifiPhyStateHelper::NotifyRxEndOk (void)
241
{
243
{
244
  NS_LOG_FUNCTION (this);
242
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
245
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
243
    {
246
    {
244
      (*i)->NotifyRxEndOk ();
247
      (*i)->NotifyRxEndOk ();
 Lines 248-253    Link Here 
248
void
251
void
249
WifiPhyStateHelper::NotifyRxEndError (void)
252
WifiPhyStateHelper::NotifyRxEndError (void)
250
{
253
{
254
  NS_LOG_FUNCTION (this);
251
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
255
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
252
    {
256
    {
253
      (*i)->NotifyRxEndError ();
257
      (*i)->NotifyRxEndError ();
 Lines 257-262    Link Here 
257
void
261
void
258
WifiPhyStateHelper::NotifyMaybeCcaBusyStart (Time duration)
262
WifiPhyStateHelper::NotifyMaybeCcaBusyStart (Time duration)
259
{
263
{
264
  NS_LOG_FUNCTION (this);
260
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
265
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
261
    {
266
    {
262
      (*i)->NotifyMaybeCcaBusyStart (duration);
267
      (*i)->NotifyMaybeCcaBusyStart (duration);
 Lines 266-271    Link Here 
266
void
271
void
267
WifiPhyStateHelper::NotifySwitchingStart (Time duration)
272
WifiPhyStateHelper::NotifySwitchingStart (Time duration)
268
{
273
{
274
  NS_LOG_FUNCTION (this);
269
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
275
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
270
    {
276
    {
271
      (*i)->NotifySwitchingStart (duration);
277
      (*i)->NotifySwitchingStart (duration);
 Lines 275-280    Link Here 
275
void
281
void
276
WifiPhyStateHelper::NotifySleep (void)
282
WifiPhyStateHelper::NotifySleep (void)
277
{
283
{
284
  NS_LOG_FUNCTION (this);
278
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
285
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
279
    {
286
    {
280
      (*i)->NotifySleep ();
287
      (*i)->NotifySleep ();
 Lines 284-289    Link Here 
284
void
291
void
285
WifiPhyStateHelper::NotifyWakeup (void)
292
WifiPhyStateHelper::NotifyWakeup (void)
286
{
293
{
294
  NS_LOG_FUNCTION (this);
287
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
295
  for (Listeners::const_iterator i = m_listeners.begin (); i != m_listeners.end (); i++)
288
    {
296
    {
289
      (*i)->NotifyWakeup ();
297
      (*i)->NotifyWakeup ();
 Lines 293-298    Link Here 
293
void
301
void
294
WifiPhyStateHelper::LogPreviousIdleAndCcaBusyStates (void)
302
WifiPhyStateHelper::LogPreviousIdleAndCcaBusyStates (void)
295
{
303
{
304
  NS_LOG_FUNCTION (this);
296
  Time now = Simulator::Now ();
305
  Time now = Simulator::Now ();
297
  Time idleStart = Max (m_endCcaBusy, m_endRx);
306
  Time idleStart = Max (m_endCcaBusy, m_endRx);
298
  idleStart = Max (idleStart, m_endTx);
307
  idleStart = Max (idleStart, m_endTx);
 Lines 314-319    Link Here 
314
WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr<const Packet> packet, double txPowerDbm,
323
WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr<const Packet> packet, double txPowerDbm,
315
                                WifiTxVector txVector)
324
                                WifiTxVector txVector)
316
{
325
{
326
  NS_LOG_FUNCTION (this << txDuration << packet << txPowerDbm << txVector);
317
  m_txTrace (packet, txVector.GetMode (), txVector.GetPreambleType (), txVector.GetTxPowerLevel ());
327
  m_txTrace (packet, txVector.GetMode (), txVector.GetPreambleType (), txVector.GetTxPowerLevel ());
318
  Time now = Simulator::Now ();
328
  Time now = Simulator::Now ();
319
  switch (GetState ())
329
  switch (GetState ())
 Lines 352-357    Link Here 
352
void
362
void
353
WifiPhyStateHelper::SwitchToRx (Time rxDuration)
363
WifiPhyStateHelper::SwitchToRx (Time rxDuration)
354
{
364
{
365
  NS_LOG_FUNCTION (this << rxDuration);
355
  NS_ASSERT (IsStateIdle () || IsStateCcaBusy ());
366
  NS_ASSERT (IsStateIdle () || IsStateCcaBusy ());
356
  NS_ASSERT (!m_rxing);
367
  NS_ASSERT (!m_rxing);
357
  Time now = Simulator::Now ();
368
  Time now = Simulator::Now ();
 Lines 385-390    Link Here 
385
void
396
void
386
WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration)
397
WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration)
387
{
398
{
399
  NS_LOG_FUNCTION (this << switchingDuration);
388
  Time now = Simulator::Now ();
400
  Time now = Simulator::Now ();
389
  switch (GetState ())
401
  switch (GetState ())
390
    {
402
    {
 Lines 430-435    Link Here 
430
void
442
void
431
WifiPhyStateHelper::SwitchFromRxEndOk (Ptr<Packet> packet, double snr, WifiTxVector txVector)
443
WifiPhyStateHelper::SwitchFromRxEndOk (Ptr<Packet> packet, double snr, WifiTxVector txVector)
432
{
444
{
445
  NS_LOG_FUNCTION (this << packet << snr << txVector);
433
  m_rxOkTrace (packet, snr, txVector.GetMode (), txVector.GetPreambleType ());
446
  m_rxOkTrace (packet, snr, txVector.GetMode (), txVector.GetPreambleType ());
434
  NotifyRxEndOk ();
447
  NotifyRxEndOk ();
435
  DoSwitchFromRx ();
448
  DoSwitchFromRx ();
 Lines 443-448    Link Here 
443
void
456
void
444
WifiPhyStateHelper::SwitchFromRxEndError (Ptr<Packet> packet, double snr)
457
WifiPhyStateHelper::SwitchFromRxEndError (Ptr<Packet> packet, double snr)
445
{
458
{
459
  NS_LOG_FUNCTION (this << packet << snr);
446
  m_rxErrorTrace (packet, snr);
460
  m_rxErrorTrace (packet, snr);
447
  NotifyRxEndError ();
461
  NotifyRxEndError ();
448
  DoSwitchFromRx ();
462
  DoSwitchFromRx ();
 Lines 455-460    Link Here 
455
void
469
void
456
WifiPhyStateHelper::DoSwitchFromRx (void)
470
WifiPhyStateHelper::DoSwitchFromRx (void)
457
{
471
{
472
  NS_LOG_FUNCTION (this);
458
  NS_ASSERT (IsStateRx ());
473
  NS_ASSERT (IsStateRx ());
459
  NS_ASSERT (m_rxing);
474
  NS_ASSERT (m_rxing);
460
475
 Lines 469-474    Link Here 
469
void
484
void
470
WifiPhyStateHelper::SwitchMaybeToCcaBusy (Time duration)
485
WifiPhyStateHelper::SwitchMaybeToCcaBusy (Time duration)
471
{
486
{
487
  NS_LOG_FUNCTION (this << duration);
472
  NotifyMaybeCcaBusyStart (duration);
488
  NotifyMaybeCcaBusyStart (duration);
473
  Time now = Simulator::Now ();
489
  Time now = Simulator::Now ();
474
  switch (GetState ())
490
  switch (GetState ())
 Lines 497-502    Link Here 
497
void
513
void
498
WifiPhyStateHelper::SwitchToSleep (void)
514
WifiPhyStateHelper::SwitchToSleep (void)
499
{
515
{
516
  NS_LOG_FUNCTION (this);
500
  Time now = Simulator::Now ();
517
  Time now = Simulator::Now ();
501
  switch (GetState ())
518
  switch (GetState ())
502
    {
519
    {
 Lines 527-532    Link Here 
527
void
544
void
528
WifiPhyStateHelper::SwitchFromSleep (Time duration)
545
WifiPhyStateHelper::SwitchFromSleep (Time duration)
529
{
546
{
547
  NS_LOG_FUNCTION (this << duration);
530
  NS_ASSERT (IsStateSleep ());
548
  NS_ASSERT (IsStateSleep ());
531
  Time now = Simulator::Now ();
549
  Time now = Simulator::Now ();
532
  m_stateLogger (m_startSleep, now - m_startSleep, WifiPhy::SLEEP);
550
  m_stateLogger (m_startSleep, now - m_startSleep, WifiPhy::SLEEP);
 Lines 541-544    Link Here 
541
    }
559
    }
542
}
560
}
543
561
562
void
563
WifiPhyStateHelper::SwitchFromRxAbort (void)
564
{
565
  NS_LOG_FUNCTION (this);
566
  NS_ASSERT (IsStateRx ());
567
  NS_ASSERT (m_rxing);
568
  m_endRx = Simulator::Now ();
569
  DoSwitchFromRx ();
570
  NS_ASSERT (!IsStateRx ());
571
}
572
544
} //namespace ns3
573
} //namespace ns3
(-)a/src/wifi/model/wifi-phy-state-helper.h (+4 lines)
 Lines 185-190    Link Here 
185
   * \param duration the duration of CCA busy state
185
   * \param duration the duration of CCA busy state
186
   */
186
   */
187
  void SwitchFromSleep (Time duration);
187
  void SwitchFromSleep (Time duration);
188
  /**
189
   * Abort current reception
190
   */
191
  void SwitchFromRxAbort (void);
188
192
189
  /**
193
  /**
190
   * TracedCallback signature for state changes.
194
   * TracedCallback signature for state changes.
(-)a/src/wifi/model/wifi-phy.cc (-85 / +145 lines)
 Lines 30-35    Link Here 
30
#include "wifi-phy-tag.h"
30
#include "wifi-phy-tag.h"
31
#include "ampdu-tag.h"
31
#include "ampdu-tag.h"
32
#include "wifi-utils.h"
32
#include "wifi-utils.h"
33
#include "frame-capture-model.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
35
36
 Lines 314-319    Link Here 
314
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
315
                   MakeBooleanAccessor (&WifiPhy::GetShortPlcpPreambleSupported,
315
                                        &WifiPhy::SetShortPlcpPreambleSupported),
316
                                        &WifiPhy::SetShortPlcpPreambleSupported),
316
                   MakeBooleanChecker ())
317
                   MakeBooleanChecker ())
318
    .AddAttribute ("FrameCaptureModel",
319
                   "Ptr to an object that implements the frame capture model",
320
                   PointerValue (0), //StringValue ("ns3::SimpleFrameCaptureModel"),
321
                   MakePointerAccessor (&WifiPhy::GetFrameCaptureModel,
322
                                        &WifiPhy::SetFrameCaptureModel),
323
                   MakePointerChecker <FrameCaptureModel>())
317
    .AddTraceSource ("PhyTxBegin",
324
    .AddTraceSource ("PhyTxBegin",
318
                     "Trace source indicating a packet "
325
                     "Trace source indicating a packet "
319
                     "has begun transmitting over the channel medium",
326
                     "has begun transmitting over the channel medium",
 Lines 378-384    Link Here 
378
    m_channelNumber (0),
385
    m_channelNumber (0),
379
    m_initialChannelNumber (0),
386
    m_initialChannelNumber (0),
380
    m_totalAmpduSize (0),
387
    m_totalAmpduSize (0),
381
    m_totalAmpduNumSymbols (0)
388
    m_totalAmpduNumSymbols (0),
389
    m_currentEvent (0)
382
{
390
{
383
  NS_LOG_FUNCTION (this);
391
  NS_LOG_FUNCTION (this);
384
  NS_UNUSED (m_numberOfTransmitters);
392
  NS_UNUSED (m_numberOfTransmitters);
 Lines 702-707    Link Here 
702
  return m_interference.GetErrorRateModel ();
710
  return m_interference.GetErrorRateModel ();
703
}
711
}
704
712
713
void
714
WifiPhy::SetFrameCaptureModel (Ptr<FrameCaptureModel> model)
715
{
716
  m_frameCaptureModel = model;
717
}
718
719
Ptr<FrameCaptureModel>
720
WifiPhy::GetFrameCaptureModel (void) const
721
{
722
  return m_frameCaptureModel;
723
}
724
705
double
725
double
706
WifiPhy::GetPowerDbm (uint8_t power) const
726
WifiPhy::GetPowerDbm (uint8_t power) const
707
{
727
{
 Lines 2356-2362    Link Here 
2356
  //This function should be later split to check separately whether plcp preamble and plcp header can be successfully received.
2376
  //This function should be later split to check separately whether plcp preamble and plcp header can be successfully received.
2357
  //Note: plcp preamble reception is not yet modeled.
2377
  //Note: plcp preamble reception is not yet modeled.
2358
  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2378
  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2359
  AmpduTag ampduTag;
2360
  Time endRx = Simulator::Now () + rxDuration;
2379
  Time endRx = Simulator::Now () + rxDuration;
2361
2380
2362
  WifiPhyTag tag;
2381
  WifiPhyTag tag;
 Lines 2380-2395    Link Here 
2380
      NS_FATAL_ERROR ("Reception ends in failure because of an unsupported number of spatial streams");
2399
      NS_FATAL_ERROR ("Reception ends in failure because of an unsupported number of spatial streams");
2381
    }
2400
    }
2382
2401
2383
  WifiPreamble preamble = txVector.GetPreambleType ();
2384
  MpduType mpdutype = tag.GetMpduType ();
2385
  Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
2386
2387
  Ptr<InterferenceHelper::Event> event;
2402
  Ptr<InterferenceHelper::Event> event;
2388
  event = m_interference.Add (packet->GetSize (),
2403
  event = m_interference.Add (packet->GetSize (),
2389
                              txVector,
2404
                              txVector,
2390
                              rxDuration,
2405
                              rxDuration,
2391
                              rxPowerW);
2406
                              rxPowerW);
2392
2407
2408
  MpduType mpdutype = tag.GetMpduType ();
2393
  switch (m_state->GetState ())
2409
  switch (m_state->GetState ())
2394
    {
2410
    {
2395
    case WifiPhy::SWITCHING:
2411
    case WifiPhy::SWITCHING:
 Lines 2408-2425    Link Here 
2408
        {
2424
        {
2409
          //that packet will be noise _after_ the completion of the
2425
          //that packet will be noise _after_ the completion of the
2410
          //channel switching.
2426
          //channel switching.
2411
          goto maybeCcaBusy;
2427
          MaybeCcaBusyDuration ();
2428
          return;
2412
        }
2429
        }
2413
      break;
2430
      break;
2414
    case WifiPhy::RX:
2431
    case WifiPhy::RX:
2415
      NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2432
      NS_ASSERT (m_currentEvent != 0);
2416
                    rxPowerW << "W)");
2433
      if (m_frameCaptureModel != 0 &&
2417
      NotifyRxDrop (packet);
2434
          m_frameCaptureModel->CalculateFrameCapture(m_currentEvent, event))
2418
      if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2419
        {
2435
        {
2420
          //that packet will be noise _after_ the reception of the
2436
          AbortCurrentReception ();
2421
          //currently-received packet.
2437
          NS_LOG_DEBUG ("Switch to new packet");
2422
          goto maybeCcaBusy;
2438
          StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2439
        }
2440
      else
2441
        {
2442
          NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2443
                        rxPowerW << "W)");
2444
          NotifyRxDrop (packet);
2445
          if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2446
            {
2447
              //that packet will be noise _after_ the reception of the
2448
              //currently-received packet.
2449
              MaybeCcaBusyDuration ();
2450
              return;
2451
            }
2423
        }
2452
        }
2424
      break;
2453
      break;
2425
    case WifiPhy::TX:
2454
    case WifiPhy::TX:
 Lines 2430-2506    Link Here 
2430
        {
2459
        {
2431
          //that packet will be noise _after_ the transmission of the
2460
          //that packet will be noise _after_ the transmission of the
2432
          //currently-transmitted packet.
2461
          //currently-transmitted packet.
2433
          goto maybeCcaBusy;
2462
          MaybeCcaBusyDuration ();
2463
          return;
2434
        }
2464
        }
2435
      break;
2465
      break;
2436
    case WifiPhy::CCA_BUSY:
2466
    case WifiPhy::CCA_BUSY:
2437
    case WifiPhy::IDLE:
2467
    case WifiPhy::IDLE:
2438
      if (rxPowerW > GetEdThresholdW ()) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
2468
      StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2439
        {
2440
          if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
2441
            {
2442
              m_plcpSuccess = false;
2443
              m_mpdusNum = 0;
2444
              NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
2445
              NotifyRxDrop (packet);
2446
              goto maybeCcaBusy;
2447
            }
2448
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
2449
            {
2450
              //received the first MPDU in an MPDU
2451
              m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
2452
              m_rxMpduReferenceNumber++;
2453
            }
2454
          else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
2455
            {
2456
              //received the other MPDUs that are part of the A-MPDU
2457
              if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
2458
                {
2459
                  NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
2460
                  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
2461
                }
2462
              else
2463
                {
2464
                  m_mpdusNum--;
2465
                }
2466
            }
2467
          else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
2468
            {
2469
              NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
2470
              m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
2471
            }
2472
          else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
2473
            {
2474
              NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
2475
              m_mpdusNum = 0;
2476
            }
2477
2478
          NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
2479
          //sync to signal
2480
          m_state->SwitchToRx (rxDuration);
2481
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2482
          NotifyRxBegin (packet);
2483
          m_interference.NotifyRxStart ();
2484
2485
          if (preamble != WIFI_PREAMBLE_NONE)
2486
            {
2487
              NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
2488
              m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
2489
                                                      packet, txVector, mpdutype, event);
2490
            }
2491
2492
          NS_ASSERT (m_endRxEvent.IsExpired ());
2493
          m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
2494
                                              packet, preamble, mpdutype, event);
2495
        }
2496
      else
2497
        {
2498
          NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
2499
                        rxPowerW << "<" << GetEdThresholdW () << ")");
2500
          NotifyRxDrop (packet);
2501
          m_plcpSuccess = false;
2502
          goto maybeCcaBusy;
2503
        }
2504
      break;
2469
      break;
2505
    case WifiPhy::SLEEP:
2470
    case WifiPhy::SLEEP:
2506
      NS_LOG_DEBUG ("drop packet because in sleep mode");
2471
      NS_LOG_DEBUG ("drop packet because in sleep mode");
 Lines 2508-2517    Link Here 
2508
      m_plcpSuccess = false;
2473
      m_plcpSuccess = false;
2509
      break;
2474
      break;
2510
    }
2475
    }
2511
2476
}
2512
  return;
2477
2513
2478
void
2514
maybeCcaBusy:
2479
WifiPhy::MaybeCcaBusyDuration ()
2480
{
2515
  //We are here because we have received the first bit of a packet and we are
2481
  //We are here because we have received the first bit of a packet and we are
2516
  //not going to be able to synchronize on it
2482
  //not going to be able to synchronize on it
2517
  //In this model, CCA becomes busy when the aggregation of all signals as
2483
  //In this model, CCA becomes busy when the aggregation of all signals as
 Lines 2572-2577    Link Here 
2572
  InterferenceHelper::SnrPer snrPer;
2538
  InterferenceHelper::SnrPer snrPer;
2573
  snrPer = m_interference.CalculatePlcpPayloadSnrPer (event);
2539
  snrPer = m_interference.CalculatePlcpPayloadSnrPer (event);
2574
  m_interference.NotifyRxEnd ();
2540
  m_interference.NotifyRxEnd ();
2541
  m_currentEvent = 0;
2575
2542
2576
  if (m_plcpSuccess == true)
2543
  if (m_plcpSuccess == true)
2577
    {
2544
    {
 Lines 3662-3667    Link Here 
3662
    }
3629
    }
3663
}
3630
}
3664
3631
3632
void
3633
WifiPhy::AbortCurrentReception ()
3634
{
3635
  NS_LOG_FUNCTION (this);
3636
  if (m_endPlcpRxEvent.IsRunning ())
3637
    {
3638
      m_endPlcpRxEvent.Cancel ();
3639
    }
3640
  if (m_endRxEvent.IsRunning ())
3641
    {
3642
      m_endRxEvent.Cancel ();
3643
    }
3644
  m_interference.NotifyRxEnd ();
3645
  m_state->SwitchFromRxAbort ();
3646
  m_currentEvent = 0;
3647
}
3648
3649
void
3650
WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<InterferenceHelper::Event> event)
3651
{
3652
  NS_LOG_FUNCTION (this << packet << txVector << (uint16_t)mpdutype << rxPowerW << rxDuration);
3653
  if (rxPowerW > GetEdThresholdW ()) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
3654
    {
3655
      AmpduTag ampduTag;
3656
      WifiPreamble preamble = txVector.GetPreambleType ();
3657
      if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3658
        {
3659
          m_plcpSuccess = false;
3660
          m_mpdusNum = 0;
3661
          NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3662
          NotifyRxDrop (packet);
3663
          MaybeCcaBusyDuration ();
3664
          return;
3665
        }
3666
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3667
        {
3668
          //received the first MPDU in an MPDU
3669
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3670
          m_rxMpduReferenceNumber++;
3671
        }
3672
      else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3673
        {
3674
          //received the other MPDUs that are part of the A-MPDU
3675
          if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3676
            {
3677
              NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3678
              m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3679
            }
3680
          else
3681
            {
3682
              m_mpdusNum--;
3683
            }
3684
        }
3685
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3686
        {
3687
          NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3688
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3689
        }
3690
      else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3691
        {
3692
          NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3693
          m_mpdusNum = 0;
3694
        }
3695
3696
      NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3697
      m_currentEvent = event;
3698
      m_state->SwitchToRx (rxDuration);
3699
      NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3700
      NotifyRxBegin (packet);
3701
      m_interference.NotifyRxStart ();
3702
    
3703
      if (preamble != WIFI_PREAMBLE_NONE)
3704
        {
3705
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3706
          Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3707
          m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3708
                                                  packet, txVector, mpdutype, event);
3709
        }
3710
3711
      NS_ASSERT (m_endRxEvent.IsExpired ());
3712
      m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3713
                                          packet, preamble, mpdutype, event);
3714
    }
3715
  else
3716
    {
3717
      NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
3718
                    rxPowerW << "<" << GetEdThresholdW () << ")");
3719
      NotifyRxDrop (packet);
3720
      m_plcpSuccess = false;
3721
      MaybeCcaBusyDuration ();
3722
    }
3723
}
3724
3665
int64_t
3725
int64_t
3666
WifiPhy::AssignStreams (int64_t stream)
3726
WifiPhy::AssignStreams (int64_t stream)
3667
{
3727
{
(-)a/src/wifi/model/wifi-phy.h (+51 lines)
 Lines 32-37    Link Here 
32
#include "wifi-phy-standard.h"
32
#include "wifi-phy-standard.h"
33
#include "interference-helper.h"
33
#include "interference-helper.h"
34
#include "ns3/node.h"
34
#include "ns3/node.h"
35
#include "ns3/string.h"
35
36
36
namespace ns3 {
37
namespace ns3 {
37
38
 Lines 45-50    Link Here 
45
class WifiPhyStateHelper;
46
class WifiPhyStateHelper;
46
47
47
/**
48
/**
49
 * FrameCaptureModel class
50
 */
51
class FrameCaptureModel;
52
53
/**
48
 * This enumeration defines the type of an MPDU.
54
 * This enumeration defines the type of an MPDU.
49
 */
55
 */
50
/// MpduType enumeration
56
/// MpduType enumeration
 Lines 1445-1450    Link Here 
1445
   * \return the reception gain in dB
1451
   * \return the reception gain in dB
1446
   */
1452
   */
1447
  double GetRxGain (void) const;
1453
  double GetRxGain (void) const;
1454
1448
  /**
1455
  /**
1449
   * Sets the device this PHY is associated with.
1456
   * Sets the device this PHY is associated with.
1450
   *
1457
   *
 Lines 1603-1608    Link Here 
1603
  Ptr<ErrorRateModel> GetErrorRateModel (void) const;
1610
  Ptr<ErrorRateModel> GetErrorRateModel (void) const;
1604
1611
1605
  /**
1612
  /**
1613
   * Sets the frame capture model.
1614
   *
1615
   * \param rate the frame capture model
1616
   */
1617
  void SetFrameCaptureModel (Ptr<FrameCaptureModel> rate);
1618
  /**
1619
   * Return the frame capture model this PHY is using.
1620
   *
1621
   * \return the frame capture model this PHY is using
1622
   */
1623
  Ptr<FrameCaptureModel> GetFrameCaptureModel (void) const;
1624
1625
  /**
1606
   * \return the channel width
1626
   * \return the channel width
1607
   */
1627
   */
1608
  uint8_t GetChannelWidth (void) const;
1628
  uint8_t GetChannelWidth (void) const;
 Lines 1771-1776    Link Here 
1771
   * \return the FrequencyWidthPair found
1791
   * \return the FrequencyWidthPair found
1772
   */
1792
   */
1773
  FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard (uint8_t channelNumber, WifiPhyStandard standard) const;
1793
  FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard (uint8_t channelNumber, WifiPhyStandard standard) const;
1794
  
1795
  /**
1796
   * Due to newly arrived signal, the current reception cannot be continued and has to be aborted
1797
   *
1798
   */
1799
  void AbortCurrentReception (void);
1800
1801
  /**
1802
   * Eventually switch to CCA busy
1803
   */
1804
  void MaybeCcaBusyDuration (void);
1805
  
1806
  /**
1807
   * Starting receiving the packet after having detected the medium is idle or after a reception switch.
1808
   *
1809
   * \param packet the arriving packet
1810
   * \param txVector the TXVECTOR of the arriving packet
1811
   * \param mpdutype the type of the MPDU as defined in WifiPhy::MpduType.
1812
   * \param rxPowerW the receive power in W
1813
   * \param rxDuration the duration needed for the reception of the packet
1814
   * \param event the corresponding event of the first time the packet arrives
1815
   */
1816
  void StartRx (Ptr<Packet> packet,
1817
                WifiTxVector txVector,
1818
                MpduType mpdutype,
1819
                double rxPowerW,
1820
                Time rxDuration,
1821
                Ptr<InterferenceHelper::Event> event);
1774
1822
1775
  /**
1823
  /**
1776
   * The trace source fired when a packet begins the transmission process on
1824
   * The trace source fired when a packet begins the transmission process on
 Lines 1931-1936    Link Here 
1931
1979
1932
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1980
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1933
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1981
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1982
1983
  Ptr<InterferenceHelper::Event> m_currentEvent; //!< Hold the current event
1984
  Ptr<FrameCaptureModel> m_frameCaptureModel; //!< Frame capture model
1934
};
1985
};
1935
1986
1936
/**
1987
/**
(-)a/src/wifi/wscript (+4 lines)
 Lines 83-88    Link Here 
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/he-capabilities.cc',
85
        'model/he-capabilities.cc',
86
        'model/frame-capture-model.cc',
87
        'model/simple-frame-capture-model.cc',
86
        'helper/wifi-radio-energy-model-helper.cc',
88
        'helper/wifi-radio-energy-model-helper.cc',
87
        'helper/vht-wifi-mac-helper.cc',
89
        'helper/vht-wifi-mac-helper.cc',
88
        'helper/ht-wifi-mac-helper.cc',
90
        'helper/ht-wifi-mac-helper.cc',
 Lines 190-195    Link Here 
190
        'model/dsss-parameter-set.h',
192
        'model/dsss-parameter-set.h',
191
        'model/edca-parameter-set.h',
193
        'model/edca-parameter-set.h',
192
        'model/he-capabilities.h',
194
        'model/he-capabilities.h',
195
        'model/frame-capture-model.h',
196
        'model/simple-frame-capture-model.h',
193
        'helper/wifi-radio-energy-model-helper.h',
197
        'helper/wifi-radio-energy-model-helper.h',
194
        'helper/vht-wifi-mac-helper.h',
198
        'helper/vht-wifi-mac-helper.h',
195
        'helper/ht-wifi-mac-helper.h',
199
        'helper/ht-wifi-mac-helper.h',

Return to bug 2368