sat-iot-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-iot-example");
40 
41 int
42 main(int argc, char* argv[])
43 {
44  // Variables
45  std::string beam = "8";
46  uint32_t nbGw = 1;
47  uint32_t nbUtsPerBeam = 1;
48  uint32_t nbEndUsersPerUt = 1;
49 
50  Time appStartTime = Seconds(0.001);
51  Time simLength = Seconds(60.0);
52 
53  uint32_t queueSize = 50;
54  double maxPowerTerminalW = 0.3;
55 
56  double rtnFeederLinkBaseFrequency = 1.77e+10;
57  double rtnUserLinkBaseFrequency = 2.95e+10;
58  double rtnFeederLinkBandwidth = 4.6848e+6;
59  double frame0_AllocatedBandwidthHz = 2.928e+05;
60  double frame0_CarrierAllocatedBandwidthHz = 2.928e+05;
61  double frame0_CarrierRollOff = 0.22;
62  double frame0_CarrierSpacing = 0;
63 
64  std::string modcodsUsed =
65  "QPSK_1_TO_2 QPSK_3_TO_5 QPSK_2_TO_3 QPSK_3_TO_4 QPSK_4_TO_5 QPSK_5_TO_6 QPSK_8_TO_9 "
66  "QPSK_9_TO_10 "
67  "8PSK_3_TO_5 8PSK_2_TO_3 8PSK_3_TO_4 8PSK_5_TO_6 8PSK_8_TO_9 8PSK_9_TO_10 "
68  "16APSK_2_TO_3 16APSK_3_TO_4 16APSK_4_TO_5 16APSK_5_TO_6 16APSK_8_TO_9 16APSK_9_TO_10 "
69  "32APSK_3_TO_4 32APSK_4_TO_5 32APSK_5_TO_6 32APSK_8_TO_9";
70 
71  Ptr<SimulationHelper> simulationHelper = CreateObject<SimulationHelper>("sat-iot-example");
72 
73  // Read command line parameters given by user
74  CommandLine cmd;
75  cmd.AddValue("Beam", "Id of beam used (cannot use multiple beams)", beam);
76  cmd.AddValue("NbGw", "Number of GWs", nbGw);
77  cmd.AddValue("NbUtsPerBeam", "Number of UTs per spot-beam", nbUtsPerBeam);
78  cmd.AddValue("NbEndUsersPerUt", "Number of end users per UT", nbEndUsersPerUt);
79  cmd.AddValue("QueueSize", "Satellite queue sizes in packets", queueSize);
80  cmd.AddValue("AppStartTime", "Applications start time (in seconds, or add unit)", appStartTime);
81  cmd.AddValue("SimLength", "Simulation length (in seconds, or add unit)", simLength);
82  cmd.AddValue("MaxPowerTerminalW", "Maximum power of terminals in W", maxPowerTerminalW);
83  cmd.AddValue("RtnFeederLinkBaseFrequency",
84  "Base frequency of the return feeder link band",
85  rtnFeederLinkBaseFrequency);
86  cmd.AddValue("RtnUserLinkBaseFrequency",
87  "Base frequency of the return user link band",
88  rtnUserLinkBaseFrequency);
89  cmd.AddValue("RtnFeederLinkBandwidth",
90  "Bandwidth of the return feeder link band",
91  rtnFeederLinkBandwidth);
92  cmd.AddValue("Frame0_AllocatedBandwidthHz",
93  "The allocated bandwidth [Hz] for frame",
94  frame0_AllocatedBandwidthHz);
95  cmd.AddValue("Frame0_CarrierAllocatedBandwidthHz",
96  "The allocated carrier bandwidth [Hz] for frame",
97  frame0_CarrierAllocatedBandwidthHz);
98  cmd.AddValue("Frame0_CarrierRollOff", "The roll-off factor for frame", frame0_CarrierRollOff);
99  cmd.AddValue("Frame0_CarrierSpacing",
100  "The carrier spacing factor for frame",
101  frame0_CarrierSpacing);
102  simulationHelper->AddDefaultUiArguments(cmd);
103  cmd.Parse(argc, argv);
104 
105  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
106  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
107 
108  /*
109  * FWD link
110  */
111  // Set defaults
112  Config::SetDefault("ns3::SatConf::FwdUserLinkBandwidth", DoubleValue(2e+08));
113  Config::SetDefault("ns3::SatConf::FwdFeederLinkBandwidth", DoubleValue(8e+08));
114  Config::SetDefault("ns3::SatConf::FwdCarrierAllocatedBandwidth", DoubleValue(50e+06));
115  Config::SetDefault("ns3::SatConf::FwdCarrierRollOff", DoubleValue(0.05));
116 
117  // ModCods selection
118  Config::SetDefault("ns3::SatBeamHelper::DvbVersion", StringValue("DVB_S2"));
119  Config::SetDefault("ns3::SatBbFrameConf::ModCodsUsed", StringValue(modcodsUsed));
120  Config::SetDefault("ns3::SatBbFrameConf::DefaultModCod", StringValue("QPSK_1_TO_2"));
121 
122  // Queue size
123  Config::SetDefault("ns3::SatQueue::MaxPackets", UintegerValue(queueSize));
124 
125  // Power limitation
126  Config::SetDefault("ns3::SatUtPhy::TxMaxPowerDbw",
127  DoubleValue(SatUtils::LinearToDb(maxPowerTerminalW)));
128 
129  /*
130  * RTN link
131  */
132  // Default plan
133  Config::SetDefault("ns3::SatSuperframeConf0::FrameCount", UintegerValue(1));
134  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
136  Config::SetDefault("ns3::SatSuperframeConf0::FrameConfigType",
138 
139  Config::SetDefault("ns3::SatConf::RtnFeederLinkBaseFrequency",
140  DoubleValue(rtnFeederLinkBaseFrequency)); // Default value
141  Config::SetDefault("ns3::SatConf::RtnUserLinkBaseFrequency",
142  DoubleValue(rtnUserLinkBaseFrequency)); // Default value
143  Config::SetDefault("ns3::SatConf::RtnFeederLinkBandwidth", DoubleValue(rtnFeederLinkBandwidth));
144  Config::SetDefault("ns3::SatConf::RtnUserLinkBandwidth",
145  DoubleValue(rtnFeederLinkBandwidth / 4));
146 
147  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_AllocatedBandwidthHz",
148  DoubleValue(frame0_AllocatedBandwidthHz));
149  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierAllocatedBandwidthHz",
150  DoubleValue(frame0_CarrierAllocatedBandwidthHz));
151  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierRollOff",
152  DoubleValue(frame0_CarrierRollOff));
153  Config::SetDefault("ns3::SatSuperframeConf0::Frame0_CarrierSpacing",
154  DoubleValue(frame0_CarrierSpacing));
155 
156  /*
157  * Traffics
158  */
159  simulationHelper->SetSimulationTime(simLength);
160 
161  simulationHelper->SetGwUserCount(nbGw);
162  simulationHelper->SetUtCountPerBeam(nbUtsPerBeam);
163  simulationHelper->SetUserCountPerUt(nbEndUsersPerUt);
164  simulationHelper->SetBeams(beam);
165 
166  simulationHelper->LoadScenario("geo-33E");
167 
168  simulationHelper->CreateSatScenario();
169 
170  Ptr<SatHelper> satHelper = simulationHelper->GetSatelliteHelper();
171  Ptr<SatTrafficHelper> trafficHelper = simulationHelper->GetTrafficHelper();
172  trafficHelper->AddPoissonTraffic(SatTrafficHelper::RTN_LINK,
173  Seconds(1),
174  Seconds(0.1),
175  DataRate("200kb/s"),
176  300,
177  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
178  Singleton<SatTopology>::Get()->GetUtUserNodes(),
179  appStartTime,
180  simLength,
181  Seconds(0.001)); // 200kb/s == 100kBaud
182  trafficHelper->AddCbrTraffic(SatTrafficHelper::RTN_LINK,
184  MilliSeconds(8.5),
185  300,
186  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
187  Singleton<SatTopology>::Get()->GetUtUserNodes(),
188  appStartTime,
189  simLength,
190  Seconds(0.001)); // 280kb/s == 140kBaud
191 
192  // Link results
193  // Uncomment to use custom C/N0 traces or constants for some links
194  /*
195  Ptr<SatCnoHelper> satCnoHelper = simulationHelper->GetCnoHelper ();
196  satCnoHelper->UseTracesForDefault (false);
197  for (uint32_t i = 0; i < Singleton<SatTopology>::Get()->GetNUtNodes(); i++)
198  {
199  satCnoHelper->SetUtNodeCnoFile (Singleton<SatTopology>::Get()->GetUtNode(i),
200  SatEnums::FORWARD_USER_CH, "path_to_cno_file"); // For input trace file
201  // or
202  satCnoHelper->SetGwNodeCno (Singleton<SatTopology>::Get()->GetUtNode(i),
203  SatEnums::FORWARD_USER_CH, 1e10); // For constant value
204  }
205  */
206 
207  /*
208  * Outputs
209  * Note: some outputs are automatically generated by traffic helper
210  */
211  simulationHelper->EnableProgressLogs();
212 
213  Config::SetDefault("ns3::ConfigStore::Filename", StringValue("output-attributes.xml"));
214  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
215  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Save"));
216  ConfigStore outputConfig;
217  outputConfig.ConfigureDefaults();
218 
219  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
220 
221  // Link SINR
222  s->AddGlobalFwdFeederLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
223  s->AddGlobalFwdUserLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
224  s->AddGlobalRtnFeederLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
225  s->AddGlobalRtnUserLinkSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
226 
227  s->AddGlobalFwdFeederLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
228  s->AddGlobalFwdUserLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
229  s->AddGlobalRtnFeederLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
230  s->AddGlobalRtnUserLinkSinr(SatStatsHelper::OUTPUT_SCALAR_FILE);
231 
232  // SINR
233  s->AddGlobalFwdCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
234  s->AddGlobalFwdCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
235  s->AddPerUtFwdCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
236  s->AddPerUtFwdCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
237  s->AddPerUtFwdCompositeSinr(SatStatsHelper::OUTPUT_CDF_PLOT);
238  s->AddGlobalRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
239  s->AddGlobalRtnCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
240  s->AddPerBeamRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
241  s->AddPerBeamRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_PLOT);
242  s->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_FILE);
243  s->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_SCATTER_FILE);
244  s->AddPerUtRtnCompositeSinr(SatStatsHelper::OUTPUT_CDF_PLOT);
245 
246  // Link RX Power
247  s->AddGlobalFwdFeederLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
248  s->AddGlobalFwdUserLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
249  s->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
250  s->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCATTER_FILE);
251 
252  s->AddGlobalFwdFeederLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
253  s->AddGlobalFwdUserLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
254  s->AddGlobalRtnFeederLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
255  s->AddGlobalRtnUserLinkRxPower(SatStatsHelper::OUTPUT_SCALAR_FILE);
256 
257  // Return link load
258  s->AddGlobalFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
259  s->AddPerGwFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
260  s->AddPerBeamFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
261 
262  s->AddGlobalFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
263  s->AddPerGwFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
264  s->AddPerBeamFrameUserLoad(SatStatsHelper::OUTPUT_SCALAR_FILE);
265 
266  // Frame type usage
267  s->AddGlobalFrameTypeUsage(SatStatsHelper::OUTPUT_SCALAR_FILE);
268 
269  simulationHelper->RunSimulation();
270 
271  return 0;
272 
273 } // end of `int main (int argc, char *argv[])`
@ SUPER_FRAME_CONFIG_0
SUPER_FRAME_CONFIG_0.
@ CONFIG_TYPE_0
Configuration type 0.
static T LinearToDb(T linear)
Converts linear to decibels.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.