A Discrete-Event Network Simulator
API
mac-extension-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: Junling Bu <linlinjavaer@gmail.com>
17  */
18 #include <cmath>
19 #include "ns3/test.h"
20 #include "ns3/config.h"
21 #include "ns3/string.h"
22 #include "ns3/node-list.h"
23 #include "ns3/mobility-model.h"
24 #include "ns3/yans-wifi-helper.h"
25 #include "ns3/mobility-helper.h"
26 #include "ns3/wave-net-device.h"
27 #include "ns3/wave-mac-helper.h"
28 #include "ns3/wave-helper.h"
29 
30 using namespace ns3;
31 
50 {
51 public:
53  virtual ~ChannelCoordinationTestCase (void);
54 
55  // below three methods are used in CoordinationTestListener
60  void NotifyCchStartNow (Time duration);
65  void NotifySchStartNow (Time duration);
71  void NotifyGuardStartNow (Time duration, bool inCchInterval);
72 private:
79  void TestIntervalAfter (bool cchi, bool schi, bool guardi);
80  virtual void DoRun (void);
82 
83 };
84 
92 {
93 public:
100  : m_coordinatorTest (coordinatorTest)
101  {
102  }
104  {
105  }
106  virtual void NotifyCchSlotStart (Time duration)
107  {
108  m_coordinatorTest->NotifyCchStartNow (duration);
109  }
110  virtual void NotifySchSlotStart (Time duration)
111  {
112  m_coordinatorTest->NotifySchStartNow (duration);
113  }
114  virtual void NotifyGuardSlotStart (Time duration, bool cchi)
115  {
116  m_coordinatorTest->NotifyGuardStartNow (duration, cchi);
117  }
119 };
120 
122  : TestCase ("channel-coordination")
123 {
124 }
126 {
127 }
128 
129 void
130 ChannelCoordinationTestCase::TestIntervalAfter (bool cchi, bool schi, bool guardi)
131 {
132  uint32_t now = Now ().GetMilliSeconds ();
133  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsCchInterval (), cchi, "now is " << now << "ms "
134  "check whether is CCH interval");
135  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsSchInterval (), schi, "now is " << now << "ms "
136  "check whether is SCH interval");
137  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsGuardInterval (), guardi, "now is " << now << "ms "
138  "check whether is Guard interval");
139 }
140 void
142 {
143  // this method shall be called at 4ms, 104ms, ... synci * n + guardi
144  // synci is sync interval with default value 100ms
145  // guardi is guard interval with default value 4ms
146  // n is sequence number
147  int64_t now = Now ().GetMilliSeconds ();
148  int64_t synci = m_coordinator->GetSyncInterval ().GetMilliSeconds ();
149  int64_t guardi = m_coordinator->GetGuardInterval ().GetMilliSeconds ();
150  bool test = (((now - guardi) % synci) == 0);
151  NS_TEST_EXPECT_MSG_EQ (test, true, "the time of now shall be synci * n + guardi");
152 
153  // besides that, the argument duration shall be cchi - guardi
155  NS_TEST_EXPECT_MSG_EQ ((duration == d), true, "the duration shall be cchi - guardi");
156 }
157 
158 void
160 {
161  // this method shall be called at 54ms, 154ms, ... synci * n + cchi + guardi
162  // synci is sync interval with default value 100ms
163  // cchi is CCH interval with default value 50ms
164  // guardi is guard interval with default value 4ms
165  // n is sequence number
166  int64_t now = Now ().GetMilliSeconds ();
167  int64_t synci = m_coordinator->GetSyncInterval ().GetMilliSeconds ();
168  int64_t cchi = m_coordinator->GetCchInterval ().GetMilliSeconds ();
169  int64_t guardi = m_coordinator->GetGuardInterval ().GetMilliSeconds ();
170  bool test = ((now - guardi - cchi) % synci == 0);
171  NS_TEST_EXPECT_MSG_EQ (test, true, "the time of now shall be synci * n + cchi + guardi");
172 
173  // besides that, the argument duration shall be schi - guardi
175  NS_TEST_EXPECT_MSG_EQ ((duration == d), true, "the duration shall be schi - guardi");
176 }
177 
178 void
180 {
181  int64_t now = Now ().GetMilliSeconds ();
182  int64_t sync = m_coordinator->GetSyncInterval ().GetMilliSeconds ();
183  int64_t cchi = m_coordinator->GetCchInterval ().GetMilliSeconds ();
184  bool test = false;
185  if (inCchInterval)
186  {
187  // if cchi, this method will be called at 0ms, 100ms, sync * n
188  test = ((now % sync) == 0);
189  NS_TEST_EXPECT_MSG_EQ (test, true, "the time of now shall be sync * n");
190  }
191  else
192  {
193  // if schi, this method will be called at 50ms, 150ms, sync * n + cchi
194  test = (((now - cchi) % sync) == 0);
195  NS_TEST_EXPECT_MSG_EQ (test, true, "the time of now shall be sync * n");
196  }
197  // the duration shall be guardi
198  test = (duration == m_coordinator->GetGuardInterval ());
199  NS_TEST_EXPECT_MSG_EQ (test, true, "the duration shall be guard interval");
200 }
201 
202 void
204 {
205  // first test configure method
206  m_coordinator = CreateObject<ChannelCoordinator> ();
207  NS_TEST_EXPECT_MSG_EQ (m_coordinator->GetCchInterval (), MilliSeconds (50), "normally CCH interval is 50ms");
208  NS_TEST_EXPECT_MSG_EQ (m_coordinator->GetSchInterval (), MilliSeconds (50), "normally SCH interval is 50ms");
209  NS_TEST_EXPECT_MSG_EQ (m_coordinator->GetSyncInterval (), MilliSeconds (100), "normally Sync interval is 50ms");
210  NS_TEST_EXPECT_MSG_EQ (m_coordinator->GetGuardInterval (), MilliSeconds (4), "normally Guard interval is 50ms");
213  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsValidConfig (), true, "valid configuration of channel intervals");
216  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsValidConfig (), false, "invalid configuration of channel intervals");
220  NS_TEST_EXPECT_MSG_EQ (m_coordinator->IsValidConfig (), false, "invalid configuration of channel intervals");
221 
222  // second test member method
223  m_coordinator = CreateObject<ChannelCoordinator> ();
224  Simulator::Schedule (MilliSeconds (0), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
225  Simulator::Schedule (MilliSeconds (1), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
226  Simulator::Schedule (MilliSeconds (3), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
227  Simulator::Schedule (MilliSeconds (4), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, false);
228  Simulator::Schedule (MilliSeconds (5), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, false);
229  Simulator::Schedule (MilliSeconds (50), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
230  Simulator::Schedule (MilliSeconds (51), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
231  Simulator::Schedule (MilliSeconds (53), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
232  Simulator::Schedule (MilliSeconds (54), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, false);
233  Simulator::Schedule (MilliSeconds (55), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, false);
234  Simulator::Schedule (MilliSeconds (100), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
235  Simulator::Schedule (MilliSeconds (200), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
236  Simulator::Schedule (MilliSeconds (201), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
237  Simulator::Schedule (MilliSeconds (203), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
238  Simulator::Schedule (MilliSeconds (204), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, false);
239  Simulator::Schedule (MilliSeconds (205), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, false);
240  Simulator::Schedule (MilliSeconds (250), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
241  Simulator::Schedule (MilliSeconds (251), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
242  Simulator::Schedule (MilliSeconds (253), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, true);
243  Simulator::Schedule (MilliSeconds (254), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, false);
244  Simulator::Schedule (MilliSeconds (255), &ChannelCoordinationTestCase::TestIntervalAfter, this, false, true, false);
245  Simulator::Schedule (MilliSeconds (300), &ChannelCoordinationTestCase::TestIntervalAfter, this, true, false, true);
246  Simulator::Stop (Seconds (1.0));
247  Simulator::Run ();
248  Simulator::Destroy ();
249 
250  m_coordinator = CreateObject<ChannelCoordinator> ();
251  // third test channel coordination events
252  Ptr<CoordinationTestListener> ptr = Create<CoordinationTestListener> (this);
254  Simulator::Stop (Seconds (100.0));
255  Simulator::Run ();
256  Simulator::Destroy ();
257 }
258 
266 {
267 public:
273  static NetDeviceContainer CreatWaveDevice (uint32_t nodesNumber = 2);
274 };
275 
276 #define PI 3.14159265
277 
279 TestCaseHelper::CreatWaveDevice (uint32_t nodesNumber)
280 {
282  nodes.Create (nodesNumber);
283 
285  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
286  mobility.Install (nodes);
287  // this is a circle with radius 10
288  Ptr<MobilityModel> model = NodeList::GetNode (0)->GetObject<MobilityModel> ();
289  model->SetPosition (Vector (0, 0, 0));
290  for (uint32_t n = 1; n != nodesNumber; ++n)
291  {
292  double angle = (PI / 180) * (360 / (nodesNumber - 1) * n);
293  double x = cos (angle) * 10;
294  double y = sin (angle) * 10;
295  Ptr<MobilityModel> model = NodeList::GetNode (n)->GetObject<MobilityModel> ();
296  model->SetPosition (Vector (x, y,0));
297  }
298 
299  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
300  YansWavePhyHelper wifiPhy = YansWavePhyHelper::Default ();
301  wifiPhy.SetChannel (wifiChannel.Create ());
302  QosWaveMacHelper waveMac = QosWaveMacHelper::Default ();
303  WaveHelper waveHelper = WaveHelper::Default ();
304  NetDeviceContainer devices = waveHelper.Install (wifiPhy, waveMac, nodes);
305  return devices;
306 }
307 
313 {
314 public:
315  ChannelRoutingTestCase (void);
316  virtual ~ChannelRoutingTestCase (void);
317 
324  void SendIp (bool shouldSucceed, bool ipv6);
330  void SendWsmp (bool shouldSucceed, const TxInfo &txInfo);
336  void SendWsa (bool shouldSucceed, const VsaInfo &vsaInfo);
337 
338 private:
339  virtual void DoRun (void);
348  bool Receive (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
355  bool ReceiveVsa (Ptr<const Packet> pkt,const Address & address, uint32_t, uint32_t);
356 
358 };
359 
361  : TestCase ("channel-routing")
362 {
363 
364 }
366 {
367 
368 }
369 void
370 ChannelRoutingTestCase::SendWsmp (bool shouldSucceed, const TxInfo &txInfo)
371 {
372  Ptr<Packet> packet = Create<Packet> (100);
373  const Address dest = Mac48Address::GetBroadcast ();
374  uint16_t protocol = 0x80dd; // any number is OK even ipv4 and ipv6
375  bool result = m_sender->SendX (packet, dest, protocol, txInfo);
376  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "test SendWsmp method error");
377 }
378 void
379 ChannelRoutingTestCase::SendIp (bool shouldSucceed, bool ipv6)
380 {
381  Ptr<Packet> packet = Create<Packet> (100);
382  const Address dest = Mac48Address::GetBroadcast ();
383  const static uint16_t IPv4_PROT_NUMBER = 0x0800;
384  const static uint16_t IPv6_PROT_NUMBER = 0x86DD;
385  uint16_t protocol = ipv6 ? IPv6_PROT_NUMBER : IPv4_PROT_NUMBER;
386  bool result = m_sender->Send (packet, dest, protocol);
387  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "test SendIp method error");
388 }
389 
390 void
391 ChannelRoutingTestCase::SendWsa (bool shouldSucceed, const VsaInfo &vsaInfo)
392 {
393  bool result = m_sender->StartVsa (vsaInfo);
394  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "test SendWsa method error");
395 }
396 
397 void
399 {
400  // check SendX method for WSMP packets
401  {
403  m_sender = DynamicCast<WaveNetDevice> (devices.Get (0));
404 
405  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (CCH));
406  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH1));
407  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH2));
408 
409  const SchInfo schInfo = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
410  Simulator::Schedule (Seconds (0.2), &WaveNetDevice::StartSch, m_sender, schInfo);
411 
412  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (CCH));
413  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (SCH1));
414  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH2));
415  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH3));
416  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH4));
417  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH5));
418  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH6));
419 
420  // invalid channel number
421  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (0));
422  // invalid user priority
423  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (CCH, 8));
424  // invalid tx parameters
425  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (CCH, 7, WifiMode ("OfdmRate6Mbps"), WIFI_PREAMBLE_LONG, 7));
426  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (CCH, 7, WifiMode ("OfdmRate3MbpsBW10MHz"), WIFI_PREAMBLE_LONG, 10));
427  // valid tx parameters
428  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (CCH, 7, WifiMode ("OfdmRate3MbpsBW10MHz"), WIFI_PREAMBLE_LONG, 7));
429  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (CCH, 7, WifiMode (), WIFI_PREAMBLE_LONG, 8));
430 
431  // release channel access at 0.6s
432  Simulator::Schedule (Seconds (0.5), &WaveNetDevice::StopSch, m_sender, SCH1);
433 
434  // the packet will be dropped because channel access is not assigned again
435  Simulator::Schedule (Seconds (0.6), &ChannelRoutingTestCase::SendWsmp, this, true, TxInfo (CCH));
436  Simulator::Schedule (Seconds (0.6), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH1));
437  Simulator::Schedule (Seconds (0.6), &ChannelRoutingTestCase::SendWsmp, this, false, TxInfo (SCH2));
438 
439  Simulator::Stop (Seconds (1.0));
440  Simulator::Run ();
441  Simulator::Destroy ();
442  }
443 
444  // check Send method for IP-based packets
445  {
447  m_sender = DynamicCast<WaveNetDevice> (devices.Get (0));
448 
449  bool ipv6 = true, ipv4 = false;
450  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendIp, this, false, ipv6);
451  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendIp, this, false, ipv4);
452 
453  const SchInfo schInfo = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
454  Simulator::Schedule (Seconds (0.2), &WaveNetDevice::StartSch, m_sender, schInfo);
455 
456  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendIp, this, false, ipv6);
457  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendIp, this, false, ipv4);
458 
459  TxProfile txProfile = TxProfile (SCH1);
460  Simulator::Schedule (Seconds (0.4), &WaveNetDevice::RegisterTxProfile, m_sender, txProfile);
461 
462  Simulator::Schedule (Seconds (0.5), &ChannelRoutingTestCase::SendIp, this, true, ipv6);
463  Simulator::Schedule (Seconds (0.5), &ChannelRoutingTestCase::SendIp, this, true, ipv4);
464 
465  // unregister txprofile
466  Simulator::Schedule (Seconds (0.5), &WaveNetDevice::DeleteTxProfile, m_sender,SCH1);
467 
468  Simulator::Schedule (Seconds (0.6), &ChannelRoutingTestCase::SendIp, this, false, ipv6);
469  Simulator::Schedule (Seconds (0.6), &ChannelRoutingTestCase::SendIp, this, false, ipv4);
470 
471  // release channel access
472  // mac entities have no channel resource even phy device has ability to send
473  Simulator::Schedule (Seconds (0.7),&WaveNetDevice::StopSch, m_sender, SCH1);
474 
475  Simulator::Schedule (Seconds (0.8), &ChannelRoutingTestCase::SendIp, this, false, ipv6);
476  Simulator::Schedule (Seconds (0.8), &ChannelRoutingTestCase::SendIp, this, false, ipv4);
477 
478  Simulator::Stop (Seconds (1.0));
479  Simulator::Run ();
480  Simulator::Destroy ();
481  }
482 
483  // check StartVsa method for WSA management frames
484  {
486  m_sender = DynamicCast<WaveNetDevice> (devices.Get (0));
487 
488  Ptr<Packet> packet = Create<Packet> (100);
489  const Mac48Address dest = Mac48Address::GetBroadcast ();
490  VsaInfo vsaInfo = VsaInfo (dest, OrganizationIdentifier (), 3, packet, SCH1, 50, VSA_TRANSMIT_IN_BOTHI);
491  Simulator::Schedule (Seconds (0.1), &ChannelRoutingTestCase::SendWsa, this, false, vsaInfo);
492 
493  vsaInfo.channelNumber = 0;
494  Simulator::Schedule (Seconds (0.2), &ChannelRoutingTestCase::SendWsa, this, false, vsaInfo);
495 
496  vsaInfo.channelNumber = CCH;
497  Simulator::Schedule (Seconds (0.3), &ChannelRoutingTestCase::SendWsa, this, true, vsaInfo);
498  Simulator::Schedule (Seconds (0.39), &WaveNetDevice::StopVsa, m_sender, CCH);
499 
500  const SchInfo schInfo = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
501  Simulator::Schedule (Seconds (0.4), &WaveNetDevice::StartSch, m_sender, schInfo);
502  vsaInfo.channelNumber = CCH;
503  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsa, this, true, vsaInfo);
504  vsaInfo.channelNumber = SCH1;
505  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsa, this, true, vsaInfo);
506  vsaInfo.channelNumber = SCH2;
507  Simulator::Schedule (Seconds (0.4), &ChannelRoutingTestCase::SendWsa, this, false, vsaInfo);
508 
509  Simulator::Schedule (Seconds (0.49), &WaveNetDevice::StopVsa, m_sender, CCH);
510  Simulator::Schedule (Seconds (0.49), &WaveNetDevice::StopVsa, m_sender, SCH1);
511  Simulator::Schedule (Seconds (0.49),&WaveNetDevice::StopSch, m_sender, SCH1);
512 
513  vsaInfo.channelNumber = CCH;
514  Simulator::Schedule (Seconds (0.5), &ChannelRoutingTestCase::SendWsa, this, true, vsaInfo);
515  vsaInfo.channelNumber = SCH1;
516  Simulator::Schedule (Seconds (0.5), &ChannelRoutingTestCase::SendWsa, this, false, vsaInfo);
517  vsaInfo.channelNumber = SCH2;
518  Simulator::Schedule (Seconds (0.5), &ChannelRoutingTestCase::SendWsa, this, false, vsaInfo);
519 
520  Simulator::Stop (Seconds (1.0));
521  Simulator::Run ();
522  Simulator::Destroy ();
523  }
524 }
525 
535 {
536 public:
537  ChannelAccessTestCase (void);
538  virtual ~ChannelAccessTestCase (void);
539 private:
545  void TestContinuous (SchInfo &info, bool shouldSucceed);
551  void TestContinuousAfter (uint32_t channelNumber, bool isAccessAssigned);
557  void TestExtended (SchInfo &info, bool shouldSucceed);
563  void TestExtendedAfter (uint32_t channelNumber, bool isAccessAssigned);
569  void TestAlternating (SchInfo &info, bool shouldSucceed);
575  void TestAlternatingAfter (uint32_t channelNumber, bool isAccessAssigned);
576 
582  void SendX (uint32_t channel, uint32_t receiverId);
591  bool Receive (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
592 
593  virtual void DoRun (void);
594 
597  uint32_t m_received;
598 };
599 
601  : TestCase ("channel-access")
602 {
603 }
605 {
606 
607 }
608 void
610 {
611  bool result = m_sender->StartSch (info);
612  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "TestContinuous fail at " << Now ().GetSeconds ());
613 }
614 void
615 ChannelAccessTestCase::TestContinuousAfter (uint32_t channelNumber, bool isAccessAssigned)
616 {
617  bool result = m_sender->GetChannelScheduler ()->IsContinuousAccessAssigned (channelNumber);
618  NS_TEST_EXPECT_MSG_EQ (result, isAccessAssigned, "TestContinuousAfter fail at " << Now ().GetSeconds ());
619 }
620 void
621 ChannelAccessTestCase::TestExtended (SchInfo &info, bool shouldSucceed)
622 {
623  bool result = m_sender->StartSch (info);
624  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "TestExtended fail at " << Now ().GetSeconds ());
625 }
626 void
627 ChannelAccessTestCase::TestExtendedAfter (uint32_t channelNumber, bool isAccessAssigned)
628 {
629  bool result = m_sender->GetChannelScheduler ()->IsExtendedAccessAssigned (channelNumber);
630  NS_TEST_EXPECT_MSG_EQ (result, isAccessAssigned, "TestExtendedAfter fail at " << Now ().GetSeconds ());
631 }
632 
633 void
635 {
636  bool result = m_sender->StartSch (info);
637  NS_TEST_EXPECT_MSG_EQ (result, shouldSucceed, "TestAlternating fail at " << Now ().GetSeconds ());
638 }
639 void
640 ChannelAccessTestCase::TestAlternatingAfter (uint32_t channelNumber, bool isAccessAssigned)
641 {
642  bool result = m_sender->GetChannelScheduler ()->IsAlternatingAccessAssigned (channelNumber);
643  NS_TEST_EXPECT_MSG_EQ (result, isAccessAssigned, "TestAlternating fail at " << Now ().GetSeconds ());
644 }
645 
646 void
647 ChannelAccessTestCase::SendX (uint32_t channel, uint32_t receiverId)
648 {
649  const static uint16_t WSMP_PROT_NUMBER = 0x88DC;
650  const Mac48Address dest = Mac48Address::GetBroadcast ();
651  const TxInfo txInfo = TxInfo (channel);
652 
653  uint8_t *data = new uint8_t [112];
654  data [0] = (receiverId >> 24) & 0xFF;
655  data [1] = (receiverId >> 16) & 0xFF;
656  data [2] = (receiverId >> 8) & 0xFF;
657  data [3] = (receiverId >> 0) & 0xFF;
658 
659  uint64_t ts = Simulator::Now ().GetTimeStep ();
660  data [4] = (ts >> 56) & 0xFF;
661  data [5] = (ts >> 48) & 0xFF;
662  data [6] = (ts >> 40) & 0xFF;
663  data [7] = (ts >> 32) & 0xFF;
664  data [8] = (ts >> 24) & 0xFF;
665  data [9] = (ts >> 16) & 0xFF;
666  data [10] = (ts >> 8) & 0xFF;
667  data [11] = (ts >> 0) & 0xFF;
668 
669  Ptr<Packet> p = Create<Packet> (data, 112);
670 
671  m_sender->SendX (p, dest, WSMP_PROT_NUMBER, txInfo);
672 
673  delete [] data;
674 }
675 
676 bool
678 {
679  uint8_t *data = new uint8_t [pkt->GetSize ()];
680  pkt->CopyData(data, pkt->GetSize ());
681 
682  uint32_t seq = data [0];
683  seq <<= 8;
684  seq |= data [1];
685  seq <<= 8;
686  seq |= data [2];
687  seq <<= 8;
688  seq |= data [3];
689 
690  uint64_t ts = data [4];
691  ts <<= 8;
692  ts |= data [5];
693  ts <<= 8;
694  ts |= data [6];
695  ts <<= 8;
696  ts |= data [7];
697  ts <<= 8;
698  ts |= data [8];
699  ts <<= 8;
700  ts |= data [9];
701  ts <<= 8;
702  ts |= data [10];
703  ts <<= 8;
704  ts |= data [11];
705  Time sendTime = TimeStep (ts);
706 
707  delete [] data;
708 
709 // SeqTsHeader seqTs;
710 // ConstCast<Packet> (pkt)->RemoveHeader (seqTs);
711  uint32_t curNodeId = dev->GetNode ()->GetId ();
712  NS_TEST_EXPECT_MSG_EQ (curNodeId, seq, "fail to assign channel access");
713  m_received++;
714  return true;
715 }
716 
717 void
719 {
720  // test ContinuousAccess in the sender side
721  {
723  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
724 
725  // there is no need for assigning CCH continuous access.
726  SchInfo info = SchInfo (CCH, false, EXTENDED_CONTINUOUS);
727  Simulator::Schedule (Seconds (1), &ChannelAccessTestCase::TestContinuous, this, info, false);
728 
729  info = SchInfo (SCH1, false, EXTENDED_CONTINUOUS);
730  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestContinuous, this, info, true);
731 
732  // BE ATTENTION !!!
733  // because channel access is assigned in non-immediate mode, the first CCH Interval will be
734  // the wait time with DefaultCchAccess assigned, thus there is no ContinuousAccess assigned.
735  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, false);
736  Simulator::Schedule (Seconds (2.01), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, false);
737  Simulator::Schedule (Seconds (2.049), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, false);
738  Simulator::Schedule (Seconds (2.05), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, false);
739  Simulator::Schedule (Seconds (2.051), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, true);
740  Simulator::Schedule (Seconds (2.99), &ChannelAccessTestCase::TestContinuousAfter, this, SCH1, true);
741 
742  // it's OK to assign same access again,
743  Simulator::Schedule (Seconds (3), &ChannelAccessTestCase::TestContinuous, this, info, true);
744  // fail to assign continuous access for other SCH if current channel is assigned
745  info = SchInfo (SCH2, false, EXTENDED_CONTINUOUS);
746  Simulator::Schedule (Seconds (4), &ChannelAccessTestCase::TestContinuous, this, info, false);
747 
748  // then we release channel access at 0.5s
749  Simulator::Schedule (Seconds (5), &WaveNetDevice::StopSch, m_sender, SCH1);
750 
751  info = SchInfo (SCH2, false, EXTENDED_CONTINUOUS);
752  // succeed to assign access for other SCH is previous SCH access is released
753  Simulator::Schedule (Seconds (6), &ChannelAccessTestCase::TestContinuous, this, info, true);
754 
755  Simulator::Stop (Seconds (7.0));
756  Simulator::Run ();
757  Simulator::Destroy ();
758  }
759 
760  // test ContinuousAccess again in the receiver side
761  {
763  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
764  m_received = 0;
765 
766  for (uint32_t i = 1; i != 8; ++i)
767  {
768  Ptr<WaveNetDevice> device = DynamicCast<WaveNetDevice> (m_devices.Get (i));
770 
771  // at 0s, receivers are assigned ContinuousAccess from CCH, SCH1 to SCH6
772  static std::vector<uint32_t> WaveChannels = ChannelManager::GetWaveChannels ();
773  uint32_t channel = WaveChannels[i - 1];
774  const SchInfo info = SchInfo (channel, false, EXTENDED_CONTINUOUS);
775  Simulator::Schedule (Seconds (0), &WaveNetDevice::StartSch, device, info);
776  }
777 
778  // at 0s, the sender is assigned DefaultCchAccess, so only node-1 can receive packets.
779  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, CCH, 1);
780  // if receivers assigned for SCH access can receive packets, there shall be crashed
781  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH1, 0);
782  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
783  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
784  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
785  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
786  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
787 
788  // at 1s, the sender is assigned ContinuousAccess for SCH1, so only node-2 can receive packets.
789  SchInfo info = SchInfo (SCH1, false, EXTENDED_CONTINUOUS);
790  Simulator::Schedule (Seconds (1), &WaveNetDevice::StartSch, m_sender, info);
791  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH1, 2);
792  // other channel access cannot receive packets
793  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, CCH, 0);
794  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
795  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
796  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
797  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
798  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
799 
800  Simulator::Stop (Seconds (10.0));
801  Simulator::Run ();
802  Simulator::Destroy ();
803 
804  NS_TEST_EXPECT_MSG_EQ (m_received, 2, "test ContinuousAccess fail in receive side");
805  }
806 
807  // test ExtendedAccess in the sender side
808  {
810  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
811 
812  // there is no need for assigning CCH extended access.
813  SchInfo info = SchInfo (CCH, false, 10);
814  Simulator::Schedule (Seconds (1), &ChannelAccessTestCase::TestExtended, this, info, false);
815 
816  info = SchInfo (SCH1, false, 10);
817  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestExtended, this, info, true);
818  // succeed because request for extends 8 can be fulfilled by previous extends 10..
819  info = SchInfo (SCH1, false, 8);
820  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestExtended, this, info, true);
821  // fail because request for extends 12 cannot be fulfilled by previous extends 10..
822  info = SchInfo (SCH1, false, 12);
823  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestExtended, this, info, false);
824 
825  // BE ATTENTION !!!
826  // because channel access is assigned in non-immediate mode, the first CCH Interval will be
827  // the wait time with DefaultCchAccess assigned, while there is no ExtendedAccess assigned.
828  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
829  Simulator::Schedule (Seconds (2.01), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
830  Simulator::Schedule (Seconds (2.049), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
831  Simulator::Schedule (Seconds (2.05), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
832  Simulator::Schedule (Seconds (2.051), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, true);
833  Simulator::Schedule (Seconds (2.99), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, true);
834 
835  // the end of extended access is (2s + 100ms + 100ms * 10) = 3.1s
836  Simulator::Schedule (Seconds (3), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, true);
837  Simulator::Schedule (Seconds (3.1), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, true);
838  Simulator::Schedule (Seconds (3.2), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
839  Simulator::Schedule (Seconds (3.3), &ChannelAccessTestCase::TestExtendedAfter, this, SCH1, false);
840 
841  // succeed to assign extended access for other SCH since previous extended access is released automatically
842  info = SchInfo (SCH2, false, 10);
843  Simulator::Schedule (Seconds (4), &ChannelAccessTestCase::TestExtended, this, info, true);
844 
845  // stop it at 5s even the end of extended access is (4s + 100ms + 100ms * 10) = 5.1s
846  Simulator::Schedule (Seconds (5), &WaveNetDevice::StopSch, m_sender, SCH2);
847 
848  Simulator::Schedule (Seconds (5), &ChannelAccessTestCase::TestExtendedAfter, this, SCH2, false);
849  Simulator::Schedule (Seconds (5.1), &ChannelAccessTestCase::TestExtendedAfter, this, SCH2, false);
850  Simulator::Schedule (Seconds (5.2), &ChannelAccessTestCase::TestExtendedAfter, this, SCH2, false);
851 
852  Simulator::Stop (Seconds (6.0));
853  Simulator::Run ();
854  Simulator::Destroy ();
855  }
856 
857  // test ExtendedAccess again in the receiver side
858  {
860  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
861  m_received = 0;
862 
863  for (uint32_t i = 1; i != 8; ++i)
864  {
865  Ptr<WaveNetDevice> device = DynamicCast<WaveNetDevice> (m_devices.Get (i));
867 
868  // at 0s, receivers are assigned ContinuosAccess from CCH, SCH1 to SCH6
869  static std::vector<uint32_t> WaveChannels = ChannelManager::GetWaveChannels ();
870  uint32_t channel = WaveChannels[i - 1];
871  const SchInfo info = SchInfo (channel, false, EXTENDED_CONTINUOUS);
872  Simulator::Schedule (Seconds (0), &WaveNetDevice::StartSch, device, info);
873  }
874 
875  // at 0s, the sender is assigned DefaultCchAccess, so only node-1 can receive packets.
876  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, CCH, 1);
877  // if receivers assigned for SCH access can receive packets, there shall be crashed
878  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH1, 0);
879  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
880  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
881  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
882  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
883  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
884 
885  // at 1s, the sender is assigned ExtendedAccess for SCH1 with extends 10,
886  //, so only node-2 can receive packets from 1s - 2.1s ( 1s + 100ms + 100ms * 10)
887  SchInfo info = SchInfo (SCH1, false, 10);
888  Simulator::Schedule (Seconds (1), &WaveNetDevice::StartSch, m_sender, info);
889  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH1, 2);
890  // other channel access cannot receive packets
891  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, CCH, 0);
892  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
893  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
894  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
895  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
896  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
897  // at 2.2s the node-2 cannot receive this packet because of extended access released in node-0
898  // but sended is assigned DefaultCchAccess again, thus node-1 can receive broadcasted packets.
899  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, CCH, 1);
900  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH1, 0);
901  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH2, 0);
902  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH3, 0);
903  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH4, 0);
904  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH5, 0);
905  Simulator::Schedule (Seconds (2.2), &ChannelAccessTestCase::SendX, this, SCH6, 0);
906 
907  Simulator::Stop (Seconds (10.0));
908  Simulator::Run ();
909  Simulator::Destroy ();
910 
911  NS_TEST_EXPECT_MSG_EQ (m_received, 3, "test ExtendedAccess fail in receive side");
912  }
913 
914  // test AlternatingAccess in the sender side
915  {
917  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
918 
919  // there is no need for assigning CCH alternating access.
920  SchInfo info = SchInfo (CCH, false, EXTENDED_ALTERNATING);
921  Simulator::Schedule (Seconds (1), &ChannelAccessTestCase::TestAlternating, this, info, false);
922 
923  info = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
924  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestAlternating, this, info, true);
925 
926  // BE ATTENTION !!!
927  // No matter whether channel access is assigned in immediate mode or non-immediate mode,
928  // the channel access will assigned immediately which is different from the test results in
929  // ExtendedAccess assignment and ContinuousAccess assignment.
930  Simulator::Schedule (Seconds (2), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
931  Simulator::Schedule (Seconds (2.01), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
932  Simulator::Schedule (Seconds (2.049), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
933  Simulator::Schedule (Seconds (2.05), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
934  Simulator::Schedule (Seconds (2.051), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
935  Simulator::Schedule (Seconds (2.99), &ChannelAccessTestCase::TestAlternatingAfter, this, SCH1, true);
936 
937  Simulator::Schedule (Seconds (3), &ChannelAccessTestCase::TestAlternating, this, info, true);
938  info = SchInfo (SCH2, false, EXTENDED_ALTERNATING);
939  Simulator::Schedule (Seconds (3), &ChannelAccessTestCase::TestAlternating, this, info, false);
940  info = SchInfo (0, false, EXTENDED_ALTERNATING);
941  Simulator::Schedule (Seconds (3), &ChannelAccessTestCase::TestAlternating, this, info, false);
942 
943  // then we release channel access at 0.5s
944  Simulator::Schedule (Seconds (4), &WaveNetDevice::StopSch, m_sender, SCH1);
945 
946  info = SchInfo (SCH2, false, EXTENDED_ALTERNATING);
947  // succeed to assign access for other SCH is previous SCH access is released
948  Simulator::Schedule (Seconds (5), &ChannelAccessTestCase::TestAlternating, this, info, true);
949 
950  Simulator::Stop (Seconds (6.0));
951  Simulator::Run ();
952  Simulator::Destroy ();
953  }
954 
955  // test AlternatingAccess again in the receiver side
956  {
958  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
959  m_received = 0;
960 
961  for (uint32_t i = 1; i != 8; ++i)
962  {
963  Ptr<WaveNetDevice> device = DynamicCast<WaveNetDevice> (m_devices.Get (i));
965 
966  // at 0s, receivers are assigned ContinuosAccess from CCH, SCH1 to SCH6
967  static std::vector<uint32_t> WaveChannels = ChannelManager::GetWaveChannels ();
968  uint32_t channel = WaveChannels[i - 1];
969  const SchInfo info = SchInfo (channel, false, EXTENDED_CONTINUOUS);
970  Simulator::Schedule (Seconds (0), &WaveNetDevice::StartSch, device, info);
971  }
972 
973  // at 0s, the sender is assigned DefaultCchAccess, so only node-1 can receive packets.
974  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, CCH, 1);
975  // if receivers assigned for SCH access can receive packets, there shall be crashed
976  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH1, 0);
977  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
978  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
979  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
980  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
981  Simulator::Schedule (Seconds (0.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
982 
983  // at 1s, the sender is assigned ContinuosAccess for SCH1, so only node-2 can receive packets.
984  SchInfo info = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
985  Simulator::Schedule (Seconds (1), &WaveNetDevice::StartSch, m_sender, info);
986  // node-1 (assigned CCH access) and node-2 (assigned SCH1 access) can receive packets
987  // in different channel interval
988  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH1, 2);
989  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, CCH, 1);
990  // other channel access cannot receive packets
991  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
992  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
993  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
994  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
995  Simulator::Schedule (Seconds (1.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
996 
997  Simulator::Schedule (Seconds (2), &WaveNetDevice::StopSch, m_sender, SCH1);
998  // if ContinuousAccess for SCH1 is released, node-2 cannot receive packets again
999  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, CCH, 1);
1000  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH1, 0);
1001  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH2, 0);
1002  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH3, 0);
1003  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH4, 0);
1004  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH5, 0);
1005  Simulator::Schedule (Seconds (2.1), &ChannelAccessTestCase::SendX, this, SCH6, 0);
1006 
1007  Simulator::Stop (Seconds (10.0));
1008  Simulator::Run ();
1009  Simulator::Destroy ();
1010 
1011  NS_TEST_EXPECT_MSG_EQ (m_received, 4, "test AlternatingAccess fail in receive side");
1012  }
1013 }
1014 
1023 {
1024 public:
1025  AnnexC_TestCase ();
1026  virtual ~AnnexC_TestCase ();
1027 private:
1028  virtual void DoRun (void);
1029 
1036  void SendPacket (uint32_t packetSize, const TxInfo & txInfo, uint32_t sequence);
1045  bool Receive (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
1046 
1050 };
1051 
1053  : TestCase ("annex-c")
1054 {
1055 }
1056 
1058 {
1059 }
1060 
1061 void
1062 AnnexC_TestCase::SendPacket (uint32_t packetSize, const TxInfo & txInfo, uint32_t sequence)
1063 {
1064  const static uint16_t WSMP_PROT_NUMBER = 0x88DC;
1065  const Mac48Address dest = Mac48Address::ConvertFrom (m_receiver->GetAddress ());
1066 
1067  uint8_t *data = new uint8_t [packetSize];
1068  data [0] = (sequence >> 24) & 0xFF;
1069  data [1] = (sequence >> 16) & 0xFF;
1070  data [2] = (sequence >> 8) & 0xFF;
1071  data [3] = (sequence >> 0) & 0xFF;
1072 
1073  uint64_t ts = Simulator::Now ().GetTimeStep ();
1074  data [4] = (ts >> 56) & 0xFF;
1075  data [5] = (ts >> 48) & 0xFF;
1076  data [6] = (ts >> 40) & 0xFF;
1077  data [7] = (ts >> 32) & 0xFF;
1078  data [8] = (ts >> 24) & 0xFF;
1079  data [9] = (ts >> 16) & 0xFF;
1080  data [10] = (ts >> 8) & 0xFF;
1081  data [11] = (ts >> 0) & 0xFF;
1082 
1083  Ptr<Packet> p = Create<Packet> (data, packetSize);
1084 
1085  m_sender->SendX (p, dest, WSMP_PROT_NUMBER, txInfo);
1086 
1087  delete [] data;
1088 }
1089 
1090 bool
1091 AnnexC_TestCase::Receive (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender)
1092 {
1093  uint8_t *data = new uint8_t [pkt->GetSize ()];
1094  pkt->CopyData(data, pkt->GetSize ());
1095 
1096  uint32_t seq = data [0];
1097  seq <<= 8;
1098  seq |= data [1];
1099  seq <<= 8;
1100  seq |= data [2];
1101  seq <<= 8;
1102  seq |= data [3];
1103 
1104  uint64_t ts = data [4];
1105  ts <<= 8;
1106  ts |= data [5];
1107  ts <<= 8;
1108  ts |= data [6];
1109  ts <<= 8;
1110  ts |= data [7];
1111  ts <<= 8;
1112  ts |= data [8];
1113  ts <<= 8;
1114  ts |= data [9];
1115  ts <<= 8;
1116  ts |= data [10];
1117  ts <<= 8;
1118  ts |= data [11];
1119  Time sendTime = TimeStep (ts);
1120 
1121  delete [] data;
1122 
1123  Time curTime = Now ();
1124  Time duration = curTime - sendTime;
1125 
1126  if (seq == 1)
1127  {
1128  NS_TEST_EXPECT_MSG_GT (duration, ChannelCoordinator::GetDefaultSchInterval (), "fail to test Annex C when packet sequence is " << seq);
1129  }
1130  else if (seq == 2)
1131  {
1132  NS_TEST_EXPECT_MSG_LT (duration, ChannelCoordinator::GetDefaultSchInterval (), "fail to test Annex C when packet sequence is " << seq);
1133  }
1134  else if (seq == 3)
1135  {
1136  NS_TEST_EXPECT_MSG_GT (duration, ChannelCoordinator::GetDefaultCchInterval (), "fail to test Annex C when packet sequence is " << seq);
1137  }
1138  else if (seq == 4)
1139  {
1140  NS_TEST_EXPECT_MSG_LT (duration, ChannelCoordinator::GetDefaultCchInterval (), "fail to test Annex C when packet sequence is " << seq);
1141  }
1142  return true;
1143 }
1144 
1145 void
1147 {
1149  m_sender = DynamicCast<WaveNetDevice> (m_devices.Get (0));
1150  m_receiver = DynamicCast<WaveNetDevice> (m_devices.Get (1));
1152 
1153  // at 0s, the receiver is assigned AlternatingAccess for SCH1
1154  SchInfo infoReceiver = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
1155  Simulator::Schedule (MilliSeconds (0), &WaveNetDevice::StartSch, m_receiver, infoReceiver);
1156 
1157  // at 0s, the sender is assigned AlternatingAccess for SCH1
1158  SchInfo infoSender = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
1159  Simulator::Schedule (MilliSeconds (0), &WaveNetDevice::StartSch, m_sender, infoSender);
1160 
1161  TxInfo txInfo = TxInfo (CCH, 0, WifiMode ("OfdmRate3MbpsBW10MHz"), WIFI_PREAMBLE_LONG, 0);
1162  // the packet size with 2312 bytes costs 6.42s, which will cancel this transmission in the CCH Interval
1163  // so the receiver will receive this packet in next CCH Interval
1164  Simulator::Schedule (MilliSeconds (45), &AnnexC_TestCase::SendPacket, this, 2304, txInfo, 1);
1165 
1166  // the packet size with 312 bytes costs 1.104ms, which will not cancel transmission in the CCH Interval
1167  // so the receiver can this packet is this CCH Interval
1168  Simulator::Schedule (MilliSeconds (145), &AnnexC_TestCase::SendPacket, this, 312, txInfo, 2);
1169 
1170  txInfo = TxInfo (SCH1, 0, WifiMode ("OfdmRate3MbpsBW10MHz"), WIFI_PREAMBLE_LONG, 0);
1171  // the packet size with 2312 bytes costs 6.42ms, which will cancel this transmission in the SCH Interval
1172  // so the receiver will receive this packet in next SCH Interval
1173  Simulator::Schedule (MilliSeconds (295), &AnnexC_TestCase::SendPacket, this, 2304, txInfo, 3);
1174 
1175  // the packet size with 312 bytes costs 1.104ms, which will not cancel transmission in the SCH Interval
1176  // so the receiver can this packet is this SCH Interval
1177  Simulator::Schedule (MilliSeconds (395), &AnnexC_TestCase::SendPacket, this, 312, txInfo, 4);
1178 
1179  Simulator::Stop (Seconds (1.0));
1180  Simulator::Run ();
1181  Simulator::Destroy ();
1182 }
1183 
1191 {
1192 public:
1193  WaveMacTestSuite ();
1194 };
1195 
1197  : TestSuite ("wave-mac-extension", UNIT)
1198 {
1199  // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
1200  AddTestCase (new ChannelCoordinationTestCase, TestCase::QUICK);
1201  AddTestCase (new ChannelRoutingTestCase, TestCase::QUICK);
1202  AddTestCase (new ChannelAccessTestCase, TestCase::QUICK);
1203  AddTestCase (new AnnexC_TestCase, TestCase::QUICK);
1204 }
1205 
1206 // Do not forget to allocate an instance of this TestSuite
void SendX(uint32_t channel, uint32_t receiverId)
Send X function.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Test Case Helper.
This test case tests channel access assignments which is done by StartSch and StopSch method of WaveN...
virtual void NotifyGuardSlotStart(Time duration, bool cchi)
bool StartSch(const SchInfo &schInfo)
uint32_t GetId(void) const
Definition: node.cc:107
void TestContinuousAfter(uint32_t channelNumber, bool isAccessAssigned)
Test continuous after function.
bool IsCchInterval(Time duration=Seconds(0.0)) const
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
void NotifySchStartNow(Time duration)
Notify SCH start now function.
A suite of tests to run.
Definition: test.h:1342
void TestContinuous(SchInfo &info, bool shouldSucceed)
Test continuous function.
bool Receive(Ptr< NetDevice > dev, Ptr< const Packet > pkt, uint16_t mode, const Address &sender)
Receive function.
virtual Ptr< Node > GetNode(void) const =0
bool SendX(Ptr< Packet > packet, const Address &dest, uint32_t protocol, const TxInfo &txInfo)
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
static NetDeviceContainer CreatWaveDevice(uint32_t nodesNumber=2)
Create WAVE device function.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:285
virtual void DoRun(void)
Implementation to actually run this TestCase.
bool IsGuardInterval(Time duration=Seconds(0.0)) const
Ptr< ChannelScheduler > GetChannelScheduler(void) const
Ptr< ChannelCoordinator > m_coordinator
coordinator
encapsulates test code
Definition: test.h:1155
void SendWsmp(bool shouldSucceed, const TxInfo &txInfo)
Send WSMP or other packets.
#define CCH
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
a polymophic address class
Definition: address.h:90
The Annex C of IEEE 1609.4 : "Avoiding transmission at scheduled guard intervals" This feature is imp...
Ptr< YansWifiChannel > Create(void) const
channel
Definition: third.py:85
void TestExtended(SchInfo &info, bool shouldSucceed)
Test extended function.
mobility
Definition: third.py:101
virtual Address GetAddress(void) const
bool ReceiveVsa(Ptr< const Packet > pkt, const Address &address, uint32_t, uint32_t)
Receive VSA function.
Keep track of the current position and velocity of an object.
void SetChannel(Ptr< YansWifiChannel > channel)
#define PI
nodes
Definition: first.py:25
Ptr< WaveNetDevice > m_sender
sender
#define EXTENDED_ALTERNATING
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
the organization identifier is a public organizationally unique identifier assigned by the IEEE...
helps to create WaveNetDevice objects
Definition: wave-helper.h:112
uint8_t data[writeSize]
void RegisterListener(Ptr< ChannelCoordinationListener > listener)
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
#define EXTENDED_CONTINUOUS
Ptr< WaveNetDevice > m_sender
sender
#define SCH2
Qos Wave Mac Helper class.
void SendPacket(uint32_t packetSize, const TxInfo &txInfo, uint32_t sequence)
Send packet function.
This test case tests the channel coordination.
NetDeviceContainer m_devices
devices
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
void SendIp(bool shouldSucceed, bool ipv6)
Send IP-based packets.
CoordinationTestListener(ChannelCoordinationTestCase *coordinatorTest)
Constructor.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
address
Definition: first.py:37
void NotifyGuardStartNow(Time duration, bool inCchInterval)
Notify guard start now function.
uint32_t channelNumber
channel number
Definition: vsa-manager.h:68
void SendWsa(bool shouldSucceed, const VsaInfo &vsaInfo)
Send VSA management frames.
CoordinationTestListener is used to test channel coordination events.
Wave Mac Test Suite.
route packets or frames in different approaches see 1609.4-2010 chapter 5.3.4
an EUI-48 address
Definition: mac48-address.h:43
Time TimeStep(uint64_t ts)
Definition: nstime.h:1119
bool Receive(Ptr< NetDevice > dev, Ptr< const Packet > pkt, uint16_t mode, const Address &sender)
Receive function.
void TestAlternating(SchInfo &info, bool shouldSucceed)
Test aternating function.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wave-helper.cc:361
manage and create wifi channel objects for the yans model.
To trace WaveNetDevice, we have to overwrite the trace functions of class YansWifiPhyHelper.
Definition: wave-helper.h:40
NetDeviceContainer m_devices
the devices
ChannelCoordinationTestCase * m_coordinatorTest
coordinator test
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report if not.
Definition: test.h:1090
void SetPosition(const Vector &position)
virtual void NotifySchSlotStart(Time duration)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void TestAlternatingAfter(uint32_t channelNumber, bool isAccessAssigned)
Test alternating after function.
void NotifyCchStartNow(Time duration)
Notify CCS start now function.
Helper class used to assign positions and mobility models to nodes.
bool IsSchInterval(Time duration=Seconds(0.0)) const
bool StartVsa(const VsaInfo &vsaInfo)
Ptr< WaveNetDevice > m_sender
sender
#define SCH5
#define SCH3
void TestExtendedAfter(uint32_t channelNumber, bool isAccessAssigned)
Test extended after function.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
receive notifications about channel coordination events.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
Definition: test.h:903
virtual void DoRun(void)
Implementation to actually run this TestCase.
bool Receive(Ptr< NetDevice > dev, Ptr< const Packet > pkt, uint16_t mode, const Address &sender)
Receive function.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:309
static const uint32_t packetSize
static WaveMacTestSuite waveMacTestSuite
the test suite
devices
Definition: first.py:32
void TestIntervalAfter(bool cchi, bool schi, bool guardi)
Test interval after function.
Time GetSyncInterval(void) const
#define SCH4
virtual void NotifyCchSlotStart(Time duration)
Time GetGuardInterval(void) const
Ptr< WaveNetDevice > m_receiver
receiver
#define SCH1
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
void SetGuardInterval(Time guardi)
#define SCH6
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:391