sat-mobility-beam-tracer.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 CNES
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: Mathias Ettinger <mettinger@toulouse.viveris.fr>
19  */
20 
21 #include <ns3/config-store-module.h>
22 #include <ns3/core-module.h>
23 #include <ns3/internet-module.h>
24 #include <ns3/network-module.h>
25 #include <ns3/satellite-module.h>
26 #include <ns3/traffic-module.h>
27 
28 #include <iostream>
29 
30 using namespace ns3;
31 
32 Ptr<SatMobilityModel> satMobility = nullptr;
33 std::set<std::pair<uint32_t, uint32_t>> visitedBeams;
34 std::map<uint32_t, std::vector<double>> relativeSpeeds;
35 
36 static void
37 SatCourseChange(std::string context, Ptr<const SatMobilityModel> position)
38 {
39  auto tracedPosition = DynamicCast<const SatTracedMobilityModel>(position);
40  NS_ASSERT_MSG(tracedPosition != nullptr, "Course changed for a non-mobile UT");
41 
42  uint32_t sat = tracedPosition->GetSatId();
43  uint32_t beam = tracedPosition->GetBestBeamId(true);
44 
45  visitedBeams.insert(std::make_pair(sat, beam));
46  relativeSpeeds[sat].push_back(tracedPosition->GetRelativeSpeed(satMobility));
47 }
48 
59 NS_LOG_COMPONENT_DEFINE("sat-mobility-beam-tracer");
60 
61 int
62 main(int argc, char* argv[])
63 {
64  std::string inputFileNameWithPath =
65  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
66  "/generic-input-attributes.xml";
67  std::string mobileUtTraceFile = "";
68  // mobileUtTraceFile = Singleton<SatEnvVariables>::Get()->LocateDataDirectory() +
69  // "/additional-input/utpositions/mobiles/scenario6/trajectory";
70 
71  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
73  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
75 
76  Ptr<SimulationHelper> simulationHelper =
77  CreateObject<SimulationHelper>("sat-mobility-position-generator");
78  simulationHelper->EnableProgressLogs();
79  simulationHelper->DisableAllCapacityAssignmentCategories();
80  simulationHelper->EnableCrdsa();
81 
82  // Parse command-line and XML file
83  CommandLine cmd;
84  cmd.AddValue("TraceFile", "Path to the trace file to check beams from", mobileUtTraceFile);
85  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
86  cmd.Parse(argc, argv);
87  simulationHelper->ReadInputAttributesFromFile(inputFileNameWithPath);
88  simulationHelper->SetSimulationTime(Seconds(100));
89 
90  simulationHelper->SetUserCountPerUt(1);
91 
92  simulationHelper->LoadScenario("constellation-eutelsat-geo-2-sats-no-isls");
93 
94  if (mobileUtTraceFile != "")
95  {
96  Ptr<SatHelper> satHelper =
97  simulationHelper->CreateSatScenario(SatHelper::FULL, mobileUtTraceFile);
98  satMobility =
99  Singleton<SatTopology>::Get()->GetOrbiterNode(0)->GetObject<SatMobilityModel>();
100 
101  uint32_t satNb = Singleton<SatTopology>::Get()->GetNOrbiterNodes();
102  for (uint32_t i = 0; i < satNb; i++)
103  {
104  Ptr<Node> node = satHelper->LoadMobileUtFromFile(mobileUtTraceFile);
105  DynamicCast<SatTracedMobilityModel>(node->GetObject<SatMobilityModel>())->SetSatId(i);
106  node->GetObject<SatMobilityModel>()->TraceConnect("SatCourseChange",
107  "BeamTracer",
108  MakeCallback(SatCourseChange));
109  }
110 
111  simulationHelper->RunSimulation();
112  Simulator::Destroy();
113 
114  std::cout << "Visited beams are:";
115  for (std::pair<uint32_t, uint32_t> satAndBeam : visitedBeams)
116  {
117  std::cout << " (" << satAndBeam.first << ", " << satAndBeam.second << ")";
118  }
119  std::cout << std::endl;
120 
121  for (uint32_t satId = 0; satId < satNb; satId++)
122  {
123  double minSpeed = 0.0, maxSpeed = 0.0, totalSpeed = 0.0;
124  uint32_t valuesCount = 0;
125  for (double& speed : relativeSpeeds[satId])
126  {
127  if (!minSpeed)
128  {
129  minSpeed = speed;
130  }
131  if (speed)
132  {
133  minSpeed = std::min(minSpeed, speed);
134  maxSpeed = std::max(maxSpeed, speed);
135  totalSpeed += speed;
136  ++valuesCount;
137  }
138  }
139  std::cout << "Speeding stats (m/s) for satellite " << satId << ":\n\tmin: " << minSpeed
140  << "\n\tmax: " << maxSpeed << "\n\tmean: " << totalSpeed / valuesCount
141  << std::endl;
142  }
143  }
144 }
@ FULL
FULL Full scenario used as base.
Keep track of the current position and velocity of an object in satellite network.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Ptr< SatMobilityModel > satMobility
std::map< uint32_t, std::vector< double > > relativeSpeeds
std::set< std::pair< uint32_t, uint32_t > > visitedBeams
static void SatCourseChange(std::string context, Ptr< const SatMobilityModel > position)