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

(-)a/src/wifi/examples/test-interference-helper.cc (-6 / +67 lines)
 Lines 55-63    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"
59
#include "ns3/log.h"
58
60
59
using namespace ns3;
61
using namespace ns3;
60
62
63
NS_LOG_COMPONENT_DEFINE ("test-interference-helper");
64
65
bool checkResults = false;
66
bool expectRxASuccessfull = false;
67
bool expectRxBSuccessfull = false;
68
61
/// InterferenceExperiment
69
/// InterferenceExperiment
62
class InterferenceExperiment
70
class InterferenceExperiment
63
{
71
{
 Lines 71-82    Link Here 
71
    double xB; ///< x B
79
    double xB; ///< x B
72
    std::string txModeA; ///< transmit mode A
80
    std::string txModeA; ///< transmit mode A
73
    std::string txModeB; ///< transmit mode B
81
    std::string txModeB; ///< transmit mode B
74
    uint32_t txPowerLevelA; ///< transmit power level A
82
    double txPowerLevelA; ///< transmit power level A
75
    uint32_t txPowerLevelB; ///< transmit power level B
83
    double txPowerLevelB; ///< transmit power level B
76
    uint32_t packetSizeA; ///< packet size A
84
    uint32_t packetSizeA; ///< packet size A
77
    uint32_t packetSizeB; ///< packet size B
85
    uint32_t packetSizeB; ///< packet size B
78
    WifiPhyStandard standard; ///< standard
86
    WifiPhyStandard standard; ///< standard
79
    WifiPreamble preamble; ///< preamble
87
    WifiPreamble preamble; ///< preamble
88
    bool captureEnabled; ///< whether physical layer capture is enabled
89
    double captureMargin; ///< margin used for physical layer capture
80
  };
90
  };
81
91
82
  InterferenceExperiment ();
92
  InterferenceExperiment ();
 Lines 87-92    Link Here 
87
  void Run (struct InterferenceExperiment::Input input);
97
  void Run (struct InterferenceExperiment::Input input);
88
98
89
private:
99
private:
100
  /// Function triggered when a packet is dropped
101
  void PacketDropped(Ptr<const Packet> packet);
90
  /// Send A function
102
  /// Send A function
91
  void SendA (void) const;
103
  void SendA (void) const;
92
  /// Send B function
104
  /// Send B function
 Lines 94-99    Link Here 
94
  Ptr<YansWifiPhy> m_txA; ///< transmit A function
106
  Ptr<YansWifiPhy> m_txA; ///< transmit A function
95
  Ptr<YansWifiPhy> m_txB; ///< transmit B function
107
  Ptr<YansWifiPhy> m_txB; ///< transmit B function
96
  struct Input m_input; ///< input
108
  struct Input m_input; ///< input
109
  bool m_droppedA; ///< flag to indicate whether packet A has been dropped
110
  bool m_droppedB; ///< flag to indicate whether packet B has been dropped
97
};
111
};
98
112
99
void
113
void
 Lines 118-138    Link Here 
118
  m_txB->SendPacket (p, txVector);
132
  m_txB->SendPacket (p, txVector);
119
}
133
}
120
134
135
void
136
InterferenceExperiment::PacketDropped(Ptr<const Packet> packet)
137
{
138
    if (packet->GetUid () == 0)
139
    {
140
      m_droppedA = true;
141
    }
142
    else if (packet->GetUid () == 1)
143
    {
144
      m_droppedB = true;
145
    }
146
    else
147
    {
148
      NS_LOG_ERROR ("Unknown packet!");
149
      exit (1);
150
    }
151
}
152
121
InterferenceExperiment::InterferenceExperiment ()
153
InterferenceExperiment::InterferenceExperiment ()
154
  : m_droppedA (false),
155
    m_droppedB (false)
122
{
156
{
123
}
157
}
158
124
InterferenceExperiment::Input::Input ()
159
InterferenceExperiment::Input::Input ()
125
  : interval (MicroSeconds (0)),
160
  : interval (MicroSeconds (0)),
126
    xA (-5),
161
    xA (-5),
127
    xB (5),
162
    xB (5),
128
    txModeA ("OfdmRate54Mbps"),
163
    txModeA ("OfdmRate54Mbps"),
129
    txModeB ("OfdmRate54Mbps"),
164
    txModeB ("OfdmRate54Mbps"),
130
    txPowerLevelA (0),
165
    txPowerLevelA (16.0206),
131
    txPowerLevelB (0),
166
    txPowerLevelB (16.0206),
132
    packetSizeA (1500),
167
    packetSizeA (1500),
133
    packetSizeB (1500),
168
    packetSizeB (1500),
134
    standard (WIFI_PHY_STANDARD_80211a),
169
    standard (WIFI_PHY_STANDARD_80211a),
135
    preamble (WIFI_PREAMBLE_LONG)
170
    preamble (WIFI_PREAMBLE_LONG),
171
    captureEnabled (false),
172
    captureMargin (0)
136
{
173
{
137
}
174
}
138
175
 Lines 157-163    Link Here 
157
  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
194
  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
158
195
159
  m_txA = CreateObject<YansWifiPhy> ();
196
  m_txA = CreateObject<YansWifiPhy> ();
197
  m_txA->SetTxPowerStart (input.txPowerLevelA);
198
  m_txA->SetTxPowerEnd (input.txPowerLevelA);
160
  m_txB = CreateObject<YansWifiPhy> ();
199
  m_txB = CreateObject<YansWifiPhy> ();
200
  m_txB->SetTxPowerStart (input.txPowerLevelB);
201
  m_txB->SetTxPowerEnd (input.txPowerLevelB);
161
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
202
  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
162
203
163
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
204
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
 Lines 170-188    Link Here 
170
  m_txA->SetMobility (posTxA);
211
  m_txA->SetMobility (posTxA);
171
  m_txB->SetMobility (posTxB);
212
  m_txB->SetMobility (posTxB);
172
  rx->SetMobility (posRx);
213
  rx->SetMobility (posRx);
214
  if (input.captureEnabled)
215
    {
216
      Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel> ();
217
      frameCaptureModel->SetMargin (input.captureMargin);
218
      rx->SetFrameCaptureModel (frameCaptureModel);
219
    }
173
220
174
  m_txA->ConfigureStandard (input.standard);
221
  m_txA->ConfigureStandard (input.standard);
175
  m_txB->ConfigureStandard (input.standard);
222
  m_txB->ConfigureStandard (input.standard);
176
  rx->ConfigureStandard (input.standard);
223
  rx->ConfigureStandard (input.standard);
177
224
225
  rx->TraceConnectWithoutContext("PhyRxDrop", MakeCallback(&InterferenceExperiment::PacketDropped, this));
226
178
  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
227
  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
179
  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
228
  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
180
229
181
  Simulator::Run ();
230
  Simulator::Run ();
182
  Simulator::Destroy ();
231
  Simulator::Destroy ();
232
233
  if(checkResults && (m_droppedA == expectRxASuccessfull || m_droppedB == expectRxBSuccessfull))
234
  {
235
    NS_LOG_ERROR ("Results are not expected!");
236
    exit (1);
237
  }
183
}
238
}
184
239
185
186
int main (int argc, char *argv[])
240
int main (int argc, char *argv[])
187
{
241
{
188
  InterferenceExperiment::Input input;
242
  InterferenceExperiment::Input input;
 Lines 202-211    Link Here 
202
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
256
  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
203
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
257
  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
204
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
258
  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
259
  cmd.AddValue ("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
260
  cmd.AddValue ("captureMargin", "Margin used for physical layer capture", input.captureMargin);
261
  cmd.AddValue ("checkResults", "Used to check results at the end of the test", checkResults);
262
  cmd.AddValue ("expectRxASuccessfull", "Indicate whether packet A is expected to be successfully received", expectRxASuccessfull);
263
  cmd.AddValue ("expectRxBSuccessfull", "Indicate whether packet B is expected to be successfully received", expectRxBSuccessfull);
205
  cmd.Parse (argc, argv);
264
  cmd.Parse (argc, argv);
206
265
266
  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
207
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
267
  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
208
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
268
  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
269
  LogComponentEnable ("SimpleFrameCaptureModel", LOG_LEVEL_ALL);
209
270
210
  input.interval = MicroSeconds (delay);
271
  input.interval = MicroSeconds (delay);
211
272
(-)29043eb051f5 (+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
(-)29043eb051f5 (+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 switched 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 switched to a new incoming frame,
52
   *         false otherwise
53
   */
54
  virtual bool CaptureNewFrame (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 (-17 / +56 lines)
 Lines 33-45    Link Here 
33
 *       Phy event class
33
 *       Phy event class
34
 ****************************************************************/
34
 ****************************************************************/
35
35
36
InterferenceHelper::Event::Event (uint32_t size, WifiTxVector txVector, Time duration, double rxPower)
36
InterferenceHelper::Event::Event (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPower)
37
  : m_size (size),
37
  : //m_packet (packet),
38
    m_txVector (txVector),
38
    m_txVector (txVector),
39
    m_startTime (Simulator::Now ()),
39
    m_startTime (Simulator::Now ()),
40
    m_endTime (m_startTime + duration),
40
    m_endTime (m_startTime + duration),
41
    m_rxPowerW (rxPower)
41
    m_rxPowerW (rxPower)
42
{
42
{
43
  m_packet = packet;
43
}
44
}
44
45
45
InterferenceHelper::Event::~Event ()
46
InterferenceHelper::Event::~Event ()
 Lines 70-79    Link Here 
70
  return m_rxPowerW;
71
  return m_rxPowerW;
71
}
72
}
72
73
74
Ptr<const Packet>
75
InterferenceHelper::Event::GetPacket (void) const
76
{
77
  return m_packet;
78
}
79
73
uint32_t
80
uint32_t
74
InterferenceHelper::Event::GetSize (void) const
81
InterferenceHelper::Event::GetSize (void) const
75
{
82
{
76
  return m_size;
83
  return m_packet->GetSize();
77
}
84
}
78
85
79
WifiTxVector
86
WifiTxVector
 Lines 94-102    Link Here 
94
 *       short period of time.
101
 *       short period of time.
95
 ****************************************************************/
102
 ****************************************************************/
96
103
97
InterferenceHelper::NiChange::NiChange (Time time, double delta)
104
InterferenceHelper::NiChange::NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event)
98
  : m_time (time),
105
  : m_time (time),
99
    m_delta (delta)
106
    m_delta (delta),
107
    m_event (event)
100
{
108
{
101
}
109
}
102
110
 Lines 112-117    Link Here 
112
  return m_delta;
120
  return m_delta;
113
}
121
}
114
122
123
Ptr<InterferenceHelper::Event>
124
InterferenceHelper::NiChange::GetEvent (void) const
125
{
126
  return m_event;
127
}
128
115
bool
129
bool
116
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const
130
InterferenceHelper::NiChange::operator < (const InterferenceHelper::NiChange& o) const
117
{
131
{
 Lines 138-148    Link Here 
138
}
152
}
139
153
140
Ptr<InterferenceHelper::Event>
154
Ptr<InterferenceHelper::Event>
141
InterferenceHelper::Add (uint32_t size, WifiTxVector txVector, Time duration, double rxPowerW)
155
InterferenceHelper::Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPowerW)
142
{
156
{
143
  Ptr<InterferenceHelper::Event> event;
157
  Ptr<InterferenceHelper::Event> event;
144
158
145
  event = Create<InterferenceHelper::Event> (size, txVector, duration, rxPowerW);
159
  event = Create<InterferenceHelper::Event> (packet, txVector, duration, rxPowerW);
146
  AppendEvent (event);
160
  AppendEvent (event);
147
  return event;
161
  return event;
148
}
162
}
 Lines 153-159    Link Here 
153
  // Parameters other than duration and rxPowerW are unused for this type
167
  // Parameters other than duration and rxPowerW are unused for this type
154
  // of signal, so we provide dummy versions
168
  // of signal, so we provide dummy versions
155
  WifiTxVector fakeTxVector;
169
  WifiTxVector fakeTxVector;
156
  Add (0, fakeTxVector, duration, rxPowerW);
170
  Ptr<const Packet> packet (0);
171
  Add (packet, fakeTxVector, duration, rxPowerW);
157
}
172
}
158
173
159
void
174
void
 Lines 221-233    Link Here 
221
          m_firstPower += i->GetDelta ();
236
          m_firstPower += i->GetDelta ();
222
        }
237
        }
223
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
238
      m_niChanges.erase (m_niChanges.begin (), nowIterator);
224
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW ()));
239
      m_niChanges.insert (m_niChanges.begin (), NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
225
    }
240
    }
226
  else
241
  else
227
    {
242
    {
228
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW ()));
243
      AddNiChangeEvent (NiChange (event->GetStartTime (), event->GetRxPowerW (), event));
229
    }
244
    }
230
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW ()));
245
  AddNiChangeEvent (NiChange (event->GetEndTime (), -event->GetRxPowerW (), event));
231
246
232
}
247
}
233
248
 Lines 251-267    Link Here 
251
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
266
InterferenceHelper::CalculateNoiseInterferenceW (Ptr<InterferenceHelper::Event> event, NiChanges *ni) const
252
{
267
{
253
  double noiseInterference = m_firstPower;
268
  double noiseInterference = m_firstPower;
254
  NS_ASSERT (m_rxing);
269
  NiChanges::const_iterator eventIterator = m_niChanges.begin ();
255
  for (NiChanges::const_iterator i = m_niChanges.begin () + 1; i != m_niChanges.end (); i++)
270
  while (eventIterator != m_niChanges.end ())
256
    {
271
    {
257
      if ((event->GetEndTime () == i->GetTime ()) && event->GetRxPowerW () == -i->GetDelta ())
272
      // Iterate the NI change list from the beginning to the end
273
      // until find the position of the event in the NI change list
274
      // The reason of using the event that causes the NI change to identify
275
      // different NI changes is because in some special cases
276
      // different NI changes happen at the same time with the same delta
277
      // value. Therefore, it may be impossible to identify a NI change that belongs
278
      // to which event based on just the NI time and NI delta value
279
      if (eventIterator->GetEvent () != event)
280
        {
281
          // The NI changes which happen before the event should be considered
282
          // as the interference. This considers the case that the receiving event
283
          // arrives while another receiving event is going on. The SINR of
284
          // the newly arrived event is calculated for checking the possibility of frame capture
285
          noiseInterference += eventIterator->GetDelta ();
286
        }
287
      else
288
        {
289
          break;
290
        }
291
      ++eventIterator;
292
    }
293
294
  for (NiChanges::const_iterator i = eventIterator + 1; i != m_niChanges.end (); ++i)
295
    {
296
      if (event->GetEndTime () == i->GetTime () && event == i->GetEvent ())
258
        {
297
        {
259
          break;
298
          break;
260
        }
299
        }
261
      ni->push_back (*i);
300
      ni->push_back (*i);
262
    }
301
    }
263
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference));
302
  ni->insert (ni->begin (), NiChange (event->GetStartTime (), noiseInterference, event));
264
  ni->push_back (NiChange (event->GetEndTime (), 0));
303
  ni->push_back (NiChange (event->GetEndTime (), 0, event));
265
  return noiseInterference;
304
  return noiseInterference;
266
}
305
}
267
306
 Lines 846-852    Link Here 
846
InterferenceHelper::NiChanges::iterator
885
InterferenceHelper::NiChanges::iterator
847
InterferenceHelper::GetPosition (Time moment)
886
InterferenceHelper::GetPosition (Time moment)
848
{
887
{
849
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0));
888
  return std::upper_bound (m_niChanges.begin (), m_niChanges.end (), NiChange (moment, 0, NULL));
850
}
889
}
851
890
852
void
891
void
(-)a/src/wifi/model/interference-helper.h (-6 / +22 lines)
 Lines 22-27    Link Here 
22
#define INTERFERENCE_HELPER_H
22
#define INTERFERENCE_HELPER_H
23
23
24
#include "ns3/nstime.h"
24
#include "ns3/nstime.h"
25
#include "ns3/packet.h"
25
#include "wifi-tx-vector.h"
26
#include "wifi-tx-vector.h"
26
#include "error-rate-model.h"
27
#include "error-rate-model.h"
27
28
 Lines 43-54    Link Here 
43
    /**
44
    /**
44
     * Create an Event with the given parameters.
45
     * Create an Event with the given parameters.
45
     *
46
     *
46
     * \param size packet size
47
     * \param packet the packet
47
     * \param txVector TXVECTOR of the packet
48
     * \param txVector TXVECTOR of the packet
48
     * \param duration duration of the signal
49
     * \param duration duration of the signal
49
     * \param rxPower the receive power (w)
50
     * \param rxPower the receive power (w)
50
     */
51
     */
51
    Event (uint32_t size, WifiTxVector txVector, Time duration, double rxPower);
52
    Event (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPower);
52
    ~Event ();
53
    ~Event ();
53
54
54
    /**
55
    /**
 Lines 76-81    Link Here 
76
     */
77
     */
77
    double GetRxPowerW (void) const;
78
    double GetRxPowerW (void) const;
78
    /**
79
    /**
80
     * Return the packet.
81
     *
82
     * \return the packet
83
     */
84
    Ptr<const Packet> GetPacket (void) const;
85
    /**
79
     * Return the size of the packet (bytes).
86
     * Return the size of the packet (bytes).
80
     *
87
     *
81
     * \return the size of the packet (bytes)
88
     * \return the size of the packet (bytes)
 Lines 96-102    Link Here 
96
103
97
104
98
private:
105
private:
99
    uint32_t m_size; ///< size
106
    Ptr<const Packet> m_packet; ///< packet
100
    WifiTxVector m_txVector; ///< TXVECTOR
107
    WifiTxVector m_txVector; ///< TXVECTOR
101
    Time m_startTime; ///< start time
108
    Time m_startTime; ///< start time
102
    Time m_endTime; ///< end time
109
    Time m_endTime; ///< end time
 Lines 160-173    Link Here 
160
  /**
167
  /**
161
   * Add the packet-related signal to interference helper.
168
   * Add the packet-related signal to interference helper.
162
   *
169
   *
163
   * \param size packet size
170
   * \param packet the packet
164
   * \param txVector TXVECTOR of the packet
171
   * \param txVector TXVECTOR of the packet
165
   * \param duration the duration of the signal
172
   * \param duration the duration of the signal
166
   * \param rxPower receive power (W)
173
   * \param rxPower receive power (W)
167
   *
174
   *
168
   * \return InterferenceHelper::Event
175
   * \return InterferenceHelper::Event
169
   */
176
   */
170
  Ptr<InterferenceHelper::Event> Add (uint32_t size, WifiTxVector txVector, Time duration, double rxPower);
177
  Ptr<InterferenceHelper::Event> Add (Ptr<const Packet> packet, WifiTxVector txVector, Time duration, double rxPower);
171
178
172
  /**
179
  /**
173
   * Add a non-Wifi signal to interference helper.
180
   * Add a non-Wifi signal to interference helper.
 Lines 220-227    Link Here 
220
     *
227
     *
221
     * \param time time of the event
228
     * \param time time of the event
222
     * \param delta the power
229
     * \param delta the power
230
     * \param event causes this NI change
223
     */
231
     */
224
    NiChange (Time time, double delta);
232
    NiChange (Time time, double delta, Ptr<InterferenceHelper::Event> event);
225
    /**
233
    /**
226
     * Return the event time.
234
     * Return the event time.
227
     *
235
     *
 Lines 235-240    Link Here 
235
     */
243
     */
236
    double GetDelta (void) const;
244
    double GetDelta (void) const;
237
    /**
245
    /**
246
     * Return the event causes the corresponding NI change
247
     *
248
     * \return the event
249
     */
250
    Ptr<InterferenceHelper::Event> GetEvent (void) const;
251
    /**
238
     * Compare the event time of two NiChange objects (a < o).
252
     * Compare the event time of two NiChange objects (a < o).
239
     *
253
     *
240
     * \param o
254
     * \param o
 Lines 246-251    Link Here 
246
private:
260
private:
247
    Time m_time; ///< time
261
    Time m_time; ///< time
248
    double m_delta; ///< delta
262
    double m_delta; ///< delta
263
    Ptr<InterferenceHelper::Event> m_event;
249
  };
264
  };
250
  /**
265
  /**
251
   * typedef for a vector of NiChanges
266
   * typedef for a vector of NiChanges
 Lines 322-327    Link Here 
322
  NiChanges m_niChanges;
337
  NiChanges m_niChanges;
323
  double m_firstPower; ///< first power
338
  double m_firstPower; ///< first power
324
  bool m_rxing; ///< flag whether it is in receiving state
339
  bool m_rxing; ///< flag whether it is in receiving state
340
325
  /// Returns an iterator to the first nichange, which is later than moment
341
  /// Returns an iterator to the first nichange, which is later than moment
326
  NiChanges::iterator GetPosition (Time moment);
342
  NiChanges::iterator GetPosition (Time moment);
327
  /**
343
  /**
(-)29043eb051f5 (+88 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::CaptureNewFrame (Ptr<InterferenceHelper::Event> currentEvent, Ptr<InterferenceHelper::Event> newEvent) const
77
{
78
  NS_LOG_FUNCTION (this);
79
  if (newEvent->GetTxVector ().GetPreambleType () != WIFI_PREAMBLE_NONE
80
      && (WToDbm (currentEvent->GetRxPowerW ()) + m_margin) < WToDbm (newEvent->GetRxPowerW ())
81
      && ((currentEvent->GetStartTime () + WifiPhy::GetPlcpPreambleDuration (currentEvent->GetTxVector ())) > Simulator::Now ()))
82
    {
83
      return true;
84
    }
85
  return false;
86
}
87
88
} //namespace ns3
(-)29043eb051f5 (+82 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 threshold-based model for frame capture effect.
31
 * If the new incoming frame arrives while the receiver is
32
 * receiving the preamble of another frame and the SIR of 
33
 * the new incoming frame is above a fixed margin, then 
34
 * the current frame is dropped and the receiver locks 
35
 * onto the new incoming frame.
36
 */
37
class SimpleFrameCaptureModel : public FrameCaptureModel
38
{
39
public:
40
  /**
41
   * \brief Get the type ID.
42
   * \return the object TypeId
43
   */
44
  static TypeId GetTypeId (void);
45
46
  SimpleFrameCaptureModel ();
47
  ~SimpleFrameCaptureModel ();
48
49
  /**
50
   * Sets the frame capture margin (dB).
51
   *
52
   * \param margin the frame capture margin in dB
53
   */
54
  void SetMargin (double margin);
55
  /**
56
   * Return the frame capture margin (dB).
57
   *
58
   * \return the frame capture margin in dB
59
   */
60
  double GetMargin (void) const;
61
62
  /**
63
   * This method returns whether the reception should be switched to a
64
   * new incoming frame.
65
   *
66
   * \param currentEvent the event of the current frame
67
   * \param newEvent the event of the new incoming frame
68
   *
69
   * \return true if the reception should be switched to a new incoming frame,
70
   *         false otherwise
71
   */
72
  bool CaptureNewFrame (Ptr<InterferenceHelper::Event> currentEvent, Ptr<InterferenceHelper::Event> newEvent) const;
73
74
75
private:
76
  double m_margin;
77
};
78
79
} //namespace ns3
80
81
#endif /* SIMPLE_FRAME_CAPTURE_MODEL_H */
82
(-)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 (-86 / +147 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,
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->CaptureNewFrame(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
  NotifyRxDrop (m_currentEvent->GetPacket ());
3645
  m_interference.NotifyRxEnd ();
3646
  m_state->SwitchFromRxAbort ();
3647
  m_currentEvent = 0;
3648
}
3649
3650
void
3651
WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<InterferenceHelper::Event> event)
3652
{
3653
  NS_LOG_FUNCTION (this << packet << txVector << (uint16_t)mpdutype << rxPowerW << rxDuration);
3654
  if (rxPowerW > GetEdThresholdW ()) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
3655
    {
3656
      AmpduTag ampduTag;
3657
      WifiPreamble preamble = txVector.GetPreambleType ();
3658
      if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3659
        {
3660
          m_plcpSuccess = false;
3661
          m_mpdusNum = 0;
3662
          NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3663
          NotifyRxDrop (packet);
3664
          MaybeCcaBusyDuration ();
3665
          return;
3666
        }
3667
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3668
        {
3669
          //received the first MPDU in an MPDU
3670
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3671
          m_rxMpduReferenceNumber++;
3672
        }
3673
      else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3674
        {
3675
          //received the other MPDUs that are part of the A-MPDU
3676
          if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3677
            {
3678
              NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3679
              m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3680
            }
3681
          else
3682
            {
3683
              m_mpdusNum--;
3684
            }
3685
        }
3686
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3687
        {
3688
          NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3689
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3690
        }
3691
      else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3692
        {
3693
          NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3694
          m_mpdusNum = 0;
3695
        }
3696
3697
      NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3698
      m_currentEvent = event;
3699
      m_state->SwitchToRx (rxDuration);
3700
      NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3701
      NotifyRxBegin (packet);
3702
      m_interference.NotifyRxStart ();
3703
    
3704
      if (preamble != WIFI_PREAMBLE_NONE)
3705
        {
3706
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3707
          Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3708
          m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3709
                                                  packet, txVector, mpdutype, event);
3710
        }
3711
3712
      NS_ASSERT (m_endRxEvent.IsExpired ());
3713
      m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3714
                                          packet, preamble, mpdutype, event);
3715
    }
3716
  else
3717
    {
3718
      NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
3719
                    rxPowerW << "<" << GetEdThresholdW () << ")");
3720
      NotifyRxDrop (packet);
3721
      m_plcpSuccess = false;
3722
      MaybeCcaBusyDuration ();
3723
    }
3724
}
3725
3665
int64_t
3726
int64_t
3666
WifiPhy::AssignStreams (int64_t stream)
3727
WifiPhy::AssignStreams (int64_t stream)
3667
{
3728
{
(-)a/src/wifi/model/wifi-phy.h (-1 / +51 lines)
 Lines 25-37    Link Here 
25
#include <map>
25
#include <map>
26
#include "ns3/callback.h"
26
#include "ns3/callback.h"
27
#include "ns3/event-id.h"
27
#include "ns3/event-id.h"
28
#include "ns3/packet.h"
29
#include "ns3/mobility-model.h"
28
#include "ns3/mobility-model.h"
30
#include "ns3/random-variable-stream.h"
29
#include "ns3/random-variable-stream.h"
31
#include "ns3/channel.h"
30
#include "ns3/channel.h"
32
#include "wifi-phy-standard.h"
31
#include "wifi-phy-standard.h"
33
#include "interference-helper.h"
32
#include "interference-helper.h"
34
#include "ns3/node.h"
33
#include "ns3/node.h"
34
#include "ns3/string.h"
35
35
36
namespace ns3 {
36
namespace ns3 {
37
37
 Lines 45-50    Link Here 
45
class WifiPhyStateHelper;
45
class WifiPhyStateHelper;
46
46
47
/**
47
/**
48
 * FrameCaptureModel class
49
 */
50
class FrameCaptureModel;
51
52
/**
48
 * This enumeration defines the type of an MPDU.
53
 * This enumeration defines the type of an MPDU.
49
 */
54
 */
50
/// MpduType enumeration
55
/// MpduType enumeration
 Lines 1445-1450    Link Here 
1445
   * \return the reception gain in dB
1450
   * \return the reception gain in dB
1446
   */
1451
   */
1447
  double GetRxGain (void) const;
1452
  double GetRxGain (void) const;
1453
1448
  /**
1454
  /**
1449
   * Sets the device this PHY is associated with.
1455
   * Sets the device this PHY is associated with.
1450
   *
1456
   *
 Lines 1603-1608    Link Here 
1603
  Ptr<ErrorRateModel> GetErrorRateModel (void) const;
1609
  Ptr<ErrorRateModel> GetErrorRateModel (void) const;
1604
1610
1605
  /**
1611
  /**
1612
   * Sets the frame capture model.
1613
   *
1614
   * \param rate the frame capture model
1615
   */
1616
  void SetFrameCaptureModel (Ptr<FrameCaptureModel> rate);
1617
  /**
1618
   * Return the frame capture model this PHY is using.
1619
   *
1620
   * \return the frame capture model this PHY is using
1621
   */
1622
  Ptr<FrameCaptureModel> GetFrameCaptureModel (void) const;
1623
1624
  /**
1606
   * \return the channel width
1625
   * \return the channel width
1607
   */
1626
   */
1608
  uint8_t GetChannelWidth (void) const;
1627
  uint8_t GetChannelWidth (void) const;
 Lines 1771-1776    Link Here 
1771
   * \return the FrequencyWidthPair found
1790
   * \return the FrequencyWidthPair found
1772
   */
1791
   */
1773
  FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard (uint8_t channelNumber, WifiPhyStandard standard) const;
1792
  FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard (uint8_t channelNumber, WifiPhyStandard standard) const;
1793
  
1794
  /**
1795
   * Due to newly arrived signal, the current reception cannot be continued and has to be aborted
1796
   *
1797
   */
1798
  void AbortCurrentReception (void);
1799
1800
  /**
1801
   * Eventually switch to CCA busy
1802
   */
1803
  void MaybeCcaBusyDuration (void);
1804
  
1805
  /**
1806
   * Starting receiving the packet after having detected the medium is idle or after a reception switch.
1807
   *
1808
   * \param packet the arriving packet
1809
   * \param txVector the TXVECTOR of the arriving packet
1810
   * \param mpdutype the type of the MPDU as defined in WifiPhy::MpduType.
1811
   * \param rxPowerW the receive power in W
1812
   * \param rxDuration the duration needed for the reception of the packet
1813
   * \param event the corresponding event of the first time the packet arrives
1814
   */
1815
  void StartRx (Ptr<Packet> packet,
1816
                WifiTxVector txVector,
1817
                MpduType mpdutype,
1818
                double rxPowerW,
1819
                Time rxDuration,
1820
                Ptr<InterferenceHelper::Event> event);
1774
1821
1775
  /**
1822
  /**
1776
   * The trace source fired when a packet begins the transmission process on
1823
   * The trace source fired when a packet begins the transmission process on
 Lines 1931-1936    Link Here 
1931
1978
1932
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1979
  Ptr<NetDevice>     m_device;   //!< Pointer to the device
1933
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1980
  Ptr<MobilityModel> m_mobility; //!< Pointer to the mobility model
1981
1982
  Ptr<InterferenceHelper::Event> m_currentEvent; //!< Hold the current event
1983
  Ptr<FrameCaptureModel> m_frameCaptureModel; //!< Frame capture model
1934
};
1984
};
1935
1985
1936
/**
1986
/**
(-)a/src/wifi/test/examples-to-run.py (+3 lines)
 Lines 247-252    Link Here 
247
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=1 --clientShortGuardInterval=1 --serverNss=4 --clientNss=4 --stepTime=0.1", "False", "False"),
247
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=1 --clientShortGuardInterval=1 --serverNss=4 --clientNss=4 --stepTime=0.1", "False", "False"),
248
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=0 --clientShortGuardInterval=0 --serverNss=4 --clientNss=4 --stepTime=0.1", "False", "False"),
248
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=0 --clientShortGuardInterval=0 --serverNss=4 --clientNss=4 --stepTime=0.1", "False", "False"),
249
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=1 --clientShortGuardInterval=1 --serverNss=4 --clientNss=4 --stepTime=0.1", "True", "True"),
249
    ("wifi-manager-example --wifiManager=Ideal --standard=802.11ac --serverChannelWidth=160 --clientChannelWidth=160 --serverShortGuardInterval=1 --clientShortGuardInterval=1 --serverNss=4 --clientNss=4 --stepTime=0.1", "True", "True"),
250
    ("test-interference-helper --enableCapture=0 --txPowerA=5 --txPowerB=15 --delay=10 --txModeA=OfdmRate6Mbps --txModeB=OfdmRate6Mbps --checkResults=1 --expectRxASuccessfull=0 --expectRxBSuccessfull=0", "True", "True"),
251
    ("test-interference-helper --enableCapture=1 --txPowerA=5 --txPowerB=15 --delay=10 --txModeA=OfdmRate6Mbps --txModeB=OfdmRate6Mbps --checkResults=1 --expectRxASuccessfull=0 --expectRxBSuccessfull=1", "True", "True"),
252
250
]
253
]
251
254
252
# A list of Python examples to run in order to ensure that they remain
255
# A list of Python examples to run in order to ensure that they remain
(-)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