satellite-constellation-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
19  */
20 
29 #include <ns3/cbr-application.h>
30 #include <ns3/cbr-helper.h>
31 #include <ns3/config.h>
32 #include <ns3/log.h>
33 #include <ns3/packet-sink-helper.h>
34 #include <ns3/packet-sink.h>
35 #include <ns3/satellite-env-variables.h>
36 #include <ns3/satellite-gw-mac.h>
37 #include <ns3/satellite-helper.h>
38 #include <ns3/satellite-id-mapper.h>
39 #include <ns3/satellite-isl-arbiter-unicast.h>
40 #include <ns3/satellite-isl-arbiter.h>
41 #include <ns3/satellite-orbiter-feeder-phy.h>
42 #include <ns3/satellite-orbiter-net-device.h>
43 #include <ns3/satellite-orbiter-user-phy.h>
44 #include <ns3/satellite-phy-rx-carrier.h>
45 #include <ns3/satellite-topology.h>
46 #include <ns3/satellite-ut-mac-state.h>
47 #include <ns3/simulation-helper.h>
48 #include <ns3/simulator.h>
49 #include <ns3/singleton.h>
50 #include <ns3/string.h>
51 #include <ns3/test.h>
52 
53 #include <fstream>
54 #include <iostream>
55 
56 using namespace ns3;
57 
72 class SatConstellationTest1 : public TestCase
73 {
74  public:
76  virtual ~SatConstellationTest1();
77 
78  private:
79  virtual void DoRun(void);
80 };
81 
82 // Add some help text to this case to describe what it is intended to test
84  : TestCase("This case tests that a topology is correctly loaded.")
85 {
86 }
87 
88 // This destructor does nothing but we include it as a reminder that
89 // the test case should clean up after itself
91 {
92 }
93 
94 //
95 // SatConstellationTest1 TestCase implementation
96 //
97 void
99 {
100  Config::Reset();
101 
102  // Set simulation output details
103  Singleton<SatEnvVariables>::Get()->DoInitialize();
104  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-constellation", "test1", true);
105 
107  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
108  EnumValue(SatEnums::REGENERATION_NETWORK));
109  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
110  EnumValue(SatEnums::REGENERATION_NETWORK));
111 
113  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionEachRequest", BooleanValue(false));
114  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionPeriod",
115  TimeValue(MilliSeconds(10)));
116  Config::SetDefault("ns3::SatHelper::GwUsers", UintegerValue(3));
117 
118  Ptr<SimulationHelper> simulationHelper =
119  CreateObject<SimulationHelper>("test-sat-constellation");
120 
121  // Creating the reference system.
122  simulationHelper->SetBeamSet({43, 30});
123  simulationHelper->SetUserCountPerUt(5);
124 
125  simulationHelper->LoadScenario("constellation-eutelsat-geo-2-sats-no-isls");
126 
127  simulationHelper->CreateSatScenario();
128 
129  NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
130  NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
131  NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
132  NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
133  NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
134 
135  uint32_t countNetDevices = 0;
136  for (uint32_t i = 0; i < sats.GetN(); i++)
137  {
138  for (uint32_t j = 0; j < sats.Get(i)->GetNDevices(); j++)
139  {
140  if (DynamicCast<SatOrbiterNetDevice>(sats.Get(i)->GetDevice(j)) != nullptr)
141  {
142  countNetDevices += 1;
143  }
144  }
145  }
146 
147  NS_TEST_ASSERT_MSG_EQ(sats.GetN(), 2, "Topology must contain 2 satellites");
148  NS_TEST_ASSERT_MSG_EQ(countNetDevices,
149  2,
150  "Topology must contain 2 satellite Orbiter Net Devices");
151  NS_TEST_ASSERT_MSG_EQ(gws.GetN(), 2, "Topology must contain 2 GWs");
152  NS_TEST_ASSERT_MSG_EQ(uts.GetN(), 3, "Topology must contain 3 UTs");
153  NS_TEST_ASSERT_MSG_EQ(gwUsers.GetN(), 3, "Topology must contain 3 GW users");
154  NS_TEST_ASSERT_MSG_EQ(utUsers.GetN(), 15, "Topology must contain 15 UT users");
155 
156  GeoCoordinate sat1 = GeoCoordinate(sats.Get(0)->GetObject<SatMobilityModel>()->GetPosition());
157  GeoCoordinate sat2 = GeoCoordinate(sats.Get(1)->GetObject<SatMobilityModel>()->GetPosition());
158 
159  GeoCoordinate gw1 = GeoCoordinate(gws.Get(0)->GetObject<SatMobilityModel>()->GetPosition());
160  GeoCoordinate gw2 = GeoCoordinate(gws.Get(1)->GetObject<SatMobilityModel>()->GetPosition());
161 
162  GeoCoordinate ut1 = GeoCoordinate(uts.Get(0)->GetObject<SatMobilityModel>()->GetPosition());
163  GeoCoordinate ut2 = GeoCoordinate(uts.Get(1)->GetObject<SatMobilityModel>()->GetPosition());
164  GeoCoordinate ut3 = GeoCoordinate(uts.Get(2)->GetObject<SatMobilityModel>()->GetPosition());
165 
166  NS_TEST_ASSERT_MSG_EQ_TOL(sat1.GetLatitude(),
167  0.013043,
168  0.001,
169  "Incorrect latitude for satellite 1");
170  NS_TEST_ASSERT_MSG_EQ_TOL(sat1.GetLongitude(),
171  7.20835,
172  0.001,
173  "Incorrect longitude for satellite 1");
174  NS_TEST_ASSERT_MSG_EQ_TOL(sat1.GetAltitude(),
175  35786400,
176  100,
177  "Incorrect altitude for satellite 1");
178 
179  NS_TEST_ASSERT_MSG_EQ_TOL(sat2.GetLatitude(),
180  -0.0219759,
181  0.001,
182  "Incorrect latitude for satellite 2");
183  NS_TEST_ASSERT_MSG_EQ_TOL(sat2.GetLongitude(),
184  47.7047,
185  0.001,
186  "Incorrect longitude for satellite 2");
187  NS_TEST_ASSERT_MSG_EQ_TOL(sat2.GetAltitude(),
188  35779000,
189  100,
190  "Incorrect altitude for satellite 2");
191 
192  NS_TEST_ASSERT_MSG_EQ_TOL(gw1.GetLatitude(), 48.85, 0.001, "Incorrect latitude for GW 1");
193  NS_TEST_ASSERT_MSG_EQ_TOL(gw1.GetLongitude(), 2.34, 0.001, "Incorrect longitude for GW 1");
194  NS_TEST_ASSERT_MSG_EQ(gw1.GetAltitude(), 0, "Incorrect altitude for GW 1");
195 
196  NS_TEST_ASSERT_MSG_EQ_TOL(gw2.GetLatitude(), 55.75, 0.001, "Incorrect latitude for GW 2");
197  NS_TEST_ASSERT_MSG_EQ_TOL(gw2.GetLongitude(), 37.62, 0.001, "Incorrect longitude for GW 2");
198  NS_TEST_ASSERT_MSG_EQ(gw2.GetAltitude(), 0, "Incorrect altitude for GW 2");
199 
200  NS_TEST_ASSERT_MSG_EQ_TOL(ut1.GetLatitude(), 48.8534, 0.001, "Incorrect latitude for UT 1");
201  NS_TEST_ASSERT_MSG_EQ_TOL(ut1.GetLongitude(), 2.3488, 0.001, "Incorrect longitude for UT 1");
202  NS_TEST_ASSERT_MSG_EQ(ut1.GetAltitude(), 0, "Incorrect altitude for UT 1");
203 
204  NS_TEST_ASSERT_MSG_EQ_TOL(ut2.GetLatitude(), 55.755, 0.001, "Incorrect latitude for UT 2");
205  NS_TEST_ASSERT_MSG_EQ_TOL(ut2.GetLongitude(), 37.6218, 0.001, "Incorrect longitude for UT 2");
206  NS_TEST_ASSERT_MSG_EQ(ut2.GetAltitude(), 0, "Incorrect altitude for UT 2");
207 
208  NS_TEST_ASSERT_MSG_EQ_TOL(ut3.GetLatitude(), 55.754, 0.001, "Incorrect latitude for UT 3");
209  NS_TEST_ASSERT_MSG_EQ_TOL(ut3.GetLongitude(), 37.621, 0.001, "Incorrect longitude for UT 3");
210  NS_TEST_ASSERT_MSG_EQ(ut3.GetAltitude(), 0, "Incorrect altitude for UT 3");
211 
212  Simulator::Destroy();
213 }
214 
231 class SatConstellationTest2 : public TestCase
232 {
233  public:
235  virtual ~SatConstellationTest2();
236 
237  private:
238  virtual void DoRun(void);
239 
240  std::vector<std::string> Split(std::string s, char del);
241  void TestFileValue(std::string path, uint32_t time, uint32_t expectedValue);
242 };
243 
244 // Add some help text to this case to describe what it is intended to test
246  : TestCase("This case tests that a application throughputs PerEntity are correct.")
247 {
248 }
249 
250 // This destructor does nothing but we include it as a reminder that
251 // the test case should clean up after itself
253 {
254 }
255 
256 std::vector<std::string>
257 SatConstellationTest2::Split(std::string s, char del)
258 {
259  std::stringstream ss(s);
260  std::string word;
261  std::vector<std::string> tokens;
262  while (!ss.eof())
263  {
264  std::getline(ss, word, del);
265  tokens.push_back(word);
266  }
267  return tokens;
268 }
269 
270 void
271 SatConstellationTest2::TestFileValue(std::string path, uint32_t time, uint32_t expectedValue)
272 {
273  std::string line;
274  std::ifstream myfile(path);
275  std::string delimiter = " ";
276  std::string token;
277  bool valueFound;
278 
279  if (myfile.is_open())
280  {
281  valueFound = false;
282  while (std::getline(myfile, line))
283  {
284  std::vector<std::string> tokens = Split(line, ' ');
285  if (tokens.size() == 2)
286  {
287  if ((uint32_t)std::stoi(tokens[0]) == time)
288  {
289  NS_TEST_ASSERT_MSG_EQ_TOL(std::stof(tokens[1]),
290  expectedValue,
291  expectedValue / 10,
292  "Incorrect throughput for statistic " << path);
293  valueFound = true;
294  break;
295  }
296  }
297  }
298  myfile.close();
299  if (!valueFound)
300  {
301  NS_TEST_ASSERT_MSG_EQ(0, 1, "Cannot find time " << time << " for trace file " << path);
302  }
303  }
304  else
305  {
306  NS_TEST_ASSERT_MSG_EQ(0, 1, "Cannot read trace file " << path);
307  }
308 }
309 
310 //
311 // SatConstellationTest2 TestCase implementation
312 //
313 void
315 {
316  Config::Reset();
317  Singleton<SatIdMapper>::Get()->Reset();
318 
319  // Set simulation output details
320  Singleton<SatEnvVariables>::Get()->DoInitialize();
321  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-constellation", "test2", true);
322 
324  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
325  EnumValue(SatEnums::REGENERATION_NETWORK));
326  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
327  EnumValue(SatEnums::REGENERATION_NETWORK));
328 
330  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionEachRequest", BooleanValue(false));
331  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionPeriod",
332  TimeValue(MilliSeconds(10)));
333  Config::SetDefault("ns3::SatHelper::GwUsers", UintegerValue(3));
334 
335  Ptr<SimulationHelper> simulationHelper =
336  CreateObject<SimulationHelper>("test-sat-constellation/test2");
337 
338  // Creating the reference system.
339  simulationHelper->SetBeamSet({43, 30});
340  simulationHelper->SetUserCountPerUt(5);
341 
342  simulationHelper->LoadScenario("constellation-eutelsat-geo-2-sats-no-isls");
343 
344  simulationHelper->CreateSatScenario();
345 
346  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
347  SatTrafficHelper::FWD_LINK,
348  SatTrafficHelper::UDP,
349  MilliSeconds(10),
350  512,
351  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
352  Singleton<SatTopology>::Get()->GetUtUserNodes(),
353  Seconds(1.0),
354  Seconds(29.0),
355  Seconds(0));
356 
357  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
358  SatTrafficHelper::RTN_LINK,
359  SatTrafficHelper::UDP,
360  MilliSeconds(10),
361  512,
362  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
363  Singleton<SatTopology>::Get()->GetUtUserNodes(),
364  Seconds(1.0),
365  Seconds(29.0),
366  Seconds(0));
367 
368  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
369 
370  s->AddGlobalFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
371  s->AddGlobalRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
372  s->AddPerGwFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
373  s->AddPerGwRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
374  s->AddPerSatFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
375  s->AddPerSatRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
376  s->AddPerBeamFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
377  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
378  s->AddPerUtFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
379  s->AddPerUtRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
380 
381  simulationHelper->SetSimulationTime(Seconds(10));
382  simulationHelper->RunSimulation();
383 
384  Simulator::Destroy();
385 
386  // Global throughput
387  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
388  "stat-global-fwd-app-throughput-scatter-0.txt",
389  5,
390  6144);
391  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
392  "stat-global-rtn-app-throughput-scatter-0.txt",
393  5,
394  6144);
395 
396  // Per satellite throughput
397  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
398  "stat-per-sat-fwd-app-throughput-scatter-1.txt",
399  5,
400  2048);
401  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
402  "stat-per-sat-fwd-app-throughput-scatter-2.txt",
403  5,
404  4096);
405  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
406  "stat-per-sat-rtn-app-throughput-scatter-1.txt",
407  5,
408  2048);
409  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
410  "stat-per-sat-rtn-app-throughput-scatter-2.txt",
411  5,
412  4096);
413 
414  // Per beam throughput
415  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
416  "stat-per-beam-fwd-app-throughput-scatter-1-30.txt",
417  5,
418  0);
419  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
420  "stat-per-beam-fwd-app-throughput-scatter-1-43.txt",
421  5,
422  2048);
423  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
424  "stat-per-beam-fwd-app-throughput-scatter-2-30.txt",
425  5,
426  4096);
427  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
428  "stat-per-beam-fwd-app-throughput-scatter-2-43.txt",
429  5,
430  0);
431  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
432  "stat-per-beam-rtn-app-throughput-scatter-1-30.txt",
433  5,
434  0);
435  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
436  "stat-per-beam-rtn-app-throughput-scatter-1-43.txt",
437  5,
438  2048);
439  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
440  "stat-per-beam-rtn-app-throughput-scatter-2-30.txt",
441  5,
442  4096);
443  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
444  "stat-per-beam-rtn-app-throughput-scatter-2-43.txt",
445  5,
446  0);
447 
448  // Per GW throughput
449  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
450  "stat-per-gw-fwd-app-throughput-scatter-1.txt",
451  5,
452  2048);
453  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
454  "stat-per-gw-fwd-app-throughput-scatter-2.txt",
455  5,
456  4096);
457  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
458  "stat-per-gw-rtn-app-throughput-scatter-1.txt",
459  5,
460  2048);
461  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
462  "stat-per-gw-rtn-app-throughput-scatter-2.txt",
463  5,
464  4096);
465 
466  // Per UT throughput
467  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
468  "stat-per-ut-fwd-app-throughput-scatter-1.txt",
469  5,
470  2048);
471  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
472  "stat-per-ut-fwd-app-throughput-scatter-2.txt",
473  5,
474  2048);
475  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
476  "stat-per-ut-fwd-app-throughput-scatter-3.txt",
477  5,
478  2048);
479  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
480  "stat-per-ut-rtn-app-throughput-scatter-1.txt",
481  5,
482  2048);
483  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
484  "stat-per-ut-rtn-app-throughput-scatter-2.txt",
485  5,
486  2048);
487  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test2/"
488  "stat-per-ut-rtn-app-throughput-scatter-3.txt",
489  5,
490  2048);
491 }
492 
509 class SatConstellationTest3 : public TestCase
510 {
511  public:
513  virtual ~SatConstellationTest3();
514 
515  private:
516  virtual void DoRun(void);
517 
518  std::vector<std::string> Split(std::string s, char del);
519  void TestFileValue(std::string path, uint32_t time, uint32_t expectedValue);
520 };
521 
522 // Add some help text to this case to describe what it is intended to test
524  : TestCase("This case tests that a application throughputs PerEntity are correct.")
525 {
526 }
527 
528 // This destructor does nothing but we include it as a reminder that
529 // the test case should clean up after itself
531 {
532 }
533 
534 std::vector<std::string>
535 SatConstellationTest3::Split(std::string s, char del)
536 {
537  std::stringstream ss(s);
538  std::string word;
539  std::vector<std::string> tokens;
540  while (!ss.eof())
541  {
542  std::getline(ss, word, del);
543  tokens.push_back(word);
544  }
545  return tokens;
546 }
547 
548 void
549 SatConstellationTest3::TestFileValue(std::string path, uint32_t time, uint32_t expectedValue)
550 {
551  std::string line;
552  std::ifstream myfile(path);
553  std::string delimiter = " ";
554  std::string token;
555  bool valueFound;
556 
557  if (myfile.is_open())
558  {
559  valueFound = false;
560  while (std::getline(myfile, line))
561  {
562  std::vector<std::string> tokens = Split(line, ' ');
563  if (tokens.size() == 2)
564  {
565  if ((uint32_t)std::stoi(tokens[0]) == time)
566  {
567  NS_TEST_ASSERT_MSG_EQ_TOL(std::stof(tokens[1]),
568  expectedValue,
569  expectedValue / 10,
570  "Incorrect throughput for statistic " << path);
571  valueFound = true;
572  break;
573  }
574  }
575  }
576  myfile.close();
577  if (!valueFound)
578  {
579  NS_TEST_ASSERT_MSG_EQ(0, 1, "Cannot find time " << time << " for trace file " << path);
580  }
581  }
582  else
583  {
584  NS_TEST_ASSERT_MSG_EQ(0, 1, "Cannot read trace file " << path);
585  }
586 }
587 
588 //
589 // SatConstellationTest3 TestCase implementation
590 //
591 void
593 {
594  Config::Reset();
595  Singleton<SatIdMapper>::Get()->Reset();
596 
597  // Set simulation output details
598  Singleton<SatEnvVariables>::Get()->DoInitialize();
599  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-constellation", "test3", true);
600 
602  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
603  EnumValue(SatEnums::REGENERATION_NETWORK));
604  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
605  EnumValue(SatEnums::REGENERATION_NETWORK));
606 
608  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionEachRequest", BooleanValue(false));
609  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionPeriod",
610  TimeValue(MilliSeconds(10)));
611  Config::SetDefault("ns3::SatHelper::GwUsers", UintegerValue(3));
612 
613  Ptr<SimulationHelper> simulationHelper =
614  CreateObject<SimulationHelper>("test-sat-constellation/test3");
615 
616  // Creating the reference system.
617  simulationHelper->SetBeamSet({43, 30});
618  simulationHelper->SetUserCountPerUt(5);
619 
620  simulationHelper->LoadScenario("constellation-eutelsat-geo-2-sats-isls");
621 
622  simulationHelper->CreateSatScenario();
623 
624  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
625  SatTrafficHelper::FWD_LINK,
626  SatTrafficHelper::UDP,
627  MilliSeconds(10),
628  512,
629  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
630  Singleton<SatTopology>::Get()->GetUtUserNodes(),
631  Seconds(1.0),
632  Seconds(29.0),
633  Seconds(0));
634 
635  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
636  SatTrafficHelper::RTN_LINK,
637  SatTrafficHelper::UDP,
638  MilliSeconds(10),
639  512,
640  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
641  Singleton<SatTopology>::Get()->GetUtUserNodes(),
642  Seconds(1.0),
643  Seconds(29.0),
644  Seconds(0));
645 
646  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
647 
648  s->AddGlobalFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
649  s->AddGlobalRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
650  s->AddPerGwFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
651  s->AddPerGwRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
652  s->AddPerSatFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
653  s->AddPerSatRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
654  s->AddPerBeamFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
655  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
656  s->AddPerUtFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
657  s->AddPerUtRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
658 
659  simulationHelper->SetSimulationTime(Seconds(10));
660  simulationHelper->RunSimulation();
661 
662  Simulator::Destroy();
663 
664  // Global throughput
665  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
666  "stat-global-fwd-app-throughput-scatter-0.txt",
667  5,
668  6144);
669  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
670  "stat-global-rtn-app-throughput-scatter-0.txt",
671  5,
672  6144);
673 
674  // Per satellite throughput
675  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
676  "stat-per-sat-fwd-app-throughput-scatter-1.txt",
677  5,
678  2048);
679  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
680  "stat-per-sat-fwd-app-throughput-scatter-2.txt",
681  5,
682  4096);
683  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
684  "stat-per-sat-rtn-app-throughput-scatter-1.txt",
685  5,
686  2048);
687  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
688  "stat-per-sat-rtn-app-throughput-scatter-2.txt",
689  5,
690  4096);
691 
692  // Per beam throughput
693  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
694  "stat-per-beam-fwd-app-throughput-scatter-1-30.txt",
695  5,
696  0);
697  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
698  "stat-per-beam-fwd-app-throughput-scatter-1-43.txt",
699  5,
700  2048);
701  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
702  "stat-per-beam-fwd-app-throughput-scatter-2-30.txt",
703  5,
704  4096);
705  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
706  "stat-per-beam-fwd-app-throughput-scatter-2-43.txt",
707  5,
708  0);
709  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
710  "stat-per-beam-rtn-app-throughput-scatter-1-30.txt",
711  5,
712  0);
713  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
714  "stat-per-beam-rtn-app-throughput-scatter-1-43.txt",
715  5,
716  2048);
717  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
718  "stat-per-beam-rtn-app-throughput-scatter-2-30.txt",
719  5,
720  4096);
721  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
722  "stat-per-beam-rtn-app-throughput-scatter-2-43.txt",
723  5,
724  0);
725 
726  // Per GW throughput
727  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
728  "stat-per-gw-fwd-app-throughput-scatter-1.txt",
729  5,
730  2048);
731  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
732  "stat-per-gw-fwd-app-throughput-scatter-2.txt",
733  5,
734  4096);
735  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
736  "stat-per-gw-rtn-app-throughput-scatter-1.txt",
737  5,
738  2048);
739  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
740  "stat-per-gw-rtn-app-throughput-scatter-2.txt",
741  5,
742  4096);
743 
744  // Per UT throughput
745  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
746  "stat-per-ut-fwd-app-throughput-scatter-1.txt",
747  5,
748  2048);
749  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
750  "stat-per-ut-fwd-app-throughput-scatter-2.txt",
751  5,
752  2048);
753  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
754  "stat-per-ut-fwd-app-throughput-scatter-3.txt",
755  5,
756  2048);
757  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
758  "stat-per-ut-rtn-app-throughput-scatter-1.txt",
759  5,
760  2048);
761  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
762  "stat-per-ut-rtn-app-throughput-scatter-2.txt",
763  5,
764  2048);
765  TestFileValue("contrib/satellite/data/sims/test-sat-constellation/test3/"
766  "stat-per-ut-rtn-app-throughput-scatter-3.txt",
767  5,
768  2048);
769 }
770 
783 class SatConstellationTest4 : public TestCase
784 {
785  public:
787  virtual ~SatConstellationTest4();
788 
789  private:
790  virtual void DoRun(void);
791 };
792 
793 // Add some help text to this case to describe what it is intended to test
795  : TestCase(
796  "This case tests that a topology with hundreds of LEO satellites is correctly loaded.")
797 {
798 }
799 
800 // This destructor does nothing but we include it as a reminder that
801 // the test case should clean up after itself
803 {
804 }
805 
806 //
807 // SatConstellationTest4 TestCase implementation
808 //
809 void
811 {
812  Config::Reset();
813 
814  // Set simulation output details
815  Singleton<SatEnvVariables>::Get()->DoInitialize();
816  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-constellation", "test4", true);
817 
819  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
820  EnumValue(SatEnums::REGENERATION_NETWORK));
821  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
822  EnumValue(SatEnums::REGENERATION_NETWORK));
823 
825  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionEachRequest", BooleanValue(false));
826  Config::SetDefault("ns3::SatSGP4MobilityModel::UpdatePositionPeriod",
827  TimeValue(MilliSeconds(10)));
828  Config::SetDefault("ns3::SatOrbiterHelper::IslArbiterType", EnumValue(SatEnums::UNICAST));
829  Config::SetDefault("ns3::SatHelper::GwUsers", UintegerValue(3));
830 
832  Config::SetDefault("ns3::SatHelper::BeamNetworkAddress", Ipv4AddressValue("20.1.0.0"));
833  Config::SetDefault("ns3::SatHelper::GwNetworkAddress", Ipv4AddressValue("10.1.0.0"));
834  Config::SetDefault("ns3::SatHelper::UtNetworkAddress", Ipv4AddressValue("250.1.0.0"));
835 
836  Ptr<SimulationHelper> simulationHelper =
837  CreateObject<SimulationHelper>("test-sat-constellation");
838 
839  // Creating the reference system.
840  simulationHelper->SetBeamSet({1, 43, 60, 64});
841  simulationHelper->SetUserCountPerUt(5);
842 
843  simulationHelper->LoadScenario("constellation-telesat-351-sats");
844 
845  simulationHelper->CreateSatScenario();
846 
847  NodeContainer sats = Singleton<SatTopology>::Get()->GetOrbiterNodes();
848  NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
849  NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
850  NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
851  NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
852 
853  uint32_t countNetDevices = 0;
854  uint32_t countIslNetDevice = 0;
855  for (uint32_t i = 0; i < sats.GetN(); i++)
856  {
857  for (uint32_t j = 0; j < sats.Get(i)->GetNDevices(); j++)
858  {
859  if (DynamicCast<SatOrbiterNetDevice>(sats.Get(i)->GetDevice(j)) != nullptr)
860  {
861  countNetDevices += 1;
862  countIslNetDevice += DynamicCast<SatOrbiterNetDevice>(sats.Get(i)->GetDevice(j))
863  ->GetIslsNetDevices()
864  .size();
865  }
866  }
867  }
868 
869  NS_TEST_ASSERT_MSG_EQ(sats.GetN(), 351, "Topology must contain 351 satellites");
870  NS_TEST_ASSERT_MSG_EQ(countNetDevices,
871  351,
872  "Topology must contain 351 satellite Orbiter Net Devices");
873  NS_TEST_ASSERT_MSG_EQ(countIslNetDevice,
874  1404,
875  "Topology must contain 1404 (351*4) satellite ISL Net Devices");
876  NS_TEST_ASSERT_MSG_EQ(gws.GetN(), 2, "Topology must contain 2 GWs");
877  NS_TEST_ASSERT_MSG_EQ(uts.GetN(), 3, "Topology must contain 3 UTs");
878  NS_TEST_ASSERT_MSG_EQ(gwUsers.GetN(), 3, "Topology must contain 3 GW users");
879  NS_TEST_ASSERT_MSG_EQ(utUsers.GetN(), 15, "Topology must contain 15 UT users");
880 
881  for (uint32_t i = 0; i < sats.GetN(); i++)
882  {
883  Ptr<SatIslArbiter> arbiter =
884  DynamicCast<SatOrbiterNetDevice>(sats.Get(i)->GetDevice(0))->GetArbiter();
885  Ptr<SatIslArbiterUnicast> arbiterUnicast = DynamicCast<SatIslArbiterUnicast>(arbiter);
886  NS_TEST_ASSERT_MSG_NE(arbiterUnicast,
887  nullptr,
888  "Arbiter of satellite " << i
889  << " is not of type SatIslArbiterUnicast");
890  for (uint32_t j = 0; j < sats.GetN(); j++)
891  {
892  if (i != j)
893  {
894  NS_TEST_ASSERT_MSG_NE(arbiterUnicast->Decide(i, j, nullptr),
895  -1,
896  "No entry in arbiter of satellite " << i << " to satellite "
897  << j);
898  }
899  }
900  }
901 
902  Simulator::Destroy();
903 }
904 
905 // The TestSuite class names the TestSuite as sat-constellation-test, identifies what type of
906 // TestSuite (Type::SYSTEM), and enables the TestCases to be run. Typically, only the constructor
907 // for this class must be defined
908 //
909 class SatConstellationTestSuite : public TestSuite
910 {
911  public:
913 };
914 
916  : TestSuite("sat-constellation-test", Type::SYSTEM)
917 {
918  AddTestCase(new SatConstellationTest1, TestCase::Duration::QUICK); // Test topology loading
919  AddTestCase(new SatConstellationTest2,
920  TestCase::Duration::QUICK); // Test good throughputs without ISLs
921  AddTestCase(new SatConstellationTest3,
922  TestCase::Duration::QUICK); // Test good throughputs with ISLs
923  AddTestCase(new SatConstellationTest4,
924  TestCase::Duration::QUICK); // Test topology loading with huge constellation
925 }
926 
927 // Allocate an instance of this TestSuite
'Constellation, test 1' test case implementation.
'Constellation, test 2 test case implementation.
std::vector< std::string > Split(std::string s, char del)
void TestFileValue(std::string path, uint32_t time, uint32_t expectedValue)
'Constellation, test 3 test case implementation.
std::vector< std::string > Split(std::string s, char del)
void TestFileValue(std::string path, uint32_t time, uint32_t expectedValue)
'Constellation, test 4' test case implementation.
GeoCoordinate class is used to store and operate with geodetic coordinates.
double GetAltitude() const
Gets altitude value of coordinate.
double GetLatitude() const
Gets latitude value of coordinate.
double GetLongitude() const
Gets longitude value of coordinate.
Keep track of the current position and velocity of an object in satellite network.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatConstellationTestSuite satConstellationTestSuite