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<uint32_t> visitedBeams;
34 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 != NULL, "Course changed for a non-mobile UT");
41 
42  uint32_t beam = tracedPosition->GetBestBeamId();
43  visitedBeams.insert(beam);
44  relativeSpeeds.push_back(tracedPosition->GetRelativeSpeed(satMobility));
45 }
46 
57 NS_LOG_COMPONENT_DEFINE("sat-mobility-beam-tracer");
58 
59 int
60 main(int argc, char* argv[])
61 {
62  std::string inputFileNameWithPath =
63  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
64  "/generic-input-attributes.xml";
65  std::string mobileUtTraceFile("");
66 
67  Ptr<SimulationHelper> simulationHelper =
68  CreateObject<SimulationHelper>("sat-mobility-position-generator");
69  simulationHelper->DisableAllCapacityAssignmentCategories();
70  simulationHelper->EnableCrdsa();
71 
72  // Parse command-line and XML file
73  CommandLine cmd;
74  cmd.AddValue("TraceFile", "Path to the trace file to check beams from", mobileUtTraceFile);
75  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
76  cmd.Parse(argc, argv);
77  simulationHelper->ReadInputAttributesFromFile(inputFileNameWithPath);
78 
79  if (mobileUtTraceFile != "")
80  {
81  Ptr<SatHelper> satHelper = CreateObject<SatHelper>();
82  satMobility =
83  satHelper->GetBeamHelper()->GetGeoSatNodes().Get(0)->GetObject<SatMobilityModel>();
84  Ptr<Node> node = satHelper->LoadMobileUtFromFile(0, mobileUtTraceFile);
85  node->GetObject<SatMobilityModel>()->TraceConnect("SatCourseChange",
86  "BeamTracer",
87  MakeCallback(SatCourseChange));
88 
89  Ptr<SimulationHelperConf> simulationConf = CreateObject<SimulationHelperConf>();
90  Simulator::Stop(simulationConf->m_simTime);
91  Simulator::Run();
92  Simulator::Destroy();
93 
94  std::cout << "Visited beams are:";
95  for (auto& beam : visitedBeams)
96  {
97  std::cout << " " << beam;
98  }
99  std::cout << std::endl;
100 
101  double minSpeed = 0.0, maxSpeed = 0.0, totalSpeed = 0.0;
102  uint32_t valuesCount = 0;
103  for (double& speed : relativeSpeeds)
104  {
105  if (!minSpeed)
106  {
107  minSpeed = speed;
108  }
109  if (speed)
110  {
111  minSpeed = std::min(minSpeed, speed);
112  maxSpeed = std::max(maxSpeed, speed);
113  totalSpeed += speed;
114  ++valuesCount;
115  }
116  }
117  std::cout << "Speeding stats (m/s):\n\tmin: " << minSpeed << "\n\tmax: " << maxSpeed
118  << "\n\tmean: " << totalSpeed / valuesCount << std::endl;
119  }
120 }
Keep track of the current position and velocity of an object in satellite network.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
std::vector< double > relativeSpeeds
Ptr< SatMobilityModel > satMobility
std::set< uint32_t > visitedBeams
static void SatCourseChange(std::string context, Ptr< const SatMobilityModel > position)