A Discrete-Event Network Simulator
API
ocb-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Dalian University of Technology
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: Junling Bu <linlinjavaer@gmail.com>
19 */
20
21#include <iostream>
22#include "ns3/test.h"
23#include "ns3/rng-seed-manager.h"
24#include "ns3/config.h"
25#include "ns3/data-rate.h"
26#include "ns3/vector.h"
27#include "ns3/string.h"
28#include "ns3/packet-socket-address.h"
29#include "ns3/mobility-model.h"
30#include "ns3/yans-wifi-helper.h"
31#include "ns3/sta-wifi-mac.h"
32#include "ns3/qos-txop.h"
33#include "ns3/position-allocator.h"
34#include "ns3/packet-socket-helper.h"
35#include "ns3/mobility-helper.h"
36#include "ns3/wifi-net-device.h"
37#include "ns3/packet-socket-server.h"
38#include "ns3/packet-socket-client.h"
39#include "ns3/ocb-wifi-mac.h"
40#include "ns3/wifi-80211p-helper.h"
41#include "ns3/wave-mac-helper.h"
42
43using namespace ns3;
44// helper function to assign streams to random variables, to control
45// randomness in the tests
46static void
48{
49 int64_t currentStream = stream;
50 PointerValue ptr;
51 if (!mac->GetQosSupported ())
52 {
53 mac->GetAttribute ("Txop", ptr);
54 Ptr<Txop> txop = ptr.Get<Txop> ();
55 currentStream += txop->AssignStreams (currentStream);
56 }
57 else
58 {
59 mac->GetAttribute ("VO_Txop", ptr);
60 Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
61 currentStream += vo_txop->AssignStreams (currentStream);
62
63 mac->GetAttribute ("VI_Txop", ptr);
64 Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
65 currentStream += vi_txop->AssignStreams (currentStream);
66
67 mac->GetAttribute ("BE_Txop", ptr);
68 Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
69 currentStream += be_txop->AssignStreams (currentStream);
70
71 mac->GetAttribute ("BK_Txop", ptr);
72 Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
73 currentStream += bk_txop->AssignStreams (currentStream);
74 }
75}
76
84{
85public:
86 OcbWifiMacTestCase (void);
87 virtual ~OcbWifiMacTestCase (void);
88private:
89 virtual void DoRun (void);
90
96 void MacAssoc (std::string context, Mac48Address bssid);
105 void PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble);
114 void PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower);
120 Vector GetCurrentPosition (uint32_t i);
125 void AdvancePosition (Ptr<Node> node);
126
128 void PreRandomConfiguration (void);
134 void ConfigureApStaMode (Ptr<Node> static_node, Ptr<Node> mobile_node);
140 void ConfigureAdhocMode (Ptr<Node> static_node, Ptr<Node> mobile_node);
146 void ConfigureOcbMode (Ptr<Node> static_node, Ptr<Node> mobile_node);
152 void PostDeviceConfiguration (Ptr<Node> static_node, Ptr<Node> mobile_node);
153
155 Vector phytx_pos;
156
159
161 Vector phyrx_pos;
162
163 // nodes.Get (0) is static node
164 // nodes.Get (1) is mobile node
166};
167
169 : TestCase ("Association time: Ap+Sta mode vs Adhoc mode vs Ocb mode")
170{
171}
172
174{
175}
176
177// mobility is like walk on line with velocity 5 m/s
178// We prefer to update 0.5m every 0.1s rather than 5m every 1s
179void
181{
183 Vector pos = mobility->GetPosition ();
184 pos.x -= 0.5;
185 if (pos.x < 1.0 )
186 {
187 pos.x = 1.0;
188 return;
189 }
190 mobility->SetPosition (pos);
191
192 Simulator::Schedule (Seconds (0.1), &OcbWifiMacTestCase::AdvancePosition, this, node);
193}
194
195// here are only two nodes, a stationary and a mobile one
196// the i value of the first = 0; the i value of second = 1.
197Vector
199{
200 NS_ASSERT (i < 2);
201 Ptr<Node> node = nodes.Get (i);
203 Vector pos = mobility->GetPosition ();
204 return pos;
205}
206
207void
209{
210 if (macassoc_time == Time (0))
211 {
212 macassoc_time = Now ();
214 std::cout << "MacAssoc time = " << macassoc_time.As (Time::NS)
215 << " position = " << macassoc_pos
216 << std::endl;
217 }
218}
219
220// We want to get the time that sta receives the first beacon frame from AP
221// it means that in this time this sta has ability to receive frame
222void
223OcbWifiMacTestCase::PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
224{
225 if (phyrx_time == Time (0))
226 {
227 phyrx_time = Now ();
229 std::cout << "PhyRxOk time = " << phyrx_time.As (Time::NS)
230 << " position = " << phyrx_pos
231 << std::endl;
232 }
233}
234
235// We want to get the time that STA sends the first data packet successfully
236void
237OcbWifiMacTestCase::PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
238{
240 packet->PeekHeader (h);
241 if ((phytx_time == Time (0)) && h.IsData ())
242 {
243 phytx_time = Now ();
245 std::cout << "PhyTx data time = " << phytx_time.As (Time::NS)
246 << " position = " << phytx_pos
247 << std::endl;
248 }
249}
250
251void
253{
254 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
255 YansWifiPhyHelper wifiPhy;
256 wifiPhy.SetChannel (wifiChannel.Create ());
257
258 Ssid ssid = Ssid ("wifi-default");
259 WifiMacHelper wifiStaMac;
260 wifiStaMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid));
261 WifiMacHelper wifiApMac;
262 wifiApMac.SetType ("ns3::ApWifiMac","Ssid", SsidValue (ssid));
263
265 wifi.SetStandard (WIFI_STANDARD_80211p);
266 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
267 "DataMode", StringValue ("OfdmRate6MbpsBW10MHz"),
268 "ControlMode",StringValue ("OfdmRate6MbpsBW10MHz"));
269 wifi.Install (wifiPhy, wifiStaMac, mobile_node);
270 wifi.Install (wifiPhy, wifiApMac, static_node);
271}
272
273void
275{
276 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
277 YansWifiPhyHelper wifiPhy;
278 wifiPhy.SetChannel (wifiChannel.Create ());
279
280 WifiMacHelper wifiMac;
281 wifiMac.SetType ("ns3::AdhocWifiMac");
282
284 wifi.SetStandard (WIFI_STANDARD_80211p);
285 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
286 "DataMode", StringValue ("OfdmRate6MbpsBW10MHz"),
287 "ControlMode",StringValue ("OfdmRate6MbpsBW10MHz"));
288 wifi.Install (wifiPhy, wifiMac, mobile_node);
289 wifi.Install (wifiPhy, wifiMac, static_node);
290}
291
292void
294{
295 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
296 YansWifiPhyHelper wifiPhy;
297 wifiPhy.SetChannel (wifiChannel.Create ());
298
299 NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
300
301 Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
302 wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
303 "DataMode", StringValue ("OfdmRate6MbpsBW10MHz"),
304 "ControlMode",StringValue ("OfdmRate6MbpsBW10MHz"));
305 wifi80211p.Install (wifiPhy, wifi80211pMac, mobile_node);
306 wifi80211p.Install (wifiPhy, wifi80211pMac, static_node);
307}
308
309void
311{
312 Ptr<WifiNetDevice> static_device = DynamicCast<WifiNetDevice> (static_node->GetDevice (0));
313 Ptr<WifiNetDevice> mobile_device = DynamicCast<WifiNetDevice> (mobile_node->GetDevice (0));
314
315 // Fix the stream assignment to the Dcf Txop objects (backoffs)
316 // The below stream assignment will result in the Txop object
317 // using a backoff value of zero for this test when the
318 // Txop::EndTxNoAck() calls to StartBackoffNow()
319 AssignWifiRandomStreams (static_device->GetMac (), 21);
320 AssignWifiRandomStreams (mobile_device->GetMac (), 22);
321
322 // setup mobility
323 // the initial position of static node is at 0,
324 // and the initial position of mobile node is 350.
326 mobility.Install (mobile_node);
327 mobility.Install (static_node);
328 Ptr<MobilityModel> mm = mobile_node->GetObject<MobilityModel> ();
329 Vector possta = mm->GetPosition ();
330 possta.x = 350;
331 mm->SetPosition (possta);
332 Simulator::Schedule (Seconds (1.0), &OcbWifiMacTestCase::AdvancePosition, this, mobile_node);
333
334 PacketSocketAddress socket;
335 socket.SetSingleDevice (mobile_device->GetIfIndex ());
336 socket.SetPhysicalAddress (static_device->GetAddress ());
337 socket.SetProtocol (1);
338
339 // give packet socket powers to nodes.
340 PacketSocketHelper packetSocket;
341 packetSocket.Install (static_node);
342 packetSocket.Install (mobile_node);
343
344 Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
345 client->SetRemote (socket);
346 mobile_node->AddApplication (client);
347 client->SetStartTime (Seconds (0.5));
348 client->SetStopTime (Seconds (70.0));
349
350 Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
351 server->SetLocal (socket);
352 static_node->AddApplication (server);
353 server->SetStartTime (Seconds (0.0));
354 server->SetStopTime (Seconds (70.5));
355
357 phytx_pos = macassoc_pos = phyrx_pos = Vector ();
358
359 if ( DynamicCast<StaWifiMac> (mobile_device->GetMac () ) )
360 {
361 // This trace is available only in a StaWifiMac
362 Config::Connect ("/NodeList/1/DeviceList/*/Mac/Assoc", MakeCallback (&OcbWifiMacTestCase::MacAssoc, this));
363 }
364 Config::Connect ("/NodeList/1/DeviceList/*/Phy/State/RxOk", MakeCallback (&OcbWifiMacTestCase::PhyRxOkTrace, this));
365 Config::Connect ("/NodeList/1/DeviceList/*/Phy/State/Tx", MakeCallback (&OcbWifiMacTestCase::PhyTxTrace, this));
366}
367
381void
383{
384 std::cout << "test time point for Ap-Sta mode" << std::endl;
386 nodes = NodeContainer ();
387 nodes.Create (2);
388 Ptr<Node> static_node = nodes.Get (0);
389 Ptr<Node> mobile_node = nodes.Get (1);
390 ConfigureApStaMode (static_node, mobile_node);
391 PostDeviceConfiguration (static_node, mobile_node);
392 Simulator::Stop (Seconds (71.0));
393 Simulator::Run ();
394 Simulator::Destroy ();
395 NS_TEST_ASSERT_MSG_LT (phyrx_time, macassoc_time, "In Sta mode with AP, you cannot associate until receive beacon or AssocResponse frame" );
396 NS_TEST_ASSERT_MSG_LT (macassoc_time, phytx_time, "In Sta mode with AP, you cannot send data packet until associate" );
397 //Are these position tests redundant with time check tests?
398 //NS_TEST_ASSERT_MSG_GT ((phyrx_pos.x - macassoc_pos.x), 0.0, "");
399 //actually macassoc_pos.x - phytx_pos.x is greater than 0
400 //however associate switch to send is so fast with less than 100ms
401 //and in our mobility model that every 0.1s update position,
402 //so turn out to be that macassoc_pos.x - phytx_pos.x is equal to 0
403 //NS_TEST_ASSERT_MSG_GT ((macassoc_pos.x - phytx_pos.x), 0.0, "");
404
405 std::cout << "test time point for Adhoc mode" << std::endl;
407 nodes = NodeContainer ();
408 nodes.Create (2);
409 static_node = nodes.Get (0);
410 mobile_node = nodes.Get (1);
411 ConfigureAdhocMode (static_node, mobile_node);
412 PostDeviceConfiguration (static_node, mobile_node);
413 Simulator::Stop (Seconds (71.0));
414 Simulator::Run ();
415 Simulator::Destroy ();
416 // below test assert will fail, because AdhocWifiMac has not implement state machine.
417 // if someone takes a look at the output in adhoc mode and in Ocb mode
418 // he will find these two outputs are almost same.
419 //NS_TEST_ASSERT_MSG_LT (phyrx_time, macassoc_time, "In Adhoc mode, you cannot associate until receive beacon or AssocResponse frame" );
420 //NS_TEST_ASSERT_MSG_LT (macassoc_time, phytx_time, "In Adhoc mode, you cannot send data packet until associate" );
421 //NS_TEST_ASSERT_MSG_GT ((phyrx_pos.x - macassoc_pos.x), 0.0, "");
422 // below test assert result refer to Ap-Sta mode
423 //NS_TEST_ASSERT_MSG_GT ((macassoc_pos.x - phytx_pos.x), 0.0, "");
424
425 std::cout << "test time point for Ocb mode" << std::endl;
427 nodes = NodeContainer ();
428 nodes.Create (2);
429 static_node = nodes.Get (0);
430 mobile_node = nodes.Get (1);
431 ConfigureOcbMode (static_node, mobile_node);
432 PostDeviceConfiguration (static_node, mobile_node);
433 Simulator::Stop (Seconds (71.0));
434 Simulator::Run ();
435 Simulator::Destroy ();
436 NS_TEST_ASSERT_MSG_EQ (macassoc_time.GetNanoSeconds(), 0, "In Ocb mode, there is no associate state machine" );
437 NS_TEST_ASSERT_MSG_LT (phytx_time, phyrx_time, "before mobile node receives frames from far static node, it can send data packet directly" );
439 NS_TEST_ASSERT_MSG_GT ((phytx_pos.x - phyrx_pos.x), 0.0, "");
440}
441void
443{
444 // Assign a seed and run number, and later fix the assignment of streams to
445 // WiFi random variables, so that the first backoff used is zero slots
446 RngSeedManager::SetSeed (1);
447 RngSeedManager::SetRun (17);
448 // the WiFi random variables is set in PostDeviceConfiguration method.
449}
450
458{
459public:
460 OcbTestSuite ();
461};
462
464 : TestSuite ("wave-80211p-ocb", UNIT)
465{
466 // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
467 AddTestCase (new OcbWifiMacTestCase, TestCase::QUICK);
468}
469
470// Do not forget to allocate an instance of this TestSuite
472
Ocb Test Suite.
Ocb Wifi Mac Test Case.
Time phytx_time
Phy transmit time.
void PhyTxTrace(std::string context, Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
Phy transmit trace function.
Vector macassoc_pos
MAC associate position.
void ConfigureApStaMode(Ptr< Node > static_node, Ptr< Node > mobile_node)
Configure AP STA mode function.
void PostDeviceConfiguration(Ptr< Node > static_node, Ptr< Node > mobile_node)
Post device configuration function.
virtual void DoRun(void)
static-node:0 <-— mobile-node:1
void PreRandomConfiguration(void)
Pre random configuration function.
Vector GetCurrentPosition(uint32_t i)
Get current position function.
Time macassoc_time
MAC associate time.
void PhyRxOkTrace(std::string context, Ptr< const Packet > packet, double snr, WifiMode mode, enum WifiPreamble preamble)
Phy receive ok trace function.
void ConfigureAdhocMode(Ptr< Node > static_node, Ptr< Node > mobile_node)
Configure adhoc mode function.
void MacAssoc(std::string context, Mac48Address bssid)
MAC associate function.
virtual ~OcbWifiMacTestCase(void)
void AdvancePosition(Ptr< Node > node)
Advance position function.
void ConfigureOcbMode(Ptr< Node > static_node, Ptr< Node > mobile_node)
Configure OCB mode function.
Vector phytx_pos
Phy transmit position.
NodeContainer nodes
the nodes
Time phyrx_time
Phy receive time.
Vector phyrx_pos
Phy receive position.
an EUI-48 address
Definition: mac48-address.h:44
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
void SetPosition(const Vector &position)
Vector GetPosition(void) const
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
Nqos Wave Mac Helper class.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Ptr< T > Get(void) const
Definition: pointer.h:201
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:72
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:432
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:65
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:309
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
helps to create wifi 802.11p objects of WifiNetDevice class
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &macHelper, NodeContainer c) const
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:723
Implements the IEEE 802.11 MAC header.
bool IsData(void) const
Return true if the Type is DATA.
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
represent a single transmission mode
Definition: wifi-mode.h:48
Ptr< WifiMac > GetMac(void) const
Address GetAddress(void) const override
uint32_t GetIfIndex(void) const override
manage and create wifi channel objects for the YANS model.
Ptr< YansWifiChannel > Create(void) const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:675
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:141
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:825
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
@ WIFI_STANDARD_80211p
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
ssid
Definition: third.py:97
mac
Definition: third.py:96
wifi
Definition: third.py:99
mobility
Definition: third.py:107
static void AssignWifiRandomStreams(Ptr< WifiMac > mac, int64_t stream)
static OcbTestSuite ocbTestSuite
the test suite