sat-ra-sim-tn9.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 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: Frans Laakso <frans.laakso@magister.fi>
19  */
20 
21 #include "ns3/applications-module.h"
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 
28 using namespace ns3;
29 
45 NS_LOG_COMPONENT_DEFINE("sat-ra-sim-tn9");
46 
47 int
48 main(int argc, char* argv[])
49 {
50  uint32_t beamId = 1;
51  uint32_t endUsersPerUt(1);
52  uint32_t raMode(3);
53  uint32_t utsPerBeam(1);
54  uint32_t packetSize(64);
55  std::string dataRate = "5kb/s";
56  std::string onTime = "0.2";
57  std::string offTime = "0.8";
58 
59  double simLength(300.0); // in seconds
60 
62  auto sh = CreateObject<SimulationHelper>("example-ra-sim-tn9");
63 
64  // To read attributes from file
65  std::string inputFileNameWithPath =
66  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
67  "/tn9-ra-input-attributes.xml";
68 
69  // read command line parameters given by user
70  CommandLine cmd;
71  cmd.AddValue("utsPerBeam", "Number of UTs per spot-beam", utsPerBeam);
72  cmd.AddValue("raMode", "RA mode", raMode);
73  cmd.AddValue("simLength", "Simulation duration in seconds", simLength);
74  cmd.AddValue("packetSize", "Constant packet size in bytes", packetSize);
75  cmd.AddValue("dataRate", "Data rate (e.g. 500kb/s)", dataRate);
76  cmd.AddValue("onTime", "Time for packet sending is on in seconds", onTime);
77  cmd.AddValue("offTime", "Time for packet sending is off in seconds", offTime);
78  sh->AddDefaultUiArguments(cmd, inputFileNameWithPath);
79  cmd.Parse(argc, argv);
80 
81  Config::SetDefault("ns3::ConfigStore::Filename", StringValue(inputFileNameWithPath));
82  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Load"));
83  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
84  ConfigStore inputConfig;
85  inputConfig.ConfigureDefaults();
86 
87  // Enable Random Access with all available modules
88  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
90 
91  // Set Random Access interference model
92  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
94 
95  // Set Random Access collision model
96  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
98 
99  // Set dynamic load control parameters
100  Config::SetDefault("ns3::SatPhyRxCarrierConf::EnableRandomAccessDynamicLoadControl",
101  BooleanValue(false));
102  Config::SetDefault(
103  "ns3::SatPhyRxCarrierConf::RandomAccessAverageNormalizedOfferedLoadMeasurementWindowSize",
104  UintegerValue(10));
105 
106  // Set random access parameters
107  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumUniquePayloadPerBlock",
108  UintegerValue(3));
109  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumConsecutiveBlockAccessed",
110  UintegerValue(6));
111  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MinimumIdleBlock",
112  UintegerValue(2));
113  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffTimeInMilliSeconds",
114  UintegerValue(50));
115  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffProbability",
116  UintegerValue(1));
117  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_HighLoadBackOffProbability",
118  UintegerValue(1));
119  Config::SetDefault(
120  "ns3::SatLowerLayerServiceConf::RaService0_AverageNormalizedOfferedLoadThreshold",
121  DoubleValue(0.99));
122  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
123  UintegerValue(3));
124 
125  switch (raMode)
126  {
127  // CRDSA + VBDC
128  case 0: {
129  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
130  BooleanValue(false));
131  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
132  BooleanValue(false));
133  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
134  BooleanValue(false));
135  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
136  BooleanValue(false));
137  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
138  BooleanValue(false));
139  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
140  BooleanValue(false));
141  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
142  BooleanValue(false));
143  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
144  BooleanValue(false));
145  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
146  BooleanValue(false));
147  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
148  BooleanValue(false));
149  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
150  BooleanValue(false));
151  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
152  BooleanValue(true));
153 
154  // Disable periodic control slots
155  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
156  break;
157  }
158  // SA + VBDC
159  case 1: {
160  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
161  BooleanValue(false));
162  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
163  BooleanValue(false));
164  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
165  BooleanValue(false));
166  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
167  BooleanValue(false));
168  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
169  BooleanValue(false));
170  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
171  BooleanValue(false));
172  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
173  BooleanValue(false));
174  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
175  BooleanValue(false));
176  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
177  BooleanValue(false));
178  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
179  BooleanValue(false));
180  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
181  BooleanValue(false));
182  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
183  BooleanValue(true));
184 
185  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
186  UintegerValue(1));
187 
188  // Disable periodic control slots
189  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
190  break;
191  }
192  // Periodic control slots + VBDC
193  case 2: {
194  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
195  BooleanValue(false));
196  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
197  BooleanValue(false));
198  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
199  BooleanValue(false));
200  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
201  BooleanValue(false));
202  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
203  BooleanValue(false));
204  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
205  BooleanValue(false));
206  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
207  BooleanValue(false));
208  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
209  BooleanValue(false));
210  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
211  BooleanValue(false));
212  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
213  BooleanValue(false));
214  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
215  BooleanValue(false));
216  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
217  BooleanValue(true));
218 
219  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
220  EnumValue(SatEnums::RA_MODEL_OFF));
221 
222  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(true));
223  break;
224  }
225  // CRDSA only
226  case 3: {
227  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
228  BooleanValue(false));
229  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
230  BooleanValue(false));
231  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
232  BooleanValue(false));
233  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
234  BooleanValue(false));
235  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
236  BooleanValue(false));
237  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
238  BooleanValue(false));
239  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
240  BooleanValue(false));
241  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
242  BooleanValue(false));
243  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
244  BooleanValue(false));
245  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
246  BooleanValue(false));
247  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
248  BooleanValue(false));
249  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
250  BooleanValue(false));
251 
252  // Disable periodic control slots
253  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
254  break;
255  }
256  default: {
257  NS_FATAL_ERROR("Unsupported raMode: " << raMode);
258  break;
259  }
260  }
261 
262  // Creating the reference system. Note, currently the satellite module supports
263  // only one reference system, which is named as "Scenario72". The string is utilized
264  // in mapping the scenario to the needed reference system configuration files. Arbitrary
265  // scenario name results in fatal error.
266  sh->SetSimulationTime(simLength);
267  sh->SetUserCountPerUt(endUsersPerUt);
268  sh->SetUtCountPerBeam(utsPerBeam);
269  sh->SetBeamSet({beamId});
270  sh->CreateSatScenario();
271 
275  // Set up user given parameters for on/off functionality.
276  Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
277  Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(dataRate));
278  Config::SetDefault("ns3::OnOffApplication::OnTime",
279  StringValue("ns3::ConstantRandomVariable[Constant=" + onTime + "]"));
280  Config::SetDefault("ns3::OnOffApplication::OffTime",
281  StringValue("ns3::ConstantRandomVariable[Constant=" + offTime + "]"));
282  sh->InstallTrafficModel(SimulationHelper::ONOFF,
285  Seconds(0),
286  Seconds(simLength - 2.0));
287 
291  Ptr<SatStatsHelperContainer> s = sh->GetStatisticsContainer();
292 
293  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
294  s->AddPerBeamRtnFeederDevThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
295  s->AddPerBeamRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
296  s->AddPerBeamRtnFeederPhyThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
297 
298  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_FILE);
299  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_PLOT);
300 
301  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
302  s->AddPerBeamRtnDevDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
303  s->AddPerBeamRtnPhyDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
304  s->AddPerBeamRtnMacDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
305 
306  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_CDF_FILE);
307  s->AddPerBeamRtnDevDelay(SatStatsHelper::OUTPUT_CDF_FILE);
308  s->AddPerBeamRtnPhyDelay(SatStatsHelper::OUTPUT_CDF_FILE);
309  s->AddPerBeamRtnMacDelay(SatStatsHelper::OUTPUT_CDF_FILE);
310 
311  // s->AddPerUtUserRtnAppThroughput (SatStatsHelper::OUTPUT_SCALAR_FILE);
312  // s->AddPerUtUserRtnAppThroughput (SatStatsHelper::OUTPUT_SCATTER_FILE);
313  // s->AddPerUtUserRtnAppThroughput (SatStatsHelper::OUTPUT_SCATTER_PLOT);
314  // s->AddPerUtUserRtnDevThroughput (SatStatsHelper::OUTPUT_SCATTER_FILE);
315  // s->AddPerUtUserRtnDevThroughput (SatStatsHelper::OUTPUT_SCATTER_PLOT);
316 
317  // s->AddPerUtUserRtnAppDelay (SatStatsHelper::OUTPUT_CDF_FILE);
318  // s->AddPerUtUserRtnAppDelay (SatStatsHelper::OUTPUT_CDF_PLOT);
319  // s->AddPerUtRtnDevDelay (SatStatsHelper::OUTPUT_CDF_FILE);
320  // s->AddPerUtRtnDevDelay (SatStatsHelper::OUTPUT_CDF_PLOT);
321 
322  s->AddPerBeamRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
323  s->AddPerBeamRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_PLOT);
324 
325  s->AddPerBeamResourcesGranted(SatStatsHelper::OUTPUT_CDF_FILE);
326  s->AddPerBeamResourcesGranted(SatStatsHelper::OUTPUT_CDF_PLOT);
327 
328  s->AddPerBeamFrameSymbolLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
329  s->AddPerBeamWaveformUsage(SatStatsHelper::OUTPUT_SCALAR_FILE);
330 
331  s->AddPerBeamRtnFeederDaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
332 
333  s->AddPerBeamFeederCrdsaPacketCollision(SatStatsHelper::OUTPUT_SCALAR_FILE);
334  s->AddPerBeamFeederCrdsaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
335  s->AddPerBeamFeederSlottedAlohaPacketCollision(SatStatsHelper::OUTPUT_SCALAR_FILE);
336  s->AddPerBeamFeederSlottedAlohaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
337 
338  // s->AddPerUtFeederCrdsaPacketCollision (SatStatsHelper::OUTPUT_SCALAR_FILE);
339  // s->AddPerUtFeederCrdsaPacketError (SatStatsHelper::OUTPUT_SCALAR_FILE);
340  // s->AddPerUtFeederSlottedAlohaPacketCollision (SatStatsHelper::OUTPUT_SCALAR_FILE);
341  // s->AddPerUtFeederSlottedAlohaPacketError (SatStatsHelper::OUTPUT_SCALAR_FILE);
342 
343  NS_LOG_INFO("--- sat-ra-sim-tn9 ---");
344  NS_LOG_INFO(" Packet size: " << packetSize);
345  NS_LOG_INFO(" Simulation length: " << simLength);
346  NS_LOG_INFO(" Number of UTs: " << utsPerBeam);
347  NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
348  NS_LOG_INFO(" ");
349 
353  // std::stringstream filename;
354  // filename << "tn9-ra-output-attributes-ut" << utsPerBeam
355  // << "-mode" << raMode << ".xml";
356  //
357  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue (filename.str ()));
358  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
359  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
360  // ConfigStore outputConfig;
361  // outputConfig.ConfigureDefaults ();
362 
366  sh->RunSimulation();
367 
368  return 0;
369 }
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.