sat-dynamic-frequency-plan-example.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 
22 #include "ns3/config-store-module.h"
23 #include "ns3/core-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/network-module.h"
26 #include "ns3/satellite-module.h"
27 #include "ns3/traffic-module.h"
28 
29 using namespace ns3;
30 
41 NS_LOG_COMPONENT_DEFINE("sat-generic-launcher");
42 
43 static double g_txMaxPower = 5.0;
44 static bool g_ascending = false;
45 static Time g_cnoInterval = MilliSeconds(100);
46 static Time g_simulationTime = Minutes(1);
47 
48 static void
49 ChangeCno(const std::vector<Ptr<SatUtPhy>>& utsPhysicalLayers)
50 {
51  g_txMaxPower += g_ascending ? 0.2 : -0.2;
52  g_ascending = (g_ascending && g_txMaxPower < 30.0) || (!g_ascending && g_txMaxPower < -30.0);
53 
54  for (auto& phy : utsPhysicalLayers)
55  {
56  phy->SetAttribute("TxMaxPowerDbw", DoubleValue(g_txMaxPower));
57  phy->Initialize();
58  }
59 
60  Simulator::Schedule(g_cnoInterval, &ChangeCno, utsPhysicalLayers);
61 }
62 
63 int
64 main(int argc, char* argv[])
65 {
66  bool varyingCno(false);
67  uint32_t maxSubdivisions(0);
68  uint32_t frameConfigType(2);
69  double initialBandwidth(3.75e6);
70  Time superframeDuration(MicroSeconds(26500));
71  std::string inputFileNameWithPath =
72  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
73  "/generic-input-attributes.xml";
74 
75  Ptr<SimulationHelper> simulationHelper = CreateObject<SimulationHelper>("generic-launcher");
76  simulationHelper->SetDefaultValues();
77 
78  CommandLine cmd;
79  cmd.AddValue("MaxCarrierSubdivision",
80  "The maximum amount of subdivision for a single carrier",
81  maxSubdivisions);
82  cmd.AddValue("FrameConfigType",
83  "The frame configuration type used for super frame",
84  frameConfigType);
85  cmd.AddValue("UseVaryingCno",
86  "Simulate varying C/N0 for UTs instead of changing their traffic overtime",
87  varyingCno);
88  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
89  cmd.Parse(argc, argv);
90 
91  Config::SetDefault("ns3::SimulationHelperConf::BeamsIDs", StringValue("12"));
92  Config::SetDefault("ns3::SimulationHelperConf::UtCountPerBeam",
93  StringValue("ns3::ConstantRandomVariable[Constant=30]"));
94  Config::SetDefault("ns3::SimulationHelperConf::UserCountPerUt",
95  StringValue("ns3::ConstantRandomVariable[Constant=1]"));
96 
97  Config::SetDefault("ns3::SatSuperframeConf0::FrameCount", UintegerValue(1));
98  Config::SetDefault("ns3::SatSuperframeConf0::FrameConfigType",
99  StringValue("ConfigType_" + std::to_string(frameConfigType)));
100  Config::SetDefault("ns3::SatSuperframeConf0::MaxCarrierSubdivision",
101  UintegerValue(maxSubdivisions));
102  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_AllocatedBandwidthHz",
103  DoubleValue(initialBandwidth));
104  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierAllocatedBandwidthHz",
105  DoubleValue(initialBandwidth));
106  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierRollOff", DoubleValue(0.2));
107  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierSpacing", DoubleValue(0.0));
108  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_RandomAccessFrame", BooleanValue(false));
109 
110  Config::SetDefault("ns3::SatSuperframeSeq::TargetDuration", TimeValue(superframeDuration));
111  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(superframeDuration));
112 
113  Config::SetDefault("ns3::SatFwdLinkScheduler::CnoEstimationWindow",
114  TimeValue(MilliSeconds(500)));
115  Config::SetDefault("ns3::SatRequestManager::CnoReportInterval", TimeValue(g_cnoInterval));
116  Config::SetDefault("ns3::SatBeamScheduler::CnoEstimationMode",
117  StringValue("MinimumValueInWindow"));
118  Config::SetDefault("ns3::SatBeamScheduler::CnoEstimationWindow", TimeValue(g_cnoInterval));
119 
120  Config::SetDefault("ns3::SatUtPhy::TxMaxPowerDbw", DoubleValue(g_txMaxPower));
121  Config::SetDefault("ns3::SatGeoUserPhy::TxMaxPowerDbw", DoubleValue(15.0));
122  Config::SetDefault("ns3::SatGeoFeederPhy::FixedAmplificationGainDb", DoubleValue(200.0));
123 
124  simulationHelper->ReadInputAttributesFromFile(inputFileNameWithPath);
125 
126  // Manual configuration of the simulation to avoid creating unnecessary traffic
127  Ptr<SimulationHelperConf> simulationConf = CreateObject<SimulationHelperConf>();
128  g_simulationTime = simulationConf->m_simTime;
129  simulationHelper->SetBeams(simulationConf->m_enabledBeams);
130  simulationHelper->SetUtCountPerBeam(simulationConf->m_utCount);
131  simulationHelper->SetUserCountPerUt(simulationConf->m_utUserCount);
132  simulationHelper->SetUserCountPerMobileUt(simulationConf->m_utMobileUserCount);
133  simulationHelper->SetSimulationTime(g_simulationTime);
134  simulationHelper->CreateSatScenario(SatHelper::NONE, simulationConf->m_mobileUtsFolder);
135  if (simulationConf->m_activateProgressLogging)
136  {
137  simulationHelper->EnableProgressLogs();
138  }
139 
140  simulationHelper->StoreAttributesToFile("parametersUsed.xml");
141 
142  if (varyingCno)
143  {
144  std::vector<Ptr<SatUtPhy>> utsPhysicalLayers;
145  NodeContainer utNodes = simulationHelper->GetSatelliteHelper()->UtNodes();
146  for (uint32_t i = 0; i < utNodes.GetN(); ++i)
147  {
148  Ptr<Node> node = utNodes.Get(i);
149  for (uint32_t j = 0; j < node->GetNDevices(); ++j)
150  {
151  Ptr<SatNetDevice> dev = DynamicCast<SatNetDevice>(node->GetDevice(j));
152  if (dev != nullptr)
153  {
154  Ptr<SatUtPhy> phy = DynamicCast<SatUtPhy>(dev->GetPhy());
155  if (phy != nullptr)
156  {
157  utsPhysicalLayers.push_back(phy);
158  }
159  }
160  }
161  }
162  Simulator::Schedule(Seconds(0), &ChangeCno, utsPhysicalLayers);
163 
164  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
167  Seconds(0),
169  MilliSeconds(50),
170  1.0);
171  }
172  else
173  {
174  // Configure our own kind of traffic
175  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(40));
176  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
179  Seconds(0),
181  MilliSeconds(50),
182  1.0);
183 
184  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(25600));
185  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
188  Seconds(0),
189  Seconds(10),
190  MilliSeconds(50),
191  0.3);
192 
193  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(1000));
194  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
197  Seconds(5),
198  Seconds(15),
199  MilliSeconds(50),
200  0.4);
201 
202  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(1000));
203  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
206  Seconds(10),
207  Seconds(20),
208  MilliSeconds(50),
209  0.5);
210 
211  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(40000));
212  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
215  Seconds(15),
216  Seconds(25),
217  MilliSeconds(50),
218  0.2);
219 
220  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(1));
221  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
224  Seconds(20),
225  Seconds(30),
226  MilliSeconds(50),
227  0.7);
228 
229  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(100));
230  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
233  Seconds(25),
234  Seconds(35),
235  MilliSeconds(50),
236  0.45);
237 
238  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(3000));
239  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
242  Seconds(30),
243  Seconds(40),
244  MilliSeconds(50),
245  0.55);
246 
247  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(40000));
248  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
251  Seconds(35),
252  Seconds(45),
253  MilliSeconds(50),
254  0.2);
255 
256  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(30000));
257  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
260  Seconds(40),
261  Seconds(50),
262  MilliSeconds(50),
263  0.3);
264 
265  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(1500));
266  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
269  Seconds(45),
270  Seconds(55),
271  MilliSeconds(50),
272  0.6);
273 
274  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(800));
275  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
278  Seconds(50),
279  Seconds(60),
280  MilliSeconds(50),
281  0.9);
282  }
283 
284  if (simulationConf->m_activateStatistics)
285  {
286  simulationHelper->CreateDefaultStats();
287  Ptr<SatStatsHelperContainer> stats = simulationHelper->GetStatisticsContainer();
288  stats->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
289  stats->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
290  stats->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
291  stats->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
292  stats->AddPerUtRtnAppDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
293  stats->AddPerUtRtnAppDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
294  stats->AddPerUtRtnMacDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
295  stats->AddPerUtRtnMacDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
296  stats->AddPerUtRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
297  stats->AddPerUtRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
298  stats->AddPerUtCarrierId(SatStatsHelper::OUTPUT_SCALAR_FILE);
299  stats->AddPerUtCarrierId(SatStatsHelper::OUTPUT_SCATTER_FILE);
300  stats->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
301  stats->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
302  }
303 
304  simulationHelper->RunSimulation();
305 }
@ NONE
NONE Not used.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static Time g_simulationTime
static double g_txMaxPower
static bool g_ascending
static Time g_cnoInterval
static void ChangeCno(const std::vector< Ptr< SatUtPhy >> &utsPhysicalLayers)