sat-rtn-system-test-example.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
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: Sami Rantanen <sami.rantanen@magister.fi>
19  *
20  */
21 
22 #include "ns3/applications-module.h"
23 #include "ns3/config-store-module.h"
24 #include "ns3/core-module.h"
25 #include "ns3/internet-module.h"
26 #include "ns3/network-module.h"
27 #include "ns3/satellite-module.h"
28 #include "ns3/traffic-module.h"
29 
30 using namespace ns3;
31 
43 NS_LOG_COMPONENT_DEFINE("sat-rtn-system-test-example");
44 
45 // Callback called when RBDC CR has been sent by request manager
46 static void
47 RbcdRcvdCb(uint32_t value)
48 {
49  NS_LOG_INFO("RBDC request generated with " << value << " kbps");
50 }
51 
52 // Callback called when AVBDC CR has been sent by request manager
53 static void
54 AvbcdRcvdCb(uint32_t value)
55 {
56  NS_LOG_INFO("AVBDC request generated with " << value << " Bytes");
57 }
58 
59 // Callback called when VBDC CR has been sent by request manager
60 static void
61 VbcdRcvdCb(uint32_t value)
62 {
63  NS_LOG_INFO("VBDC request generated with " << value << " Bytes");
64 }
65 
66 // Callback called when VBDC CR has been sent by request manager
67 static void
68 TbtpResources(uint32_t value)
69 {
70  if (value > 0)
71  {
72  NS_LOG_INFO("" << value << " Bytes allocated within TBTP");
73  }
74 }
75 
76 int
77 main(int argc, char* argv[])
78 {
79  uint32_t beamId = 26;
80  uint32_t endUsersPerUt = 10;
81  uint32_t utsPerBeam = 10;
82  Time utAppStartTime = Seconds(0.1);
83 
84  // UintegerValue packetSize (1280); // in bytes
85  // TimeValue interval (MilliSeconds (500));
86  // DataRateValue dataRate (16000);
87 
88  double simLength(30.0); // in seconds
89  std::string preDefinedFrameConfig = "Configuration_0";
90  uint32_t testCase = 0;
91  uint32_t trafficModel = 0;
92 
93  LogComponentEnable("sat-rtn-system-test-example", LOG_LEVEL_INFO);
94 
96  std::string simulationName = "example-rtn-system-test";
97  auto simulationHelper = CreateObject<SimulationHelper>(simulationName);
98 
99  // set default values for traffic model apps here
100  // attributes can be overridden by command line arguments or input xml when needed
101  // Config::SetDefault ("ns3::CbrApplication::PacketSize", packetSize);
102  // Config::SetDefault ("ns3::CbrApplication::Interval", interval);
103  // Config::SetDefault ("ns3::OnOffApplication::PacketSize", packetSize);
104  // Config::SetDefault ("ns3::OnOffApplication::DataRate", dataRate);
105  Config::SetDefault("ns3::OnOffApplication::OnTime",
106  StringValue("ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]"));
107  Config::SetDefault("ns3::OnOffApplication::OffTime",
108  StringValue("ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]"));
109 
110  // To read input attributes from input xml-file
111  std::string inputFileNameWithPath =
112  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
113  "/sys-rtn-test.xml";
114 
115  // read command line parameters given by user
116  CommandLine cmd;
117  cmd.AddValue("testCase", "Test case to execute", testCase);
118  cmd.AddValue("frameConf", "Pre-defined super frame configuration", preDefinedFrameConfig);
119  cmd.AddValue("trafficModel", "Traffic model to use (0 = CBR, 1 = OnOff)", trafficModel);
120  cmd.AddValue("simLength", "Simulation length", simLength);
121  cmd.AddValue("beamId", "Beam Id", beamId);
122  cmd.AddValue("utAppStartTime", "Application (first) start time.", utAppStartTime);
123  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
124  cmd.Parse(argc, argv);
125 
126  Config::SetDefault("ns3::ConfigStore::Filename", StringValue(inputFileNameWithPath));
127  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Load"));
128  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
129  ConfigStore inputFrameConfig;
130  inputFrameConfig.ConfigureDefaults();
131 
132  // select pre-defined super frame configuration wanted to use.
133  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0", StringValue(preDefinedFrameConfig));
134 
135  // use the default SuperframeAllocator
136  Config::SetDefault("ns3::SatBeamScheduler::SuperFrameAllocatorType", StringValue("Default"));
137 
138  switch (testCase)
139  {
140  case 0: // scheduler, CRA, ACM is selected by command line arguments (
141  // --"ns3::SatWaveformConf::AcmEnabled=true" or
142  // --"ns3::SatWaveformConf::AcmEnabled=false" )
143  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
144  BooleanValue(true));
145  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
146  StringValue("ns3::ConstantRandomVariable[Constant=2]"));
147  Config::SetDefault("ns3::SatDefaultSuperframeAllocator::FcaEnabled", BooleanValue(false));
148  break;
149 
150  case 1: // scheduler, FCA (CRA + VBDC), ACM is selected by command line arguments (
151  // --"ns3::SatWaveformConf::AcmEnabled=true" or
152  // --"ns3::SatWaveformConf::AcmEnabled=false" )
153  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
154  BooleanValue(true));
155  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
156  StringValue("ns3::ConstantRandomVariable[Constant=2]"));
157  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
158  BooleanValue(true));
159  Config::SetDefault("ns3::SatDefaultSuperframeAllocator::FcaEnabled", BooleanValue(true));
160  break;
161 
162  case 2: // ACM, one UT with one user, MARKOV fading on, external fading on
163  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
164  BooleanValue(true));
165  Config::SetDefault("ns3::SatWaveformConf::AcmEnabled", BooleanValue(true));
166  Config::SetDefault("ns3::SatBeamHelper::FadingModel", StringValue("FadingMarkov"));
167 
168  // Note, that the positions of the fading files do not necessarily match with the
169  // beam location, since this example is not using list position allocator!
170  Config::SetDefault("ns3::SatChannel::EnableExternalFadingInputTrace", BooleanValue(true));
171  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtFwdDownIndexFileName",
172  StringValue("BeamId-1_256_UT_fading_fwddwn_trace_index.txt"));
173  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtRtnUpIndexFileName",
174  StringValue("BeamId-1_256_UT_fading_rtnup_trace_index.txt"));
175  endUsersPerUt = 1;
176  utsPerBeam = 1;
177  break;
178 
179  case 3: // RM, one UT with one user, CRA only
180 
186  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
187  BooleanValue(false));
188  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
189  BooleanValue(false));
190  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
191  BooleanValue(false));
192  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
193  BooleanValue(true));
194  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantServiceRate",
195  StringValue("ns3::ConstantRandomVariable[Constant=100]"));
196  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
197  BooleanValue(false));
198  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
199  BooleanValue(false));
200  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
201  BooleanValue(false));
202  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
203  BooleanValue(false));
204  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
205  BooleanValue(false));
206  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
207  BooleanValue(false));
208  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
209  BooleanValue(false));
210  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
211  BooleanValue(false));
212 
213  endUsersPerUt = 1;
214  utsPerBeam = 1;
215 
216  break;
217 
218  case 4: // RM, one UT with one user, RBDC only
219 
223  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
224  BooleanValue(false));
225  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
226  StringValue("ns3::ConstantRandomVariable[Constant=1]"));
227  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
228  BooleanValue(false));
229  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
230  BooleanValue(false));
231  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
232  BooleanValue(false));
233  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
234  BooleanValue(false));
235  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
236  BooleanValue(false));
237  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
238  BooleanValue(false));
239  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
240  BooleanValue(true));
241  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
242  BooleanValue(false));
243  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
244  BooleanValue(false));
245  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
246  BooleanValue(false));
247  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
248  BooleanValue(false));
249 
250  // Change ways of sending the capacity requests!
251 
252  // CRA
253  // Config::SetDefault
254  // ("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided", BooleanValue
255  // (true)); Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
256  // (SatEnums::RA_MODEL_OFF));
257 
258  // Slotted Aloha
259  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
261  // Config::SetDefault ("ns3::SatBeamHelper::RaCollisionModel", StringValue
262  // ("RaCollisionConstantErrorProbability")); Config::SetDefault
263  // ("ns3::SatBeamHelper::RaConstantErrorRate", DoubleValue (0.3));
264 
265  // CRDSA
266  // Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
267  // (SatEnums::RA_MODEL_CRDSA)); Config::SetDefault
268  // ("ns3::SatUtHelper::UseCrdsaOnlyForControlPackets", BooleanValue (true));
269 
270  // Periodical control slots
271  // Config::SetDefault ("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue (true));
272 
273  Config::SetDefault("ns3::OnOffApplication::OffTime",
274  StringValue("ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]"));
275 
276  endUsersPerUt = 1;
277  utsPerBeam = 1;
278 
279  break;
280 
281  case 5: // RM, one UT with one user, VBDC only
282 
286  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
287  BooleanValue(false));
288  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
289  StringValue("ns3::ConstantRandomVariable[Constant=1]"));
290  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
291  BooleanValue(false));
292  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
293  BooleanValue(false));
294  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
295  BooleanValue(false));
296  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
297  BooleanValue(false));
298  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
299  BooleanValue(false));
300  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
301  BooleanValue(false));
302  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
303  BooleanValue(false));
304  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
305  BooleanValue(false));
306  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
307  BooleanValue(false));
308  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
309  BooleanValue(false));
310  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
311  BooleanValue(true));
312 
313  // Change ways of sending the capacity requests!
314 
315  // CRA
316  // Config::SetDefault
317  // ("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided", BooleanValue
318  // (true)); Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
319  // (SatEnums::RA_MODEL_OFF));
320 
321  // Slotted Aloha
322  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
324  // Config::SetDefault ("ns3::SatBeamHelper::RaCollisionModel", StringValue
325  // ("RaCollisionConstantErrorProbability")); Config::SetDefault
326  // ("ns3::SatBeamHelper::RaConstantErrorRate", DoubleValue (0.3));
327 
328  // CRDSA
329  // Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
330  // (SatEnums::RA_MODEL_CRDSA)); Config::SetDefault
331  // ("ns3::SatUtHelper::UseCrdsaOnlyForControlPackets", BooleanValue (true));
332 
333  // Periodical control slots
334  // Config::SetDefault ("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue (true));
335 
336  Config::SetDefault("ns3::OnOffApplication::OffTime",
337  StringValue("ns3::ExponentialRandomVariable[Mean=10.0|Bound=0.0]"));
338 
339  endUsersPerUt = 1;
340  utsPerBeam = 1;
341  break;
342 
343  default:
344  break;
345  }
346 
347  // Creating the reference system. Note, currently the satellite module supports
348  // only one reference system, which is named as "Scenario72". The string is utilized
349  // in mapping the scenario to the needed reference system configuration files. Arbitrary
350  // scenario name results in fatal error.
351  simulationHelper->SetUtCountPerBeam(utsPerBeam);
352  simulationHelper->SetUserCountPerUt(endUsersPerUt);
353  simulationHelper->SetBeamSet({beamId});
354  simulationHelper->SetSimulationTime(simLength);
355 
356  // Create satellite scenario
357  simulationHelper->CreateSatScenario();
358 
359  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/RbdcTrace",
360  MakeCallback(&RbcdRcvdCb));
361 
362  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/VbdcTrace",
363  MakeCallback(&VbcdRcvdCb));
364 
365  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/AvbdcTrace",
366  MakeCallback(&AvbcdRcvdCb));
367 
368  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatMac/DaResourcesTrace",
369  MakeCallback(&TbtpResources));
370 
371  // Config::ConnectWithoutContext
372  // ("/NodeList/*/DeviceList/*/SatLlc/SatEncapsulator/SatQueue/Enqueue",
373  // MakeCallback (&PacketEnqueu));
374 
379 
380  switch (trafficModel)
381  {
382  case 0: // CBR
383  model = SimulationHelper::CBR;
384  break;
385 
386  case 1: // On-Off
387  model = SimulationHelper::ONOFF;
388  break;
389 
390  default:
391  NS_FATAL_ERROR("Not Supported Traffic Model!");
392  break;
393  }
394 
395  simulationHelper->InstallTrafficModel(model,
398  utAppStartTime,
399  Seconds(simLength + 1),
400  Seconds(0.1));
401 
405  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
406 
407  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_PLOT);
408  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
409  s->AddPerBeamRtnFeederDevThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
410  s->AddPerBeamRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
411  s->AddPerBeamRtnFeederPhyThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
412 
413  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_FILE);
414  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_PLOT);
415 
416  s->AddAverageUtUserRtnAppDelay(SatStatsHelper::OUTPUT_CDF_FILE);
417  s->AddAverageUtUserRtnAppDelay(SatStatsHelper::OUTPUT_CDF_PLOT);
418  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_CDF_FILE);
419  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_CDF_PLOT);
420 
421  s->AddPerBeamRtnFeederDaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
422  s->AddPerBeamFrameSymbolLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
423  s->AddPerBeamWaveformUsage(SatStatsHelper::OUTPUT_SCALAR_FILE);
424 
425  // enable application info logs
426  // LogComponentEnable ("CbrApplication", LOG_LEVEL_INFO);
427  // LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
428  // LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
429 
430  NS_LOG_INFO("--- sat-rtn-sys-test ---");
431  NS_LOG_INFO(" Test case: " << testCase);
432  NS_LOG_INFO(" Traffic model: " << trafficModel);
433  // NS_LOG_INFO(" Packet size: " << packetSize.Get ());
434  // NS_LOG_INFO(" Data rate (on-off): " << dataRate.Get ());
435  // NS_LOG_INFO(" Interval (CBR): " << interval.Get ().GetSeconds ());
436  NS_LOG_INFO(" Simulation length: " << simLength);
437  NS_LOG_INFO(" Number of UTs: " << utsPerBeam);
438  NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
439  NS_LOG_INFO(" ");
440 
444  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-rtn-sys-test.xml"));
445  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
446  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
447  // ConfigStore outputConfig;
448  // outputConfig.ConfigureDefaults ();
449 
453  simulationHelper->RunSimulation();
454 
455  return 0;
456 }
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static void AvbcdRcvdCb(uint32_t value)
static void TbtpResources(uint32_t value)
static void VbcdRcvdCb(uint32_t value)
static void RbcdRcvdCb(uint32_t value)