sat-group-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 
64 NS_LOG_COMPONENT_DEFINE("sat-group-example");
65 
66 typedef enum
67 {
72 
73 void
74 ConfigureAllStats(Ptr<SatStatsHelperContainer> s)
75 {
76  SatStatsHelper::OutputType_t outputType =
77  SatStatsHelper::OUTPUT_SCATTER_FILE; // Only format compatible with all per group statistics
78 
79  s->AddPerBeamFwdAppDelay(outputType);
80 
81  s->AddPerGroupFwdAppDelay(outputType);
82  s->AddPerGroupRtnAppDelay(outputType);
83 
84  s->AddPerGroupFwdDevDelay(outputType);
85  s->AddPerGroupRtnDevDelay(outputType);
86  s->AddPerGroupFwdMacDelay(outputType);
87  s->AddPerGroupRtnMacDelay(outputType);
88  s->AddPerGroupFwdPhyDelay(outputType);
89  s->AddPerGroupRtnPhyDelay(outputType);
90 
91  s->AddAverageGroupFwdAppDelay(outputType);
92  s->AddAverageGroupRtnAppDelay(outputType);
93 
94  s->AddAverageGroupFwdDevDelay(outputType);
95  s->AddAverageGroupRtnDevDelay(outputType);
96  s->AddAverageGroupFwdMacDelay(outputType);
97  s->AddAverageGroupRtnMacDelay(outputType);
98  s->AddAverageGroupFwdPhyDelay(outputType);
99  s->AddAverageGroupRtnPhyDelay(outputType);
100 
101  s->AddPerGroupFwdAppJitter(outputType);
102  s->AddPerGroupRtnAppJitter(outputType);
103 
104  s->AddPerGroupFwdDevJitter(outputType);
105  s->AddPerGroupRtnDevJitter(outputType);
106  s->AddPerGroupFwdMacJitter(outputType);
107  s->AddPerGroupRtnMacJitter(outputType);
108  s->AddPerGroupFwdPhyJitter(outputType);
109  s->AddPerGroupRtnPhyJitter(outputType);
110 
111  s->AddAverageGroupFwdAppJitter(outputType);
112  s->AddAverageGroupRtnAppJitter(outputType);
113 
114  s->AddAverageGroupFwdDevJitter(outputType);
115  s->AddAverageGroupRtnDevJitter(outputType);
116  s->AddAverageGroupFwdMacJitter(outputType);
117  s->AddAverageGroupRtnMacJitter(outputType);
118  s->AddAverageGroupFwdPhyJitter(outputType);
119  s->AddAverageGroupRtnPhyJitter(outputType);
120 
121  s->AddPerGroupFwdAppPlt(outputType);
122  s->AddPerGroupRtnAppPlt(outputType);
123 
124  s->AddAverageGroupFwdAppPlt(outputType);
125  s->AddAverageGroupRtnAppPlt(outputType);
126 
127  s->AddPerGroupFwdQueueBytes(outputType);
128  s->AddPerGroupRtnQueueBytes(outputType);
129 
130  s->AddPerGroupFwdQueuePackets(outputType);
131  s->AddPerGroupRtnQueuePackets(outputType);
132 
133  s->AddPerGroupFwdSignallingLoad(outputType);
134  s->AddPerGroupRtnSignallingLoad(outputType);
135 
136  s->AddPerGroupFwdCompositeSinr(outputType);
137  s->AddPerGroupRtnCompositeSinr(outputType);
138 
139  s->AddPerGroupFwdAppThroughput(outputType);
140  s->AddPerGroupRtnAppThroughput(outputType);
141 
142  s->AddPerGroupFwdUserDevThroughput(outputType);
143  s->AddPerGroupRtnFeederDevThroughput(outputType);
144  s->AddPerGroupFwdUserMacThroughput(outputType);
145  s->AddPerGroupRtnFeederMacThroughput(outputType);
146  s->AddPerGroupFwdUserPhyThroughput(outputType);
147  s->AddPerGroupRtnFeederPhyThroughput(outputType);
148 
149  s->AddAverageGroupFwdAppThroughput(outputType);
150  s->AddAverageGroupRtnAppThroughput(outputType);
151 
152  s->AddAverageGroupFwdUserDevThroughput(outputType);
153  s->AddAverageGroupRtnFeederDevThroughput(outputType);
154  s->AddAverageGroupFwdUserMacThroughput(outputType);
155  s->AddAverageGroupRtnFeederMacThroughput(outputType);
156  s->AddAverageGroupFwdUserPhyThroughput(outputType);
157  s->AddAverageGroupRtnFeederPhyThroughput(outputType);
158 
159  s->AddPerGroupFwdUserDaPacketError(outputType);
160  s->AddPerGroupRtnFeederDaPacketError(outputType);
161  s->AddPerGroupFeederSlottedAlohaPacketError(outputType);
162  s->AddPerGroupFeederCrdsaPacketError(outputType);
163  s->AddPerGroupFeederEssaPacketError(outputType);
164 
165  s->AddPerGroupFeederSlottedAlohaPacketCollision(outputType);
166  s->AddPerGroupFeederCrdsaPacketCollision(outputType);
167  s->AddPerGroupFeederEssaPacketCollision(outputType);
168 
169  s->AddPerGroupCapacityRequest(outputType);
170 
171  s->AddPerGroupResourcesGranted(outputType);
172 }
173 
174 int
175 main(int argc, char* argv[])
176 {
177  // Enable info logs
178  LogComponentEnable("sat-group-example", LOG_LEVEL_INFO);
179 
180  // Variables
181  uint32_t beamId = 1;
182  uint32_t endUsersPerUt(1);
183  uint32_t utsPerBeam(20);
184 
185  uint32_t packetSize(1500);
186  Time interval(Seconds(1.0));
187 
188  Time appStartTime = Seconds(0.1);
189  Time simLength(Seconds(60.0));
190 
191  Ptr<SimulationHelper> simulationHelper = CreateObject<SimulationHelper>("sat-group-example");
192 
193  // Parse command-line
194  CommandLine cmd;
195  cmd.AddValue("UtsPerBeam", "Number of UTs per beam", utsPerBeam);
196  cmd.AddValue("PacketSize", "UDP packet size (in bytes)", packetSize);
197  cmd.AddValue("Interval", "CBR interval (in seconds, or add unit)", interval);
198  cmd.AddValue("SimLength", "Simulation length (in seconds, or add unit)", simLength);
199  simulationHelper->AddDefaultUiArguments(cmd);
200  cmd.Parse(argc, argv);
201 
203  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
204  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
205 
206  simulationHelper->SetSimulationTime(simLength);
207  simulationHelper->SetUserCountPerUt(endUsersPerUt);
208  simulationHelper->SetUtCountPerBeam(utsPerBeam);
209 
210  // Set beam ID
211  std::stringstream beamsEnabled;
212  beamsEnabled << beamId;
213  simulationHelper->SetBeams(beamsEnabled.str());
214 
215  Ptr<SatGroupHelper> groupHelper = simulationHelper->GetGroupHelper();
216 
217  // Create group 5 and create 100 UTs (in addition to the ones are created by SimulationHelper,
218  // using utsPerBeam) to in this group
219  groupHelper->CreateUtNodesFromPosition(5, 10, GeoCoordinate(56.4243, -16.042, 122.427), 100000);
220 
221  // Create reference system
222  Ptr<SatHelper> satHelper = simulationHelper->CreateSatScenario();
223 
224  // Create groups
225  NodeContainer utNodes = satHelper->UtNodes();
226 
228 
229  if (creationMethod == GroupCreationMethod_t::MANUAL)
230  {
231  groupHelper->AddUtNodeToGroup(1, utNodes.Get(0));
232 
233  NodeContainer nodes2To10;
234  for (uint32_t i = 2; i < 11; i++)
235  {
236  nodes2To10.Add(utNodes.Get(i));
237  }
238  groupHelper->AddUtNodesToGroup(2, nodes2To10);
239  }
240  else if (creationMethod == GroupCreationMethod_t::POSITION)
241  {
242  // Add all nodes less than 100km from node 0
243  groupHelper->CreateGroupFromPosition(
244  2,
245  utNodes,
246  utNodes.Get(0)->GetObject<SatMobilityModel>()->GetGeoPosition(),
247  100000);
248  }
249  else if (creationMethod == GroupCreationMethod_t::NUMBER)
250  {
251  std::vector<uint32_t> groups = {1, 2, 3};
252  groupHelper->CreateGroupsUniformly(groups, utNodes);
253  }
254  else
255  {
256  NS_FATAL_ERROR("Unknown value of GroupCreationMethod_t: " << creationMethod);
257  }
258 
259  // setup CBR traffic
260  Config::SetDefault("ns3::CbrApplication::Interval", TimeValue(interval));
261  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(packetSize));
262 
263  // Setup custom traffics
264  Ptr<SatTrafficHelper> trafficHelper = simulationHelper->GetTrafficHelper();
265  trafficHelper->AddCbrTraffic(SatTrafficHelper::FWD_LINK,
266  "100ms",
267  packetSize,
268  satHelper->GetGwUsers().Get(0),
269  satHelper->GetUtUsers(groupHelper->GetUtNodes(2)),
270  appStartTime,
271  appStartTime + simLength,
272  Seconds(0.05));
273 
274  trafficHelper->AddCbrTraffic(SatTrafficHelper::RTN_LINK,
275  "1000ms",
276  packetSize,
277  satHelper->GetGwUsers().Get(0),
278  satHelper->GetUtUsers(groupHelper->GetUtNodes(0)),
279  appStartTime,
280  appStartTime + simLength,
281  Seconds(0.05));
282 
283  trafficHelper->AddHttpTraffic(SatTrafficHelper::FWD_LINK,
284  satHelper->GetGwUsers().Get(0),
285  satHelper->GetUtUsers(groupHelper->GetUtNodes(1)),
286  appStartTime,
287  appStartTime + simLength,
288  Seconds(0.05));
289 
290  trafficHelper->AddVoipTraffic(SatTrafficHelper::FWD_LINK,
292  satHelper->GetGwUsers().Get(0),
293  satHelper->GetUtUsers(groupHelper->GetUtNodes(5)),
294  appStartTime,
295  appStartTime + simLength,
296  Seconds(0.05));
297 
298  NS_LOG_INFO("--- sat-group-example ---");
299  NS_LOG_INFO(" Packet size in bytes: " << packetSize);
300  NS_LOG_INFO(" Packet sending interval: " << interval.GetSeconds());
301  NS_LOG_INFO(" Simulation length: " << simLength.GetSeconds());
302  NS_LOG_INFO(" Number total of UTs: " << satHelper->UtNodes().GetN());
303  NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
304  NS_LOG_INFO(" Number of groups: " << groupHelper->GetN());
305  NS_LOG_INFO(" Nodes in default group: " << groupHelper->GetUtNodes(0).GetN());
306  std::list<uint32_t> groupIds = groupHelper->GetGroups();
307  groupIds.sort();
308  for (uint32_t groupId : groupIds)
309  {
310  NS_LOG_INFO(" Nodes in group " << groupId << ": "
311  << groupHelper->GetUtNodes(groupId).GetN());
312  }
313  NS_LOG_INFO(" ");
314 
315  // Set statistics
316  Ptr<SatStatsHelperContainer> s = simulationHelper->GetStatisticsContainer();
317  simulationHelper->EnableProgressLogs();
318 
319  Config::SetDefault("ns3::ConfigStore::Filename", StringValue("output-attributes.xml"));
320  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
321  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Save"));
322  ConfigStore outputConfig;
323  outputConfig.ConfigureDefaults();
324 
326 
327  simulationHelper->RunSimulation();
328 
329  return 0;
330 }
GeoCoordinate class is used to store and operate with geodetic coordinates.
Keep track of the current position and velocity of an object in satellite network.
GeoCoordinate GetGeoPosition(void) const
OutputType_t
Possible types and formats of statistics output.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
void ConfigureAllStats(Ptr< SatStatsHelperContainer > s)
GroupCreationMethod_t
@ NUMBER
@ MANUAL
@ POSITION