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