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

(-)a/src/devices/wifi/wifi-test.cc (+111 lines)
 Lines 1-6    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
2
/*
3
 * Copyright (c) 2005,2006 INRIA
3
 * Copyright (c) 2005,2006 INRIA
4
 *               2010      NICTA
4
 *
5
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * 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
 * it under the terms of the GNU General Public License version 2 as 
 Lines 16-21    Link Here 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 *
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
 *         Quincy Tse <quincy.tse@nicta.com.au> (Case for Bug 991)
19
 */
21
 */
20
22
21
#include "wifi-net-device.h"
23
#include "wifi-net-device.h"
 Lines 176-181    Link Here 
176
};
178
};
177
179
178
//-----------------------------------------------------------------------------
180
//-----------------------------------------------------------------------------
181
class InterferenceHelperSequenceTest : public TestCase
182
{
183
public:
184
  InterferenceHelperSequenceTest ();
185
186
  virtual bool DoRun (void);
187
private:
188
  Ptr<Node> CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
189
  void SendOnePacket (Ptr<WifiNetDevice> dev);
190
  void SwitchCh (Ptr<WifiNetDevice> dev);
191
192
  ObjectFactory m_manager;
193
  ObjectFactory m_mac;
194
  ObjectFactory m_propDelay;
195
};
196
197
InterferenceHelperSequenceTest::InterferenceHelperSequenceTest ()
198
  : TestCase ("InterferenceHelperSequence")
199
{}
200
201
void 
202
InterferenceHelperSequenceTest::SendOnePacket (Ptr<WifiNetDevice> dev)
203
{
204
  Ptr<Packet> p = Create<Packet> (9999);
205
  dev->Send (p, dev->GetBroadcast (), 1);
206
}
207
208
void
209
InterferenceHelperSequenceTest::SwitchCh (Ptr<WifiNetDevice> dev)
210
{
211
  Time now = Simulator::Now();
212
  Ptr<WifiPhy> p = dev->GetPhy ();
213
  p->SetChannelNumber (1);
214
}
215
216
Ptr<Node>
217
InterferenceHelperSequenceTest::CreateOne (Vector pos, Ptr<YansWifiChannel> channel)
218
{
219
  Ptr<Node> node = CreateObject<Node> ();
220
  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
221
222
  Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
223
  mac->ConfigureStandard (WIFI_PHY_STANDARD_80211a);
224
  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
225
  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
226
  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
227
  phy->SetErrorRateModel (error);
228
  phy->SetChannel (channel);
229
  phy->SetDevice (dev);
230
  phy->SetMobility (node);
231
  phy->ConfigureStandard (WIFI_PHY_STANDARD_80211a);
232
  Ptr<WifiRemoteStationManager> manager = m_manager.Create<WifiRemoteStationManager> ();
233
234
  mobility->SetPosition (pos);
235
  node->AggregateObject (mobility);
236
  mac->SetAddress (Mac48Address::Allocate ());
237
  dev->SetMac (mac);
238
  dev->SetPhy (phy);
239
  dev->SetRemoteStationManager (manager);
240
  node->AddDevice (dev);
241
242
  return node;
243
}
244
245
bool
246
InterferenceHelperSequenceTest::DoRun (void)
247
{
248
  m_mac.SetTypeId ("ns3::AdhocWifiMac");
249
  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
250
  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
251
252
  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
253
  Ptr<PropagationDelayModel> propDelay = m_propDelay.Create<PropagationDelayModel> ();
254
  Ptr<MatrixPropagationLossModel> propLoss = CreateObject<MatrixPropagationLossModel> ();
255
  channel->SetPropagationDelayModel (propDelay);
256
  channel->SetPropagationLossModel (propLoss);
257
258
  Ptr<Node> rxOnly = CreateOne (Vector (0.0, 0.0, 0.0), channel);
259
  Ptr<Node> senderA = CreateOne (Vector (5.0, 0.0, 0.0), channel);
260
  Ptr<Node> senderB = CreateOne (Vector (-5.0, 0.0, 0.0), channel);
261
262
  propLoss->SetLoss (senderB, rxOnly, 0, true);
263
  propLoss->SetDefaultLoss (999);
264
265
  Simulator::Schedule (Seconds (1.0),
266
      &InterferenceHelperSequenceTest::SendOnePacket, this,
267
      DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
268
269
  Simulator::Schedule (Seconds (1.0000001),
270
      &InterferenceHelperSequenceTest::SwitchCh, this,
271
      DynamicCast<WifiNetDevice> (rxOnly->GetDevice (0)));
272
273
  Simulator::Schedule (Seconds (5.0),
274
      &InterferenceHelperSequenceTest::SendOnePacket, this,
275
      DynamicCast<WifiNetDevice> (senderA->GetDevice (0)));
276
277
  Simulator::Schedule (Seconds (7.0),
278
      &InterferenceHelperSequenceTest::SendOnePacket, this,
279
      DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
280
281
  Simulator::Stop (Seconds (100.0));
282
  Simulator::Run ();
283
284
  Simulator::Destroy ();
285
  return false;
286
}
287
288
//-----------------------------------------------------------------------------
179
289
180
class WifiTestSuite : public TestSuite
290
class WifiTestSuite : public TestSuite
181
{
291
{
 Lines 188-193    Link Here 
188
{
298
{
189
  AddTestCase (new WifiTest);
299
  AddTestCase (new WifiTest);
190
  AddTestCase (new QosUtilsIsOldPacketTest);
300
  AddTestCase (new QosUtilsIsOldPacketTest);
301
  AddTestCase (new InterferenceHelperSequenceTest); // Bug 991
191
}
302
}
192
303
193
WifiTestSuite g_wifiTestSuite;
304
WifiTestSuite g_wifiTestSuite;

Return to bug 991