A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wifi-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  * 2010 NICTA
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Quincy Tse <quincy.tse@nicta.com.au> (Case for Bug 991)
21  */
22 
23 #include "ns3/wifi-net-device.h"
24 #include "ns3/yans-wifi-channel.h"
25 #include "ns3/adhoc-wifi-mac.h"
26 #include "ns3/yans-wifi-phy.h"
27 #include "ns3/arf-wifi-manager.h"
28 #include "ns3/propagation-delay-model.h"
29 #include "ns3/propagation-loss-model.h"
30 #include "ns3/error-rate-model.h"
31 #include "ns3/yans-error-rate-model.h"
32 #include "ns3/constant-position-mobility-model.h"
33 #include "ns3/node.h"
34 #include "ns3/simulator.h"
35 #include "ns3/test.h"
36 #include "ns3/object-factory.h"
37 #include "ns3/dca-txop.h"
38 #include "ns3/mac-rx-middle.h"
39 #include "ns3/pointer.h"
40 
41 namespace ns3 {
42 
43 class WifiTest : public TestCase
44 {
45 public:
46  WifiTest ();
47 
48  virtual void DoRun (void);
49 private:
50  void RunOne (void);
51  void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
53 
57 };
58 
60  : TestCase ("Wifi")
61 {
62 }
63 
64 void
66 {
67  Ptr<Packet> p = Create<Packet> ();
68  dev->Send (p, dev->GetBroadcast (), 1);
69 }
70 
71 void
73 {
74  Ptr<Node> node = CreateObject<Node> ();
75  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
76 
77  Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
79  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
80  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
81  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
82  phy->SetErrorRateModel (error);
83  phy->SetChannel (channel);
84  phy->SetDevice (dev);
85  phy->SetMobility (node);
86  phy->ConfigureStandard (WIFI_PHY_STANDARD_80211a);
88 
89  mobility->SetPosition (pos);
90  node->AggregateObject (mobility);
91  mac->SetAddress (Mac48Address::Allocate ());
92  dev->SetMac (mac);
93  dev->SetPhy (phy);
94  dev->SetRemoteStationManager (manager);
95  node->AddDevice (dev);
96 
98 }
99 
100 void
102 {
103  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
105  Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
106  channel->SetPropagationDelayModel (propDelay);
107  channel->SetPropagationLossModel (propLoss);
108 
109  CreateOne (Vector (0.0, 0.0, 0.0), channel);
110  CreateOne (Vector (5.0, 0.0, 0.0), channel);
111  CreateOne (Vector (5.0, 0.0, 0.0), channel);
112 
113  Simulator::Run ();
115 
116  Simulator::Stop (Seconds (10.0));
117 }
118 
119 void
121 {
122  m_mac.SetTypeId ("ns3::AdhocWifiMac");
123  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
124 
125  m_manager.SetTypeId ("ns3::ArfWifiManager");
126  RunOne ();
127  m_manager.SetTypeId ("ns3::AarfWifiManager");
128  RunOne ();
129  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
130  RunOne ();
131  m_manager.SetTypeId ("ns3::OnoeWifiManager");
132  RunOne ();
133  m_manager.SetTypeId ("ns3::AmrrWifiManager");
134  RunOne ();
135  m_manager.SetTypeId ("ns3::IdealWifiManager");
136  RunOne ();
137 
138  m_mac.SetTypeId ("ns3::AdhocWifiMac");
139  RunOne ();
140  m_mac.SetTypeId ("ns3::ApWifiMac");
141  RunOne ();
142  m_mac.SetTypeId ("ns3::StaWifiMac");
143  RunOne ();
144 
145 
146  m_propDelay.SetTypeId ("ns3::RandomPropagationDelayModel");
147  m_mac.SetTypeId ("ns3::AdhocWifiMac");
148  RunOne ();
150 }
151 
152 //-----------------------------------------------------------------------------
154 {
155 public:
156  QosUtilsIsOldPacketTest () : TestCase ("QosUtilsIsOldPacket")
157  {
158  }
159  virtual void DoRun (void)
160  {
161  // startingSeq=0, seqNum=2047
162  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2047), false, "2047 is new in comparison to 0");
163  // startingSeq=0, seqNum=2048
164  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2048), true, "2048 is old in comparison to 0");
165  // startingSeq=2048, seqNum=0
166  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 0), true, "0 is old in comparison to 2048");
167  // startingSeq=4095, seqNum=0
168  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 0), false, "0 is new in comparison to 4095");
169  // startingSeq=0, seqNum=4095
170  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 4095), true, "4095 is old in comparison to 0");
171  // startingSeq=4095 seqNum=2047
172  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 2047), true, "2047 is old in comparison to 4095");
173  // startingSeq=2048 seqNum=4095
174  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 4095), false, "4095 is new in comparison to 2048");
175  // startingSeq=2049 seqNum=0
176  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2049, 0), false, "0 is new in comparison to 2049");
177  }
178 };
179 
180 //-----------------------------------------------------------------------------
182 {
183 public:
185 
186  virtual void DoRun (void);
187 private:
190  void SwitchCh (Ptr<WifiNetDevice> dev);
191 
195 };
196 
198  : TestCase ("InterferenceHelperSequence")
199 {
200 }
201 
202 void
204 {
205  Ptr<Packet> p = Create<Packet> (9999);
206  dev->Send (p, dev->GetBroadcast (), 1);
207 }
208 
209 void
211 {
212  Ptr<WifiPhy> p = dev->GetPhy ();
213  p->SetChannelNumber (1);
214 }
215 
216 Ptr<Node>
218 {
219  Ptr<Node> node = CreateObject<Node> ();
220  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
221 
222  Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
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);
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 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> ();
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->GetObject<MobilityModel> (), rxOnly->GetObject<MobilityModel> (), 0, true);
263  propLoss->SetDefaultLoss (999);
264 
267  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
268 
269  Simulator::Schedule (Seconds (1.0000001),
271  DynamicCast<WifiNetDevice> (rxOnly->GetDevice (0)));
272 
275  DynamicCast<WifiNetDevice> (senderA->GetDevice (0)));
276 
279  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
280 
281  Simulator::Stop (Seconds (100.0));
282  Simulator::Run ();
283 
285 }
286 
287 //-----------------------------------------------------------------------------
288 
289 class WifiTestSuite : public TestSuite
290 {
291 public:
292  WifiTestSuite ();
293 };
294 
296  : TestSuite ("devices-wifi", UNIT)
297 {
298  AddTestCase (new WifiTest);
301 }
302 
304 
305 } // namespace ns3