satellite-regeneration-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-geo-feeder-phy.h"
37 #include "ns3/satellite-geo-net-device.h"
38 #include "ns3/satellite-geo-user-phy.h"
39 #include "ns3/satellite-gw-mac.h"
40 #include "ns3/satellite-helper.h"
41 #include "ns3/satellite-phy-rx-carrier.h"
42 #include "ns3/satellite-ut-mac-state.h"
43 #include "ns3/simulation-helper.h"
44 #include "ns3/simulator.h"
45 #include "ns3/singleton.h"
46 #include "ns3/string.h"
47 #include "ns3/test.h"
48 
49 using namespace ns3;
50 
60 class SatRegenerationTest1 : public TestCase
61 {
62  public:
64  virtual ~SatRegenerationTest1();
65 
66  private:
67  virtual void DoRun(void);
68  void PhyDelayTraceCb(std::string context, const Time& time, const Address& address);
69  void GeoFeederPhyTraceDelayCb(const Time& time, const Address& address);
70  void GeoUserPhyTraceDelayCb(const Time& time, const Address& address);
71 
72  Ptr<SatHelper> m_helper;
73 
74  Address m_gwAddress;
75  Address m_stAddress;
76 
77  std::vector<Time> m_forwardDelay;
78  std::vector<Time> m_returnDelay;
79  std::vector<Time> m_geoForwardDelay;
80  std::vector<Time> m_geoReturnDelay;
81 };
82 
83 // Add some help text to this case to describe what it is intended to test
85  : TestCase(
86  "This case tests that delay of packets takes into account regeneration in satellite.")
87 {
88 }
89 
90 // This destructor does nothing but we include it as a reminder that
91 // the test case should clean up after itself
93 {
94 }
95 
96 void
97 SatRegenerationTest1::PhyDelayTraceCb(std::string context, const Time& time, const Address& address)
98 {
99  if (address == m_gwAddress)
100  {
101  m_forwardDelay.push_back(time);
102  }
103  if (address == m_stAddress)
104  {
105  m_returnDelay.push_back(time);
106  }
107 }
108 
109 void
110 SatRegenerationTest1::GeoFeederPhyTraceDelayCb(const Time& time, const Address& address)
111 {
112  m_geoForwardDelay.push_back(time);
113 }
114 
115 void
116 SatRegenerationTest1::GeoUserPhyTraceDelayCb(const Time& time, const Address& address)
117 {
118  m_geoReturnDelay.push_back(time);
119 }
120 
121 //
122 // SatRegenerationTest1 TestCase implementation
123 //
124 void
126 {
127  Config::Reset();
128 
129  // Set simulation output details
130  Singleton<SatEnvVariables>::Get()->DoInitialize();
131  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test1", true);
132 
134  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
135  EnumValue(SatEnums::REGENERATION_PHY));
136  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
137  EnumValue(SatEnums::REGENERATION_PHY));
138 
139  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
140 
141  // Enable traces
142  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
143  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
144 
146  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
147 
148  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("500ms"));
149  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
150 
151  // Creating the reference system.
152  m_helper = CreateObject<SatHelper>();
153  m_helper->CreatePredefinedScenario(SatHelper::SIMPLE);
154 
155  NodeContainer utUsers = m_helper->GetUtUsers();
156  NodeContainer gwUsers = m_helper->GetGwUsers();
157  uint16_t port = 9;
158 
159  // Install forward traffic
160  CbrHelper cbrForward(
161  "ns3::UdpSocketFactory",
162  Address(InetSocketAddress(m_helper->GetUserAddress(utUsers.Get(0)), port)));
163  ApplicationContainer gwAppsForward = cbrForward.Install(gwUsers);
164  gwAppsForward.Start(Seconds(1.0));
165  gwAppsForward.Stop(Seconds(5.0));
166 
167  PacketSinkHelper sinkForward(
168  "ns3::UdpSocketFactory",
169  Address(InetSocketAddress(m_helper->GetUserAddress(utUsers.Get(0)), port)));
170  ApplicationContainer utAppsForward = sinkForward.Install(utUsers);
171  utAppsForward.Start(Seconds(1.0));
172  utAppsForward.Stop(Seconds(10.0));
173 
174  // Install return traffic
175  CbrHelper cbrReturn("ns3::UdpSocketFactory",
176  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
177  ApplicationContainer utAppsReturn = cbrReturn.Install(utUsers);
178  utAppsReturn.Start(Seconds(1.0));
179  utAppsReturn.Stop(Seconds(5.0));
180 
181  PacketSinkHelper sinkReturn(
182  "ns3::UdpSocketFactory",
183  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
184  ApplicationContainer gwAppsReturn = sinkReturn.Install(gwUsers);
185  gwAppsReturn.Start(Seconds(1.0));
186  gwAppsReturn.Stop(Seconds(10.0));
187 
188  m_gwAddress = m_helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
189  m_stAddress = m_helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
190 
191  Ptr<SatGeoFeederPhy> satGeoFeederPhy = DynamicCast<SatGeoFeederPhy>(
192  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))
193  ->GetFeederPhy(8));
194  Ptr<SatGeoUserPhy> satGeoUserPhy = DynamicCast<SatGeoUserPhy>(
195  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetUserPhy(8));
196 
197  satGeoFeederPhy->TraceConnectWithoutContext(
198  "RxLinkDelay",
200  satGeoUserPhy->TraceConnectWithoutContext(
201  "RxLinkDelay",
202  MakeCallback(&SatRegenerationTest1::GeoUserPhyTraceDelayCb, this));
203  Config::Connect("/NodeList/*/DeviceList/*/SatPhy/RxLinkDelay",
204  MakeCallback(&SatRegenerationTest1::PhyDelayTraceCb, this));
205 
206  Ptr<SatChannel> feederChannel = satGeoFeederPhy->GetPhyTx()->GetChannel();
207  Ptr<SatChannel> userChannel = satGeoUserPhy->GetPhyTx()->GetChannel();
208 
209  Ptr<PropagationDelayModel> feederDelayModel = feederChannel->GetPropagationDelayModel();
210  Ptr<PropagationDelayModel> userDelayModel = userChannel->GetPropagationDelayModel();
211 
212  Time feederDelay = feederDelayModel->GetDelay(
213  DynamicCast<SatNetDevice>(m_helper->GwNodes().Get(0)->GetDevice(1))
214  ->GetPhy()
215  ->GetPhyTx()
216  ->GetMobility(),
217  satGeoFeederPhy->GetPhyTx()->GetMobility());
218 
219  Time userDelay =
220  userDelayModel->GetDelay(DynamicCast<SatNetDevice>(m_helper->UtNodes().Get(0)->GetDevice(2))
221  ->GetPhy()
222  ->GetPhyTx()
223  ->GetMobility(),
224  satGeoUserPhy->GetPhyTx()->GetMobility());
225 
226  Simulator::Stop(Seconds(10));
227  Simulator::Run();
228 
229  Simulator::Destroy();
230 
231  // In default configuration, we have:
232  // - FWD transmission delay (NORMAL BBFrame = 32400 symbols, QPSK 1/2, BW = 104 MHz): 319 507
233  // ns
234  // - RTN transmission delay (frame = 536 symbols, QPSK 1/3, BW = 801 kHz): 668 928 ns
235  // We have to remove 1 us default guard time to these delays to get transmission time.
236 
237  Time fwdTime = NanoSeconds(319507) - MicroSeconds(1);
238  Time rtnTime = NanoSeconds(668928) - MicroSeconds(1);
239 
240  for (uint32_t i = 0; i < m_geoForwardDelay.size(); i++)
241  {
242  NS_TEST_ASSERT_MSG_EQ(m_geoForwardDelay[i] - feederDelay,
243  fwdTime,
244  "Transmission time on FWD FEEDER incorrect.");
245  }
246 
247  for (uint32_t i = 0; i < m_geoReturnDelay.size(); i++)
248  {
249  NS_TEST_ASSERT_MSG_EQ(m_geoReturnDelay[i] - userDelay,
250  rtnTime,
251  "Transmission time on RTN USER incorrect.");
252  }
253 
254  for (uint32_t i = 0; i < m_forwardDelay.size(); i++)
255  {
256  NS_TEST_ASSERT_MSG_EQ(m_forwardDelay[i] - userDelay,
257  fwdTime,
258  "Transmission time on FWD USER incorrect.");
259  }
260 
261  for (uint32_t i = 0; i < m_returnDelay.size(); i++)
262  {
263  NS_TEST_ASSERT_MSG_EQ(m_returnDelay[i] - feederDelay,
264  rtnTime,
265  "Transmission time on RTN FEEDER incorrect.");
266  }
267 }
268 
281 class SatRegenerationTest2 : public TestCase
282 {
283  public:
285  virtual ~SatRegenerationTest2();
286 
287  private:
288  virtual void DoRun(void);
289  void GeoPhyTraceCb(Time time,
292  uint32_t nodeId,
293  Mac48Address address,
296  std::string packetInfo);
297  void PhyTraceCb(Time time,
300  uint32_t nodeId,
301  Mac48Address address,
304  std::string packetInfo);
305 
306  Ptr<SatHelper> m_helper;
307 
312 
317 };
318 
319 // Add some help text to this case to describe what it is intended to test
321  : TestCase("This case tests physical regeneration on satellite. It is based on a SIMPLE "
322  "scenario, with losses on uplink, forward and return."),
323  m_packetsReceivedFeeder(0),
324  m_packetsDroppedFeeder(0),
325  m_packetsReceivedUser(0),
326  m_packetsDroppedUser(0),
327  m_packetsReceivedUt(0),
328  m_packetsDroppedUt(0),
329  m_packetsReceivedGw(0),
330  m_packetsDroppedGw(0)
331 {
332 }
333 
334 // This destructor does nothing but we include it as a reminder that
335 // the test case should clean up after itself
337 {
338 }
339 
340 void
344  uint32_t nodeId,
345  Mac48Address address,
348  std::string packetInfo)
349 {
350  switch (dir)
351  {
352  case SatEnums::LD_FORWARD:
353  if (event == SatEnums::PACKET_RECV)
354  {
356  }
357  else if (event == SatEnums::PACKET_DROP)
358  {
360  }
361  break;
362  case SatEnums::LD_RETURN:
363  if (event == SatEnums::PACKET_RECV)
364  {
366  }
367  else if (event == SatEnums::PACKET_DROP)
368  {
370  }
371  break;
372  default:
373  break;
374  }
375 }
376 
377 void
381  uint32_t nodeId,
382  Mac48Address address,
385  std::string packetInfo)
386 {
387  switch (dir)
388  {
389  case SatEnums::LD_FORWARD:
390  if (event == SatEnums::PACKET_RECV)
391  {
393  }
394  else if (event == SatEnums::PACKET_DROP)
395  {
397  }
398  break;
399  case SatEnums::LD_RETURN:
400  if (event == SatEnums::PACKET_RECV)
401  {
403  }
404  else if (event == SatEnums::PACKET_DROP)
405  {
407  }
408  break;
409  default:
410  break;
411  }
412 }
413 
414 //
415 // SatRegenerationTest2 TestCase implementation
416 //
417 void
419 {
420  Config::Reset();
421 
422  // Set simulation output details
423  Singleton<SatEnvVariables>::Get()->DoInitialize();
424  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test2", true);
425 
427  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
428  EnumValue(SatEnums::REGENERATION_PHY));
429  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
430  EnumValue(SatEnums::REGENERATION_PHY));
431 
432  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
433 
435  Config::SetDefault("ns3::SatGeoHelper::FwdLinkErrorModel",
436  EnumValue(SatPhyRxCarrierConf::EM_CONSTANT));
437  Config::SetDefault("ns3::SatGeoHelper::FwdLinkConstantErrorRate", DoubleValue(0.1));
438  Config::SetDefault("ns3::SatGeoHelper::RtnLinkErrorModel",
439  EnumValue(SatPhyRxCarrierConf::EM_CONSTANT));
440  Config::SetDefault("ns3::SatGeoHelper::RtnLinkConstantErrorRate", DoubleValue(0.1));
441 
442  // Enable SatMac traces
443  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
444  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
445 
447  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
448 
449  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("10ms"));
450  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
451 
452  // Creating the reference system.
453  m_helper = CreateObject<SatHelper>();
454  m_helper->CreatePredefinedScenario(SatHelper::SIMPLE);
455 
456  NodeContainer utUsers = m_helper->GetUtUsers();
457  NodeContainer gwUsers = m_helper->GetGwUsers();
458  uint16_t port = 9;
459 
460  // Install forward traffic
461  CbrHelper cbrForward(
462  "ns3::UdpSocketFactory",
463  Address(InetSocketAddress(m_helper->GetUserAddress(utUsers.Get(0)), port)));
464  ApplicationContainer gwAppsForward = cbrForward.Install(gwUsers);
465  gwAppsForward.Start(Seconds(1.0));
466  gwAppsForward.Stop(Seconds(59.0));
467 
468  PacketSinkHelper sinkForward(
469  "ns3::UdpSocketFactory",
470  Address(InetSocketAddress(m_helper->GetUserAddress(utUsers.Get(0)), port)));
471  ApplicationContainer utAppsForward = sinkForward.Install(utUsers);
472  utAppsForward.Start(Seconds(1.0));
473  utAppsForward.Stop(Seconds(60.0));
474 
475  // Install return traffic
476  CbrHelper cbrReturn("ns3::UdpSocketFactory",
477  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
478  ApplicationContainer utAppsReturn = cbrReturn.Install(utUsers);
479  utAppsReturn.Start(Seconds(1.0));
480  utAppsReturn.Stop(Seconds(59.0));
481 
482  PacketSinkHelper sinkReturn(
483  "ns3::UdpSocketFactory",
484  Address(InetSocketAddress(m_helper->GetUserAddress(gwUsers.Get(0)), port)));
485  ApplicationContainer gwAppsReturn = sinkReturn.Install(gwUsers);
486  gwAppsReturn.Start(Seconds(1.0));
487  gwAppsReturn.Stop(Seconds(60.0));
488 
489  Ptr<SatGeoFeederPhy> satGeoFeederPhy = DynamicCast<SatGeoFeederPhy>(
490  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))
491  ->GetFeederPhy(8));
492  Ptr<SatGeoUserPhy> satGeoUserPhy = DynamicCast<SatGeoUserPhy>(
493  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetUserPhy(8));
494 
495  satGeoFeederPhy->TraceConnectWithoutContext(
496  "PacketTrace",
497  MakeCallback(&SatRegenerationTest2::GeoPhyTraceCb, this));
498  satGeoUserPhy->TraceConnectWithoutContext(
499  "PacketTrace",
500  MakeCallback(&SatRegenerationTest2::GeoPhyTraceCb, this));
501 
502  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatPhy/PacketTrace",
503  MakeCallback(&SatRegenerationTest2::PhyTraceCb, this));
504 
505  Simulator::Stop(Seconds(60));
506  Simulator::Run();
507 
508  Simulator::Destroy();
509 
510  double dropRateForwardFeeder =
512  double dropRateReturnUser =
514 
515  double forwardDifference =
517  double returnDifference =
519 
520  NS_TEST_ASSERT_MSG_GT(dropRateForwardFeeder, 8.0, "Not enough losses on FWD feeder");
521  NS_TEST_ASSERT_MSG_LT(dropRateForwardFeeder, 12.0, "Too much losses on FWD feeder");
522  NS_TEST_ASSERT_MSG_GT(dropRateReturnUser, 8.0, "Not enough losses on RTN user");
523  NS_TEST_ASSERT_MSG_LT(dropRateReturnUser, 12.0, "Too much losses on RTN user");
524 
525  NS_TEST_ASSERT_MSG_NE(m_packetsReceivedGw, 0, "Packets must be received by GW");
526  NS_TEST_ASSERT_MSG_NE(m_packetsReceivedUt, 0, "Packets must be received by UT");
527  NS_TEST_ASSERT_MSG_EQ(m_packetsDroppedGw, 0, "Packets must not be dropped by GW");
528  NS_TEST_ASSERT_MSG_EQ(m_packetsDroppedUt, 0, "Packets must not be dropped by UT");
529 
530  NS_TEST_ASSERT_MSG_LT(
531  forwardDifference,
532  0.01,
533  "Number of packets received on FWD should be almost the same between SAT and UT");
534  NS_TEST_ASSERT_MSG_LT(
535  returnDifference,
536  0.01,
537  "Number of packets received on RTN should be almost the same between SAT and GW");
538 }
539 
552 class SatRegenerationTest3 : public TestCase
553 {
554  public:
556  virtual ~SatRegenerationTest3();
557 
558  private:
559  virtual void DoRun(void);
560  void GeoPhyTraceErrorCb(std::string, uint32_t nPackets, const Address& address, bool hasError);
561  void GeoPhyTraceCollisionCb(std::string,
562  uint32_t nPackets,
563  const Address& address,
564  bool hasCollision);
565  void GeoPhyTraceCb(Time time,
568  uint32_t nodeId,
569  Mac48Address address,
572  std::string packetInfo);
573 
574  Ptr<SatHelper> m_helper;
575 
576  Address m_gwAddress;
577 
582 
587 };
588 
589 // Add some help text to this case to describe what it is intended to test
591  : TestCase("This case tests physical regeneration on satellite. It is based on a LARGER "
592  "scenario, with collisions on return uplink."),
593  m_nbErrorpacketsFwd(0),
594  m_nbErrorpacketsRtn(0),
595  m_nbCollisionPacketsFwd(0),
596  m_nbCollisionPacketsRtn(0),
597  m_packetsReceivedFeeder(0),
598  m_packetsDroppedFeeder(0),
599  m_packetsReceivedUser(0),
600  m_packetsDroppedUser(0)
601 {
602 }
603 
604 // This destructor does nothing but we include it as a reminder that
605 // the test case should clean up after itself
607 {
608 }
609 
610 void
612  uint32_t nPackets,
613  const Address& address,
614  bool hasError)
615 {
616  if (!hasError)
617  {
618  return;
619  }
620  if (address == m_gwAddress)
621  {
622  m_nbErrorpacketsFwd += nPackets;
623  }
624  else
625  {
626  m_nbErrorpacketsRtn += nPackets;
627  }
628 }
629 
630 void
632  uint32_t nPackets,
633  const Address& address,
634  bool hasCollision)
635 {
636  if (!hasCollision)
637  {
638  return;
639  }
640  if (address == m_gwAddress)
641  {
642  m_nbCollisionPacketsFwd += nPackets;
643  }
644  else
645  {
646  m_nbCollisionPacketsRtn += nPackets;
647  }
648 }
649 
650 void
654  uint32_t nodeId,
655  Mac48Address address,
658  std::string packetInfo)
659 {
660  switch (dir)
661  {
662  case SatEnums::LD_FORWARD:
663  if (event == SatEnums::PACKET_RECV)
664  {
666  }
667  else if (event == SatEnums::PACKET_DROP)
668  {
670  }
671  break;
672  case SatEnums::LD_RETURN:
673  if (event == SatEnums::PACKET_RECV)
674  {
676  }
677  else if (event == SatEnums::PACKET_DROP)
678  {
680  }
681  break;
682  default:
683  break;
684  }
685 }
686 
687 //
688 // SatRegenerationTest3 TestCase implementation
689 //
690 void
692 {
693  Config::Reset();
694 
695  // Set simulation output details
696  Singleton<SatEnvVariables>::Get()->DoInitialize();
697  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test3", true);
698 
700  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
701  EnumValue(SatEnums::REGENERATION_PHY));
702  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
703  EnumValue(SatEnums::REGENERATION_PHY));
704 
705  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
706 
708  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
709  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
710 
712  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
713 
714  // Enable Random Access
715  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
716  EnumValue(SatEnums::RA_MODEL_SLOTTED_ALOHA));
717 
718  // Set Random Access interference model
719  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
720  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
721 
722  // Disable periodic control slots
723  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
724 
725  // Set dynamic load control parameters
726  Config::SetDefault("ns3::SatPhyRxCarrierConf::EnableRandomAccessDynamicLoadControl",
727  BooleanValue(false));
728  Config::SetDefault(
729  "ns3::SatPhyRxCarrierConf::RandomAccessAverageNormalizedOfferedLoadMeasurementWindowSize",
730  UintegerValue(10));
731 
732  // Set random access parameters
733  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumUniquePayloadPerBlock",
734  UintegerValue(3));
735  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumConsecutiveBlockAccessed",
736  UintegerValue(6));
737  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MinimumIdleBlock",
738  UintegerValue(2));
739  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffTimeInMilliSeconds",
740  UintegerValue(250));
741  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffProbability",
742  UintegerValue(10000));
743  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_HighLoadBackOffProbability",
744  UintegerValue(30000));
745  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
746  UintegerValue(3));
747  Config::SetDefault(
748  "ns3::SatLowerLayerServiceConf::RaService0_AverageNormalizedOfferedLoadThreshold",
749  DoubleValue(0.5));
750  Config::SetDefault("ns3::SatLowerLayerServiceConf::DefaultControlRandomizationInterval",
751  TimeValue(MilliSeconds(100)));
752  Config::SetDefault("ns3::SatRandomAccessConf::CrdsaSignalingOverheadInBytes", UintegerValue(5));
753  Config::SetDefault("ns3::SatRandomAccessConf::SlottedAlohaSignalingOverheadInBytes",
754  UintegerValue(3));
755 
756  // Disable CRA and DA
757  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
758  BooleanValue(false));
759  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
760  BooleanValue(false));
761  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
762  BooleanValue(false));
763  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
764  BooleanValue(false));
765  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
766  BooleanValue(false));
767  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
768  BooleanValue(false));
769  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
770  BooleanValue(false));
771  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
772  BooleanValue(false));
773  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
774  BooleanValue(false));
775  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
776  BooleanValue(false));
777  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
778  BooleanValue(false));
779  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
780  BooleanValue(false));
781 
782  Config::SetDefault("ns3::SatGeoHelper::FwdLinkErrorModel",
783  EnumValue(SatPhyRxCarrierConf::EM_NONE));
784  Config::SetDefault("ns3::SatGeoHelper::RtnLinkErrorModel",
785  EnumValue(SatPhyRxCarrierConf::EM_AVI));
786  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
787  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
788 
789  Ptr<SimulationHelper> simulationHelper =
790  CreateObject<SimulationHelper>("test-sat-regeneration");
791  simulationHelper->SetSimulationTime(Seconds(5));
792  simulationHelper->SetUserCountPerUt(1);
793  simulationHelper->SetUtCountPerBeam(50);
794  simulationHelper->SetBeamSet({1});
795  simulationHelper->CreateSatScenario();
796 
797  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(MilliSeconds(1)));
798  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
799  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
800  SimulationHelper::UDP,
801  SimulationHelper::RTN_LINK,
802  Seconds(0.01),
803  Seconds(5),
804  Seconds(0.01));
805 
806  m_helper = simulationHelper->GetSatelliteHelper();
807 
808  Ptr<SatGeoFeederPhy> satGeoFeederPhy = DynamicCast<SatGeoFeederPhy>(
809  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))
810  ->GetFeederPhy(1));
811  Ptr<SatGeoUserPhy> satGeoUserPhy = DynamicCast<SatGeoUserPhy>(
812  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetUserPhy(1));
813 
814  m_gwAddress = m_helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
815 
816  satGeoFeederPhy->TraceConnectWithoutContext(
817  "PacketTrace",
818  MakeCallback(&SatRegenerationTest3::GeoPhyTraceCb, this));
819  satGeoUserPhy->TraceConnectWithoutContext(
820  "PacketTrace",
821  MakeCallback(&SatRegenerationTest3::GeoPhyTraceCb, this));
822 
823  Config::Connect(
824  "/NodeList/*/DeviceList/*/FeederPhy/1/PhyRx/RxCarrierList/*/SlottedAlohaRxError",
825  MakeCallback(&SatRegenerationTest3::GeoPhyTraceErrorCb, this));
826  Config::Connect(
827  "/NodeList/*/DeviceList/*/FeederPhy/1/PhyRx/RxCarrierList/*/SlottedAlohaRxCollision",
828  MakeCallback(&SatRegenerationTest3::GeoPhyTraceCollisionCb, this));
829  Config::Connect("/NodeList/*/DeviceList/*/UserPhy/1/PhyRx/RxCarrierList/*/SlottedAlohaRxError",
830  MakeCallback(&SatRegenerationTest3::GeoPhyTraceErrorCb, this));
831  Config::Connect(
832  "/NodeList/*/DeviceList/*/UserPhy/1/PhyRx/RxCarrierList/*/SlottedAlohaRxCollision",
833  MakeCallback(&SatRegenerationTest3::GeoPhyTraceCollisionCb, this));
834 
835  Simulator::Stop(Seconds(5));
836  Simulator::Run();
837 
838  Simulator::Destroy();
839 
840  NS_TEST_ASSERT_MSG_NE(m_packetsReceivedFeeder, 0, "Packets received on FWD feeder link");
841  NS_TEST_ASSERT_MSG_NE(m_packetsReceivedUser,
842  0,
843  "Packets received on RTN user link due to collisions");
844  NS_TEST_ASSERT_MSG_EQ(m_packetsDroppedFeeder, 0, "No packets dropped on FWD feeder link");
845  NS_TEST_ASSERT_MSG_NE(m_packetsDroppedUser,
846  0,
847  "Packets dropped on RTN user link due to collisions");
848 
849  NS_TEST_ASSERT_MSG_EQ(m_nbErrorpacketsFwd, 0, "No errors on FWD feeder link");
850  NS_TEST_ASSERT_MSG_EQ(m_nbCollisionPacketsFwd, 0, "No collisions on FWD feeder link");
851  NS_TEST_ASSERT_MSG_NE(m_nbErrorpacketsRtn, 0, "Need errors on RTN feeder link");
852  NS_TEST_ASSERT_MSG_NE(m_nbCollisionPacketsRtn, 0, "Need collisions on RTN feeder link");
853 }
854 
865 class SatRegenerationTest4 : public TestCase
866 {
867  public:
869  virtual ~SatRegenerationTest4();
870 
871  private:
872  virtual void DoRun(void);
873  void GeoDevGwTxTraceCb(Ptr<const Packet> packet);
874  void GeoDevUtTxTraceCb(Ptr<const Packet> packet);
875  void GeoDevGwRxTraceCb(Ptr<const Packet> packet, const Address&);
876  void GeoDevUtRxTraceCb(Ptr<const Packet> packet, const Address&);
877  bool HasSinkInstalled(Ptr<Node> node, uint16_t port);
878 
879  Ptr<SatHelper> m_helper;
880 
881  uint32_t m_totalSentGw;
882  uint32_t m_totalSentUt;
885 };
886 
887 void
889 {
890  m_totalSentGw += packet->GetSize();
891 }
892 
893 void
895 {
896  m_totalSentUt += packet->GetSize();
897 }
898 
899 void
900 SatRegenerationTest4::GeoDevGwRxTraceCb(Ptr<const Packet> packet, const Address&)
901 {
902  m_totalReceivedGw += packet->GetSize();
903 }
904 
905 void
906 SatRegenerationTest4::GeoDevUtRxTraceCb(Ptr<const Packet> packet, const Address& address)
907 {
908  m_totalReceivedUt += packet->GetSize();
909 }
910 
911 bool
912 SatRegenerationTest4::HasSinkInstalled(Ptr<Node> node, uint16_t port)
913 {
914  for (uint32_t i = 0; i < node->GetNApplications(); i++)
915  {
916  Ptr<PacketSink> sink = DynamicCast<PacketSink>(node->GetApplication(i));
917  if (sink != NULL)
918  {
919  AddressValue av;
920  sink->GetAttribute("Local", av);
921  if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
922  {
923  return true;
924  }
925  }
926  }
927  return false;
928 }
929 
930 // Add some help text to this case to describe what it is intended to test
932  : TestCase("This case tests link regeneration on satellite. It is based on a LARGER scenario.")
933 {
934  m_totalSentGw = 0;
935  m_totalSentUt = 0;
936  m_totalReceivedGw = 0;
937  m_totalReceivedUt = 0;
938 }
939 
940 // This destructor does nothing but we include it as a reminder that
941 // the test case should clean up after itself
943 {
944 }
945 
946 //
947 // SatRegenerationTest4 TestCase implementation
948 //
949 void
951 {
952  Config::Reset();
953 
954  // Set simulation output details
955  Singleton<SatEnvVariables>::Get()->DoInitialize();
956  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test4", true);
957 
959  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
960  EnumValue(SatEnums::REGENERATION_PHY));
961  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
962  EnumValue(SatEnums::REGENERATION_LINK));
963 
964  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
965 
966  // Enable SatMac traces
967  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
968  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
969 
971  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
972 
973  Ptr<SimulationHelper> simulationHelper =
974  CreateObject<SimulationHelper>("test-sat-regeneration");
975  simulationHelper->SetSimulationTime(Seconds(20));
976  simulationHelper->CreateSatScenario(SatHelper::LARGER);
977 
978  m_helper = simulationHelper->GetSatelliteHelper();
979 
980  NodeContainer gws = m_helper->GwNodes();
981  NodeContainer uts = m_helper->UtNodes();
982 
983  uint32_t i;
984  for (i = 0; i < gws.GetN(); i++)
985  {
986  gws.Get(i)->GetDevice(1)->TraceConnectWithoutContext(
987  "Tx",
988  MakeCallback(&SatRegenerationTest4::GeoDevGwTxTraceCb, this));
989  gws.Get(i)->GetDevice(1)->TraceConnectWithoutContext(
990  "Rx",
991  MakeCallback(&SatRegenerationTest4::GeoDevGwRxTraceCb, this));
992  }
993  for (i = 0; i < uts.GetN(); i++)
994  {
995  uts.Get(i)->GetDevice(2)->TraceConnectWithoutContext(
996  "Tx",
997  MakeCallback(&SatRegenerationTest4::GeoDevUtTxTraceCb, this));
998  uts.Get(i)->GetDevice(2)->TraceConnectWithoutContext(
999  "Rx",
1000  MakeCallback(&SatRegenerationTest4::GeoDevUtRxTraceCb, this));
1001  }
1002 
1003  std::string socketFactory = "ns3::UdpSocketFactory";
1004  uint16_t port = 9;
1005 
1006  PacketSinkHelper sinkHelper(socketFactory, Address());
1007  CbrHelper cbrHelper(socketFactory, Address());
1008  ApplicationContainer sinkContainer;
1009  ApplicationContainer cbrContainer;
1010 
1011  Time startTime = Seconds(1);
1012  Time stopTime = Seconds(15);
1013  Time startDelay = MilliSeconds(10);
1014  Time interval = MilliSeconds(100);
1015  uint32_t packetSize = 512;
1016 
1017  for (uint32_t j = 0; j < gws.GetN(); j++)
1018  {
1019  for (uint32_t i = 0; i < uts.GetN(); i++)
1020  {
1021  InetSocketAddress gwUserAddr =
1022  InetSocketAddress(m_helper->GetUserAddress(gws.Get(j)), port);
1023  if (!HasSinkInstalled(gws.Get(j), port))
1024  {
1025  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
1026  sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
1027  }
1028 
1029  cbrHelper.SetConstantTraffic(Time(interval), packetSize);
1030  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
1031  auto app = cbrHelper.Install(uts.Get(i)).Get(0);
1032  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
1033  app->SetStopTime(stopTime);
1034  cbrContainer.Add(app);
1035  }
1036  }
1037 
1038  sinkContainer.Start(startTime);
1039  sinkContainer.Stop(stopTime + Seconds(1));
1040 
1041  simulationHelper->RunSimulation();
1042 
1043  Simulator::Destroy();
1044 
1045  NS_TEST_ASSERT_MSG_EQ(m_totalSentGw, 0, "No packets sent on FWD link");
1046  NS_TEST_ASSERT_MSG_EQ(m_totalReceivedUt, 0, "No packets received on FWD link");
1047  NS_TEST_ASSERT_MSG_EQ(m_totalSentUt,
1049  "Same number of packets sent and received on RTN link");
1050 }
1051 
1065 class SatRegenerationTest5 : public TestCase
1066 {
1067  public:
1069  virtual ~SatRegenerationTest5();
1070 
1071  private:
1072  virtual void DoRun(void);
1073  void GeoPhyGwModcodTraceCb(uint32_t modcod, const Address& address);
1074  void GeoPhyUtModcodTraceCb(uint32_t modcod, const Address& address);
1075  void GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address& address);
1076  void GeoPhyUserModcodTraceCb(uint32_t modcod, const Address& address);
1077 
1078  double GetAverage(std::vector<uint32_t> list, uint32_t beg, uint32_t end);
1079  double GetMostFrequent(std::vector<uint32_t> list, uint32_t beg, uint32_t end);
1080 
1081  Ptr<SatHelper> m_helper;
1082 
1083  std::vector<uint32_t> m_gwModcods;
1084  std::vector<uint32_t> m_utModcods;
1085  std::vector<uint32_t> m_feederModcods;
1086  std::vector<uint32_t> m_userModcods;
1087 };
1088 
1089 void
1090 SatRegenerationTest5::GeoPhyGwModcodTraceCb(uint32_t modcod, const Address& address)
1091 {
1092  m_gwModcods.push_back(modcod);
1093 }
1094 
1095 void
1096 SatRegenerationTest5::GeoPhyUtModcodTraceCb(uint32_t modcod, const Address& address)
1097 {
1098  m_utModcods.push_back(modcod);
1099 }
1100 
1101 void
1102 SatRegenerationTest5::GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address& address)
1103 {
1104  m_feederModcods.push_back(modcod);
1105 }
1106 
1107 void
1108 SatRegenerationTest5::GeoPhyUserModcodTraceCb(uint32_t modcod, const Address& address)
1109 {
1110  m_userModcods.push_back(modcod);
1111 }
1112 
1113 double
1114 SatRegenerationTest5::GetAverage(std::vector<uint32_t> list, uint32_t beg, uint32_t end)
1115 {
1116  uint32_t sum = 0;
1117  for (uint32_t i = beg; i < end; i++)
1118  {
1119  sum += list[i];
1120  }
1121  return 1.0 * sum / (end - beg);
1122 }
1123 
1124 double
1125 SatRegenerationTest5::GetMostFrequent(std::vector<uint32_t> list, uint32_t beg, uint32_t end)
1126 {
1127  std::map<uint32_t, uint32_t> frequencies;
1128  for (uint32_t i = beg; i < end; i++)
1129  {
1130  frequencies[list[i]]++;
1131  }
1132 
1133  uint32_t max_count = 0;
1134  uint32_t index = -1;
1135  for (std::pair<const uint32_t, uint32_t>& i : frequencies)
1136  {
1137  if (max_count < i.second)
1138  {
1139  index = i.first;
1140  max_count = i.second;
1141  }
1142  }
1143 
1144  return index;
1145 }
1146 
1147 // Add some help text to this case to describe what it is intended to test
1149  : TestCase("This case tests ACM on all links. It is based on a SIMPLE scenario.")
1150 {
1151 }
1152 
1153 // This destructor does nothing but we include it as a reminder that
1154 // the test case should clean up after itself
1156 {
1157 }
1158 
1159 //
1160 // SatRegenerationTest5 TestCase implementation
1161 //
1162 void
1164 {
1165  Config::Reset();
1166 
1167  // Set simulation output details
1168  Singleton<SatEnvVariables>::Get()->DoInitialize();
1169  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test5", true);
1170 
1172  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
1173  EnumValue(SatEnums::REGENERATION_PHY));
1174  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
1175  EnumValue(SatEnums::REGENERATION_LINK));
1176 
1177  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
1178 
1180  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
1181 
1182  // Enable SatMac traces
1183  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
1184  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
1185 
1187  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
1188 
1189  Ptr<SimulationHelper> simulationHelper =
1190  CreateObject<SimulationHelper>("test-sat-regeneration");
1191  simulationHelper->SetSimulationTime(Seconds(20));
1192  simulationHelper->CreateSatScenario(SatHelper::SIMPLE);
1193 
1194  m_helper = simulationHelper->GetSatelliteHelper();
1195 
1196  Ptr<Node> gwNode = m_helper->GwNodes().Get(0);
1197  Ptr<Node> utNode = m_helper->UtNodes().Get(0);
1198  Ptr<Node> geoNode = m_helper->GeoSatNodes().Get(0);
1199  Ptr<SatGeoFeederPhy> satGeoFeederPhy = DynamicCast<SatGeoFeederPhy>(
1200  DynamicCast<SatGeoNetDevice>(geoNode->GetDevice(0))->GetFeederPhy(8));
1201  Ptr<SatGeoUserPhy> satGeoUserPhy = DynamicCast<SatGeoUserPhy>(
1202  DynamicCast<SatGeoNetDevice>(geoNode->GetDevice(0))->GetUserPhy(8));
1203  Ptr<SatPhy> satGwPhy =
1204  DynamicCast<SatPhy>(DynamicCast<SatNetDevice>(gwNode->GetDevice(1))->GetPhy());
1205  Ptr<SatPhy> satUtPhy =
1206  DynamicCast<SatPhy>(DynamicCast<SatNetDevice>(utNode->GetDevice(2))->GetPhy());
1207 
1208  satGwPhy->TraceConnectWithoutContext(
1209  "RxLinkModcod",
1210  MakeCallback(&SatRegenerationTest5::GeoPhyGwModcodTraceCb, this));
1211  satUtPhy->TraceConnectWithoutContext(
1212  "RxLinkModcod",
1213  MakeCallback(&SatRegenerationTest5::GeoPhyUtModcodTraceCb, this));
1214  satGeoFeederPhy->TraceConnectWithoutContext(
1215  "RxLinkModcod",
1217  satGeoUserPhy->TraceConnectWithoutContext(
1218  "RxLinkModcod",
1219  MakeCallback(&SatRegenerationTest5::GeoPhyUserModcodTraceCb, this));
1220 
1221  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(MilliSeconds(20)));
1222  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
1223 
1224  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1225  SimulationHelper::UDP,
1226  SimulationHelper::RTN_LINK,
1227  Seconds(1),
1228  Seconds(10),
1229  Seconds(0.01));
1230 
1231  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1232  SimulationHelper::UDP,
1233  SimulationHelper::FWD_LINK,
1234  Seconds(1),
1235  Seconds(10),
1236  Seconds(0.01));
1237 
1238  simulationHelper->RunSimulation();
1239 
1240  Simulator::Destroy();
1241 
1242  double averageGwModcodsBeg = GetAverage(m_gwModcods, 0, 5);
1243  double averageUtModcodsBeg = GetAverage(m_utModcods, 0, 5);
1244  double averageFeederModcodsBeg = GetAverage(m_feederModcods, 0, 5);
1245  double averageUserModcodsBeg = GetAverage(m_userModcods, 0, 5);
1246  double averageGwModcodsEnd =
1247  GetMostFrequent(m_gwModcods, m_gwModcods.size() - 200, m_gwModcods.size());
1248  double averageUtModcodsEnd =
1249  GetMostFrequent(m_utModcods, m_utModcods.size() - 200, m_utModcods.size());
1250  double averageFeederModcodsEnd =
1252  double averageUserModcodsEnd =
1254 
1255  NS_TEST_ASSERT_MSG_EQ(averageFeederModcodsBeg,
1256  2,
1257  "Most robust MODCOD on FWD feeder link at startup");
1258  NS_TEST_ASSERT_MSG_EQ(averageUtModcodsBeg, 2, "Most robust MODCOD on FWD user link at startup");
1259  NS_TEST_ASSERT_MSG_EQ(averageGwModcodsBeg,
1260  2,
1261  "Most robust MODCOD on RTN feeder link at startup");
1262  NS_TEST_ASSERT_MSG_EQ(averageUserModcodsBeg,
1263  1,
1264  "Most robust MODCOD on RTN user link at startup");
1265 
1266  NS_TEST_ASSERT_MSG_LT(averageFeederModcodsEnd, 28, "Max MODCOD on FWD feeder link is 27");
1267  NS_TEST_ASSERT_MSG_LT(averageUtModcodsEnd, 28, "Max MODCOD on FWD user link is 27");
1268  NS_TEST_ASSERT_MSG_LT(averageGwModcodsEnd, 28, "Max MODCOD on RTN feeder link is 27");
1269  NS_TEST_ASSERT_MSG_LT(averageUserModcodsEnd, 24, "Max MODCOD on RTN user link is 23");
1270 
1271  NS_TEST_ASSERT_MSG_GT(averageFeederModcodsEnd,
1272  2,
1273  "Most robust MODCOD on FWD feeder link not used after a few seconds");
1274  NS_TEST_ASSERT_MSG_GT(averageUtModcodsEnd,
1275  2,
1276  "Most robust MODCOD on FWD user link not used after a few seconds");
1277  NS_TEST_ASSERT_MSG_GT(averageGwModcodsEnd,
1278  2,
1279  "Most robust MODCOD on RTN feeder link not used after a few seconds");
1280  NS_TEST_ASSERT_MSG_GT(averageUserModcodsEnd,
1281  1,
1282  "Most robust MODCOD on RTN user link not used after a few seconds");
1283 
1284  NS_TEST_ASSERT_MSG_EQ(averageFeederModcodsEnd,
1285  averageUtModcodsEnd,
1286  "Same MODCOD on both FWD links");
1287  NS_TEST_ASSERT_MSG_NE(averageUserModcodsEnd,
1288  averageGwModcodsEnd,
1289  "Not same MODCOD on both RTN links");
1290 }
1291 
1302 class SatRegenerationTest6 : public TestCase
1303 {
1304  public:
1306  virtual ~SatRegenerationTest6();
1307 
1308  private:
1309  virtual void DoRun(void);
1310  void GeoDevGwTxTraceCb(Ptr<const Packet> packet);
1311  void GeoDevUtTxTraceCb(Ptr<const Packet> packet);
1312  void GeoDevGwRxTraceCb(Ptr<const Packet> packet, const Address&);
1313  void GeoDevUtRxTraceCb(Ptr<const Packet> packet, const Address&);
1314  bool HasSinkInstalled(Ptr<Node> node, uint16_t port);
1315 
1316  Ptr<SatHelper> m_helper;
1317 
1318  uint32_t m_totalSentGw;
1319  uint32_t m_totalSentUt;
1322 };
1323 
1324 void
1326 {
1327  m_totalSentGw += packet->GetSize();
1328 }
1329 
1330 void
1332 {
1333  m_totalSentUt += packet->GetSize();
1334 }
1335 
1336 void
1337 SatRegenerationTest6::GeoDevGwRxTraceCb(Ptr<const Packet> packet, const Address&)
1338 {
1339  m_totalReceivedGw += packet->GetSize();
1340 }
1341 
1342 void
1343 SatRegenerationTest6::GeoDevUtRxTraceCb(Ptr<const Packet> packet, const Address& address)
1344 {
1345  m_totalReceivedUt += packet->GetSize();
1346 }
1347 
1348 bool
1349 SatRegenerationTest6::HasSinkInstalled(Ptr<Node> node, uint16_t port)
1350 {
1351  for (uint32_t i = 0; i < node->GetNApplications(); i++)
1352  {
1353  Ptr<PacketSink> sink = DynamicCast<PacketSink>(node->GetApplication(i));
1354  if (sink != NULL)
1355  {
1356  AddressValue av;
1357  sink->GetAttribute("Local", av);
1358  if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
1359  {
1360  return true;
1361  }
1362  }
1363  }
1364  return false;
1365 }
1366 
1367 // Add some help text to this case to describe what it is intended to test
1369  : TestCase(
1370  "This case tests network regeneration on satellite. It is based on a LARGER scenario.")
1371 {
1372  m_totalSentGw = 0;
1373  m_totalSentUt = 0;
1374  m_totalReceivedGw = 0;
1375  m_totalReceivedUt = 0;
1376 }
1377 
1378 // This destructor does nothing but we include it as a reminder that
1379 // the test case should clean up after itself
1381 {
1382 }
1383 
1384 //
1385 // SatRegenerationTest6 TestCase implementation
1386 //
1387 void
1389 {
1390  Config::Reset();
1391 
1392  // Set simulation output details
1393  Singleton<SatEnvVariables>::Get()->DoInitialize();
1394  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test6", true);
1395 
1397  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
1398  EnumValue(SatEnums::REGENERATION_NETWORK));
1399  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
1400  EnumValue(SatEnums::REGENERATION_NETWORK));
1401 
1402  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
1403 
1404  // Enable SatMac traces
1405  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
1406  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
1407 
1409  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
1410 
1411  Ptr<SimulationHelper> simulationHelper =
1412  CreateObject<SimulationHelper>("test-sat-regeneration");
1413  simulationHelper->SetSimulationTime(Seconds(20));
1414  simulationHelper->CreateSatScenario(SatHelper::LARGER);
1415 
1416  m_helper = simulationHelper->GetSatelliteHelper();
1417 
1418  NodeContainer gws = m_helper->GwNodes();
1419  NodeContainer uts = m_helper->UtNodes();
1420 
1421  uint32_t i;
1422  for (i = 0; i < gws.GetN(); i++)
1423  {
1424  gws.Get(i)->GetDevice(1)->TraceConnectWithoutContext(
1425  "Tx",
1426  MakeCallback(&SatRegenerationTest6::GeoDevGwTxTraceCb, this));
1427  gws.Get(i)->GetDevice(1)->TraceConnectWithoutContext(
1428  "Rx",
1429  MakeCallback(&SatRegenerationTest6::GeoDevGwRxTraceCb, this));
1430  }
1431  for (i = 0; i < uts.GetN(); i++)
1432  {
1433  uts.Get(i)->GetDevice(2)->TraceConnectWithoutContext(
1434  "Tx",
1435  MakeCallback(&SatRegenerationTest6::GeoDevUtTxTraceCb, this));
1436  uts.Get(i)->GetDevice(2)->TraceConnectWithoutContext(
1437  "Rx",
1438  MakeCallback(&SatRegenerationTest6::GeoDevUtRxTraceCb, this));
1439  }
1440 
1441  Time startTime = Seconds(1);
1442  Time stopTime = Seconds(15);
1443  Time startDelay = MilliSeconds(10);
1444  Time interval = MilliSeconds(1000);
1445  uint32_t packetSize = 512;
1446 
1447  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(interval));
1448  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(packetSize));
1449 
1450  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1451  SimulationHelper::UDP,
1452  SimulationHelper::RTN_LINK,
1453  Seconds(1),
1454  Seconds(10),
1455  Seconds(0.01));
1456 
1457  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1458  SimulationHelper::UDP,
1459  SimulationHelper::FWD_LINK,
1460  Seconds(1),
1461  Seconds(10),
1462  Seconds(0.01));
1463 
1464  simulationHelper->RunSimulation();
1465 
1466  Simulator::Destroy();
1467 
1468  NS_TEST_ASSERT_MSG_NE(m_totalReceivedGw, 0, "Packets are received on GW");
1469  NS_TEST_ASSERT_MSG_NE(m_totalReceivedUt, 0, "Packets are received on UT");
1470  NS_TEST_ASSERT_MSG_EQ(m_totalSentGw * 5,
1471  m_totalReceivedUt * 4,
1472  "Same number of packets sent and received on FWD link (taking into "
1473  "account 2 UTs on beam 3)");
1474  NS_TEST_ASSERT_MSG_EQ(m_totalSentUt,
1476  "Same number of packets sent and received on RTN link");
1477 }
1478 
1492 class SatRegenerationTest7 : public TestCase
1493 {
1494  public:
1496  virtual ~SatRegenerationTest7();
1497 
1498  private:
1499  virtual void DoRun(void);
1500  void GeoPhyGwModcodTraceCb(uint32_t modcod, const Address& address);
1501  void GeoPhyUtModcodTraceCb(uint32_t modcod, const Address& address);
1502  void GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address& address);
1503  void GeoPhyUserModcodTraceCb(uint32_t modcod, const Address& address);
1504 
1505  double GetAverage(std::vector<uint32_t> list, uint32_t beg, uint32_t end);
1506  double GetMostFrequent(std::vector<uint32_t> list, uint32_t beg, uint32_t end);
1507 
1508  Ptr<SatHelper> m_helper;
1509 
1510  std::vector<uint32_t> m_gwModcods;
1511  std::vector<uint32_t> m_utModcods;
1512  std::vector<uint32_t> m_feederModcods;
1513  std::vector<uint32_t> m_userModcods;
1514 };
1515 
1516 void
1517 SatRegenerationTest7::GeoPhyGwModcodTraceCb(uint32_t modcod, const Address& address)
1518 {
1519  m_gwModcods.push_back(modcod);
1520 }
1521 
1522 void
1523 SatRegenerationTest7::GeoPhyUtModcodTraceCb(uint32_t modcod, const Address& address)
1524 {
1525  m_utModcods.push_back(modcod);
1526 }
1527 
1528 void
1529 SatRegenerationTest7::GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address& address)
1530 {
1531  m_feederModcods.push_back(modcod);
1532 }
1533 
1534 void
1535 SatRegenerationTest7::GeoPhyUserModcodTraceCb(uint32_t modcod, const Address& address)
1536 {
1537  m_userModcods.push_back(modcod);
1538 }
1539 
1540 double
1541 SatRegenerationTest7::GetAverage(std::vector<uint32_t> list, uint32_t beg, uint32_t end)
1542 {
1543  uint32_t sum = 0;
1544  for (uint32_t i = beg; i < end; i++)
1545  {
1546  sum += list[i];
1547  }
1548  return 1.0 * sum / (end - beg);
1549 }
1550 
1551 double
1552 SatRegenerationTest7::GetMostFrequent(std::vector<uint32_t> list, uint32_t beg, uint32_t end)
1553 {
1554  std::map<uint32_t, uint32_t> frequencies;
1555  for (uint32_t i = beg; i < end; i++)
1556  {
1557  frequencies[list[i]]++;
1558  }
1559 
1560  uint32_t max_count = 0;
1561  uint32_t index = -1;
1562  for (std::pair<const uint32_t, uint32_t>& i : frequencies)
1563  {
1564  if (max_count < i.second)
1565  {
1566  index = i.first;
1567  max_count = i.second;
1568  }
1569  }
1570 
1571  return index;
1572 }
1573 
1574 // Add some help text to this case to describe what it is intended to test
1576  : TestCase("This case tests ACM on all links. It is based on a SIMPLE scenario.")
1577 {
1578 }
1579 
1580 // This destructor does nothing but we include it as a reminder that
1581 // the test case should clean up after itself
1583 {
1584 }
1585 
1586 //
1587 // SatRegenerationTest7 TestCase implementation
1588 //
1589 void
1591 {
1592  Config::Reset();
1593 
1594  // Set simulation output details
1595  Singleton<SatEnvVariables>::Get()->DoInitialize();
1596  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test7", true);
1597 
1599  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
1600  EnumValue(SatEnums::REGENERATION_NETWORK));
1601  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
1602  EnumValue(SatEnums::REGENERATION_NETWORK));
1603 
1604  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
1605 
1607  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
1608 
1609  // Enable SatMac traces
1610  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
1611  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
1612 
1614  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
1615 
1616  Ptr<SimulationHelper> simulationHelper =
1617  CreateObject<SimulationHelper>("test-sat-regeneration");
1618  simulationHelper->SetSimulationTime(Seconds(20));
1619  simulationHelper->CreateSatScenario(SatHelper::SIMPLE);
1620 
1621  m_helper = simulationHelper->GetSatelliteHelper();
1622 
1623  Ptr<Node> gwNode = m_helper->GwNodes().Get(0);
1624  Ptr<Node> utNode = m_helper->UtNodes().Get(0);
1625  Ptr<Node> geoNode = m_helper->GeoSatNodes().Get(0);
1626  Ptr<SatGeoFeederPhy> satGeoFeederPhy = DynamicCast<SatGeoFeederPhy>(
1627  DynamicCast<SatGeoNetDevice>(geoNode->GetDevice(0))->GetFeederPhy(8));
1628  Ptr<SatGeoUserPhy> satGeoUserPhy = DynamicCast<SatGeoUserPhy>(
1629  DynamicCast<SatGeoNetDevice>(geoNode->GetDevice(0))->GetUserPhy(8));
1630  Ptr<SatPhy> satGwPhy =
1631  DynamicCast<SatPhy>(DynamicCast<SatNetDevice>(gwNode->GetDevice(1))->GetPhy());
1632  Ptr<SatPhy> satUtPhy =
1633  DynamicCast<SatPhy>(DynamicCast<SatNetDevice>(utNode->GetDevice(2))->GetPhy());
1634 
1635  satGwPhy->TraceConnectWithoutContext(
1636  "RxLinkModcod",
1637  MakeCallback(&SatRegenerationTest7::GeoPhyGwModcodTraceCb, this));
1638  satUtPhy->TraceConnectWithoutContext(
1639  "RxLinkModcod",
1640  MakeCallback(&SatRegenerationTest7::GeoPhyUtModcodTraceCb, this));
1641  satGeoFeederPhy->TraceConnectWithoutContext(
1642  "RxLinkModcod",
1644  satGeoUserPhy->TraceConnectWithoutContext(
1645  "RxLinkModcod",
1646  MakeCallback(&SatRegenerationTest7::GeoPhyUserModcodTraceCb, this));
1647 
1648  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(MilliSeconds(20)));
1649  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
1650 
1651  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1652  SimulationHelper::UDP,
1653  SimulationHelper::RTN_LINK,
1654  Seconds(1),
1655  Seconds(10),
1656  Seconds(0.01));
1657 
1658  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1659  SimulationHelper::UDP,
1660  SimulationHelper::FWD_LINK,
1661  Seconds(1),
1662  Seconds(10),
1663  Seconds(0.01));
1664 
1665  simulationHelper->RunSimulation();
1666 
1667  Simulator::Destroy();
1668 
1669  double averageGwModcodsBeg = GetAverage(m_gwModcods, 0, 3);
1670  double averageUtModcodsBeg = GetAverage(m_utModcods, 0, 3);
1671  double averageFeederModcodsBeg = GetAverage(m_feederModcods, 0, 3);
1672  double averageUserModcodsBeg = GetAverage(m_userModcods, 0, 3);
1673  double averageGwModcodsEnd =
1674  GetMostFrequent(m_gwModcods, m_gwModcods.size() - 200, m_gwModcods.size());
1675  double averageUtModcodsEnd =
1676  GetMostFrequent(m_utModcods, m_utModcods.size() - 200, m_utModcods.size());
1677  double averageFeederModcodsEnd =
1679  double averageUserModcodsEnd =
1681 
1682  NS_TEST_ASSERT_MSG_EQ(averageFeederModcodsBeg,
1683  2,
1684  "Most robust MODCOD on FWD feeder link at startup");
1685  NS_TEST_ASSERT_MSG_EQ(averageUtModcodsBeg, 2, "Most robust MODCOD on FWD user link at startup");
1686  NS_TEST_ASSERT_MSG_EQ(averageGwModcodsBeg,
1687  2,
1688  "Most robust MODCOD on RTN feeder link at startup");
1689  NS_TEST_ASSERT_MSG_EQ(averageUserModcodsBeg,
1690  1,
1691  "Most robust MODCOD on RTN user link at startup");
1692 
1693  NS_TEST_ASSERT_MSG_LT(averageFeederModcodsEnd, 28, "Max MODCOD on FWD feeder link is 27");
1694  NS_TEST_ASSERT_MSG_LT(averageUtModcodsEnd, 28, "Max MODCOD on FWD user link is 27");
1695  NS_TEST_ASSERT_MSG_LT(averageGwModcodsEnd, 28, "Max MODCOD on RTN feeder link is 27");
1696  NS_TEST_ASSERT_MSG_LT(averageUserModcodsEnd, 24, "Max MODCOD on RTN user link is 23");
1697 
1698  NS_TEST_ASSERT_MSG_GT(averageFeederModcodsEnd,
1699  2,
1700  "Most robust MODCOD on FWD feeder link not used after a few seconds");
1701  NS_TEST_ASSERT_MSG_GT(averageUtModcodsEnd,
1702  2,
1703  "Most robust MODCOD on FWD user link not used after a few seconds");
1704  NS_TEST_ASSERT_MSG_GT(averageGwModcodsEnd,
1705  2,
1706  "Most robust MODCOD on RTN feeder link not used after a few seconds");
1707  NS_TEST_ASSERT_MSG_GT(averageUserModcodsEnd,
1708  1,
1709  "Most robust MODCOD on RTN user link not used after a few seconds");
1710 
1711  NS_TEST_ASSERT_MSG_EQ(averageFeederModcodsEnd,
1712  averageUtModcodsEnd,
1713  "Same MODCOD on both FWD links");
1714  NS_TEST_ASSERT_MSG_NE(averageUserModcodsEnd,
1715  averageGwModcodsEnd,
1716  "Not same MODCOD on both RTN links");
1717 }
1718 
1734 class SatRegenerationTest8 : public TestCase
1735 {
1736  public:
1737  SatRegenerationTest8(SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
1738  SatEnums::RegenerationMode_t returnLinkRegenerationMode);
1739  virtual ~SatRegenerationTest8();
1740 
1741  private:
1742  virtual void DoRun(void);
1743 
1744  void AddTraceEntry(Time now,
1745  SatEnums::SatPacketEvent_t packetEvent,
1746  SatEnums::SatNodeType_t nodeType,
1747  uint32_t nodeId,
1748  Mac48Address macAddress,
1749  SatEnums::SatLogLevel_t logLevel,
1750  SatEnums::SatLinkDir_t linkDir,
1751  std::string packetInfo);
1752 
1753  Ptr<SatHelper> m_helper;
1754 
1757 
1758  uint32_t m_rxFeederPhy;
1759  uint32_t m_rxFeederMac;
1760  uint32_t m_rxFeederNet;
1761  uint32_t m_rxUserPhy;
1762  uint32_t m_rxUserMac;
1763  uint32_t m_rxUserNet;
1764 };
1765 
1766 void
1768  SatEnums::SatPacketEvent_t packetEvent,
1769  SatEnums::SatNodeType_t nodeType,
1770  uint32_t nodeId,
1771  Mac48Address macAddress,
1772  SatEnums::SatLogLevel_t logLevel,
1773  SatEnums::SatLinkDir_t linkDir,
1774  std::string packetInfo)
1775 {
1776  if (packetEvent != SatEnums::PACKET_RECV)
1777  {
1778  return;
1779  }
1780  switch (logLevel)
1781  {
1782  case SatEnums::LL_PHY: {
1783  if (linkDir == SatEnums::LD_FORWARD)
1784  {
1785  m_rxFeederPhy++;
1786  }
1787  else if (linkDir == SatEnums::LD_RETURN)
1788  {
1789  m_rxUserPhy++;
1790  }
1791  break;
1792  }
1793  case SatEnums::LL_MAC: {
1794  if (linkDir == SatEnums::LD_FORWARD)
1795  {
1796  m_rxFeederMac++;
1797  }
1798  else if (linkDir == SatEnums::LD_RETURN)
1799  {
1800  m_rxUserMac++;
1801  }
1802  break;
1803  }
1804  case SatEnums::LL_ND: {
1805  if (linkDir == SatEnums::LD_FORWARD)
1806  {
1807  m_rxFeederNet++;
1808  }
1809  else if (linkDir == SatEnums::LD_RETURN)
1810  {
1811  m_rxUserNet++;
1812  }
1813  break;
1814  }
1815  default:
1816  NS_FATAL_ERROR("Wrong log level received");
1817  }
1818 }
1819 
1820 // Add some help text to this case to describe what it is intended to test
1822  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
1823  : TestCase("This test is launched several time to test every regeneration combination.")
1824 {
1825  m_forwardLinkRegenerationMode = forwardLinkRegenerationMode;
1826  m_returnLinkRegenerationMode = returnLinkRegenerationMode;
1827 
1828  m_rxFeederPhy = 0;
1829  m_rxFeederMac = 0;
1830  m_rxFeederNet = 0;
1831  m_rxUserPhy = 0;
1832  m_rxUserMac = 0;
1833  m_rxUserNet = 0;
1834 }
1835 
1836 // This destructor does nothing but we include it as a reminder that
1837 // the test case should clean up after itself
1839 {
1840 }
1841 
1842 //
1843 // SatRegenerationTest8 TestCase implementation
1844 //
1845 void
1847 {
1848  Config::Reset();
1849 
1850  // Set simulation output details
1851  Singleton<SatEnvVariables>::Get()->DoInitialize();
1852  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-regeneration", "test8", true);
1853 
1855  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
1856  EnumValue(m_forwardLinkRegenerationMode));
1857  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
1858  EnumValue(m_returnLinkRegenerationMode));
1859 
1860  SatEnums::RegenerationMode_t maxRegeneration =
1862 
1863  Config::SetDefault("ns3::SatGeoFeederPhy::QueueSize", UintegerValue(100000));
1864 
1865  // Enable SatMac traces
1866  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
1867  Config::SetDefault("ns3::SatNetDevice::EnableStatisticsTags", BooleanValue(true));
1868 
1870  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
1871 
1872  Ptr<SimulationHelper> simulationHelper =
1873  CreateObject<SimulationHelper>("test-sat-regeneration");
1874  simulationHelper->SetSimulationTime(Seconds(20));
1875  simulationHelper->CreateSatScenario(SatHelper::LARGER);
1876 
1877  m_helper = simulationHelper->GetSatelliteHelper();
1878 
1879  std::map<uint32_t, Ptr<SatPhy>> satGeoFeederPhy =
1880  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetFeederPhy();
1881  std::map<uint32_t, Ptr<SatPhy>> satGeoUserPhy =
1882  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetUserPhy();
1883  std::map<uint32_t, Ptr<SatMac>> satGeoFeederMac =
1884  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetFeederMac();
1885  std::map<uint32_t, Ptr<SatMac>> satGeoUserMac =
1886  DynamicCast<SatGeoNetDevice>(m_helper->GeoSatNodes().Get(0)->GetDevice(0))->GetUserMac();
1887 
1888  Config::ConnectWithoutContext("/NodeList/0/DeviceList/0/UserPhy/*/PacketTrace",
1889  MakeCallback(&SatRegenerationTest8::AddTraceEntry, this));
1890  Config::ConnectWithoutContext("/NodeList/0/DeviceList/0/FeederPhy/*/PacketTrace",
1891  MakeCallback(&SatRegenerationTest8::AddTraceEntry, this));
1892  if (maxRegeneration == SatEnums::REGENERATION_LINK ||
1893  maxRegeneration == SatEnums::REGENERATION_NETWORK)
1894  {
1895  Config::ConnectWithoutContext("/NodeList/0/DeviceList/0/UserMac/*/PacketTrace",
1896  MakeCallback(&SatRegenerationTest8::AddTraceEntry, this));
1897  Config::ConnectWithoutContext("/NodeList/0/DeviceList/0/FeederMac/*/PacketTrace",
1898  MakeCallback(&SatRegenerationTest8::AddTraceEntry, this));
1899  }
1900  if (maxRegeneration == SatEnums::REGENERATION_NETWORK)
1901  {
1902  Config::ConnectWithoutContext("/NodeList/0/DeviceList/0/PacketTrace",
1903  MakeCallback(&SatRegenerationTest8::AddTraceEntry, this));
1904  }
1905 
1906  Time startTime = Seconds(1);
1907  Time stopTime = Seconds(15);
1908  Time startDelay = MilliSeconds(10);
1909  Time interval = MilliSeconds(100);
1910  uint32_t packetSize = 512;
1911 
1912  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(interval));
1913  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(packetSize));
1914 
1915  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1916  SimulationHelper::UDP,
1917  SimulationHelper::RTN_LINK,
1918  startTime,
1919  stopTime,
1920  startDelay);
1921 
1922  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
1923  SimulationHelper::UDP,
1924  SimulationHelper::FWD_LINK,
1925  startTime,
1926  stopTime,
1927  startDelay);
1928 
1929  simulationHelper->RunSimulation();
1930 
1931  Simulator::Destroy();
1932 
1934  {
1935  case SatEnums::TRANSPARENT:
1936  case SatEnums::REGENERATION_PHY: {
1937  NS_TEST_ASSERT_MSG_GT(m_rxFeederPhy, 1600, "Packets should be received on feeder phy");
1938  NS_TEST_ASSERT_MSG_EQ(m_rxFeederMac, 0, "Packets should not be received on feeder MAC");
1939  NS_TEST_ASSERT_MSG_EQ(m_rxFeederNet, 0, "Packets should not be received on feeder network");
1940  break;
1941  }
1942  case SatEnums::REGENERATION_LINK: {
1943  NS_TEST_ASSERT_MSG_GT(m_rxFeederPhy, 1600, "Packets should be received on feeder phy");
1944  NS_TEST_ASSERT_MSG_GT(m_rxFeederMac, 1600, "Packets should be received on feeder MAC");
1945  NS_TEST_ASSERT_MSG_EQ(m_rxFeederNet, 0, "Packets should not be received on feeder network");
1946  break;
1947  }
1948  case SatEnums::REGENERATION_NETWORK: {
1949  NS_TEST_ASSERT_MSG_GT(m_rxFeederPhy, 1600, "Packets should be received on feeder phy");
1950  NS_TEST_ASSERT_MSG_GT(m_rxFeederMac, 1600, "Packets should be received on feeder MAC");
1951  NS_TEST_ASSERT_MSG_GT(m_rxFeederNet, 1600, "Packets should be received on feeder network");
1952  break;
1953  }
1954  }
1955 
1957  {
1958  case SatEnums::TRANSPARENT:
1959  case SatEnums::REGENERATION_PHY: {
1960  NS_TEST_ASSERT_MSG_GT(m_rxUserPhy, 1600, "Packets should be received on user phy");
1961  NS_TEST_ASSERT_MSG_EQ(m_rxUserMac, 0, "Packets should not be received on user MAC");
1962  NS_TEST_ASSERT_MSG_EQ(m_rxUserNet, 0, "Packets should not be received on user network");
1963  break;
1964  }
1965  case SatEnums::REGENERATION_LINK: {
1966  NS_TEST_ASSERT_MSG_GT(m_rxUserPhy, 1600, "Packets should be received on user phy");
1967  NS_TEST_ASSERT_MSG_GT(m_rxUserMac, 1600, "Packets should be received on user MAC");
1968  NS_TEST_ASSERT_MSG_EQ(m_rxUserNet, 0, "Packets should not be received on user network");
1969  break;
1970  }
1971  case SatEnums::REGENERATION_NETWORK: {
1972  NS_TEST_ASSERT_MSG_GT(m_rxUserPhy, 1600, "Packets should be received on user phy");
1973  NS_TEST_ASSERT_MSG_GT(m_rxUserMac, 1600, "Packets should be received on user MAC");
1974  NS_TEST_ASSERT_MSG_GT(m_rxUserNet, 1600, "Packets should be received on user network");
1975  break;
1976  }
1977  }
1978 }
1979 
1980 // The TestSuite class names the TestSuite as sat-regeneration-test, identifies what type of
1981 // TestSuite (SYSTEM), and enables the TestCases to be run. Typically, only the constructor for this
1982 // class must be defined
1983 //
1984 class SatRegenerationTestSuite : public TestSuite
1985 {
1986  public:
1988 };
1989 
1991  : TestSuite("sat-regeneration-test", SYSTEM)
1992 {
1993  AddTestCase(new SatRegenerationTest1, TestCase::QUICK); // Test delay with regeneration phy
1994  AddTestCase(new SatRegenerationTest2, TestCase::QUICK); // Test losses with regeneration phy
1995  AddTestCase(new SatRegenerationTest3, TestCase::QUICK); // Test collisions with regeneration phy
1996  AddTestCase(new SatRegenerationTest4, TestCase::QUICK); // Test regeneration link
1997  AddTestCase(new SatRegenerationTest5, TestCase::QUICK); // Test ACM loop on regeneration link
1998  AddTestCase(new SatRegenerationTest6, TestCase::QUICK); // Test regeneration network
1999  AddTestCase(new SatRegenerationTest7, TestCase::QUICK); // Test ACM loop on regeneration network
2000 
2001  // Test all regeneration combinations, and check if packets are correctly received or not on
2002  // each satellite layer
2003  AddTestCase(new SatRegenerationTest8(SatEnums::TRANSPARENT, SatEnums::TRANSPARENT),
2004  TestCase::QUICK);
2005  AddTestCase(new SatRegenerationTest8(SatEnums::TRANSPARENT, SatEnums::REGENERATION_PHY),
2006  TestCase::QUICK);
2007  AddTestCase(new SatRegenerationTest8(SatEnums::TRANSPARENT, SatEnums::REGENERATION_LINK),
2008  TestCase::QUICK);
2009  AddTestCase(new SatRegenerationTest8(SatEnums::TRANSPARENT, SatEnums::REGENERATION_NETWORK),
2010  TestCase::QUICK);
2011  AddTestCase(new SatRegenerationTest8(SatEnums::REGENERATION_PHY, SatEnums::TRANSPARENT),
2012  TestCase::QUICK);
2013  AddTestCase(new SatRegenerationTest8(SatEnums::REGENERATION_PHY, SatEnums::REGENERATION_PHY),
2014  TestCase::QUICK);
2015  AddTestCase(new SatRegenerationTest8(SatEnums::REGENERATION_PHY, SatEnums::REGENERATION_LINK),
2016  TestCase::QUICK);
2017  AddTestCase(
2018  new SatRegenerationTest8(SatEnums::REGENERATION_PHY, SatEnums::REGENERATION_NETWORK),
2019  TestCase::QUICK);
2020  AddTestCase(new SatRegenerationTest8(SatEnums::REGENERATION_NETWORK, SatEnums::TRANSPARENT),
2021  TestCase::QUICK);
2022  AddTestCase(
2023  new SatRegenerationTest8(SatEnums::REGENERATION_NETWORK, SatEnums::REGENERATION_PHY),
2024  TestCase::QUICK);
2025  AddTestCase(
2026  new SatRegenerationTest8(SatEnums::REGENERATION_NETWORK, SatEnums::REGENERATION_LINK),
2027  TestCase::QUICK);
2028  AddTestCase(
2029  new SatRegenerationTest8(SatEnums::REGENERATION_NETWORK, SatEnums::REGENERATION_NETWORK),
2030  TestCase::QUICK);
2031 }
2032 
2033 // Allocate an instance of this TestSuite
'Regeneration, test 1' test case implementation.
std::vector< Time > m_geoReturnDelay
std::vector< Time > m_forwardDelay
void GeoUserPhyTraceDelayCb(const Time &time, const Address &address)
std::vector< Time > m_geoForwardDelay
void PhyDelayTraceCb(std::string context, const Time &time, const Address &address)
void GeoFeederPhyTraceDelayCb(const Time &time, const Address &address)
'Regeneration, test 2' test case implementation.
void GeoPhyTraceCb(Time time, SatEnums::SatPacketEvent_t event, SatEnums::SatNodeType_t type, uint32_t nodeId, Mac48Address address, SatEnums::SatLogLevel_t level, SatEnums::SatLinkDir_t dir, std::string packetInfo)
void PhyTraceCb(Time time, SatEnums::SatPacketEvent_t event, SatEnums::SatNodeType_t type, uint32_t nodeId, Mac48Address address, SatEnums::SatLogLevel_t level, SatEnums::SatLinkDir_t dir, std::string packetInfo)
'Regeneration, test 3' test case implementation.
void GeoPhyTraceCb(Time time, SatEnums::SatPacketEvent_t event, SatEnums::SatNodeType_t type, uint32_t nodeId, Mac48Address address, SatEnums::SatLogLevel_t level, SatEnums::SatLinkDir_t dir, std::string packetInfo)
void GeoPhyTraceCollisionCb(std::string, uint32_t nPackets, const Address &address, bool hasCollision)
void GeoPhyTraceErrorCb(std::string, uint32_t nPackets, const Address &address, bool hasError)
'Regeneration, test 4' test case implementation.
void GeoDevGwTxTraceCb(Ptr< const Packet > packet)
void GeoDevGwRxTraceCb(Ptr< const Packet > packet, const Address &)
bool HasSinkInstalled(Ptr< Node > node, uint16_t port)
void GeoDevUtTxTraceCb(Ptr< const Packet > packet)
void GeoDevUtRxTraceCb(Ptr< const Packet > packet, const Address &)
'Regeneration, test 5' test case implementation.
void GeoPhyGwModcodTraceCb(uint32_t modcod, const Address &address)
double GetAverage(std::vector< uint32_t > list, uint32_t beg, uint32_t end)
void GeoPhyUserModcodTraceCb(uint32_t modcod, const Address &address)
void GeoPhyUtModcodTraceCb(uint32_t modcod, const Address &address)
double GetMostFrequent(std::vector< uint32_t > list, uint32_t beg, uint32_t end)
void GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address &address)
std::vector< uint32_t > m_feederModcods
std::vector< uint32_t > m_gwModcods
std::vector< uint32_t > m_userModcods
std::vector< uint32_t > m_utModcods
'Regeneration, test 6' test case implementation.
void GeoDevGwTxTraceCb(Ptr< const Packet > packet)
void GeoDevGwRxTraceCb(Ptr< const Packet > packet, const Address &)
bool HasSinkInstalled(Ptr< Node > node, uint16_t port)
void GeoDevUtRxTraceCb(Ptr< const Packet > packet, const Address &)
void GeoDevUtTxTraceCb(Ptr< const Packet > packet)
'Regeneration, test 7' test case implementation.
double GetMostFrequent(std::vector< uint32_t > list, uint32_t beg, uint32_t end)
void GeoPhyFeederModcodTraceCb(uint32_t modcod, const Address &address)
void GeoPhyUserModcodTraceCb(uint32_t modcod, const Address &address)
std::vector< uint32_t > m_gwModcods
void GeoPhyGwModcodTraceCb(uint32_t modcod, const Address &address)
std::vector< uint32_t > m_feederModcods
std::vector< uint32_t > m_utModcods
void GeoPhyUtModcodTraceCb(uint32_t modcod, const Address &address)
std::vector< uint32_t > m_userModcods
double GetAverage(std::vector< uint32_t > list, uint32_t beg, uint32_t end)
'Regeneration, test 8' test case implementation.
SatEnums::RegenerationMode_t m_forwardLinkRegenerationMode
void AddTraceEntry(Time now, SatEnums::SatPacketEvent_t packetEvent, SatEnums::SatNodeType_t nodeType, uint32_t nodeId, Mac48Address macAddress, SatEnums::SatLogLevel_t logLevel, SatEnums::SatLinkDir_t linkDir, std::string packetInfo)
SatEnums::RegenerationMode_t m_returnLinkRegenerationMode
SatRegenerationTest8(SatEnums::RegenerationMode_t forwardLinkRegenerationMode, SatEnums::RegenerationMode_t returnLinkRegenerationMode)
SatLinkDir_t
Link direction used for packet tracing.
SatNodeType_t
Node type used for packet tracing.
SatPacketEvent_t
Packet event used for packet tracing.
SatLogLevel_t
Log level used for packet tracing.
RegenerationMode_t
The regeneration mode used in satellites.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatRegenerationTestSuite satRegenerationTestSuite