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