From 218b74f3c196bab99cdb5aa3b4ded28a084960dc Mon Sep 17 00:00:00 2001 From: Quincy Tse Date: Wed, 17 Nov 2010 17:26:23 +0100 Subject: [PATCH] TestCase for bug 991 --- src/devices/wifi/wifi-test.cc | 111 ++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/devices/wifi/wifi-test.cc b/src/devices/wifi/wifi-test.cc index de09455e1..8d8ca4be4 100644 --- a/src/devices/wifi/wifi-test.cc +++ b/src/devices/wifi/wifi-test.cc @@ -1,6 +1,7 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2005,2006 INRIA + * 2010 NICTA * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -16,6 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Mathieu Lacage + * Quincy Tse (Case for Bug 991) */ #include "wifi-net-device.h" @@ -175,6 +177,114 @@ public: } }; +//----------------------------------------------------------------------------- +class InterferenceHelperSequenceTest : public TestCase +{ +public: + InterferenceHelperSequenceTest (); + + virtual bool DoRun (void); +private: + Ptr CreateOne (Vector pos, Ptr channel); + void SendOnePacket (Ptr dev); + void SwitchCh (Ptr dev); + + ObjectFactory m_manager; + ObjectFactory m_mac; + ObjectFactory m_propDelay; +}; + +InterferenceHelperSequenceTest::InterferenceHelperSequenceTest () + : TestCase ("InterferenceHelperSequence") +{} + +void +InterferenceHelperSequenceTest::SendOnePacket (Ptr dev) +{ + Ptr p = Create (9999); + dev->Send (p, dev->GetBroadcast (), 1); +} + +void +InterferenceHelperSequenceTest::SwitchCh (Ptr dev) +{ + Time now = Simulator::Now(); + Ptr p = dev->GetPhy (); + p->SetChannelNumber (1); +} + +Ptr +InterferenceHelperSequenceTest::CreateOne (Vector pos, Ptr channel) +{ + Ptr node = CreateObject (); + Ptr dev = CreateObject (); + + Ptr mac = m_mac.Create (); + mac->ConfigureStandard (WIFI_PHY_STANDARD_80211a); + Ptr mobility = CreateObject (); + Ptr phy = CreateObject (); + Ptr error = CreateObject (); + phy->SetErrorRateModel (error); + phy->SetChannel (channel); + phy->SetDevice (dev); + phy->SetMobility (node); + phy->ConfigureStandard (WIFI_PHY_STANDARD_80211a); + Ptr manager = m_manager.Create (); + + mobility->SetPosition (pos); + node->AggregateObject (mobility); + mac->SetAddress (Mac48Address::Allocate ()); + dev->SetMac (mac); + dev->SetPhy (phy); + dev->SetRemoteStationManager (manager); + node->AddDevice (dev); + + return node; +} + +bool +InterferenceHelperSequenceTest::DoRun (void) +{ + m_mac.SetTypeId ("ns3::AdhocWifiMac"); + m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel"); + m_manager.SetTypeId ("ns3::ConstantRateWifiManager"); + + Ptr channel = CreateObject (); + Ptr propDelay = m_propDelay.Create (); + Ptr propLoss = CreateObject (); + channel->SetPropagationDelayModel (propDelay); + channel->SetPropagationLossModel (propLoss); + + Ptr rxOnly = CreateOne (Vector (0.0, 0.0, 0.0), channel); + Ptr senderA = CreateOne (Vector (5.0, 0.0, 0.0), channel); + Ptr senderB = CreateOne (Vector (-5.0, 0.0, 0.0), channel); + + propLoss->SetLoss (senderB, rxOnly, 0, true); + propLoss->SetDefaultLoss (999); + + Simulator::Schedule (Seconds (1.0), + &InterferenceHelperSequenceTest::SendOnePacket, this, + DynamicCast (senderB->GetDevice (0))); + + Simulator::Schedule (Seconds (1.0000001), + &InterferenceHelperSequenceTest::SwitchCh, this, + DynamicCast (rxOnly->GetDevice (0))); + + Simulator::Schedule (Seconds (5.0), + &InterferenceHelperSequenceTest::SendOnePacket, this, + DynamicCast (senderA->GetDevice (0))); + + Simulator::Schedule (Seconds (7.0), + &InterferenceHelperSequenceTest::SendOnePacket, this, + DynamicCast (senderB->GetDevice (0))); + + Simulator::Stop (Seconds (100.0)); + Simulator::Run (); + + Simulator::Destroy (); + return false; +} + //----------------------------------------------------------------------------- class WifiTestSuite : public TestSuite @@ -188,6 +298,7 @@ WifiTestSuite::WifiTestSuite () { AddTestCase (new WifiTest); AddTestCase (new QosUtilsIsOldPacketTest); + AddTestCase (new InterferenceHelperSequenceTest); // Bug 991 } WifiTestSuite g_wifiTestSuite;