00001 #ifdef RUN_SELF_TESTS
00002
00003 #include "wifi-net-device.h"
00004 #include "yans-wifi-channel.h"
00005 #include "adhoc-wifi-mac.h"
00006 #include "yans-wifi-phy.h"
00007 #include "arf-wifi-manager.h"
00008 #include "propagation-delay-model.h"
00009 #include "propagation-loss-model.h"
00010 #include "error-rate-model.h"
00011 #include "yans-error-rate-model.h"
00012 #include "ns3/static-mobility-model.h"
00013 #include "ns3/node.h"
00014 #include "ns3/simulator.h"
00015 #include "ns3/test.h"
00016 #include "ns3/object-factory.h"
00017
00018 namespace ns3 {
00019
00020 class WifiTest : public Test
00021 {
00022 public:
00023 WifiTest ();
00024
00025 virtual bool RunTests (void);
00026 private:
00027 void RunOne (void);
00028 void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
00029 void SendOnePacket (Ptr<WifiNetDevice> dev);
00030
00031 ObjectFactory m_manager;
00032 ObjectFactory m_mac;
00033 ObjectFactory m_propDelay;
00034 };
00035
00036 WifiTest::WifiTest ()
00037 : Test ("Wifi")
00038 {}
00039
00040 void
00041 WifiTest::SendOnePacket (Ptr<WifiNetDevice> dev)
00042 {
00043 Ptr<Packet> p = Create<Packet> ();
00044 dev->Send (p, dev->GetBroadcast (), 1);
00045 }
00046
00047 void
00048 WifiTest::CreateOne (Vector pos, Ptr<YansWifiChannel> channel)
00049 {
00050 Ptr<Node> node = CreateObject<Node> ();
00051 Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
00052
00053 Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
00054 Ptr<StaticMobilityModel> mobility = CreateObject<StaticMobilityModel> ();
00055 Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
00056 Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
00057 phy->SetErrorRateModel (error);
00058 phy->SetChannel (channel);
00059 phy->SetDevice (dev);
00060 phy->SetMobility (node);
00061 Ptr<WifiRemoteStationManager> manager = m_manager.Create<WifiRemoteStationManager> ();
00062
00063 mobility->SetPosition (pos);
00064 node->AggregateObject (mobility);
00065 mac->SetAddress (Mac48Address::Allocate ());
00066 dev->SetMac (mac);
00067 dev->SetPhy (phy);
00068 dev->SetRemoteStationManager (manager);
00069 node->AddDevice (dev);
00070
00071 Simulator::Schedule (Seconds (1.0), &WifiTest::SendOnePacket, this, dev);
00072 }
00073
00074 void
00075 WifiTest::RunOne (void)
00076 {
00077 Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
00078 Ptr<PropagationDelayModel> propDelay = m_propDelay.Create<PropagationDelayModel> ();
00079 Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
00080 channel->SetPropagationDelayModel (propDelay);
00081 channel->SetPropagationLossModel (propLoss);
00082
00083 CreateOne (Vector (0.0, 0.0, 0.0), channel);
00084 CreateOne (Vector (5.0, 0.0, 0.0), channel);
00085 CreateOne (Vector (5.0, 0.0, 0.0), channel);
00086
00087 Simulator::Run ();
00088 Simulator::Destroy ();
00089
00090 Simulator::Stop (Seconds (10.0));
00091 }
00092
00093 bool
00094 WifiTest::RunTests (void)
00095 {
00096 bool result = true;
00097
00098 m_mac.SetTypeId ("ns3::AdhocWifiMac");
00099 m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
00100
00101
00102 m_manager.SetTypeId ("ns3::ArfWifiManager");
00103 RunOne ();
00104 m_manager.SetTypeId ("ns3::AarfWifiManager");
00105 RunOne ();
00106 m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
00107 RunOne ();
00108 m_manager.SetTypeId ("ns3::OnoeWifiManager");
00109 RunOne ();
00110 m_manager.SetTypeId ("ns3::AmrrWifiManager");
00111 RunOne ();
00112 m_manager.SetTypeId ("ns3::IdealWifiManager");
00113 RunOne ();
00114
00115 m_mac.SetTypeId ("ns3::AdhocWifiMac");
00116 RunOne ();
00117 m_mac.SetTypeId ("ns3::NqapWifiMac");
00118 RunOne ();
00119 m_mac.SetTypeId ("ns3::NqstaWifiMac");
00120 RunOne ();
00121
00122
00123 m_propDelay.SetTypeId ("ns3::RandomPropagationDelayModel");
00124 m_mac.SetTypeId ("ns3::AdhocWifiMac");
00125 RunOne ();
00126
00127 return result;
00128 }
00129
00130 static WifiTest g_wifiTest;
00131
00132
00133 }
00134
00135 #endif