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

(-)a/examples/energy/energy-model-example.cc (-9 / +1 lines)
 Lines 131-141   main (int argc, char *argv[]) Link Here 
131
  double interval = 1;          // seconds
131
  double interval = 1;          // seconds
132
  double startTime = 0.0;       // seconds
132
  double startTime = 0.0;       // seconds
133
  double distanceToRx = 100.0;  // meters
133
  double distanceToRx = 100.0;  // meters
134
  /*
135
   * This is a magic number used to set the transmit power, based on other
136
   * configuration.
137
   */
138
  double offset = 81;
139
134
140
  CommandLine cmd;
135
  CommandLine cmd;
141
  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
136
  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
 Lines 177-191   main (int argc, char *argv[]) Link Here 
177
  /** Wifi PHY **/
172
  /** Wifi PHY **/
178
  /***************************************************************************/
173
  /***************************************************************************/
179
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
174
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
180
  wifiPhy.Set ("RxGain", DoubleValue (-10));
181
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss));
182
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0));
183
  /***************************************************************************/
184
175
185
  /** wifi channel **/
176
  /** wifi channel **/
186
  YansWifiChannelHelper wifiChannel;
177
  YansWifiChannelHelper wifiChannel;
187
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
178
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
188
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
179
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
180
  
189
  // create wifi channel
181
  // create wifi channel
190
  Ptr<YansWifiChannel> wifiChannelPtr = wifiChannel.Create ();
182
  Ptr<YansWifiChannel> wifiChannelPtr = wifiChannel.Create ();
191
  wifiPhy.SetChannel (wifiChannelPtr);
183
  wifiPhy.SetChannel (wifiChannelPtr);
(-)a/examples/energy/energy-model-with-harvesting-example.cc (-9 / +1 lines)
 Lines 169-179   main (int argc, char *argv[]) Link Here 
169
  double interval = 1;          // seconds
169
  double interval = 1;          // seconds
170
  double startTime = 0.0;       // seconds
170
  double startTime = 0.0;       // seconds
171
  double distanceToRx = 100.0;  // meters
171
  double distanceToRx = 100.0;  // meters
172
  /*
173
   * This is a magic number used to set the transmit power, based on other
174
   * configuration.
175
   */
176
  double offset = 81;
177
  
172
  
178
  // Energy Harvester variables
173
  // Energy Harvester variables
179
  double harvestingUpdateInterval = 1;  // seconds
174
  double harvestingUpdateInterval = 1;  // seconds
 Lines 218-232   main (int argc, char *argv[]) Link Here 
218
  /** Wifi PHY **/
213
  /** Wifi PHY **/
219
  /***************************************************************************/
214
  /***************************************************************************/
220
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
215
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
221
  wifiPhy.Set ("RxGain", DoubleValue (-10));
222
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss));
223
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0));
224
  /***************************************************************************/
225
216
226
  /** wifi channel **/
217
  /** wifi channel **/
227
  YansWifiChannelHelper wifiChannel;
218
  YansWifiChannelHelper wifiChannel;
228
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
219
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
229
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
220
  wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
221
230
  // create wifi channel
222
  // create wifi channel
231
  Ptr<YansWifiChannel> wifiChannelPtr = wifiChannel.Create ();
223
  Ptr<YansWifiChannel> wifiChannelPtr = wifiChannel.Create ();
232
  wifiPhy.SetChannel (wifiChannelPtr);
224
  wifiPhy.SetChannel (wifiChannelPtr);
(-)a/examples/wireless/wifi-clear-channel-cmu.cc (-2 lines)
 Lines 208-215   int main (int argc, char *argv[]) Link Here 
208
208
209
          NS_LOG_DEBUG (modes[i]);
209
          NS_LOG_DEBUG (modes[i]);
210
          experiment = Experiment (modes[i]);
210
          experiment = Experiment (modes[i]);
211
          wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-110.0) );
212
          wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-110.0) );
213
          wifiPhy.Set ("TxPowerStart", DoubleValue (15.0) );
211
          wifiPhy.Set ("TxPowerStart", DoubleValue (15.0) );
214
          wifiPhy.Set ("TxPowerEnd", DoubleValue (15.0) );
212
          wifiPhy.Set ("TxPowerEnd", DoubleValue (15.0) );
215
          wifiPhy.Set ("RxGain", DoubleValue (0) );
213
          wifiPhy.Set ("RxGain", DoubleValue (0) );
(-)a/examples/wireless/wifi-simple-interference.cc (-4 lines)
 Lines 178-186   int main (int argc, char *argv[]) Link Here 
178
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
178
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
179
179
180
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
180
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
181
  // set it to zero; otherwise, gain will be added
182
  wifiPhy.Set ("RxGain", DoubleValue (0) );
183
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) );
184
181
185
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
182
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
186
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
183
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
 Lines 200-206   int main (int argc, char *argv[]) Link Here 
200
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c.Get (0));
197
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c.Get (0));
201
  // This will disable these sending devices from detecting a signal
198
  // This will disable these sending devices from detecting a signal
202
  // so that they do not backoff
199
  // so that they do not backoff
203
  wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (0.0) );
204
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) );
200
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) );
205
  devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
201
  devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
206
  wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) );
202
  wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) );
(-)a/examples/wireless/wifi-spectrum-per-example.cc (-3 lines)
 Lines 183-191   int main (int argc, char *argv[]) Link Here 
183
        }
183
        }
184
      else if (wifiType == "ns3::SpectrumWifiPhy")
184
      else if (wifiType == "ns3::SpectrumWifiPhy")
185
        {
185
        {
186
          //Bug 2460: CcaMode1Threshold default should be set to -62 dBm when using Spectrum
187
          Config::SetDefault ("ns3::WifiPhy::CcaMode1Threshold", DoubleValue (-62.0));
188
189
          Ptr<MultiModelSpectrumChannel> spectrumChannel
186
          Ptr<MultiModelSpectrumChannel> spectrumChannel
190
            = CreateObject<MultiModelSpectrumChannel> ();
187
            = CreateObject<MultiModelSpectrumChannel> ();
191
          Ptr<FriisPropagationLossModel> lossModel
188
          Ptr<FriisPropagationLossModel> lossModel
(-)a/examples/wireless/wifi-spectrum-per-interference.cc (-3 lines)
 Lines 212-220   int main (int argc, char *argv[]) Link Here 
212
        }
212
        }
213
      else if (wifiType == "ns3::SpectrumWifiPhy")
213
      else if (wifiType == "ns3::SpectrumWifiPhy")
214
        {
214
        {
215
          //Bug 2460: CcaMode1Threshold default should be set to -62 dBm when using Spectrum
216
          Config::SetDefault ("ns3::WifiPhy::CcaMode1Threshold", DoubleValue (-62.0));
217
218
          spectrumChannel
215
          spectrumChannel
219
            = CreateObject<MultiModelSpectrumChannel> ();
216
            = CreateObject<MultiModelSpectrumChannel> ();
220
          Ptr<FriisPropagationLossModel> lossModel
217
          Ptr<FriisPropagationLossModel> lossModel
(-)a/examples/wireless/wifi-spectrum-saturation-example.cc (-3 lines)
 Lines 178-186   int main (int argc, char *argv[]) Link Here 
178
        }
178
        }
179
      else if (wifiType == "ns3::SpectrumWifiPhy")
179
      else if (wifiType == "ns3::SpectrumWifiPhy")
180
        {
180
        {
181
          //Bug 2460: CcaMode1Threshold default should be set to -62 dBm when using Spectrum
182
          Config::SetDefault ("ns3::WifiPhy::CcaMode1Threshold", DoubleValue (-62.0));
183
184
          Ptr<MultiModelSpectrumChannel> spectrumChannel
181
          Ptr<MultiModelSpectrumChannel> spectrumChannel
185
            = CreateObject<MultiModelSpectrumChannel> ();
182
            = CreateObject<MultiModelSpectrumChannel> ();
186
          Ptr<FriisPropagationLossModel> lossModel
183
          Ptr<FriisPropagationLossModel> lossModel
(-)a/examples/wireless/wifi-tcp.cc (-8 lines)
 Lines 119-132   main (int argc, char *argv[]) Link Here 
119
  /* Setup Physical Layer */
119
  /* Setup Physical Layer */
120
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
120
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
121
  wifiPhy.SetChannel (wifiChannel.Create ());
121
  wifiPhy.SetChannel (wifiChannel.Create ());
122
  wifiPhy.Set ("TxPowerStart", DoubleValue (10.0));
123
  wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0));
124
  wifiPhy.Set ("TxPowerLevels", UintegerValue (1));
125
  wifiPhy.Set ("TxGain", DoubleValue (0));
126
  wifiPhy.Set ("RxGain", DoubleValue (0));
127
  wifiPhy.Set ("RxNoiseFigure", DoubleValue (10));
128
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79));
129
  wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3));
130
  wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
122
  wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
131
  wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
123
  wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
132
                                      "DataMode", StringValue (phyRate),
124
                                      "DataMode", StringValue (phyRate),
(-)a/src/aodv/test/aodv-regression.cc (-2 / +1 lines)
 Lines 168-175   ChainRegressionTest::CreateDevices () Link Here 
168
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
168
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
169
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
169
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
170
  wifiPhy.SetChannel (chan);
170
  wifiPhy.SetChannel (chan);
171
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
171
172
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
173
  // This test suite output was originally based on YansErrorRateModel
172
  // This test suite output was originally based on YansErrorRateModel
174
  wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
173
  wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
175
  WifiHelper wifi;
174
  WifiHelper wifi;
(-)a/src/mesh/test/dot11s/hwmp-proactive-regression.cc (-2 / +1 lines)
 Lines 113-120   HwmpProactiveRegressionTest::CreateDevices () Link Here 
113
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
113
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
114
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
114
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
115
  wifiPhy.SetChannel (chan);
115
  wifiPhy.SetChannel (chan);
116
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
116
117
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
118
  // 2. setup mesh
117
  // 2. setup mesh
119
  MeshHelper mesh = MeshHelper::Default ();
118
  MeshHelper mesh = MeshHelper::Default ();
120
  mesh.SetStackInstaller ("ns3::Dot11sStack", "Root", Mac48AddressValue (Mac48Address ("00:00:00:00:00:0d")));
119
  mesh.SetStackInstaller ("ns3::Dot11sStack", "Root", Mac48AddressValue (Mac48Address ("00:00:00:00:00:0d")));
(-)a/src/mesh/test/dot11s/hwmp-reactive-regression.cc (-2 lines)
 Lines 114-121   HwmpReactiveRegressionTest::CreateDevices () Link Here 
114
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
114
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
115
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
115
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
116
  wifiPhy.SetChannel (chan);
116
  wifiPhy.SetChannel (chan);
117
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
118
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
119
117
120
  // 2. setup mesh
118
  // 2. setup mesh
121
  MeshHelper mesh = MeshHelper::Default ();
119
  MeshHelper mesh = MeshHelper::Default ();
(-)a/src/mesh/test/dot11s/hwmp-simplest-regression.cc (-2 / +1 lines)
 Lines 122-129   HwmpSimplestRegressionTest::CreateDevices () Link Here 
122
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
122
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
123
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
123
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
124
  wifiPhy.SetChannel (chan);
124
  wifiPhy.SetChannel (chan);
125
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
125
126
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
127
  // 2. setup mesh
126
  // 2. setup mesh
128
  MeshHelper mesh = MeshHelper::Default ();
127
  MeshHelper mesh = MeshHelper::Default ();
129
  mesh.SetStackInstaller ("ns3::Dot11sStack");
128
  mesh.SetStackInstaller ("ns3::Dot11sStack");
(-)a/src/mesh/test/dot11s/hwmp-target-flags-regression.cc (-2 / +1 lines)
 Lines 140-147   HwmpDoRfRegressionTest::CreateDevices () Link Here 
140
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
140
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
141
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
141
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
142
  wifiPhy.SetChannel (chan);
142
  wifiPhy.SetChannel (chan);
143
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
143
144
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
145
  // 2. setup mesh
144
  // 2. setup mesh
146
  MeshHelper mesh = MeshHelper::Default ();
145
  MeshHelper mesh = MeshHelper::Default ();
147
  mesh.SetStackInstaller ("ns3::Dot11sStack");
146
  mesh.SetStackInstaller ("ns3::Dot11sStack");
(-)a/src/mesh/test/flame/flame-regression.cc (-2 / +1 lines)
 Lines 99-106   FlameRegressionTest::CreateDevices () Link Here 
99
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
99
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
100
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
100
  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
101
  wifiPhy.SetChannel (chan);
101
  wifiPhy.SetChannel (chan);
102
  wifiPhy.Set ("TxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
102
103
  wifiPhy.Set ("RxGain", DoubleValue (1.0)); //this configuration should go away in future revision to the test
104
  // 2. setup mesh
103
  // 2. setup mesh
105
  MeshHelper mesh = MeshHelper::Default ();
104
  MeshHelper mesh = MeshHelper::Default ();
106
  mesh.SetStackInstaller ("ns3::FlameStack");
105
  mesh.SetStackInstaller ("ns3::FlameStack");
(-)a/src/test/ns3wifi/wifi-interference-test-suite.cc (-5 lines)
 Lines 137-146   WifiInterferenceTestCase::WifiSimpleInterference (std::string phyMode,double Prs Link Here 
137
  wifi.SetStandard (wifiStandard);
137
  wifi.SetStandard (wifiStandard);
138
138
139
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
139
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
140
  // This is one parameter that matters when using FixedRssLossModel
141
  // set it to zero; otherwise, gain will be added
142
  wifiPhy.Set ("RxGain", DoubleValue (0) ); 
143
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) );
144
140
145
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
141
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
146
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO); 
142
  wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO); 
 Lines 172-178   WifiInterferenceTestCase::WifiSimpleInterference (std::string phyMode,double Prs Link Here 
172
168
173
  // This will disable these sending devices from detecting a signal 
169
  // This will disable these sending devices from detecting a signal 
174
  // so that they do not backoff
170
  // so that they do not backoff
175
  wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (0.0) );
176
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) ); 
171
  wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) ); 
177
  devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
172
  devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
178
  wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) ); 
173
  wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) ); 
(-)a/src/wifi/examples/wifi-manager-example.cc (-3 lines)
 Lines 336-344   int main (int argc, char *argv[]) Link Here 
336
  WifiHelper wifi;
336
  WifiHelper wifi;
337
  wifi.SetStandard (serverSelectedStandard.m_standard);
337
  wifi.SetStandard (serverSelectedStandard.m_standard);
338
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
338
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
339
  wifiPhy.Set ("RxNoiseFigure", DoubleValue (0.0));
340
  wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-110.0));
341
  wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-110.0));
342
339
343
  Ptr<YansWifiChannel> wifiChannel = CreateObject<YansWifiChannel> ();
340
  Ptr<YansWifiChannel> wifiChannel = CreateObject<YansWifiChannel> ();
344
  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
341
  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
(-)a/src/wifi/model/spectrum-wifi-phy.cc (+8 lines)
 Lines 242-247   SpectrumWifiPhy::StartRx (Ptr<SpectrumSignalParameters> rxParams) Link Here 
242
242
243
  // Log the signal arrival to the trace source
243
  // Log the signal arrival to the trace source
244
  m_signalCb (wifiRxParams ? true : false, senderNodeId, WToDbm (rxPowerW), rxDuration);
244
  m_signalCb (wifiRxParams ? true : false, senderNodeId, WToDbm (rxPowerW), rxDuration);
245
246
  // Do no further processing if signal is too weak
247
  // Current implementation assumes constant rx power over the packet duration
248
  if (WToDbm (rxPowerW) < GetRxSensitivity ())
249
    {
250
      NS_LOG_INFO ("Received signal too weak to process: " << WToDbm (rxPowerW) << " dBm");
251
      return;
252
    }
245
  if (wifiRxParams == 0)
253
  if (wifiRxParams == 0)
246
    {
254
    {
247
      NS_LOG_INFO ("Received non Wi-Fi signal");
255
      NS_LOG_INFO ("Received non Wi-Fi signal");
(-)a/src/wifi/model/wifi-phy-state-helper.cc (+1 lines)
 Lines 517-522   WifiPhyStateHelper::SwitchMaybeToCcaBusy (Time duration) Link Here 
517
    {
517
    {
518
      m_startCcaBusy = now;
518
      m_startCcaBusy = now;
519
    }
519
    }
520
  m_stateLogger (now, duration, WifiPhyState::CCA_BUSY);
520
  m_endCcaBusy = std::max (m_endCcaBusy, now + duration);
521
  m_endCcaBusy = std::max (m_endCcaBusy, now + duration);
521
}
522
}
522
523
(-)a/src/wifi/model/wifi-phy.cc (-80 / +77 lines)
 Lines 178-195   WifiPhy::GetTypeId (void) Link Here 
178
                   MakeUintegerAccessor (&WifiPhy::SetChannelNumber,
178
                   MakeUintegerAccessor (&WifiPhy::SetChannelNumber,
179
                                         &WifiPhy::GetChannelNumber),
179
                                         &WifiPhy::GetChannelNumber),
180
                   MakeUintegerChecker<uint8_t> (0, 196))
180
                   MakeUintegerChecker<uint8_t> (0, 196))
181
    .AddAttribute ("EnergyDetectionThreshold",
181
    .AddAttribute ("RxSensitivity",
182
                   "The energy of a received signal should be higher than "
182
                   "The energy of a received signal should be higher than "
183
                   "this threshold (dbm) to allow the PHY layer to detect the signal.",
183
                   "this threshold (dBm) for the PHY to detect the signal.",
184
                   DoubleValue (-96.0),
184
                   DoubleValue (-101.0),
185
                   MakeDoubleAccessor (&WifiPhy::SetEdThreshold),
185
                   MakeDoubleAccessor (&WifiPhy::SetRxSensitivity,
186
                                       &WifiPhy::GetRxSensitivity),
186
                   MakeDoubleChecker<double> ())
187
                   MakeDoubleChecker<double> ())
187
    .AddAttribute ("CcaMode1Threshold",
188
    .AddAttribute ("CcaEdThreshold",
188
                   "The energy of a received signal should be higher than "
189
                   "The energy of a received signal should be higher than "
189
                   "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state.",
190
                   "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state.",
190
                   DoubleValue (-99.0),
191
                   DoubleValue (-62.0),
191
                   MakeDoubleAccessor (&WifiPhy::SetCcaMode1Threshold,
192
                   MakeDoubleAccessor (&WifiPhy::SetCcaEdThreshold,
192
                                       &WifiPhy::GetCcaMode1Threshold),
193
                                       &WifiPhy::GetCcaEdThreshold),
193
                   MakeDoubleChecker<double> ())
194
                   MakeDoubleChecker<double> ())
194
    .AddAttribute ("TxGain",
195
    .AddAttribute ("TxGain",
195
                   "Transmission gain (dB).",
196
                   "Transmission gain (dB).",
 Lines 404-409   WifiPhy::DoInitialize (void) Link Here 
404
  InitializeFrequencyChannelNumber ();
405
  InitializeFrequencyChannelNumber ();
405
}
406
}
406
407
408
Ptr<WifiPhyStateHelper>
409
WifiPhy::GetState (void) const
410
{
411
  return m_state;
412
}
413
407
void
414
void
408
WifiPhy::SetReceiveOkCallback (RxOkCallback callback)
415
WifiPhy::SetReceiveOkCallback (RxOkCallback callback)
409
{
416
{
 Lines 463-491   WifiPhy::InitializeFrequencyChannelNumber (void) Link Here 
463
}
470
}
464
471
465
void
472
void
466
WifiPhy::SetEdThreshold (double threshold)
473
WifiPhy::SetRxSensitivity (double threshold)
467
{
474
{
468
  NS_LOG_FUNCTION (this << threshold);
475
  NS_LOG_FUNCTION (this << threshold);
469
  m_edThresholdW = DbmToW (threshold);
476
  m_rxSensitivityW = DbmToW (threshold);
470
}
477
}
471
478
472
double
479
double
473
WifiPhy::GetEdThreshold (void) const
480
WifiPhy::GetRxSensitivity (void) const
474
{
481
{
475
  return WToDbm (m_edThresholdW);
482
  return WToDbm (m_rxSensitivityW);
476
}
483
}
477
484
478
void
485
void
479
WifiPhy::SetCcaMode1Threshold (double threshold)
486
WifiPhy::SetCcaEdThreshold (double threshold)
480
{
487
{
481
  NS_LOG_FUNCTION (this << threshold);
488
  NS_LOG_FUNCTION (this << threshold);
482
  m_ccaMode1ThresholdW = DbmToW (threshold);
489
  m_ccaEdThresholdW = DbmToW (threshold);
483
}
490
}
484
491
485
double
492
double
486
WifiPhy::GetCcaMode1Threshold (void) const
493
WifiPhy::GetCcaEdThreshold (void) const
487
{
494
{
488
  return WToDbm (m_ccaMode1ThresholdW);
495
  return WToDbm (m_ccaEdThresholdW);
489
}
496
}
490
497
491
void
498
void
 Lines 1627-1633   WifiPhy::ResumeFromSleep (void) Link Here 
1627
    case WifiPhyState::SLEEP:
1634
    case WifiPhyState::SLEEP:
1628
      {
1635
      {
1629
        NS_LOG_DEBUG ("resuming from sleep mode");
1636
        NS_LOG_DEBUG ("resuming from sleep mode");
1630
        Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaMode1ThresholdW);
1637
        Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaEdThresholdW);
1631
        m_state->SwitchFromSleep (delayUntilCcaEnd);
1638
        m_state->SwitchFromSleep (delayUntilCcaEnd);
1632
        break;
1639
        break;
1633
      }
1640
      }
 Lines 1658-1664   WifiPhy::ResumeFromOff (void) Link Here 
1658
    case WifiPhyState::OFF:
1665
    case WifiPhyState::OFF:
1659
      {
1666
      {
1660
        NS_LOG_DEBUG ("resuming from off mode");
1667
        NS_LOG_DEBUG ("resuming from off mode");
1661
        Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ()));
1668
        Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaEdThreshold ()));
1662
        m_state->SwitchFromOff (delayUntilCcaEnd);
1669
        m_state->SwitchFromOff (delayUntilCcaEnd);
1663
        break;
1670
        break;
1664
      }
1671
      }
 Lines 2526-2532   WifiPhy::MaybeCcaBusyDuration () Link Here 
2526
  //In this model, CCA becomes busy when the aggregation of all signals as
2533
  //In this model, CCA becomes busy when the aggregation of all signals as
2527
  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
2534
  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
2528
2535
2529
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ()));
2536
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaEdThreshold ()));
2530
  if (!delayUntilCcaEnd.IsZero ())
2537
  if (!delayUntilCcaEnd.IsZero ())
2531
    {
2538
    {
2532
      m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
2539
      m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
 Lines 3622-3628   WifiPhy::SwitchMaybeToCcaBusy (void) Link Here 
3622
  //In this model, CCA becomes busy when the aggregation of all signals as
3629
  //In this model, CCA becomes busy when the aggregation of all signals as
3623
  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
3630
  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
3624
3631
3625
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ()));
3632
  Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaEdThreshold ()));
3626
  if (!delayUntilCcaEnd.IsZero ())
3633
  if (!delayUntilCcaEnd.IsZero ())
3627
    {
3634
    {
3628
      NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S));
3635
      NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S));
 Lines 3652-3727   void Link Here 
3652
WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<Event> event)
3659
WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<Event> event)
3653
{
3660
{
3654
  NS_LOG_FUNCTION (this << packet << txVector << +mpdutype << rxPowerW << rxDuration);
3661
  NS_LOG_FUNCTION (this << packet << txVector << +mpdutype << rxPowerW << rxDuration);
3655
  if (rxPowerW > m_edThresholdW) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
3662
3663
  AmpduTag ampduTag;
3664
  WifiPreamble preamble = txVector.GetPreambleType ();
3665
  if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3656
    {
3666
    {
3657
      AmpduTag ampduTag;
3667
      m_plcpSuccess = false;
3658
      WifiPreamble preamble = txVector.GetPreambleType ();
3668
      m_mpdusNum = 0;
3659
      if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3669
      NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3660
        {
3670
      NotifyRxDrop (packet);
3661
          m_plcpSuccess = false;
3671
      MaybeCcaBusyDuration ();
3662
          m_mpdusNum = 0;
3672
      return;
3663
          NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3673
    }
3664
          NotifyRxDrop (packet);
3674
  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3665
          MaybeCcaBusyDuration ();
3675
    {
3666
          return;
3676
      //received the first MPDU in an MPDU
3667
        }
3677
      m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3668
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3678
      m_rxMpduReferenceNumber++;
3669
        {
3679
    }
3670
          //received the first MPDU in an MPDU
3680
  else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3671
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3681
    {
3672
          m_rxMpduReferenceNumber++;
3682
      //received the other MPDUs that are part of the A-MPDU
3673
        }
3683
      if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3674
      else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3675
        {
3676
          //received the other MPDUs that are part of the A-MPDU
3677
          if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3678
            {
3679
              NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3680
              m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3681
            }
3682
          else
3683
            {
3684
              m_mpdusNum--;
3685
            }
3686
        }
3687
      else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3688
        {
3684
        {
3689
          NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3685
          NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3690
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3686
          m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3691
        }
3687
        }
3692
      else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3688
      else
3693
        {
3689
        {
3694
          NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3690
          m_mpdusNum--;
3695
          m_mpdusNum = 0;
3696
        }
3691
        }
3692
    }
3693
  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3694
    {
3695
      NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3696
      m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3697
    }
3698
  else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3699
    {
3700
      NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3701
      m_mpdusNum = 0;
3702
    }
3697
3703
3698
      NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3704
  NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3699
      m_currentEvent = event;
3705
  m_currentEvent = event;
3700
      m_state->SwitchToRx (rxDuration);
3706
  m_state->SwitchToRx (rxDuration);
3701
      NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3707
  NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3702
      NotifyRxBegin (packet);
3708
  NotifyRxBegin (packet);
3703
      m_interference.NotifyRxStart ();
3709
  m_interference.NotifyRxStart ();
3704
3705
      if (preamble != WIFI_PREAMBLE_NONE)
3706
        {
3707
          NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3708
          Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3709
          m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3710
                                                  packet, txVector, mpdutype, event);
3711
        }
3712
3710
3713
      NS_ASSERT (m_endRxEvent.IsExpired ());
3711
  if (preamble != WIFI_PREAMBLE_NONE)
3714
      m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3715
                                          packet, preamble, mpdutype, event);
3716
    }
3717
  else
3718
    {
3712
    {
3719
      NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
3713
      NS_ASSERT (m_endPlcpRxEvent.IsExpired ());
3720
                    rxPowerW << "<" << m_edThresholdW << ")");
3714
      Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3721
      NotifyRxDrop (packet);
3715
      m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3722
      m_plcpSuccess = false;
3716
                                              packet, txVector, mpdutype, event);
3723
      MaybeCcaBusyDuration ();
3724
    }
3717
    }
3718
3719
  NS_ASSERT (m_endRxEvent.IsExpired ());
3720
  m_endRxEvent = Simulator::Schedule (rxDuration, &WifiPhy::EndReceive, this,
3721
                                      packet, preamble, mpdutype, event);
3725
}
3722
}
3726
3723
3727
int64_t
3724
int64_t
(-)a/src/wifi/model/wifi-phy.h (-12 / +20 lines)
 Lines 23-28    Link Here 
23
#define WIFI_PHY_H
23
#define WIFI_PHY_H
24
24
25
#include "ns3/event-id.h"
25
#include "ns3/event-id.h"
26
#include "ns3/deprecated.h"
26
#include "wifi-mpdu-type.h"
27
#include "wifi-mpdu-type.h"
27
#include "wifi-phy-standard.h"
28
#include "wifi-phy-standard.h"
28
#include "interference-helper.h"
29
#include "interference-helper.h"
 Lines 72-77   public: Link Here 
72
73
73
  WifiPhy ();
74
  WifiPhy ();
74
  virtual ~WifiPhy ();
75
  virtual ~WifiPhy ();
76
  
77
  /**
78
   * Return the WifiPhyStateHelper of this PHY
79
   *
80
   * \return the WifiPhyStateHelper of this PHY
81
   */
82
  Ptr<WifiPhyStateHelper> GetState (void) const;
75
83
76
  /**
84
  /**
77
   * \param callback the callback to invoke
85
   * \param callback the callback to invoke
 Lines 1184-1202   public: Link Here 
1184
  virtual int64_t AssignStreams (int64_t stream);
1192
  virtual int64_t AssignStreams (int64_t stream);
1185
1193
1186
  /**
1194
  /**
1187
   * Sets the energy detection threshold (dBm).
1195
   * Sets the receive sensitivity threshold (dBm).
1188
   * The energy of a received signal should be higher than
1196
   * The energy of a received signal should be higher than
1189
   * this threshold (dbm) to allow the PHY layer to detect the signal.
1197
   * this threshold to allow the PHY layer to detect the signal.
1190
   *
1198
   *
1191
   * \param threshold the energy detection threshold in dBm
1199
   * \param threshold the receive sensitivity threshold in dBm
1192
   */
1200
   */
1193
  void SetEdThreshold (double threshold);
1201
  void SetRxSensitivity (double threshold);
1194
  /**
1202
  /**
1195
   * Return the energy detection threshold (dBm).
1203
   * Return the receive sensitivity threshold (dBm).
1196
   *
1204
   *
1197
   * \return the energy detection threshold in dBm
1205
   * \return the receive sensitivity threshold in dBm
1198
   */
1206
   */
1199
  double GetEdThreshold (void) const;
1207
  double GetRxSensitivity (void) const;
1200
  /**
1208
  /**
1201
   * Sets the CCA threshold (dBm). The energy of a received signal
1209
   * Sets the CCA threshold (dBm). The energy of a received signal
1202
   * should be higher than this threshold to allow the PHY
1210
   * should be higher than this threshold to allow the PHY
 Lines 1204-1216   public: Link Here 
1204
   *
1212
   *
1205
   * \param threshold the CCA threshold in dBm
1213
   * \param threshold the CCA threshold in dBm
1206
   */
1214
   */
1207
  void SetCcaMode1Threshold (double threshold);
1215
  void SetCcaEdThreshold (double threshold);
1208
  /**
1216
  /**
1209
   * Return the CCA threshold (dBm).
1217
   * Return the CCA threshold (dBm).
1210
   *
1218
   *
1211
   * \return the CCA threshold in dBm
1219
   * \return the CCA threshold in dBm
1212
   */
1220
   */
1213
  double GetCcaMode1Threshold (void) const;
1221
  double GetCcaEdThreshold (void) const;
1214
  /**
1222
  /**
1215
   * Sets the RX loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.
1223
   * Sets the RX loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.
1216
   *
1224
   *
 Lines 1480-1486   protected: Link Here 
1480
   * Check if Phy state should move to CCA busy state based on current
1488
   * Check if Phy state should move to CCA busy state based on current
1481
   * state of interference tracker.  In this model, CCA becomes busy when
1489
   * state of interference tracker.  In this model, CCA becomes busy when
1482
   * the aggregation of all signals as tracked by the InterferenceHelper
1490
   * the aggregation of all signals as tracked by the InterferenceHelper
1483
   * class is higher than the CcaMode1Threshold
1491
   * class is higher than the CcaEdThreshold
1484
   */
1492
   */
1485
  void SwitchMaybeToCcaBusy (void);
1493
  void SwitchMaybeToCcaBusy (void);
1486
1494
 Lines 1742-1749   private: Link Here 
1742
  bool m_frequencyChannelNumberInitialized; //!< Store initialization state
1750
  bool m_frequencyChannelNumberInitialized; //!< Store initialization state
1743
  uint16_t m_channelWidth;                  //!< Channel width
1751
  uint16_t m_channelWidth;                  //!< Channel width
1744
1752
1745
  double   m_edThresholdW;        //!< Energy detection threshold in watts
1753
  double   m_rxSensitivityW;      //!< Receive sensitivity threshold in watts
1746
  double   m_ccaMode1ThresholdW;  //!< Clear channel assessment (CCA) threshold in watts
1754
  double   m_ccaEdThresholdW;     //!< Clear channel assessment (CCA) threshold in watts
1747
  double   m_txGainDb;            //!< Transmission gain (dB)
1755
  double   m_txGainDb;            //!< Transmission gain (dB)
1748
  double   m_rxGainDb;            //!< Reception gain (dB)
1756
  double   m_rxGainDb;            //!< Reception gain (dB)
1749
  double   m_txPowerBaseDbm;      //!< Minimum transmission power (dBm)
1757
  double   m_txPowerBaseDbm;      //!< Minimum transmission power (dBm)
(-)a/src/wifi/model/yans-wifi-channel.cc (+7 lines)
 Lines 125-130   void Link Here 
125
YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
125
YansWifiChannel::Receive (Ptr<YansWifiPhy> phy, Ptr<Packet> packet, double rxPowerDbm, Time duration)
126
{
126
{
127
  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
127
  NS_LOG_FUNCTION (phy << packet << rxPowerDbm << duration.GetSeconds ());
128
  // Do no further processing if signal is too weak
129
  // Current implementation assumes constant rx power over the packet duration
130
  if ((rxPowerDbm + phy->GetRxGain ()) < phy->GetRxSensitivity ())
131
    {
132
      NS_LOG_INFO ("Received signal too weak to process: " << rxPowerDbm << " dBm");
133
      return;
134
    }
128
  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
135
  phy->StartReceivePreambleAndHeader (packet, DbmToW (rxPowerDbm + phy->GetRxGain ()), duration);
129
}
136
}
130
137
(-)a/src/wifi/test/spectrum-wifi-phy-test.cc (-2 lines)
 Lines 167-174   SpectrumWifiPhyBasicTest::DoSetup (void) Link Here 
167
  m_phy->SetFrequency (FREQUENCY);
167
  m_phy->SetFrequency (FREQUENCY);
168
  m_phy->SetReceiveOkCallback (MakeCallback (&SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxSuccess, this));
168
  m_phy->SetReceiveOkCallback (MakeCallback (&SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxSuccess, this));
169
  m_phy->SetReceiveErrorCallback (MakeCallback (&SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxFailure, this));
169
  m_phy->SetReceiveErrorCallback (MakeCallback (&SpectrumWifiPhyBasicTest::SpectrumWifiPhyRxFailure, this));
170
  //Bug 2460: CcaMode1Threshold default should be set to -62 dBm when using Spectrum
171
  m_phy->SetCcaMode1Threshold (-62.0);
172
}
170
}
173
171
174
// Test that the expected number of packet receptions occur.
172
// Test that the expected number of packet receptions occur.
(-)a/src/wifi/test/wifi-phy-thresholds-test.cc (+425 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2018
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
19
 */
20
21
#include "ns3/log.h"
22
#include "ns3/test.h"
23
#include "ns3/spectrum-wifi-helper.h"
24
#include "ns3/wifi-spectrum-value-helper.h"
25
#include "ns3/spectrum-wifi-phy.h"
26
#include "ns3/nist-error-rate-model.h"
27
#include "ns3/wifi-mac-header.h"
28
#include "ns3/wifi-mac-trailer.h"
29
#include "ns3/wifi-phy-tag.h"
30
#include "ns3/wifi-spectrum-signal-parameters.h"
31
#include "ns3/wifi-utils.h"
32
33
using namespace ns3;
34
35
NS_LOG_COMPONENT_DEFINE ("WifiPhyThresholdsTest");
36
37
static const uint8_t CHANNEL_NUMBER = 36;
38
static const uint32_t FREQUENCY = 5180; //MHz
39
static const uint16_t CHANNEL_WIDTH = 20; //MHz
40
41
/**
42
 * \ingroup wifi-test
43
 * \ingroup tests
44
 *
45
 * \brief Wifi Phy Threshold Test base class
46
 */
47
class WifiPhyThresholdsTest : public TestCase
48
{
49
public:
50
  WifiPhyThresholdsTest (std::string test_name);
51
  virtual ~WifiPhyThresholdsTest ();
52
53
protected:
54
  /**
55
   * Make wifi signal function
56
   * \param txPowerWatts the transmit power in watts
57
   * \returns Ptr<SpectrumSignalParameters>
58
   */
59
  virtual Ptr<SpectrumSignalParameters> MakeWifiSignal (double txPowerWatts);
60
  /**
61
   * Make foreign signal function
62
   * \param txPowerWatts the transmit power in watts
63
   * \returns Ptr<SpectrumSignalParameters>
64
   */
65
  virtual Ptr<SpectrumSignalParameters> MakeForeignSignal (double txPowerWatts);
66
  /**
67
   * Send signal function
68
   * \param txPowerWatts the transmit power in watts
69
   * \param wifiSignal whether the signal is a wifi signal or not
70
   */
71
  virtual void SendSignal (double txPowerWatts, bool wifiSignal);
72
  /**
73
   * PHY receive success callback function
74
   * \param p the packet
75
   * \param snr the SNR
76
   * \param txVector the transmit vector
77
   */
78
  virtual void RxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector);
79
  /**
80
   * PHY receive failure callback function
81
   */
82
  virtual void RxFailure (void);
83
  /**
84
   * PHY dropped packet callback function
85
   * \param p the packet
86
   */
87
  virtual void RxDropped (Ptr<const Packet> p);
88
  /**
89
   * PHY state changed callback function
90
   * \param start the start time of the new state
91
   * \param duration the duration of the new state
92
   * \param newState the new state
93
   */
94
  virtual void PhyStateChanged (Time start, Time duration, WifiPhyState newState);
95
96
  Ptr<SpectrumWifiPhy> m_phy; ///< PHY object
97
  uint32_t m_rxSuccess;       ///< count number of successfully received packets
98
  uint32_t m_rxFailure;       ///< count number of unsuccessfully received packets
99
  uint32_t m_rxDropped;       ///< count number of dropped packets
100
  uint32_t m_stateChanged;    ///< count number of PHY state change
101
  uint32_t m_rxStateCount;    ///< count number of PHY state change to RX state
102
  uint32_t m_idleStateCount;    ///< count number of PHY state change to IDLE state
103
  uint32_t m_ccabusyStateCount; ///< count number of PHY state change to CCA_BUSY state
104
105
private:
106
  virtual void DoSetup (void);
107
};
108
109
WifiPhyThresholdsTest::WifiPhyThresholdsTest (std::string test_name)
110
  : TestCase (test_name),
111
    m_rxSuccess (0),
112
    m_rxFailure (0),
113
    m_rxDropped (0),
114
    m_stateChanged (0),
115
    m_rxStateCount (0),
116
    m_idleStateCount (0),
117
    m_ccabusyStateCount (0)
118
{
119
}
120
121
WifiPhyThresholdsTest::~WifiPhyThresholdsTest ()
122
{
123
}
124
125
Ptr<SpectrumSignalParameters>
126
WifiPhyThresholdsTest::MakeWifiSignal (double txPowerWatts)
127
{
128
  WifiTxVector txVector = WifiTxVector (WifiPhy::GetOfdmRate6Mbps (), 0, WIFI_PREAMBLE_LONG, false, 1, 1, 0, 20, false, false);
129
  MpduType mpdutype = NORMAL_MPDU;
130
131
  Ptr<Packet> pkt = Create<Packet> (1000);
132
  WifiMacHeader hdr;
133
  WifiMacTrailer trailer;
134
135
  hdr.SetType (WIFI_MAC_QOSDATA);
136
  hdr.SetQosTid (0);
137
  uint32_t size = pkt->GetSize () + hdr.GetSize () + trailer.GetSerializedSize ();
138
  Time txDuration = m_phy->CalculateTxDuration (size, txVector, m_phy->GetFrequency (), mpdutype, 0);
139
  hdr.SetDuration (txDuration);
140
141
  pkt->AddHeader (hdr);
142
  pkt->AddTrailer (trailer);
143
  WifiPhyTag tag (txVector, mpdutype, 1);
144
  pkt->AddPacketTag (tag);
145
  Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH);
146
  Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> ();
147
  txParams->psd = txPowerSpectrum;
148
  txParams->txPhy = 0;
149
  txParams->duration = txDuration;
150
  txParams->packet = pkt;
151
  return txParams;
152
}
153
154
Ptr<SpectrumSignalParameters>
155
WifiPhyThresholdsTest::MakeForeignSignal (double txPowerWatts)
156
{
157
  Ptr<SpectrumValue> txPowerSpectrum = WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (FREQUENCY, CHANNEL_WIDTH, txPowerWatts, CHANNEL_WIDTH);
158
  Ptr<SpectrumSignalParameters> txParams = Create<SpectrumSignalParameters> ();
159
  txParams->psd = txPowerSpectrum;
160
  txParams->txPhy = 0;
161
  txParams->duration = Seconds (0.5);
162
  return txParams;
163
}
164
165
void
166
WifiPhyThresholdsTest::SendSignal (double txPowerWatts, bool wifiSignal)
167
{
168
  if (wifiSignal)
169
    {
170
      m_phy->StartRx (MakeWifiSignal (txPowerWatts));
171
    }
172
  else
173
    {
174
      m_phy->StartRx (MakeForeignSignal (txPowerWatts));
175
    }
176
}
177
178
void
179
WifiPhyThresholdsTest::RxSuccess (Ptr<Packet> p, double snr, WifiTxVector txVector)
180
{
181
  NS_LOG_FUNCTION (this << p << snr << txVector);
182
  m_rxSuccess++;
183
}
184
185
void
186
WifiPhyThresholdsTest::RxFailure (void)
187
{
188
  NS_LOG_FUNCTION (this);
189
  m_rxFailure++;
190
}
191
192
void
193
WifiPhyThresholdsTest::RxDropped (Ptr<const Packet> p)
194
{
195
  NS_LOG_FUNCTION (this << p);
196
  m_rxDropped++;
197
}
198
199
void
200
WifiPhyThresholdsTest::PhyStateChanged (Time start, Time duration, WifiPhyState newState)
201
{
202
  NS_LOG_FUNCTION (this << start << duration << newState);
203
  m_stateChanged++;
204
  if (newState == WifiPhyState::IDLE)
205
    {
206
      m_idleStateCount++;
207
    }
208
  else if (newState == WifiPhyState::RX)
209
    {
210
      m_rxStateCount++;
211
    }
212
  else if (newState == WifiPhyState::CCA_BUSY)
213
    {
214
      m_ccabusyStateCount++;
215
    }
216
}
217
218
void
219
WifiPhyThresholdsTest::DoSetup (void)
220
{
221
  m_phy = CreateObject<SpectrumWifiPhy> ();
222
  m_phy->ConfigureStandard (WIFI_PHY_STANDARD_80211ax_5GHZ);
223
  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
224
  m_phy->SetErrorRateModel (error);
225
  m_phy->SetChannelNumber (CHANNEL_NUMBER);
226
  m_phy->SetFrequency (FREQUENCY);
227
  m_phy->SetReceiveOkCallback (MakeCallback (&WifiPhyThresholdsTest::RxSuccess, this));
228
  m_phy->SetReceiveErrorCallback (MakeCallback (&WifiPhyThresholdsTest::RxFailure, this));
229
  m_phy->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&WifiPhyThresholdsTest::RxDropped, this));
230
  m_phy->GetState ()->TraceConnectWithoutContext ("State", MakeCallback (&WifiPhyThresholdsTest::PhyStateChanged, this));
231
}
232
233
/**
234
 * \ingroup wifi-test
235
 * \ingroup tests
236
 *
237
 * \brief Wifi Phy Threshold Weak Wifi Signal Test
238
 *
239
 * This test makes sure PHY ignores a Wi-Fi signal
240
 * if its received power lower than RxSensitivity.
241
 */
242
class WifiPhyThresholdsWeakWifiSignalTest : public WifiPhyThresholdsTest
243
{
244
public:
245
  WifiPhyThresholdsWeakWifiSignalTest ();
246
  virtual ~WifiPhyThresholdsWeakWifiSignalTest ();
247
  virtual void DoRun (void);
248
};
249
250
WifiPhyThresholdsWeakWifiSignalTest::WifiPhyThresholdsWeakWifiSignalTest ()
251
  : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak wifi signal reception")
252
{
253
}
254
255
WifiPhyThresholdsWeakWifiSignalTest::~WifiPhyThresholdsWeakWifiSignalTest ()
256
{
257
}
258
259
void
260
WifiPhyThresholdsWeakWifiSignalTest::DoRun (void)
261
{
262
  WifiHelper::EnableLogComponents ();
263
264
  double txPowerWatts = DbmToW (-110);
265
266
  Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakWifiSignalTest::SendSignal, this, txPowerWatts, true);
267
268
  Simulator::Run ();
269
  Simulator::Destroy ();
270
271
  NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception should not have been triggered if packet is weaker than RxSensitivity threshold");
272
  NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold");
273
}
274
275
/**
276
 * \ingroup wifi-test
277
 * \ingroup tests
278
 *
279
 * \brief Wifi Phy Threshold Weak Foreign Signal Test
280
 *
281
 * This test makes sure PHY keeps the state as IDLE if reception involves
282
 * a foreign signal with a received power lower than CcaEdThreshold.
283
 */
284
class WifiPhyThresholdsWeakForeignSignalTest : public WifiPhyThresholdsTest
285
{
286
public:
287
  WifiPhyThresholdsWeakForeignSignalTest ();
288
  virtual ~WifiPhyThresholdsWeakForeignSignalTest ();
289
  virtual void DoRun (void);
290
};
291
292
WifiPhyThresholdsWeakForeignSignalTest::WifiPhyThresholdsWeakForeignSignalTest ()
293
  : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception")
294
{
295
}
296
297
WifiPhyThresholdsWeakForeignSignalTest::~WifiPhyThresholdsWeakForeignSignalTest ()
298
{
299
}
300
301
void
302
WifiPhyThresholdsWeakForeignSignalTest::DoRun (void)
303
{
304
  WifiHelper::EnableLogComponents ();
305
306
  double txPowerWatts = DbmToW (-90);
307
308
  Simulator::Schedule (Seconds (1), &WifiPhyThresholdsWeakForeignSignalTest::SendSignal, this, txPowerWatts, false);
309
310
  Simulator::Run ();
311
  Simulator::Destroy ();
312
313
  NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered");
314
  NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 0, "State should stay idle if reception involves a signal weaker than RxSensitivity threshold");
315
}
316
317
/**
318
 * \ingroup wifi-test
319
 * \ingroup tests
320
 *
321
 * \brief Wifi Phy Threshold Strong Wifi Signal Test
322
 *
323
 * This test makes sure PHY processes a Wi-Fi signal
324
 * with a received power higher than RxSensitivity.
325
 */
326
class WifiPhyThresholdsStrongWifiSignalTest : public WifiPhyThresholdsTest
327
{
328
public:
329
  WifiPhyThresholdsStrongWifiSignalTest ();
330
  virtual ~WifiPhyThresholdsStrongWifiSignalTest ();
331
  virtual void DoRun (void);
332
};
333
334
WifiPhyThresholdsStrongWifiSignalTest::WifiPhyThresholdsStrongWifiSignalTest ()
335
  : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test strong wifi signal reception")
336
{
337
}
338
339
WifiPhyThresholdsStrongWifiSignalTest::~WifiPhyThresholdsStrongWifiSignalTest ()
340
{
341
}
342
343
void
344
WifiPhyThresholdsStrongWifiSignalTest::DoRun (void)
345
{
346
  WifiHelper::EnableLogComponents ();
347
348
  double txPowerWatts = DbmToW (-60);
349
350
  Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongWifiSignalTest::SendSignal, this, txPowerWatts, true);
351
352
  Simulator::Run ();
353
  Simulator::Destroy ();
354
355
  NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxFailure, 0, "Packet reception should have been successfull");
356
  NS_TEST_ASSERT_MSG_EQ (m_rxSuccess, 1, "Packet should have been successfully received");
357
  NS_TEST_ASSERT_MSG_EQ (m_stateChanged, 2, "State should have moved to RX then back to IDLE");
358
  NS_TEST_ASSERT_MSG_EQ (m_rxStateCount, 1, "State should have moved to RX once");
359
  NS_TEST_ASSERT_MSG_EQ (m_idleStateCount, 1, "State should have moved to IDLE once");
360
}
361
362
/**
363
 * \ingroup wifi-test
364
 * \ingroup tests
365
 *
366
 * \brief Wifi Phy Threshold Strong Foreign Signal Test
367
 *
368
 * This test makes sure PHY declare the state as CCA_BUSY if reception involves
369
 * a foreign signal with a received power higher than CcaEdThreshold.
370
 */
371
class WifiPhyThresholdsStrongForeignSignalTest : public WifiPhyThresholdsTest
372
{
373
public:
374
  WifiPhyThresholdsStrongForeignSignalTest ();
375
  virtual ~WifiPhyThresholdsStrongForeignSignalTest ();
376
  virtual void DoRun (void);
377
};
378
379
WifiPhyThresholdsStrongForeignSignalTest::WifiPhyThresholdsStrongForeignSignalTest ()
380
  : WifiPhyThresholdsTest ("WifiPhy reception thresholds: test weak foreign signal reception")
381
{
382
}
383
384
WifiPhyThresholdsStrongForeignSignalTest::~WifiPhyThresholdsStrongForeignSignalTest ()
385
{
386
}
387
388
void
389
WifiPhyThresholdsStrongForeignSignalTest::DoRun (void)
390
{
391
  WifiHelper::EnableLogComponents ();
392
393
  double txPowerWatts = DbmToW (-60);
394
395
  Simulator::Schedule (Seconds (1), &WifiPhyThresholdsStrongForeignSignalTest::SendSignal, this, txPowerWatts, false);
396
397
  Simulator::Run ();
398
  Simulator::Destroy ();
399
400
  NS_TEST_ASSERT_MSG_EQ (m_rxDropped + m_rxSuccess + m_rxFailure, 0, "Reception of non-wifi packet should not be triggered");
401
  NS_TEST_ASSERT_MSG_EQ (m_ccabusyStateCount, 1, "State should have moved to CCA-BUSY");
402
}
403
404
/**
405
 * \ingroup wifi-test
406
 * \ingroup tests
407
 *
408
 * \brief Wifi Phy Thresholds Test Suite
409
 */
410
class WifiPhyThresholdsTestSuite : public TestSuite
411
{
412
public:
413
  WifiPhyThresholdsTestSuite ();
414
};
415
416
WifiPhyThresholdsTestSuite::WifiPhyThresholdsTestSuite ()
417
  : TestSuite ("wifi-phy-thresholds", UNIT)
418
{
419
  AddTestCase (new WifiPhyThresholdsWeakWifiSignalTest, TestCase::QUICK);
420
  AddTestCase (new WifiPhyThresholdsWeakForeignSignalTest, TestCase::QUICK);
421
  AddTestCase (new WifiPhyThresholdsStrongWifiSignalTest, TestCase::QUICK);
422
  AddTestCase (new WifiPhyThresholdsStrongForeignSignalTest, TestCase::QUICK);
423
}
424
425
static WifiPhyThresholdsTestSuite wifiPhyThresholdsTestSuite; ///< the test suite
(-)a/src/wifi/test/wifi-test.cc (-1 lines)
 Lines 1269-1275   void Link Here 
1269
Bug2483TestCase::DoRun (void)
1269
Bug2483TestCase::DoRun (void)
1270
{
1270
{
1271
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("500")); // so as to force RTS/CTS for data frames
1271
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("500")); // so as to force RTS/CTS for data frames
1272
  Config::SetDefault ("ns3::WifiPhy::CcaMode1Threshold", DoubleValue (-62.0));
1273
1272
1274
  uint16_t channelWidth = 40; // at least 40 MHz expected here
1273
  uint16_t channelWidth = 40; // at least 40 MHz expected here
1275
1274
(-)a/src/wifi/wscript (+1 lines)
 Lines 109-114   def build(bld): Link Here 
109
        'test/wifi-aggregation-test.cc',
109
        'test/wifi-aggregation-test.cc',
110
        'test/wifi-error-rate-models-test.cc',
110
        'test/wifi-error-rate-models-test.cc',
111
        'test/wifi-transmit-mask-test.cc',
111
        'test/wifi-transmit-mask-test.cc',
112
        'test/wifi-phy-thresholds-test.cc',
112
        ]
113
        ]
113
114
114
    headers = bld(features='ns3header')
115
    headers = bld(features='ns3header')

Return to bug 2460