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 
102  std::string onPattern = "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]";
103  std::string offPattern = "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]";
104 
105  // To read input attributes from input xml-file
106  std::string inputFileNameWithPath =
107  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
108  "/sys-rtn-test.xml";
109 
110  // read command line parameters given by user
111  CommandLine cmd;
112  cmd.AddValue("testCase", "Test case to execute", testCase);
113  cmd.AddValue("frameConf", "Pre-defined super frame configuration", preDefinedFrameConfig);
114  cmd.AddValue("trafficModel", "Traffic model to use (0 = CBR, 1 = OnOff)", trafficModel);
115  cmd.AddValue("simLength", "Simulation length", simLength);
116  cmd.AddValue("beamId", "Beam Id", beamId);
117  cmd.AddValue("utAppStartTime", "Application (first) start time.", utAppStartTime);
118  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
119  cmd.Parse(argc, argv);
120 
121  Config::SetDefault("ns3::ConfigStore::Filename", StringValue(inputFileNameWithPath));
122  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Load"));
123  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
124  ConfigStore inputFrameConfig;
125  inputFrameConfig.ConfigureDefaults();
126 
127  // select pre-defined super frame configuration wanted to use.
128  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0", StringValue(preDefinedFrameConfig));
129 
130  // use the default SuperframeAllocator
131  Config::SetDefault("ns3::SatBeamScheduler::SuperFrameAllocatorType", StringValue("Default"));
132 
133  switch (testCase)
134  {
135  case 0: // scheduler, CRA, ACM is selected by command line arguments (
136  // --"ns3::SatWaveformConf::AcmEnabled=true" or
137  // --"ns3::SatWaveformConf::AcmEnabled=false" )
138  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
139  BooleanValue(true));
140  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
141  StringValue("ns3::ConstantRandomVariable[Constant=2]"));
142  Config::SetDefault("ns3::SatDefaultSuperframeAllocator::FcaEnabled", BooleanValue(false));
143  break;
144 
145  case 1: // scheduler, FCA (CRA + VBDC), ACM is selected by command line arguments (
146  // --"ns3::SatWaveformConf::AcmEnabled=true" or
147  // --"ns3::SatWaveformConf::AcmEnabled=false" )
148  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
149  BooleanValue(true));
150  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
151  StringValue("ns3::ConstantRandomVariable[Constant=2]"));
152  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
153  BooleanValue(true));
154  Config::SetDefault("ns3::SatDefaultSuperframeAllocator::FcaEnabled", BooleanValue(true));
155  break;
156 
157  case 2: // ACM, one UT with one user, MARKOV fading on, external fading on
158  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
159  BooleanValue(true));
160  Config::SetDefault("ns3::SatWaveformConf::AcmEnabled", BooleanValue(true));
161  Config::SetDefault("ns3::SatBeamHelper::FadingModel", StringValue("FadingMarkov"));
162 
163  // Note, that the positions of the fading files do not necessarily match with the
164  // beam location, since this example is not using list position allocator!
165  Config::SetDefault("ns3::SatChannel::EnableExternalFadingInputTrace", BooleanValue(true));
166  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtFwdDownIndexFileName",
167  StringValue("BeamId-1_256_UT_fading_fwddwn_trace_index.txt"));
168  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtRtnUpIndexFileName",
169  StringValue("BeamId-1_256_UT_fading_rtnup_trace_index.txt"));
170  endUsersPerUt = 1;
171  utsPerBeam = 1;
172  break;
173 
174  case 3: // RM, one UT with one user, CRA only
175 
181  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
182  BooleanValue(false));
183  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
184  BooleanValue(false));
185  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
186  BooleanValue(false));
187  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
188  BooleanValue(true));
189  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantServiceRate",
190  StringValue("ns3::ConstantRandomVariable[Constant=100]"));
191  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
192  BooleanValue(false));
193  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
194  BooleanValue(false));
195  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
196  BooleanValue(false));
197  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
198  BooleanValue(false));
199  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
200  BooleanValue(false));
201  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
202  BooleanValue(false));
203  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
204  BooleanValue(false));
205  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
206  BooleanValue(false));
207 
208  endUsersPerUt = 1;
209  utsPerBeam = 1;
210 
211  break;
212 
213  case 4: // RM, one UT with one user, RBDC only
214 
218  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
219  BooleanValue(false));
220  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
221  StringValue("ns3::ConstantRandomVariable[Constant=1]"));
222  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
223  BooleanValue(false));
224  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
225  BooleanValue(false));
226  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
227  BooleanValue(false));
228  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
229  BooleanValue(false));
230  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
231  BooleanValue(false));
232  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
233  BooleanValue(false));
234  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
235  BooleanValue(true));
236  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
237  BooleanValue(false));
238  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
239  BooleanValue(false));
240  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
241  BooleanValue(false));
242  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
243  BooleanValue(false));
244 
245  // Change ways of sending the capacity requests!
246 
247  // CRA
248  // Config::SetDefault
249  // ("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided", BooleanValue
250  // (true)); Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
251  // (SatEnums::RA_MODEL_OFF));
252 
253  // Slotted Aloha
254  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
256  // Config::SetDefault ("ns3::SatBeamHelper::RaCollisionModel", StringValue
257  // ("RaCollisionConstantErrorProbability")); Config::SetDefault
258  // ("ns3::SatBeamHelper::RaConstantErrorRate", DoubleValue (0.3));
259 
260  // CRDSA
261  // Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
262  // (SatEnums::RA_MODEL_CRDSA)); Config::SetDefault
263  // ("ns3::SatUtHelper::UseCrdsaOnlyForControlPackets", BooleanValue (true));
264 
265  // Periodical control slots
266  // Config::SetDefault ("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue (true));
267 
268  offPattern = "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]";
269 
270  endUsersPerUt = 1;
271  utsPerBeam = 1;
272 
273  break;
274 
275  case 5: // RM, one UT with one user, VBDC only
276 
280  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
281  BooleanValue(false));
282  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantServiceRate",
283  StringValue("ns3::ConstantRandomVariable[Constant=1]"));
284  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
285  BooleanValue(false));
286  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
287  BooleanValue(false));
288  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
289  BooleanValue(false));
290  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
291  BooleanValue(false));
292  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
293  BooleanValue(false));
294  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
295  BooleanValue(false));
296  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
297  BooleanValue(false));
298  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
299  BooleanValue(false));
300  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
301  BooleanValue(false));
302  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
303  BooleanValue(false));
304  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
305  BooleanValue(true));
306 
307  // Change ways of sending the capacity requests!
308 
309  // CRA
310  // Config::SetDefault
311  // ("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided", BooleanValue
312  // (true)); Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
313  // (SatEnums::RA_MODEL_OFF));
314 
315  // Slotted Aloha
316  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
318  // Config::SetDefault ("ns3::SatBeamHelper::RaCollisionModel", StringValue
319  // ("RaCollisionConstantErrorProbability")); Config::SetDefault
320  // ("ns3::SatBeamHelper::RaConstantErrorRate", DoubleValue (0.3));
321 
322  // CRDSA
323  // Config::SetDefault ("ns3::SatBeamHelper::RandomAccessModel", EnumValue
324  // (SatEnums::RA_MODEL_CRDSA)); Config::SetDefault
325  // ("ns3::SatUtHelper::UseCrdsaOnlyForControlPackets", BooleanValue (true));
326 
327  // Periodical control slots
328  // Config::SetDefault ("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue (true));
329 
330  offPattern = "ns3::ExponentialRandomVariable[Mean=10.0|Bound=0.0]";
331 
332  endUsersPerUt = 1;
333  utsPerBeam = 1;
334  break;
335 
336  default:
337  break;
338  }
339 
340  // Creating the reference system. Note, currently the satellite module supports
341  // only one reference system, which is named as "Scenario72". The string is utilized
342  // in mapping the scenario to the needed reference system configuration files. Arbitrary
343  // scenario name results in fatal error.
344  simulationHelper->SetUtCountPerBeam(utsPerBeam);
345  simulationHelper->SetUserCountPerUt(endUsersPerUt);
346  simulationHelper->SetBeamSet({beamId});
347  simulationHelper->SetSimulationTime(simLength);
348 
349  simulationHelper->LoadScenario("geo-33E");
350 
351  // Create satellite scenario
352  simulationHelper->CreateSatScenario();
353 
354  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/RbdcTrace",
355  MakeCallback(&RbcdRcvdCb));
356 
357  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/VbdcTrace",
358  MakeCallback(&VbcdRcvdCb));
359 
360  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatLlc/SatRequestManager/AvbdcTrace",
361  MakeCallback(&AvbcdRcvdCb));
362 
363  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatMac/DaResourcesTrace",
364  MakeCallback(&TbtpResources));
365 
366  // Config::ConnectWithoutContext
367  // ("/NodeList/*/DeviceList/*/SatLlc/SatEncapsulator/SatQueue/Enqueue",
368  // MakeCallback (&PacketEnqueu));
369 
373  switch (trafficModel)
374  {
375  case 0: // CBR
376  {
377  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
380  Seconds(1),
381  512,
382  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
383  Singleton<SatTopology>::Get()->GetUtUserNodes(),
384  utAppStartTime,
385  Seconds(simLength + 1),
386  Seconds(0.1));
387  }
388  break;
389  case 1: // On-Off
390  {
391  simulationHelper->GetTrafficHelper()->AddOnOffTraffic(
394  DataRate("500kb/s"),
395  512,
396  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
397  Singleton<SatTopology>::Get()->GetUtUserNodes(),
398  onPattern,
399  offPattern,
400  utAppStartTime,
401  Seconds(simLength + 1),
402  Seconds(0.1));
403  }
404  break;
405  default:
406  NS_FATAL_ERROR("Not Supported Traffic Model!");
407  break;
408  }
409 
413  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
414 
415  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_PLOT);
416  s->AddPerBeamRtnAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
417  s->AddPerBeamRtnFeederDevThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
418  s->AddPerBeamRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
419  s->AddPerBeamRtnFeederPhyThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
420 
421  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_FILE);
422  s->AddAverageUtUserRtnAppThroughput(SatStatsHelper::OUTPUT_CDF_PLOT);
423 
424  s->AddAverageUtUserRtnAppDelay(SatStatsHelper::OUTPUT_CDF_FILE);
425  s->AddAverageUtUserRtnAppDelay(SatStatsHelper::OUTPUT_CDF_PLOT);
426  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_CDF_FILE);
427  s->AddPerBeamRtnAppDelay(SatStatsHelper::OUTPUT_CDF_PLOT);
428 
429  s->AddPerBeamRtnFeederDaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
430  s->AddPerBeamFrameSymbolLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
431  s->AddPerBeamWaveformUsage(SatStatsHelper::OUTPUT_SCALAR_FILE);
432 
433  // enable application info logs
434  // LogComponentEnable ("CbrApplication", LOG_LEVEL_INFO);
435  // LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
436  // LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
437 
438  NS_LOG_INFO("--- sat-rtn-sys-test ---");
439  NS_LOG_INFO(" Test case: " << testCase);
440  NS_LOG_INFO(" Traffic model: " << trafficModel);
441  // NS_LOG_INFO(" Packet size: " << packetSize.Get ());
442  // NS_LOG_INFO(" Data rate (on-off): " << dataRate.Get ());
443  // NS_LOG_INFO(" Interval (CBR): " << interval.Get ().GetSeconds ());
444  NS_LOG_INFO(" Simulation length: " << simLength);
445  NS_LOG_INFO(" Number of UTs: " << utsPerBeam);
446  NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
447  NS_LOG_INFO(" ");
448 
452  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-rtn-sys-test.xml"));
453  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
454  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
455  // ConfigStore outputConfig;
456  // outputConfig.ConfigureDefaults ();
457 
461  simulationHelper->RunSimulation();
462 
463  return 0;
464 }
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)