satellite-ncr-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions Ltd
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: Bastien Tauran <bastien.tauran@viveris.fr>
19  */
20 
29 #include "ns3/cbr-application.h"
30 #include "ns3/cbr-helper.h"
31 #include "ns3/config.h"
32 #include "ns3/log.h"
33 #include "ns3/packet-sink-helper.h"
34 #include "ns3/packet-sink.h"
35 #include "ns3/satellite-env-variables.h"
36 #include "ns3/satellite-gw-mac.h"
37 #include "ns3/satellite-helper.h"
38 #include "ns3/satellite-ut-mac-state.h"
39 #include "ns3/simulator.h"
40 #include "ns3/singleton.h"
41 #include "ns3/string.h"
42 #include "ns3/test.h"
43 
44 using namespace ns3;
45 
57 class SatNcrTest1 : public TestCase
58 {
59  public:
60  SatNcrTest1();
61  virtual ~SatNcrTest1();
62 
63  private:
64  virtual void DoRun(void);
65  void GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver);
66 
67  Ptr<SatHelper> m_helper;
68 
69  std::vector<int> m_totalSent;
70  std::vector<int> m_totalReceived;
71  std::vector<SatUtMacState::RcstState_t> m_states;
72 };
73 
74 // Add some help text to this case to describe what it is intended to test
76  : TestCase("This case tests logon mechanism, and that no data is sent by UT before entering "
77  "TDMA_SYNC state.")
78 {
79 }
80 
81 // This destructor does nothing but we include it as a reminder that
82 // the test case should clean up after itself
84 {
85 }
86 
87 //
88 // SatNcrTest1 TestCase implementation
89 //
90 void
92 {
93  // Set simulation output details
94  Singleton<SatEnvVariables>::Get()->DoInitialize();
95  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-ncr", "", true);
96 
97  // Set 2 RA frames including one for logon
98  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
99  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_0));
100  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
101  EnumValue(SatEnums::RA_MODEL_SLOTTED_ALOHA));
102  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
103  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
104  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
105  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
106  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_RandomAccessFrame", BooleanValue(true));
107  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_RandomAccessFrame", BooleanValue(true));
108  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_LogonFrame", BooleanValue(true));
109 
110  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_GuardTimeSymbols", UintegerValue(4));
111  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_GuardTimeSymbols", UintegerValue(4));
112  Config::SetDefault("ns3::SatSuperframeConf0::Frame2_GuardTimeSymbols", UintegerValue(4));
113  Config::SetDefault("ns3::SatSuperframeConf0::Frame3_GuardTimeSymbols", UintegerValue(4));
114  Config::SetDefault("ns3::SatSuperframeConf0::Frame4_GuardTimeSymbols", UintegerValue(4));
115  Config::SetDefault("ns3::SatSuperframeConf0::Frame5_GuardTimeSymbols", UintegerValue(4));
116  Config::SetDefault("ns3::SatSuperframeConf0::Frame6_GuardTimeSymbols", UintegerValue(4));
117  Config::SetDefault("ns3::SatSuperframeConf0::Frame7_GuardTimeSymbols", UintegerValue(4));
118  Config::SetDefault("ns3::SatSuperframeConf0::Frame8_GuardTimeSymbols", UintegerValue(4));
119  Config::SetDefault("ns3::SatSuperframeConf0::Frame9_GuardTimeSymbols", UintegerValue(4));
120 
121  Config::SetDefault("ns3::SatUtMac::WindowInitLogon", TimeValue(Seconds(20)));
122  Config::SetDefault("ns3::SatUtMac::MaxWaitingTimeLogonResponse", TimeValue(Seconds(1)));
123 
124  // Set default values for NCR
125  Config::SetDefault("ns3::SatMac::NcrVersion2", BooleanValue(false));
126  Config::SetDefault("ns3::SatGwMac::NcrBroadcastPeriod", TimeValue(MilliSeconds(100)));
127  Config::SetDefault("ns3::SatGwMac::UseCmt", BooleanValue(true));
128  Config::SetDefault("ns3::SatUtMacState::NcrSyncTimeout", TimeValue(Seconds(1)));
129  Config::SetDefault("ns3::SatUtMacState::NcrRecoveryTimeout", TimeValue(Seconds(10)));
130  Config::SetDefault("ns3::SatNcc::UtTimeout", TimeValue(Seconds(10)));
131 
132  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(true));
133  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotInterval", TimeValue(MilliSeconds(500)));
134 
135  Config::SetDefault("ns3::SatUtMac::ClockDrift", IntegerValue(100));
136  Config::SetDefault("ns3::SatGwMac::CmtPeriodMin", TimeValue(MilliSeconds(550)));
137 
138  // Creating the reference system.
139  m_helper = CreateObject<SatHelper>();
140  m_helper->CreatePredefinedScenario(SatHelper::SIMPLE);
141 
142  NodeContainer gwUsers = m_helper->GetGwUsers();
143 
144  // Create the Cbr application to send UDP datagrams of size
145  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 100ms)
146  uint16_t port = 9; // Discard port (RFC 863)
147  CbrHelper cbr("ns3::UdpSocketFactory",
148  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
149  cbr.SetAttribute("Interval", StringValue("100ms"));
150  ApplicationContainer utApps = cbr.Install(m_helper->GetUtUsers());
151  utApps.Start(Seconds(1.0));
152  utApps.Stop(Seconds(59.0));
153 
154  // Create a packet sink to receive these packets
155  PacketSinkHelper sink(
156  "ns3::UdpSocketFactory",
157  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
158  ApplicationContainer gwApps = sink.Install(gwUsers);
159  gwApps.Start(Seconds(1.0));
160  gwApps.Stop(Seconds(60.0));
161 
162  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
163  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
164 
165  Simulator::Schedule(Seconds(1), &SatNcrTest1::GetData, this, sender, receiver);
166 
167  Simulator::Stop(Seconds(60));
168  Simulator::Run();
169 
170  Simulator::Destroy();
171 
172  Singleton<SatEnvVariables>::Get()->DoDispose();
173 
174  uint32_t indexSwitchTdmaSync = 0;
175  for (uint32_t i = 0; i < m_states.size(); i++)
176  {
177  if (m_states[i] == SatUtMacState::TDMA_SYNC)
178  {
179  indexSwitchTdmaSync = i;
180  break;
181  }
182  }
183 
184  // Check if switch to TDMA_SYNC state
185  NS_TEST_ASSERT_MSG_NE(indexSwitchTdmaSync,
186  0,
187  "UT should switch to TDMA_SYNC before the end of simulation");
188 
189  // Check that nothing has been received before logon
190  NS_TEST_ASSERT_MSG_NE(m_totalSent[indexSwitchTdmaSync - 1], 0, "Data sent before logon");
191  NS_TEST_ASSERT_MSG_EQ(m_totalReceived[indexSwitchTdmaSync - 1],
192  0,
193  "Nothing received before logon");
194 
195  // Receiver has always received data after logon
196  for (uint32_t i = indexSwitchTdmaSync + 1; i < m_totalReceived.size() - 1; i++)
197  {
198  NS_TEST_ASSERT_MSG_GT(m_totalReceived[i + 1],
199  m_totalReceived[i],
200  "Receiver should always receive data after logon");
201  }
202 
203  // At the end, receiver got all all data sent
204  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
205 }
206 
207 void
208 SatNcrTest1::GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver)
209 {
210  m_totalSent.push_back(sender->GetSent());
211  m_totalReceived.push_back(receiver->GetTotalRx());
212  m_states.push_back(
213  DynamicCast<SatUtMac>(
214  DynamicCast<SatNetDevice>(m_helper->UtNodes().Get(0)->GetDevice(2))->GetMac())
215  ->GetRcstState());
216 
217  Simulator::Schedule(Seconds(1), &SatNcrTest1::GetData, this, sender, receiver);
218 }
219 
231 class SatNcrTest2 : public TestCase
232 {
233  public:
234  SatNcrTest2();
235  virtual ~SatNcrTest2();
236 
237  private:
238  virtual void DoRun(void);
239  void GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver);
240  void ChangeTxStatus(bool enable);
241 
242  Ptr<SatHelper> m_helper;
243 
244  std::vector<int> m_totalSent;
245  std::vector<int> m_totalReceived;
246  std::vector<SatUtMacState::RcstState_t> m_states;
247  Ptr<SatChannel> m_channel;
248 };
249 
250 // Add some help text to this case to describe what it is intended to test
252  : TestCase("This case tests ncr recovery mechanism.")
253 {
254 }
255 
256 // This destructor does nothing but we include it as a reminder that
257 // the test case should clean up after itself
259 {
260 }
261 
262 //
263 // SatNcrTest2 TestCase implementation
264 //
265 void
267 {
268  // Set simulation output details
269  Singleton<SatEnvVariables>::Get()->DoInitialize();
270  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-ncr", "", true);
271 
272  // Configure a static error probability
273  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
274  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
275 
276  // Set 2 RA frames including one for logon
277  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
278  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_0));
279  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
280  EnumValue(SatEnums::RA_MODEL_SLOTTED_ALOHA));
281  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
282  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
283  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
284  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
285  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_RandomAccessFrame", BooleanValue(true));
286  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_RandomAccessFrame", BooleanValue(true));
287  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_LogonFrame", BooleanValue(true));
288 
289  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_GuardTimeSymbols", UintegerValue(4));
290  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_GuardTimeSymbols", UintegerValue(4));
291  Config::SetDefault("ns3::SatSuperframeConf0::Frame2_GuardTimeSymbols", UintegerValue(4));
292  Config::SetDefault("ns3::SatSuperframeConf0::Frame3_GuardTimeSymbols", UintegerValue(4));
293  Config::SetDefault("ns3::SatSuperframeConf0::Frame4_GuardTimeSymbols", UintegerValue(4));
294  Config::SetDefault("ns3::SatSuperframeConf0::Frame5_GuardTimeSymbols", UintegerValue(4));
295  Config::SetDefault("ns3::SatSuperframeConf0::Frame6_GuardTimeSymbols", UintegerValue(4));
296  Config::SetDefault("ns3::SatSuperframeConf0::Frame7_GuardTimeSymbols", UintegerValue(4));
297  Config::SetDefault("ns3::SatSuperframeConf0::Frame8_GuardTimeSymbols", UintegerValue(4));
298  Config::SetDefault("ns3::SatSuperframeConf0::Frame9_GuardTimeSymbols", UintegerValue(4));
299 
300  Config::SetDefault("ns3::SatUtMac::WindowInitLogon", TimeValue(Seconds(20)));
301  Config::SetDefault("ns3::SatUtMac::MaxWaitingTimeLogonResponse", TimeValue(Seconds(1)));
302 
303  // Set default values for NCR
304  Config::SetDefault("ns3::SatMac::NcrVersion2", BooleanValue(false));
305  Config::SetDefault("ns3::SatGwMac::NcrBroadcastPeriod", TimeValue(MilliSeconds(100)));
306  Config::SetDefault("ns3::SatGwMac::UseCmt", BooleanValue(true));
307  Config::SetDefault("ns3::SatUtMacState::NcrSyncTimeout", TimeValue(Seconds(1)));
308  Config::SetDefault("ns3::SatUtMacState::NcrRecoveryTimeout", TimeValue(Seconds(10)));
309  Config::SetDefault("ns3::SatNcc::UtTimeout", TimeValue(Seconds(10)));
310 
311  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(true));
312  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotInterval", TimeValue(MilliSeconds(500)));
313 
314  Config::SetDefault("ns3::SatUtMac::ClockDrift", IntegerValue(100));
315  Config::SetDefault("ns3::SatGwMac::CmtPeriodMin", TimeValue(MilliSeconds(550)));
316 
317  // Creating the reference system.
318  m_helper = CreateObject<SatHelper>();
319  m_helper->CreatePredefinedScenario(SatHelper::SIMPLE);
320 
321  NodeContainer gwUsers = m_helper->GetGwUsers();
322 
323  // Create the Cbr application to send UDP datagrams of size
324  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 100ms)
325  uint16_t port = 9; // Discard port (RFC 863)
326  CbrHelper cbr("ns3::UdpSocketFactory",
327  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
328  cbr.SetAttribute("Interval", StringValue("100ms"));
329  ApplicationContainer utApps = cbr.Install(m_helper->GetUtUsers());
330  utApps.Start(Seconds(1.0));
331  utApps.Stop(Seconds(59.0));
332 
333  // Create a packet sink to receive these packets
334  PacketSinkHelper sink(
335  "ns3::UdpSocketFactory",
336  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
337  ApplicationContainer gwApps = sink.Install(gwUsers);
338  gwApps.Start(Seconds(1.0));
339  gwApps.Stop(Seconds(60.0));
340 
341  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
342  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
343 
344  Simulator::Schedule(Seconds(1), &SatNcrTest2::GetData, this, sender, receiver);
345 
346  // Schedule GW transmitter switch off and switch on
347  Simulator::Schedule(Seconds(30), &SatNcrTest2::ChangeTxStatus, this, false);
348  Simulator::Schedule(Seconds(38), &SatNcrTest2::ChangeTxStatus, this, true);
349 
350  Simulator::Stop(Seconds(60));
351  Simulator::Run();
352 
353  Simulator::Destroy();
354 
355  Singleton<SatEnvVariables>::Get()->DoDispose();
356 
357  uint32_t indexSwitchTdmaSync = 0;
358  for (uint32_t i = 0; i < m_states.size(); i++)
359  {
360  if (m_states[i] == SatUtMacState::TDMA_SYNC)
361  {
362  indexSwitchTdmaSync = i;
363  break;
364  }
365  }
366 
367  // Check if switch to TDMA_SYNC state
368  NS_TEST_ASSERT_MSG_NE(indexSwitchTdmaSync,
369  0,
370  "UT should switch to TDMA_SYNC before the end of simulation");
371 
372  // State is never OFF_STANDBY nor READY_FOR_LOGON after logon
373  for (uint32_t i = indexSwitchTdmaSync; i < m_states.size() - 1; i++)
374  {
375  NS_TEST_ASSERT_MSG_NE(m_states[i],
376  SatUtMacState::OFF_STANDBY,
377  "UT should not switch to OFF_STANDBY after NCR_RECOVERY");
378  NS_TEST_ASSERT_MSG_NE(m_states[i],
379  SatUtMacState::READY_FOR_LOGON,
380  "UT should not switch to READY_FOR_LOGON after NCR_RECOVERY");
381  }
382 
383  // State is NCR RECOVERY between 32s and 38s
384  for (uint32_t i = 31; i < 39; i++)
385  {
386  NS_TEST_ASSERT_MSG_EQ(m_states[i],
387  SatUtMacState::NCR_RECOVERY,
388  "UT should be in NCR_RECOVERY after loss of NCR");
389  }
390 
391  uint32_t receivedBeforeNcrRecovery = m_totalReceived[32];
392  // Nothing received between 31s and 38s
393  for (uint32_t i = 31; i < 39; i++)
394  {
395  NS_TEST_ASSERT_MSG_EQ((uint32_t)m_totalReceived[i],
396  receivedBeforeNcrRecovery,
397  "Receiver should not receive anything between 31s and 38s");
398  }
399 
400  // Receiver has always received data after recovering NCR messages
401  for (uint32_t i = 39; i < m_totalReceived.size() - 1; i++)
402  {
403  NS_TEST_ASSERT_MSG_GT(m_totalReceived[i + 1],
404  m_totalReceived[i],
405  "Receiver should always receive data after logon");
406  }
407 
408  // At the end, receiver got all all data sent
409  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
410 }
411 
412 void
413 SatNcrTest2::GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver)
414 {
415  m_totalSent.push_back(sender->GetSent());
416  m_totalReceived.push_back(receiver->GetTotalRx());
417  m_states.push_back(
418  DynamicCast<SatUtMac>(
419  DynamicCast<SatNetDevice>(m_helper->UtNodes().Get(0)->GetDevice(2))->GetMac())
420  ->GetRcstState());
421 
422  Simulator::Schedule(Seconds(1), &SatNcrTest2::GetData, this, sender, receiver);
423 }
424 
425 void
427 {
428  if (enable)
429  {
430  DynamicCast<SatGwMac>(
431  DynamicCast<SatNetDevice>(m_helper->GwNodes().Get(0)->GetDevice(1))->GetMac())
432  ->SetAttribute("NcrBroadcastPeriod", TimeValue(MilliSeconds(100)));
433  }
434  else
435  {
436  DynamicCast<SatGwMac>(
437  DynamicCast<SatNetDevice>(m_helper->GwNodes().Get(0)->GetDevice(1))->GetMac())
438  ->SetAttribute("NcrBroadcastPeriod", TimeValue(Seconds(9)));
439  }
440 }
441 
455 class SatNcrTest3 : public TestCase
456 {
457  public:
458  SatNcrTest3(SatEnums::RegenerationMode_t regenerationMode);
459  virtual ~SatNcrTest3();
460 
461  private:
462  virtual void DoRun(void);
463  void GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver);
464  void ChangeTxStatus(bool enable);
465 
467 
468  Ptr<SatHelper> m_helper;
469 
470  std::vector<int> m_totalSent;
471  std::vector<int> m_totalReceived;
472  std::vector<SatUtMacState::RcstState_t> m_states;
473  Ptr<SatChannel> m_channel;
474 };
475 
476 // Add some help text to this case to describe what it is intended to test
478  : TestCase("This case tests ncr recovery timeout mechanism and logoff.")
479 {
480  m_regenerationMode = regenerationMode;
481 }
482 
483 // This destructor does nothing but we include it as a reminder that
484 // the test case should clean up after itself
486 {
487 }
488 
489 //
490 // SatNcrTest3 TestCase implementation
491 //
492 void
494 {
495  // Set simulation output details
496  Singleton<SatEnvVariables>::Get()->DoInitialize();
497  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-ncr", "", true);
498 
499  // Configure a static error probability
500  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
501  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
502 
503  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode", EnumValue(m_regenerationMode));
504 
505  // Set 2 RA frames including one for logon
506  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
507  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_0));
508  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
509  EnumValue(SatEnums::RA_MODEL_SLOTTED_ALOHA));
510  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
511  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
512  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
513  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
514  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_RandomAccessFrame", BooleanValue(true));
515  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_RandomAccessFrame", BooleanValue(true));
516  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_LogonFrame", BooleanValue(true));
517 
518  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_GuardTimeSymbols", UintegerValue(4));
519  Config::SetDefault("ns3::SatSuperframeConf0::Frame1_GuardTimeSymbols", UintegerValue(4));
520  Config::SetDefault("ns3::SatSuperframeConf0::Frame2_GuardTimeSymbols", UintegerValue(4));
521  Config::SetDefault("ns3::SatSuperframeConf0::Frame3_GuardTimeSymbols", UintegerValue(4));
522  Config::SetDefault("ns3::SatSuperframeConf0::Frame4_GuardTimeSymbols", UintegerValue(4));
523  Config::SetDefault("ns3::SatSuperframeConf0::Frame5_GuardTimeSymbols", UintegerValue(4));
524  Config::SetDefault("ns3::SatSuperframeConf0::Frame6_GuardTimeSymbols", UintegerValue(4));
525  Config::SetDefault("ns3::SatSuperframeConf0::Frame7_GuardTimeSymbols", UintegerValue(4));
526  Config::SetDefault("ns3::SatSuperframeConf0::Frame8_GuardTimeSymbols", UintegerValue(4));
527  Config::SetDefault("ns3::SatSuperframeConf0::Frame9_GuardTimeSymbols", UintegerValue(4));
528 
529  Config::SetDefault("ns3::SatUtMac::WindowInitLogon", TimeValue(Seconds(20)));
530  Config::SetDefault("ns3::SatUtMac::MaxWaitingTimeLogonResponse", TimeValue(Seconds(1)));
531 
532  // Set default values for NCR
533  Config::SetDefault("ns3::SatMac::NcrVersion2", BooleanValue(false));
534  Config::SetDefault("ns3::SatGwMac::NcrBroadcastPeriod", TimeValue(MilliSeconds(100)));
535  Config::SetDefault("ns3::SatGwMac::UseCmt", BooleanValue(true));
536  Config::SetDefault("ns3::SatUtMacState::NcrSyncTimeout", TimeValue(Seconds(1)));
537  Config::SetDefault("ns3::SatUtMacState::NcrRecoveryTimeout", TimeValue(Seconds(10)));
538  Config::SetDefault("ns3::SatNcc::UtTimeout", TimeValue(Seconds(10)));
539 
540  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(true));
541  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotInterval", TimeValue(MilliSeconds(500)));
542 
543  Config::SetDefault("ns3::SatUtMac::ClockDrift", IntegerValue(100));
544  Config::SetDefault("ns3::SatGwMac::CmtPeriodMin", TimeValue(MilliSeconds(550)));
545 
546  // Creating the reference system.
547  m_helper = CreateObject<SatHelper>();
548  m_helper->CreatePredefinedScenario(SatHelper::SIMPLE);
549 
550  NodeContainer gwUsers = m_helper->GetGwUsers();
551 
552  // Create the Cbr application to send UDP datagrams of size
553  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 100ms)
554  uint16_t port = 9; // Discard port (RFC 863)
555  CbrHelper cbr("ns3::UdpSocketFactory",
556  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
557  cbr.SetAttribute("Interval", StringValue("100ms"));
558  ApplicationContainer utApps = cbr.Install(m_helper->GetUtUsers());
559  utApps.Start(Seconds(1.0));
560  utApps.Stop(Seconds(119.0));
561 
562  // Create a packet sink to receive these packets
563  PacketSinkHelper sink(
564  "ns3::UdpSocketFactory",
565  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
566  ApplicationContainer gwApps = sink.Install(gwUsers);
567  gwApps.Start(Seconds(1.0));
568  gwApps.Stop(Seconds(120.0));
569 
570  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
571  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
572 
573  Simulator::Schedule(Seconds(1), &SatNcrTest3::GetData, this, sender, receiver);
574 
575  // Schedule GW transmitter switch off and switch on
576  Simulator::Schedule(Seconds(30), &SatNcrTest3::ChangeTxStatus, this, false);
577  Simulator::Schedule(Seconds(55), &SatNcrTest3::ChangeTxStatus, this, true);
578 
579  Simulator::Stop(Seconds(120));
580  Simulator::Run();
581 
582  Simulator::Destroy();
583 
584  Singleton<SatEnvVariables>::Get()->DoDispose();
585 
586  uint32_t indexSwitchTdmaSync = 0;
587  uint32_t indexSwitchNcrRecovery = 0;
588  uint32_t indexSwitchTdmaSyncSecondTime = 0;
589  for (uint32_t i = 0; i < m_states.size(); i++)
590  {
591  if (m_states[i] == SatUtMacState::TDMA_SYNC && indexSwitchTdmaSync == 0)
592  {
593  indexSwitchTdmaSync = i;
594  }
595  if (m_states[i] == SatUtMacState::NCR_RECOVERY && indexSwitchNcrRecovery == 0)
596  {
597  indexSwitchNcrRecovery = i;
598  }
599  if (indexSwitchTdmaSync & indexSwitchNcrRecovery)
600  {
601  break;
602  }
603  }
604 
605  for (uint32_t i = indexSwitchNcrRecovery; i < m_states.size(); i++)
606  {
607  if (m_states[i] == SatUtMacState::TDMA_SYNC)
608  {
609  indexSwitchTdmaSyncSecondTime = i;
610  break;
611  }
612  }
613 
614  // Check if transitions exist
615  NS_TEST_ASSERT_MSG_NE(indexSwitchTdmaSync,
616  0,
617  "UT should switch to TDMA_SYNC before the end of simulation");
618  NS_TEST_ASSERT_MSG_NE(indexSwitchNcrRecovery,
619  0,
620  "UT should switch to NCR_RECOVERY before the end of simulation");
621  NS_TEST_ASSERT_MSG_NE(
622  indexSwitchTdmaSyncSecondTime,
623  0,
624  "UT should switch to TDMA_SYNC after NCR_RECOVERY and before the end of simulation");
625 
626  // State is NCR RECOVERY between 32s and 40s
627  for (uint32_t i = 31; i < 41; i++)
628  {
629  NS_TEST_ASSERT_MSG_EQ(m_states[i],
630  SatUtMacState::NCR_RECOVERY,
631  "UT should be in NCR_RECOVERY after loss of NCR");
632  }
633 
634  // State is READY_FOR_LOGON after timeout logon
635  bool stateFound = false;
636  for (uint32_t i = indexSwitchNcrRecovery; i < m_states.size() - 1; i++)
637  {
638  if (m_states[i] == SatUtMacState::OFF_STANDBY ||
639  m_states[i] == SatUtMacState::READY_FOR_LOGON)
640  {
641  stateFound = true;
642  }
643  }
644  NS_TEST_ASSERT_MSG_EQ(stateFound,
645  true,
646  "UT should switch to OFF_STANDBY or READY_FOR_LOGON after NCR_RECOVERY");
647 
648  uint32_t receivedBeforeNcrRecovery = m_totalReceived[indexSwitchNcrRecovery + 1];
649  // Nothing received between 31s and 55s (no NCR control message)
650  for (uint32_t i = 31; i < 56; i++)
651  {
652  NS_TEST_ASSERT_MSG_EQ((uint32_t)m_totalReceived[i],
653  receivedBeforeNcrRecovery,
654  "Receiver should not receive anything between 31s and 50s");
655  }
656 
657  // Receiver has always received data after recovering NCR messages
658  for (uint32_t i = indexSwitchTdmaSyncSecondTime + 2; i < m_totalReceived.size() - 1; i++)
659  {
660  NS_TEST_ASSERT_MSG_GT(m_totalReceived[i + 1],
661  m_totalReceived[i],
662  "Receiver should always receive data after second logon");
663  }
664 
665  // At the end, receiver got all all data sent
666  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
667 }
668 
669 void
670 SatNcrTest3::GetData(Ptr<CbrApplication> sender, Ptr<PacketSink> receiver)
671 {
672  m_totalSent.push_back(sender->GetSent());
673  m_totalReceived.push_back(receiver->GetTotalRx());
674  m_states.push_back(
675  DynamicCast<SatUtMac>(
676  DynamicCast<SatNetDevice>(m_helper->UtNodes().Get(0)->GetDevice(2))->GetMac())
677  ->GetRcstState());
678 
679  Simulator::Schedule(Seconds(1), &SatNcrTest3::GetData, this, sender, receiver);
680 }
681 
682 void
684 {
685  if (enable)
686  {
687  DynamicCast<SatGwMac>(
688  DynamicCast<SatNetDevice>(m_helper->GwNodes().Get(0)->GetDevice(1))->GetMac())
689  ->SetAttribute("NcrBroadcastPeriod", TimeValue(MilliSeconds(100)));
690  }
691  else
692  {
693  DynamicCast<SatGwMac>(
694  DynamicCast<SatNetDevice>(m_helper->GwNodes().Get(0)->GetDevice(1))->GetMac())
695  ->SetAttribute("NcrBroadcastPeriod", TimeValue(Seconds(30)));
696  }
697 }
698 
699 // The TestSuite class names the TestSuite as sat-ncr-test, identifies what type of TestSuite
700 // (SYSTEM), and enables the TestCases to be run. Typically, only the constructor for this class
701 // must be defined
702 //
703 class SatNcrTestSuite : public TestSuite
704 {
705  public:
706  SatNcrTestSuite();
707 };
708 
710  : TestSuite("sat-ncr-test", SYSTEM)
711 {
712  AddTestCase(new SatNcrTest1, TestCase::QUICK);
713  AddTestCase(new SatNcrTest2, TestCase::QUICK);
714  AddTestCase(new SatNcrTest3(SatEnums::TRANSPARENT), TestCase::QUICK);
715  AddTestCase(new SatNcrTest3(SatEnums::REGENERATION_PHY), TestCase::QUICK);
716  AddTestCase(new SatNcrTest3(SatEnums::REGENERATION_LINK), TestCase::QUICK);
717  AddTestCase(new SatNcrTest3(SatEnums::REGENERATION_NETWORK), TestCase::QUICK);
718 }
719 
720 // Allocate an instance of this TestSuite
'NCR, test 1' test case implementation.
void GetData(Ptr< CbrApplication > sender, Ptr< PacketSink > receiver)
virtual void DoRun(void)
std::vector< int > m_totalSent
std::vector< int > m_totalReceived
std::vector< SatUtMacState::RcstState_t > m_states
Ptr< SatHelper > m_helper
virtual ~SatNcrTest1()
'NCR, test 2' test case implementation.
Ptr< SatHelper > m_helper
void GetData(Ptr< CbrApplication > sender, Ptr< PacketSink > receiver)
std::vector< SatUtMacState::RcstState_t > m_states
virtual void DoRun(void)
std::vector< int > m_totalReceived
void ChangeTxStatus(bool enable)
std::vector< int > m_totalSent
virtual ~SatNcrTest2()
Ptr< SatChannel > m_channel
'NCR, test 3' test case implementation.
SatNcrTest3(SatEnums::RegenerationMode_t regenerationMode)
virtual ~SatNcrTest3()
std::vector< SatUtMacState::RcstState_t > m_states
void GetData(Ptr< CbrApplication > sender, Ptr< PacketSink > receiver)
Ptr< SatHelper > m_helper
virtual void DoRun(void)
std::vector< int > m_totalReceived
void ChangeTxStatus(bool enable)
Ptr< SatChannel > m_channel
std::vector< int > m_totalSent
SatEnums::RegenerationMode_t m_regenerationMode
RegenerationMode_t
The regeneration mode used in satellites.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatNcrTestSuite satNcrTestSuite