sat-lora-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: Bastien Tauran <bastien.tauran@viveris.fr>
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 
39 NS_LOG_COMPONENT_DEFINE("sat-lora-example");
40 
41 int
42 main(int argc, char* argv[])
43 {
44  // Variables
45  std::string beams = "3 4 5 6";
46  // std::string beams = "8";
47  uint32_t nbGwUser = 1;
48  uint32_t nbUtsPerBeam = 5;
49  uint32_t nbEndUsersPerUt = 1;
50 
51  Time appStartTime = Seconds(0.001);
52  Time simLength = Seconds(15.0);
53 
54  uint32_t packetSize = 24;
55  Time loraInterval = Seconds(10);
56  std::string interval = "10s";
57 
58  double frameAllocatedBandwidthHz = 15000;
59  double frameCarrierAllocatedBandwidthHz = 15000;
60  double frameCarrierRollOff = 0.22;
61  double frameCarrierSpacing = 0;
62  uint32_t frameSpreadingFactor = 256;
63 
64  bool interferenceModePerPacket = true;
65  bool displayTraces = true;
66 
67  Time firstWindowDelay = MilliSeconds(1500);
68  Time secondWindowDelay = Seconds(2);
69  Time firstWindowDuration = MilliSeconds(400);
70  Time secondWindowDuration = MilliSeconds(400);
71  Time firstWindowAnswerDelay = Seconds(1);
72  Time secondWindowAnswerDelay = Seconds(2);
73 
74  Ptr<SimulationHelper> simulationHelper = CreateObject<SimulationHelper>("example-lora");
75 
76  // read command line parameters given by user
77  CommandLine cmd;
78  cmd.AddValue("modelPP", "interferenceModePerPacket", interferenceModePerPacket);
79  cmd.AddValue("traces", "displayTraces", displayTraces);
80  cmd.AddValue("utsPerBeam", "Number of UTs per spot-beam", nbUtsPerBeam);
81  cmd.AddValue("simLength", "Simulation duration in seconds", simLength);
82  cmd.AddValue("packetSize", "Constant packet size in bytes", packetSize);
83  cmd.AddValue("loraInterval",
84  "Interval between two transmissions for each UT in seconds",
85  loraInterval);
86  cmd.AddValue("frameAllocatedBandwidthHz",
87  "Allocated bandwidth in Hz",
88  frameAllocatedBandwidthHz);
89  cmd.AddValue("frameCarrierAllocatedBandwidthHz",
90  "Allocated carrier bandwidth in Hz",
91  frameCarrierAllocatedBandwidthHz);
92  cmd.AddValue("frameCarrierRollOff", "Roll-off factor", frameCarrierRollOff);
93  cmd.AddValue("frameCarrierSpacing", "Carrier spacing factor", frameCarrierSpacing);
94  cmd.AddValue("frameSpreadingFactor", "Carrier spreading factor", frameSpreadingFactor);
95 
96  cmd.AddValue("firstWindowDelay",
97  "Delay between end of transmission and opening of first window on End Device",
98  firstWindowDelay);
99  cmd.AddValue("secondWindowDelay",
100  "Delay between end of transmission and opening of second window on End Device",
101  secondWindowDelay);
102  cmd.AddValue("firstWindowDuration", "First window duration on End Device", firstWindowDuration);
103  cmd.AddValue("secondWindowDuration",
104  "Second window duration on End Device",
105  secondWindowDuration);
106  cmd.AddValue("firstWindowAnswerDelay",
107  "Delay between end of reception and start of ack on first window on Gateway",
108  firstWindowAnswerDelay);
109  cmd.AddValue("secondWindowAnswerDelay",
110  "Delay between end of reception and start of ack on second window on Gateway",
111  secondWindowAnswerDelay);
112  simulationHelper->AddDefaultUiArguments(cmd);
113  cmd.Parse(argc, argv);
114 
116  Config::SetDefault("ns3::SatConf::ForwardLinkRegenerationMode",
117  EnumValue(SatEnums::TRANSPARENT));
118  Config::SetDefault("ns3::SatConf::ReturnLinkRegenerationMode",
119  EnumValue(SatEnums::TRANSPARENT));
120 
121  // Enable Lora
122  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
123  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
125 
126  // Config::SetDefault ("ns3::SatLoraConf::Standard", EnumValue (SatLoraConf::EU863_870));
127  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
128 
129  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
130  TimeValue(firstWindowDelay));
131  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay",
132  TimeValue(secondWindowDelay));
133  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
134  TimeValue(firstWindowDuration));
135  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
136  TimeValue(secondWindowDuration));
137  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
138  TimeValue(firstWindowAnswerDelay));
139  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay",
140  TimeValue(secondWindowAnswerDelay));
141 
142  // Defaults
143  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
144  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
145 
146  // Superframe configuration
147  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
149  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
151  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz",
152  DoubleValue(frameAllocatedBandwidthHz));
153  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
154  DoubleValue(frameCarrierAllocatedBandwidthHz));
155  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierRollOff",
156  DoubleValue(frameCarrierRollOff));
157  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierSpacing",
158  DoubleValue(frameCarrierSpacing));
159  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_SpreadingFactor",
160  UintegerValue(frameSpreadingFactor));
161 
162  // CRDSA only
163  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaServiceCount", UintegerValue(4));
164  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
165  BooleanValue(false));
166  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
167  BooleanValue(false));
168  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
169  BooleanValue(false));
170  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
171  BooleanValue(false));
172  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
173  BooleanValue(false));
174  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
175  BooleanValue(false));
176  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
177  BooleanValue(false));
178  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
179  BooleanValue(false));
180  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
181  BooleanValue(false));
182  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
183  BooleanValue(false));
184  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
185  BooleanValue(false));
186  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
187  BooleanValue(false));
188 
189  // Configure RA
190  Config::SetDefault("ns3::SatOrbiterHelper::FwdLinkErrorModel",
191  EnumValue(SatPhyRxCarrierConf::EM_AVI));
192  Config::SetDefault("ns3::SatOrbiterHelper::RtnLinkErrorModel",
193  EnumValue(SatPhyRxCarrierConf::EM_AVI));
194  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
195  if (interferenceModePerPacket)
196  {
197  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
199  }
200  else
201  {
202  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
204  }
205  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
207  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
209  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
210 
211  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
212  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
213  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDelay", StringValue("0s"));
214  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::FirstWindow", StringValue("0s"));
215  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
216  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::SpreadingFactor", UintegerValue(1));
217  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::DetectionThreshold", DoubleValue(0));
218  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
219 
220  // Set random access parameters
221  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumUniquePayloadPerBlock",
222  UintegerValue(3));
223  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumConsecutiveBlockAccessed",
224  UintegerValue(6));
225  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MinimumIdleBlock",
226  UintegerValue(2));
227  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffTimeInMilliSeconds",
228  UintegerValue(50));
229  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffProbability",
230  UintegerValue(1));
231  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_HighLoadBackOffProbability",
232  UintegerValue(1));
233  Config::SetDefault(
234  "ns3::SatLowerLayerServiceConf::RaService0_AverageNormalizedOfferedLoadThreshold",
235  DoubleValue(0.99));
236  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
237  UintegerValue(3));
238  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_SlottedAlohaAllowed",
239  BooleanValue(false));
240  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_CrdsaAllowed",
241  BooleanValue(false));
242  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_EssaAllowed", BooleanValue(true));
243 
244  // Traffics
245  simulationHelper->SetSimulationTime(simLength);
246 
247  simulationHelper->SetGwUserCount(nbGwUser);
248  simulationHelper->SetUtCountPerBeam(nbUtsPerBeam);
249  simulationHelper->SetUserCountPerUt(nbEndUsersPerUt);
250  simulationHelper->SetBeams(beams);
251 
252  simulationHelper->LoadScenario("geo-33E-lora");
253 
254  simulationHelper->CreateSatScenario();
255 
256  simulationHelper->GetTrafficHelper()->AddLoraCbrTraffic(
257  loraInterval,
258  packetSize,
259  Singleton<SatTopology>::Get()->GetGwUserNodes(),
260  Singleton<SatTopology>::Get()->GetUtUserNodes(),
261  appStartTime,
262  simLength,
263  Seconds(1));
264 
265  /*simulationHelper->GetTrafficHelper()->AddLoraPeriodicTraffic(loraInterval,
266  packetSize,
267  Singleton<SatTopology>::Get()->GetUtNodes(),
268  appStartTime,
269  simLength,
270  Seconds(1));*/
271 
272  // Outputs
273  simulationHelper->EnableProgressLogs();
274 
275  std::string outputPath = Singleton<SatEnvVariables>::Get()->LocateDirectory(
276  "contrib/satellite/data/sims/example-lora");
277  Config::SetDefault("ns3::ConfigStore::Filename",
278  StringValue(outputPath + "/output-attributes.xml"));
279  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
280  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Save"));
281  ConfigStore outputConfig;
282  outputConfig.ConfigureDefaults();
283 
284  if (displayTraces)
285  {
286  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
287 
288  s->AddGlobalFeederEssaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
289  s->AddGlobalFeederEssaPacketError(SatStatsHelper::OUTPUT_SCATTER_FILE);
290  s->AddPerUtFeederEssaPacketError(SatStatsHelper::OUTPUT_SCALAR_FILE);
291  s->AddPerUtFeederEssaPacketError(SatStatsHelper::OUTPUT_SCATTER_FILE);
292 
293  s->AddGlobalFeederEssaPacketCollision(SatStatsHelper::OUTPUT_SCALAR_FILE);
294  s->AddGlobalFeederEssaPacketCollision(SatStatsHelper::OUTPUT_SCATTER_FILE);
295  s->AddPerUtFeederEssaPacketCollision(SatStatsHelper::OUTPUT_SCALAR_FILE);
296  s->AddPerUtFeederEssaPacketCollision(SatStatsHelper::OUTPUT_SCATTER_FILE);
297 
298  s->AddGlobalRtnFeederWindowLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
299  s->AddGlobalRtnFeederWindowLoad(SatStatsHelper::OUTPUT_SCATTER_FILE);
300  s->AddPerBeamRtnFeederWindowLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
301  s->AddPerBeamRtnFeederWindowLoad(SatStatsHelper::OUTPUT_SCATTER_FILE);
302 
303  s->AddGlobalRtnAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
304  s->AddGlobalRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
305  s->AddGlobalRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
306  s->AddGlobalRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
307 
308  s->AddPerUtRtnAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
309  s->AddPerUtRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
310  s->AddPerUtRtnAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
311  s->AddPerUtRtnFeederMacThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
312 
313  s->AddPerUtRtnAppDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
314  s->AddPerUtRtnMacDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
315  s->AddPerUtRtnAppDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
316  s->AddPerUtRtnMacDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
317 
318  s->AddGlobalRtnCompositeSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
319  s->AddGlobalRtnCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
320  s->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
321  s->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
322 
323  s->AddGlobalRtnFeederLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
324  s->AddGlobalRtnFeederLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
325  s->AddGlobalRtnUserLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
326  s->AddGlobalRtnUserLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
327 
328  s->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
329  s->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
330  s->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
331  s->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
332 
333  s->AddPerUtFwdAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
334  s->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
335  s->AddPerUtFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
336  s->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
337 
338  s->AddGlobalFwdAppThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
339  s->AddGlobalFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
340  s->AddGlobalFwdAppThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
341  s->AddGlobalFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCATTER_FILE);
342 
343  s->AddPerUtFwdAppDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
344  s->AddPerUtFwdMacDelay(SatStatsHelper::OUTPUT_SCALAR_FILE);
345  s->AddPerUtFwdAppDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
346  s->AddPerUtFwdMacDelay(SatStatsHelper::OUTPUT_SCATTER_FILE);
347  }
348 
349  simulationHelper->RunSimulation();
350 
351  return 0;
352 
353 } // end of `int main (int argc, char *argv[])`
@ SATELLITE
For Satellite.
@ SUPER_FRAME_CONFIG_4
SUPER_FRAME_CONFIG_4.
@ CONFIG_TYPE_4
Configuration type 4 (ESSA)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.