satellite-traffic-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Magister Solutions
4  * Copyright (c) 2020 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
20  */
21 
23 
25 #include "simulation-helper.h"
26 
27 #include <ns3/cbr-helper.h>
28 #include <ns3/log.h>
29 #include <ns3/lora-periodic-sender.h>
30 #include <ns3/nrtv-helper.h>
31 #include <ns3/packet-sink-helper.h>
32 #include <ns3/packet-sink.h>
33 #include <ns3/satellite-topology.h>
34 #include <ns3/singleton.h>
35 #include <ns3/three-gpp-http-satellite-helper.h>
36 #include <ns3/type-id.h>
37 
38 #include <string>
39 #include <utility>
40 #include <vector>
41 
42 NS_LOG_COMPONENT_DEFINE("SatelliteTrafficHelper");
43 
44 namespace ns3
45 {
46 
47 NS_OBJECT_ENSURE_REGISTERED(SatTrafficHelperConf);
48 
58 #define SIM_ADD_TRAFFIC_MODEL_PROTOCOL_ATTRIBUTE(index, value) \
59  AddAttribute("Traffic" TOSTRING(index) "Protocol", \
60  "Network protocol that this traffic model will use", \
61  EnumValue(value), \
62  MakeEnumAccessor<SatTrafficHelperConf::TransportLayerProtocol_t>( \
63  &SatTrafficHelperConf::SetTraffic##index##Protocol, \
64  &SatTrafficHelperConf::GetTraffic##index##Protocol), \
65  MakeEnumChecker(SatTrafficHelperConf::PROTOCOL_UDP, \
66  "UDP", \
67  SatTrafficHelperConf::PROTOCOL_TCP, \
68  "TCP", \
69  SatTrafficHelperConf::PROTOCOL_BOTH, \
70  "BOTH"))
71 
72 #define SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(index, value) \
73  AddAttribute("Traffic" TOSTRING(index) "Direction", \
74  "Satellite link direction that this traffic model will use", \
75  EnumValue(value), \
76  MakeEnumAccessor<SatTrafficHelperConf::TrafficDirection_t>( \
77  &SatTrafficHelperConf::SetTraffic##index##Direction, \
78  &SatTrafficHelperConf::GetTraffic##index##Direction), \
79  MakeEnumChecker(SatTrafficHelperConf::RTN_LINK, \
80  "ReturnLink", \
81  SatTrafficHelperConf::FWD_LINK, \
82  "ForwardLink", \
83  SatTrafficHelperConf::BOTH_LINK, \
84  "BothLinks"))
85 
86 #define SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(index, value) \
87  AddAttribute("Traffic" TOSTRING(index) "Interval", \
88  "Interval between packets", \
89  TimeValue(value), \
90  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##Interval, \
91  &SatTrafficHelperConf::GetTraffic##index##Interval), \
92  MakeTimeChecker())
93 
94 #define SIM_ADD_TRAFFIC_MODEL_DATA_RATE_ATTRIBUTE(index, value) \
95  AddAttribute("Traffic" TOSTRING(index) "DataRate", \
96  "Data rate of traffic", \
97  DataRateValue(value), \
98  MakeDataRateAccessor(&SatTrafficHelperConf::SetTraffic##index##DataRate, \
99  &SatTrafficHelperConf::GetTraffic##index##DataRate), \
100  MakeDataRateChecker())
101 
102 #define SIM_ADD_TRAFFIC_MODEL_PACKET_SIZE_ATTRIBUTE(index, value) \
103  AddAttribute("Traffic" TOSTRING(index) "PacketSize", \
104  "Packet size in bytes", \
105  UintegerValue(value), \
106  MakeUintegerAccessor(&SatTrafficHelperConf::SetTraffic##index##PacketSize, \
107  &SatTrafficHelperConf::GetTraffic##index##PacketSize), \
108  MakeUintegerChecker<uint32_t>())
109 
110 #define SIM_ADD_TRAFFIC_MODEL_ON_TIME_PATTERN_ATTRIBUTE(index, value) \
111  AddAttribute("Traffic" TOSTRING(index) "OnTimePattern", \
112  "On time patter for on/off traffic", \
113  StringValue(value), \
114  MakeStringAccessor(&SatTrafficHelperConf::SetTraffic##index##OnTimePattern, \
115  &SatTrafficHelperConf::GetTraffic##index##OnTimePattern), \
116  MakeStringChecker())
117 
118 #define SIM_ADD_TRAFFIC_MODEL_OFF_TIME_PATTERN_ATTRIBUTE(index, value) \
119  AddAttribute("Traffic" TOSTRING(index) "OffTimePattern", \
120  "Off time patter for on/off traffic", \
121  StringValue(value), \
122  MakeStringAccessor(&SatTrafficHelperConf::SetTraffic##index##OffTimePattern, \
123  &SatTrafficHelperConf::GetTraffic##index##OffTimePattern), \
124  MakeStringChecker())
125 
126 #define SIM_ADD_TRAFFIC_MODEL_ON_TIME_ATTRIBUTE(index, value) \
127  AddAttribute("Traffic" TOSTRING(index) "OnTime", \
128  "On time value for Poisson traffic", \
129  TimeValue(value), \
130  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##OnTime, \
131  &SatTrafficHelperConf::GetTraffic##index##OnTime), \
132  MakeTimeChecker())
133 
134 #define SIM_ADD_TRAFFIC_MODEL_OFF_TIME_ATTRIBUTE(index, value) \
135  AddAttribute("Traffic" TOSTRING(index) "OffTime", \
136  "Off time value for Poisson traffic", \
137  TimeValue(value), \
138  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##OffTime, \
139  &SatTrafficHelperConf::GetTraffic##index##OffTime), \
140  MakeTimeChecker())
141 
142 #define SIM_ADD_TRAFFIC_MODEL_CODEC_ATTRIBUTE(index, value) \
143  AddAttribute("Traffic" TOSTRING(index) "Codec", \
144  "Codec used for VoIP traffic", \
145  EnumValue(value), \
146  MakeEnumAccessor<SatTrafficHelper::VoipCodec_t>( \
147  &SatTrafficHelperConf::SetTraffic##index##Codec, \
148  &SatTrafficHelperConf::GetTraffic##index##Codec), \
149  MakeEnumChecker(SatTrafficHelper::G_711_1, \
150  "G_711_1", \
151  SatTrafficHelper::G_711_2, \
152  "G_711_2", \
153  SatTrafficHelper::G_723_1, \
154  "G_723_1", \
155  SatTrafficHelper::G_729_2, \
156  "G_729_2", \
157  SatTrafficHelper::G_729_3, \
158  "G_729_3"))
159 
160 #define SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(index, value) \
161  AddAttribute("Traffic" TOSTRING(index) "StartTime", \
162  "Time into the simulation when this traffic model will be started on each user", \
163  TimeValue(value), \
164  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StartTime, \
165  &SatTrafficHelperConf::GetTraffic##index##StartTime), \
166  MakeTimeChecker())
167 
168 #define SIM_ADD_TRAFFIC_MODEL_STOP_TIME_ATTRIBUTE(index, value) \
169  AddAttribute("Traffic" TOSTRING(index) "StopTime", \
170  "Time into the simulation when this traffic model will be stopped " \
171  "on each user. 0 means endless traffic generation.", \
172  TimeValue(value), \
173  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StopTime, \
174  &SatTrafficHelperConf::GetTraffic##index##StopTime), \
175  MakeTimeChecker())
176 
177 #define SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(index, value) \
178  AddAttribute("Traffic" TOSTRING(index) "StartDelay", \
179  "Cummulative delay for each user before starting this traffic model", \
180  TimeValue(value), \
181  MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StartDelay, \
182  &SatTrafficHelperConf::GetTraffic##index##StartDelay), \
183  MakeTimeChecker())
184 
185 #define SIM_ADD_TRAFFIC_MODEL_PERCENTAGE_ATTRIBUTE(index, value) \
186  AddAttribute("Traffic" TOSTRING(index) "Percentage", \
187  "Percentage of final users that will use this traffic model", \
188  DoubleValue(value), \
189  MakeDoubleAccessor(&SatTrafficHelperConf::SetTraffic##index##Percentage, \
190  &SatTrafficHelperConf::GetTraffic##index##Percentage), \
191  MakeDoubleChecker<double>(0, 1))
192 
193 TypeId
195 {
196  static TypeId tid =
197  TypeId("ns3::SatTrafficHelperConf")
198  .SetParent<Object>()
199  .AddConstructor<SatTrafficHelperConf>()
200  .SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(LoraPeriodic, Seconds(1))
202  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(LoraPeriodic, Seconds(0.1))
203  .SIM_ADD_TRAFFIC_MODEL_STOP_TIME_ATTRIBUTE(LoraPeriodic, Seconds(0))
204  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(LoraPeriodic, MilliSeconds(10))
206 
207  .SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(LoraCbr, Seconds(1))
209  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(LoraCbr, Seconds(0.1))
210  .SIM_ADD_TRAFFIC_MODEL_STOP_TIME_ATTRIBUTE(LoraCbr, Seconds(0))
211  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(LoraCbr, MilliSeconds(10))
213 
214  .SIM_ADD_TRAFFIC_MODEL_PROTOCOL_ATTRIBUTE(Cbr, SatTrafficHelperConf::PROTOCOL_UDP)
215  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(Cbr, SatTrafficHelperConf::RTN_LINK)
216  .SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(Cbr, Seconds(1))
218  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Cbr, Seconds(0.1))
220  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(Cbr, MilliSeconds(10))
222 
223  .SIM_ADD_TRAFFIC_MODEL_PROTOCOL_ATTRIBUTE(OnOff, SatTrafficHelperConf::PROTOCOL_UDP)
224  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(OnOff, SatTrafficHelperConf::RTN_LINK)
225  .SIM_ADD_TRAFFIC_MODEL_DATA_RATE_ATTRIBUTE(OnOff, DataRate("500kb/s"))
227  .SIM_ADD_TRAFFIC_MODEL_ON_TIME_PATTERN_ATTRIBUTE(
228  OnOff,
229  "ns3::ConstantRandomVariable[Constant=1000]")
230  .SIM_ADD_TRAFFIC_MODEL_OFF_TIME_PATTERN_ATTRIBUTE(
231  OnOff,
232  "ns3::ConstantRandomVariable[Constant=0]")
233  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(OnOff, Seconds(0.1))
235  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(OnOff, MilliSeconds(10))
237 
238  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(Http, SatTrafficHelperConf::RTN_LINK)
239  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Http, Seconds(0.1))
241  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(Http, MilliSeconds(10))
243 
244  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(Nrtv, SatTrafficHelperConf::RTN_LINK)
245  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Nrtv, Seconds(0.1))
247  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(Nrtv, MilliSeconds(10))
249 
250  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(Poisson, SatTrafficHelperConf::RTN_LINK)
251  .SIM_ADD_TRAFFIC_MODEL_ON_TIME_ATTRIBUTE(Poisson, Seconds(1))
252  .SIM_ADD_TRAFFIC_MODEL_OFF_TIME_ATTRIBUTE(Poisson, MilliSeconds(100))
253  .SIM_ADD_TRAFFIC_MODEL_DATA_RATE_ATTRIBUTE(Poisson, DataRate("500kb/s"))
255  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Poisson, Seconds(0.1))
256  .SIM_ADD_TRAFFIC_MODEL_STOP_TIME_ATTRIBUTE(Poisson, Seconds(0))
257  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(Poisson, MilliSeconds(10))
259 
260  .SIM_ADD_TRAFFIC_MODEL_DIRECTION_ATTRIBUTE(Voip, SatTrafficHelperConf::RTN_LINK)
261  .SIM_ADD_TRAFFIC_MODEL_CODEC_ATTRIBUTE(Voip, SatTrafficHelper::VoipCodec_t::G_711_1)
262  .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Voip, Seconds(0.1))
264  .SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(Voip, MilliSeconds(10))
266 
267  return tid;
268 }
269 
270 TypeId
272 {
273  NS_LOG_FUNCTION(this);
274 
275  return GetTypeId();
276 }
277 
279  : m_simTime(Seconds(0)),
280  m_trafficHelper(nullptr)
281 {
282  NS_LOG_FUNCTION(this);
283 
284  NS_FATAL_ERROR("Default constructor not in use");
285 }
286 
287 SatTrafficHelperConf::SatTrafficHelperConf(Ptr<SatTrafficHelper> trafficHelper, Time simTime)
288  : m_simTime(simTime),
289  m_trafficHelper(trafficHelper)
290 {
291  NS_LOG_FUNCTION(this << simTime << trafficHelper);
292 }
293 
295 {
296  NS_LOG_FUNCTION(this);
297 }
298 
299 NS_OBJECT_ENSURE_REGISTERED(SatTrafficHelper);
300 
301 TypeId
303 {
304  static TypeId tid =
305  TypeId("ns3::SatTrafficHelper")
306  .SetParent<Object>()
307  .AddConstructor<SatTrafficHelper>()
308  .AddAttribute("EnableDefaultStatistics",
309  "Enable outputing values from stats helpers",
310  BooleanValue(true),
311  MakeBooleanAccessor(&SatTrafficHelper::m_enableDefaultStatistics),
312  MakeBooleanChecker());
313  return tid;
314 }
315 
316 TypeId
318 {
319  NS_LOG_FUNCTION(this);
320 
321  return GetTypeId();
322 }
323 
325  : m_satHelper(nullptr),
326  m_satStatsHelperContainer(nullptr)
327 {
328  NS_FATAL_ERROR("Default constructor of SatTrafficHelper cannot be used.");
329 }
330 
331 SatTrafficHelper::SatTrafficHelper(Ptr<SatHelper> satHelper,
332  Ptr<SatStatsHelperContainer> satStatsHelperContainer)
333  : m_satHelper(satHelper),
334  m_satStatsHelperContainer(satStatsHelperContainer),
335  m_enableDefaultStatistics(false)
336 {
338 }
339 
340 void
342  uint32_t packetSize,
343  NodeContainer uts,
344  Time startTime,
345  Time stopTime,
346  Time startDelay)
347 {
348  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay);
349 
350  if (uts.GetN() == 0)
351  {
352  NS_LOG_WARN("UT container is empty");
353  return;
354  }
355 
356  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory", Address());
357  CbrHelper cbrHelper("ns3::UdpSocketFactory", Address());
358  ApplicationContainer sinkContainer;
359  ApplicationContainer cbrContainer;
360 
361  Ptr<Node> node;
362 
363  // create Lora Periodic sender applications from UT users to GW users
364  for (uint32_t i = 0; i < uts.GetN(); i++)
365  {
366  node = uts.Get(i);
367  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
368 
369  app->SetInterval(interval);
370  NS_LOG_DEBUG("Created an application with interval = " << interval.GetHours() << " hours");
371 
372  app->SetStartTime(startTime + (i + 1) * startDelay);
373  app->SetStopTime(stopTime);
374  app->SetPacketSize(packetSize);
375 
376  app->SetNode(node);
377  node->AddApplication(app);
378  }
379 }
380 
381 void
383  uint32_t packetSize,
384  NodeContainer uts,
385  Time startTime,
386  Time stopTime,
387  Time startDelay,
388  double percentage)
389 {
390  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay
391  << percentage);
392 
393  // Filter UTs to keep only a given percentage on which installing the application
394  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
395  NodeContainer utsUpdated;
396  for (uint32_t i = 0; i < uts.GetN(); ++i)
397  {
398  if (rng->GetValue(0.0, 1.0) < percentage)
399  {
400  utsUpdated.Add(uts.Get(i));
401  }
402  }
403 
404  AddLoraPeriodicTraffic(interval, packetSize, utsUpdated, startTime, stopTime, startDelay);
405 }
406 
407 void
409  uint32_t packetSize,
410  NodeContainer gwUsers,
411  NodeContainer utUsers,
412  Time startTime,
413  Time stopTime,
414  Time startDelay)
415 {
416  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay);
417 
418  if (gwUsers.GetN() == 0)
419  {
420  NS_LOG_WARN("Gateway users container is empty");
421  return;
422  }
423  if (utUsers.GetN() == 0)
424  {
425  NS_LOG_WARN("UT users container is empty");
426  return;
427  }
428 
429  uint16_t port = 9;
430 
431  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory", Address());
432  CbrHelper cbrHelper("ns3::UdpSocketFactory", Address());
433  ApplicationContainer sinkContainer;
434  ApplicationContainer cbrContainer;
435 
436  // create CBR applications from UT users to GW users
437  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
438  {
439  for (uint32_t i = 0; i < utUsers.GetN(); i++)
440  {
441  InetSocketAddress gwUserAddr =
442  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
443  if (!HasSinkInstalled(gwUsers.Get(j), port))
444  {
445  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
446  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
447  }
448 
449  cbrHelper.SetConstantTraffic(interval, packetSize);
450  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
451  auto app = cbrHelper.Install(utUsers.Get(i)).Get(0);
452  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
453  cbrContainer.Add(app);
454  }
455  }
456 
457  sinkContainer.Start(startTime);
458  sinkContainer.Stop(stopTime);
459 }
460 
461 void
463  uint32_t packetSize,
464  NodeContainer gwUsers,
465  NodeContainer utUsers,
466  Time startTime,
467  Time stopTime,
468  Time startDelay,
469  double percentage)
470 {
471  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay
472  << percentage);
473 
474  // Filter UT users to keep only a given percentage on which installing the application
475  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
476  NodeContainer utUsersUpdated;
477  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
478  {
479  if (rng->GetValue(0.0, 1.0) < percentage)
480  {
481  utUsersUpdated.Add(utUsers.Get(i));
482  }
483  }
484 
485  AddLoraCbrTraffic(interval,
486  packetSize,
487  gwUsers,
488  utUsersUpdated,
489  startTime,
490  stopTime,
491  startDelay);
492 }
493 
494 void
496  TransportLayerProtocol_t protocol,
497  Time interval,
498  uint32_t packetSize,
499  NodeContainer gwUsers,
500  NodeContainer utUsers,
501  Time startTime,
502  Time stopTime,
503  Time startDelay)
504 {
505  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay);
506 
507  if (gwUsers.GetN() == 0)
508  {
509  NS_LOG_WARN("Gateway users container is empty");
510  return;
511  }
512  if (utUsers.GetN() == 0)
513  {
514  NS_LOG_WARN("UT users container is empty");
515  return;
516  }
517 
518  std::string socketFactory =
519  (protocol == SatTrafficHelper::TCP ? "ns3::TcpSocketFactory" : "ns3::UdpSocketFactory");
520  uint16_t port = 9;
521 
522  PacketSinkHelper sinkHelper(socketFactory, Address());
523  CbrHelper cbrHelper(socketFactory, Address());
524  ApplicationContainer sinkContainer;
525  ApplicationContainer cbrContainer;
526 
527  // create CBR applications from GWs to UT users
528  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
529  {
530  for (uint32_t i = 0; i < utUsers.GetN(); i++)
531  {
532  if (direction == RTN_LINK)
533  {
534  InetSocketAddress gwUserAddr =
535  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
536  if (!HasSinkInstalled(gwUsers.Get(j), port))
537  {
538  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
539  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
540  }
541 
542  cbrHelper.SetConstantTraffic(interval, packetSize);
543  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
544  auto app = cbrHelper.Install(utUsers.Get(i)).Get(0);
545  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
546  cbrContainer.Add(app);
547  }
548  else if (direction == FWD_LINK)
549  {
550  InetSocketAddress utUserAddr =
551  InetSocketAddress(m_satHelper->GetUserAddress(utUsers.Get(i)), port);
552  if (!HasSinkInstalled(utUsers.Get(i), port))
553  {
554  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
555  sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
556  }
557 
558  cbrHelper.SetConstantTraffic(interval, packetSize);
559  cbrHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
560  auto app = cbrHelper.Install(gwUsers.Get(j)).Get(0);
561  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
562  cbrContainer.Add(app);
563  }
564  }
565  }
566 
567  sinkContainer.Start(startTime);
568  sinkContainer.Stop(stopTime);
569 
571  {
572  // Add throuhgput statistics
573  if (direction == FWD_LINK)
574  {
575  // Global scalar
576  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
578  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
580  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
582 
583  // Global scatter
584  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
586  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
588  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
590 
591  // Per UT scalar
593  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
595  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
597 
598  // Per UT scatter
599  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
601  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
603  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
605 
606  // Per GW scalar
608  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
610  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
612 
613  // Per GW scatter
614  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
616  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
618  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
620  }
621  else if (direction == RTN_LINK)
622  {
623  // Global scalar
624  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
626  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
628  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
630 
631  // Global scatter
632  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
634  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
636  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
638 
639  // Per UT scalar
641  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
643  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
645 
646  // Per UT scatter
647  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
649  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
651  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
653 
654  // Per GW scalar
656  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
658  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
660 
661  // Per GW scatter
662  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
664  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
666  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
668  }
669  }
670 }
671 
672 void
674  TransportLayerProtocol_t protocol,
675  Time interval,
676  uint32_t packetSize,
677  NodeContainer gwUsers,
678  NodeContainer utUsers,
679  Time startTime,
680  Time stopTime,
681  Time startDelay,
682  double percentage)
683 {
684  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay
685  << percentage);
686 
687  // Filter UT users to keep only a given percentage on which installing the application
688  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
689  NodeContainer utUsersUpdated;
690  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
691  {
692  if (rng->GetValue(0.0, 1.0) < percentage)
693  {
694  utUsersUpdated.Add(utUsers.Get(i));
695  }
696  }
697 
698  AddCbrTraffic(direction,
699  protocol,
700  interval,
701  packetSize,
702  gwUsers,
703  utUsersUpdated,
704  startTime,
705  stopTime,
706  startDelay);
707 }
708 
709 void
711  TransportLayerProtocol_t protocol,
712  DataRate dataRate,
713  uint32_t packetSize,
714  NodeContainer gwUsers,
715  NodeContainer utUsers,
716  std::string onTimePattern,
717  std::string offTimePattern,
718  Time startTime,
719  Time stopTime,
720  Time startDelay)
721 {
722  NS_LOG_FUNCTION(this << dataRate << packetSize << onTimePattern << offTimePattern << startTime
723  << stopTime << startDelay);
724 
725  if (gwUsers.GetN() == 0)
726  {
727  NS_LOG_WARN("Gateway users container is empty");
728  return;
729  }
730  if (utUsers.GetN() == 0)
731  {
732  NS_LOG_WARN("UT users container is empty");
733  return;
734  }
735 
736  std::string socketFactory =
737  (protocol == SatTrafficHelper::TCP ? "ns3::TcpSocketFactory" : "ns3::UdpSocketFactory");
738  uint16_t port = 9;
739 
740  PacketSinkHelper sinkHelper(socketFactory, Address());
741  SatOnOffHelper onOffHelper(socketFactory, Address());
742  ApplicationContainer sinkContainer;
743  ApplicationContainer onOffContainer;
744 
745  onOffHelper.SetAttribute("OnTime", StringValue(onTimePattern));
746  onOffHelper.SetAttribute("OffTime", StringValue(offTimePattern));
747  onOffHelper.SetAttribute("DataRate", DataRateValue(dataRate));
748  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
749 
750  // create ONOFF applications from GWs to UT users
751  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
752  {
753  for (uint32_t i = 0; i < utUsers.GetN(); i++)
754  {
755  if (direction == RTN_LINK)
756  {
757  InetSocketAddress gwUserAddr =
758  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
759  if (!HasSinkInstalled(gwUsers.Get(j), port))
760  {
761  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
762  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
763  }
764 
765  onOffHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
766  auto app = onOffHelper.Install(utUsers.Get(i)).Get(0);
767  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
768  onOffContainer.Add(app);
769  }
770  else if (direction == FWD_LINK)
771  {
772  InetSocketAddress utUserAddr =
773  InetSocketAddress(m_satHelper->GetUserAddress(utUsers.Get(i)), port);
774  if (!HasSinkInstalled(utUsers.Get(i), port))
775  {
776  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
777  sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
778  }
779 
780  onOffHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
781  auto app = onOffHelper.Install(gwUsers.Get(j)).Get(0);
782  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
783  onOffContainer.Add(app);
784  }
785  }
786  }
787 
788  sinkContainer.Start(startTime);
789  sinkContainer.Stop(stopTime);
790 
792  {
793  // Add throuhgput statistics
794  if (direction == FWD_LINK)
795  {
796  // Global scalar
797  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
799  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
801  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
803 
804  // Global scatter
805  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
807  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
809  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
811 
812  // Per UT scalar
814  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
816  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
818 
819  // Per UT scatter
820  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
822  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
824  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
826 
827  // Per GW scalar
829  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
831  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
833 
834  // Per GW scatter
835  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
837  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
839  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
841  }
842  else if (direction == RTN_LINK)
843  {
844  // Global scalar
845  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
847  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
849  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
851 
852  // Global scatter
853  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
855  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
857  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
859 
860  // Per UT scalar
862  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
864  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
866 
867  // Per UT scatter
868  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
870  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
872  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
874 
875  // Per GW scalar
877  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
879  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
881 
882  // Per GW scatter
883  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
885  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
887  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
889  }
890  }
891 }
892 
893 void
895  TransportLayerProtocol_t protocol,
896  DataRate dataRate,
897  uint32_t packetSize,
898  NodeContainer gwUsers,
899  NodeContainer utUsers,
900  std::string onTimePattern,
901  std::string offTimePattern,
902  Time startTime,
903  Time stopTime,
904  Time startDelay,
905  double percentage)
906 {
907  NS_LOG_FUNCTION(this << dataRate << packetSize << onTimePattern << offTimePattern << startTime
908  << stopTime << startDelay << percentage);
909 
910  // Filter UT users to keep only a given percentage on which installing the application
911  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
912  NodeContainer utUsersUpdated;
913  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
914  {
915  if (rng->GetValue(0.0, 1.0) < percentage)
916  {
917  utUsersUpdated.Add(utUsers.Get(i));
918  }
919  }
920 
921  AddOnOffTraffic(direction,
922  protocol,
923  dataRate,
924  packetSize,
925  gwUsers,
926  utUsersUpdated,
927  onTimePattern,
928  offTimePattern,
929  startTime,
930  stopTime,
931  startDelay);
932 }
933 
934 void
936  NodeContainer gwUsers,
937  NodeContainer utUsers,
938  Time startTime,
939  Time stopTime,
940  Time startDelay)
941 {
942  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay);
943 
944  if (gwUsers.GetN() == 0)
945  {
946  NS_LOG_WARN("Gateway users container is empty");
947  return;
948  }
949  if (utUsers.GetN() == 0)
950  {
951  NS_LOG_WARN("UT users container is empty");
952  return;
953  }
954 
955  ThreeGppHttpHelper httpHelper;
956  if (direction == FWD_LINK)
957  {
958  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
959  {
960  auto app = httpHelper.InstallUsingIpv4(gwUsers.Get(j), utUsers).Get(1);
961  app->SetStartTime(startTime + (j + 1) * startDelay);
962  httpHelper.GetServer().Start(startTime);
963  httpHelper.GetServer().Stop(stopTime);
964  }
965  }
966  else if (direction == RTN_LINK)
967  {
968  for (uint32_t i = 0; i < utUsers.GetN(); i++)
969  {
970  auto app = httpHelper.InstallUsingIpv4(utUsers.Get(i), gwUsers).Get(1);
971  app->SetStartTime(startTime + (i + 1) * startDelay);
972  httpHelper.GetServer().Start(startTime);
973  httpHelper.GetServer().Stop(stopTime);
974  }
975  }
976 
978  {
979  // Add PLT statistics
980  if (direction == FWD_LINK)
981  {
988  }
989  else if (direction == RTN_LINK)
990  {
997  }
998 
999  // Add throuhgput statistics
1000  if (direction == FWD_LINK)
1001  {
1002  // Global scalar
1003  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1005  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1007  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1009 
1010  // Global scatter
1011  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1013  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1015  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1017 
1018  // Per UT scalar
1020  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1022  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1024 
1025  // Per UT scatter
1026  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
1028  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1030  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1032 
1033  // Per GW scalar
1035  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1037  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1039 
1040  // Per GW scatter
1041  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
1043  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1045  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1047  }
1048  else if (direction == RTN_LINK)
1049  {
1050  // Global scalar
1051  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1053  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1055  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1057 
1058  // Global scatter
1059  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1061  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1063  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1065 
1066  // Per UT scalar
1068  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1070  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1072 
1073  // Per UT scatter
1074  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
1076  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1078  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1080 
1081  // Per GW scalar
1083  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1085  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1087 
1088  // Per GW scatter
1089  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
1091  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1093  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1095  }
1096  }
1097 }
1098 
1099 void
1101  NodeContainer gwUsers,
1102  NodeContainer utUsers,
1103  Time startTime,
1104  Time stopTime,
1105  Time startDelay,
1106  double percentage)
1107 {
1108  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay << percentage);
1109 
1110  // Filter UT users to keep only a given percentage on which installing the application
1111  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1112  NodeContainer utUsersUpdated;
1113  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1114  {
1115  if (rng->GetValue(0.0, 1.0) < percentage)
1116  {
1117  utUsersUpdated.Add(utUsers.Get(i));
1118  }
1119  }
1120 
1121  AddHttpTraffic(direction, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1122 }
1123 
1124 void
1126  NodeContainer gwUsers,
1127  NodeContainer utUsers,
1128  Time startTime,
1129  Time stopTime,
1130  Time startDelay)
1131 {
1132  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay);
1133 
1134  if (gwUsers.GetN() == 0)
1135  {
1136  NS_LOG_WARN("Gateway users container is empty");
1137  return;
1138  }
1139  if (utUsers.GetN() == 0)
1140  {
1141  NS_LOG_WARN("UT users container is empty");
1142  return;
1143  }
1144 
1145  std::string socketFactory = "ns3::TcpSocketFactory";
1146 
1147  NrtvHelper nrtvHelper(TypeId::LookupByName(socketFactory));
1148  if (direction == FWD_LINK)
1149  {
1150  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1151  {
1152  auto app = nrtvHelper.InstallUsingIpv4(gwUsers.Get(j), utUsers).Get(1);
1153  app->SetStartTime(startTime + (j + 1) * startDelay);
1154  nrtvHelper.GetServer().Start(startTime);
1155  nrtvHelper.GetServer().Stop(stopTime);
1156  }
1157  }
1158  else if (direction == RTN_LINK)
1159  {
1160  for (uint32_t i = 0; i < utUsers.GetN(); i++)
1161  {
1162  auto app = nrtvHelper.InstallUsingIpv4(utUsers.Get(i), gwUsers).Get(1);
1163  app->SetStartTime(startTime + (i + 1) * startDelay);
1164  nrtvHelper.GetServer().Start(startTime);
1165  nrtvHelper.GetServer().Stop(stopTime);
1166  }
1167  }
1168 
1170  {
1171  // Add throuhgput statistics
1172  if (direction == FWD_LINK)
1173  {
1174  // Global scalar
1175  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1177  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1179  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1181 
1182  // Global scatter
1183  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1185  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1187  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1189 
1190  // Per UT scalar
1192  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1194  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1196 
1197  // Per UT scatter
1198  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
1200  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1202  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1204 
1205  // Per GW scalar
1207  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1209  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1211 
1212  // Per GW scatter
1213  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
1215  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1217  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1219  }
1220  else if (direction == RTN_LINK)
1221  {
1222  // Global scalar
1223  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1225  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1227  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1229 
1230  // Global scatter
1231  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1233  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1235  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1237 
1238  // Per UT scalar
1240  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1242  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1244 
1245  // Per UT scatter
1246  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
1248  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1250  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1252 
1253  // Per GW scalar
1255  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1257  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1259 
1260  // Per GW scatter
1261  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
1263  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1265  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1267  }
1268  }
1269 }
1270 
1271 void
1273  NodeContainer gwUsers,
1274  NodeContainer utUsers,
1275  Time startTime,
1276  Time stopTime,
1277  Time startDelay,
1278  double percentage)
1279 {
1280  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay << percentage);
1281 
1282  // Filter UT users to keep only a given percentage on which installing the application
1283  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1284  NodeContainer utUsersUpdated;
1285  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1286  {
1287  if (rng->GetValue(0.0, 1.0) < percentage)
1288  {
1289  utUsersUpdated.Add(utUsers.Get(i));
1290  }
1291  }
1292 
1293  AddNrtvTraffic(direction, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1294 }
1295 
1296 void
1298  Time onTime,
1299  Time offTimeExpMean,
1300  DataRate rate,
1301  uint32_t packetSize,
1302  NodeContainer gwUsers,
1303  NodeContainer utUsers,
1304  Time startTime,
1305  Time stopTime,
1306  Time startDelay)
1307 {
1308  NS_LOG_FUNCTION(this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
1309  << stopTime << startDelay);
1310 
1311  if (gwUsers.GetN() == 0)
1312  {
1313  NS_LOG_WARN("Gateway users container is empty");
1314  return;
1315  }
1316  if (utUsers.GetN() == 0)
1317  {
1318  NS_LOG_WARN("UT users container is empty");
1319  return;
1320  }
1321 
1322  std::string socketFactory = "ns3::UdpSocketFactory";
1323 
1324  uint16_t port = 9;
1325 
1326  PacketSinkHelper sinkHelper(socketFactory, Address());
1327  SatOnOffHelper onOffHelper(socketFactory, Address());
1328  ApplicationContainer sinkContainer;
1329  ApplicationContainer onOffContainer;
1330 
1331  // create CBR applications from GWs to UT users
1332  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1333  {
1334  for (uint32_t i = 0; i < utUsers.GetN(); i++)
1335  {
1336  if (direction == RTN_LINK)
1337  {
1338  InetSocketAddress gwUserAddr =
1339  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1340 
1341  if (!HasSinkInstalled(gwUsers.Get(j), port))
1342  {
1343  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
1344  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
1345  }
1346 
1347  onOffHelper.SetAttribute("OnTime",
1348  StringValue("ns3::ConstantRandomVariable[Constant=" +
1349  std::to_string(onTime.GetSeconds()) + "]"));
1350  onOffHelper.SetAttribute("OffTime",
1351  StringValue("ns3::ExponentialRandomVariable[Mean=" +
1352  std::to_string(offTimeExpMean.GetSeconds()) +
1353  "]"));
1354  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
1355  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
1356  onOffHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
1357 
1358  auto app = onOffHelper.Install(utUsers.Get(i)).Get(0);
1359  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1360  onOffContainer.Add(app);
1361  }
1362  else if (direction == FWD_LINK)
1363  {
1364  InetSocketAddress utUserAddr =
1365  InetSocketAddress(m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1366 
1367  if (!HasSinkInstalled(utUsers.Get(i), port))
1368  {
1369  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
1370  sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
1371  }
1372 
1373  onOffHelper.SetAttribute("OnTime",
1374  StringValue("ns3::ConstantRandomVariable[Constant=" +
1375  std::to_string(onTime.GetSeconds()) + "]"));
1376  onOffHelper.SetAttribute("OffTime",
1377  StringValue("ns3::ExponentialRandomVariable[Mean=" +
1378  std::to_string(offTimeExpMean.GetSeconds()) +
1379  "]"));
1380  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
1381  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
1382  onOffHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
1383 
1384  auto app = onOffHelper.Install(gwUsers.Get(j)).Get(0);
1385  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1386  onOffContainer.Add(app);
1387  }
1388  }
1389  }
1390  sinkContainer.Start(startTime);
1391  sinkContainer.Stop(stopTime);
1392 
1394  {
1395  // Add throuhgput statistics
1396  if (direction == FWD_LINK)
1397  {
1398  // Global scalar
1399  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1401  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1403  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1405 
1406  // Global scatter
1407  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1409  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1411  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1413 
1414  // Per UT scalar
1416  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1418  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1420 
1421  // Per UT scatter
1422  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
1424  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1426  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1428 
1429  // Per GW scalar
1431  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1433  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1435 
1436  // Per GW scatter
1437  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
1439  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1441  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1443  }
1444  else if (direction == RTN_LINK)
1445  {
1446  // Global scalar
1447  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1449  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1451  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1453 
1454  // Global scatter
1455  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1457  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1459  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1461 
1462  // Per UT scalar
1464  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1466  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1468 
1469  // Per UT scatter
1470  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
1472  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1474  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1476 
1477  // Per GW scalar
1479  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1481  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1483 
1484  // Per GW scatter
1485  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
1487  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1489  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1491  }
1492  }
1493 }
1494 
1495 void
1497  Time onTime,
1498  Time offTimeExpMean,
1499  DataRate rate,
1500  uint32_t packetSize,
1501  NodeContainer gwUsers,
1502  NodeContainer utUsers,
1503  Time startTime,
1504  Time stopTime,
1505  Time startDelay,
1506  double percentage)
1507 {
1508  NS_LOG_FUNCTION(this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
1509  << stopTime << startDelay << percentage);
1510 
1511  // Filter UT users to keep only a given percentage on which installing the application
1512  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1513  NodeContainer utUsersUpdated;
1514  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1515  {
1516  if (rng->GetValue(0.0, 1.0) < percentage)
1517  {
1518  utUsersUpdated.Add(utUsers.Get(i));
1519  }
1520  }
1521 
1522  AddPoissonTraffic(direction,
1523  onTime,
1524  offTimeExpMean,
1525  rate,
1526  packetSize,
1527  gwUsers,
1528  utUsersUpdated,
1529  startTime,
1530  stopTime,
1531  startDelay);
1532 }
1533 
1534 void
1536  VoipCodec_t codec,
1537  NodeContainer gwUsers,
1538  NodeContainer utUsers,
1539  Time startTime,
1540  Time stopTime,
1541  Time startDelay)
1542 {
1543  NS_LOG_FUNCTION(this << direction << codec << startTime << stopTime << startDelay);
1544 
1545  if (gwUsers.GetN() == 0)
1546  {
1547  NS_LOG_WARN("Gateway users container is empty");
1548  return;
1549  }
1550  if (utUsers.GetN() == 0)
1551  {
1552  NS_LOG_WARN("UT users container is empty");
1553  return;
1554  }
1555 
1556  std::string socketFactory = "ns3::UdpSocketFactory";
1557  uint16_t port = 9;
1558 
1559  double onTime;
1560  double offTime;
1561  std::string rate;
1562  uint32_t packetSize;
1563 
1564  switch (codec)
1565  {
1566  case G_711_1:
1567  onTime = 0.5;
1568  offTime = 0.05;
1569  rate = "70kbps"; // 64kbps globally
1570  packetSize = 80;
1571  break;
1572  case G_711_2:
1573  onTime = 0.5;
1574  offTime = 0.05;
1575  rate = "70kbps"; // 64kbps globally
1576  packetSize = 160;
1577  break;
1578  case G_723_1:
1579  onTime = 0.5;
1580  offTime = 0.05;
1581  rate = "6864bps"; // 6240bps globally
1582  packetSize = 30;
1583  break;
1584  case G_729_2:
1585  onTime = 0.5;
1586  offTime = 0.05;
1587  rate = "8800bps"; // 8kbps globally
1588  packetSize = 20;
1589  break;
1590  case G_729_3:
1591  onTime = 0.5;
1592  offTime = 0.05;
1593  rate = "7920bps"; // 7200bps globally
1594  packetSize = 30;
1595  break;
1596  default:
1597  NS_FATAL_ERROR("VoIP codec does not exist or is not implemented");
1598  }
1599 
1600  PacketSinkHelper sinkHelper(socketFactory, Address());
1601  SatOnOffHelper onOffHelper(socketFactory, Address());
1602  ApplicationContainer sinkContainer;
1603  ApplicationContainer onOffContainer;
1604 
1605  // create CBR applications from GWs to UT users
1606  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1607  {
1608  for (uint32_t i = 0; i < utUsers.GetN(); i++)
1609  {
1610  if (direction == RTN_LINK)
1611  {
1612  InetSocketAddress gwUserAddr =
1613  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1614 
1615  if (!HasSinkInstalled(gwUsers.Get(j), port))
1616  {
1617  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
1618  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
1619  }
1620 
1621  onOffHelper.SetAttribute("OnTime",
1622  StringValue("ns3::ConstantRandomVariable[Constant=" +
1623  std::to_string(onTime) + "]"));
1624  onOffHelper.SetAttribute("OffTime",
1625  StringValue("ns3::ConstantRandomVariable[Constant=" +
1626  std::to_string(offTime) + "]"));
1627  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
1628  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
1629  onOffHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
1630 
1631  auto app = onOffHelper.Install(utUsers.Get(i)).Get(0);
1632  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1633  onOffContainer.Add(app);
1634  }
1635  else if (direction == FWD_LINK)
1636  {
1637  InetSocketAddress utUserAddr =
1638  InetSocketAddress(m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1639 
1640  if (!HasSinkInstalled(utUsers.Get(i), port))
1641  {
1642  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
1643  sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
1644  }
1645 
1646  onOffHelper.SetAttribute("OnTime",
1647  StringValue("ns3::ConstantRandomVariable[Constant=" +
1648  std::to_string(onTime) + "]"));
1649  onOffHelper.SetAttribute("OffTime",
1650  StringValue("ns3::ConstantRandomVariable[Constant=" +
1651  std::to_string(offTime) + "]"));
1652  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
1653  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
1654  onOffHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
1655 
1656  auto app = onOffHelper.Install(gwUsers.Get(j)).Get(0);
1657  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1658  onOffContainer.Add(app);
1659  }
1660  }
1661  }
1662  sinkContainer.Start(startTime);
1663  sinkContainer.Stop(stopTime);
1664 
1666  {
1667  // Add jitter statistics
1668  if (direction == FWD_LINK)
1669  {
1670  // Global
1673 
1674  // Per UT
1677 
1678  // Per GW
1681  }
1682  else if (direction == RTN_LINK)
1683  {
1684  // Global
1687 
1688  // Per UT
1691 
1692  // Per GW
1695  }
1696 
1697  // Add throuhgput statistics
1698  if (direction == FWD_LINK)
1699  {
1700  // Global scalar
1701  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1703  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1705  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1707 
1708  // Global scatter
1709  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1711  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1713  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1715 
1716  // Per UT scalar
1718  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1720  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1722 
1723  // Per UT scatter
1724  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
1726  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1728  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1730 
1731  // Per GW scalar
1733  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1735  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1737 
1738  // Per GW scatter
1739  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
1741  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1743  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1745  }
1746  else if (direction == RTN_LINK)
1747  {
1748  // Global scalar
1749  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1751  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1753  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1755 
1756  // Global scatter
1757  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1759  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1761  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1763 
1764  // Per UT scalar
1766  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1768  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1770 
1771  // Per UT scatter
1772  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
1774  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1776  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1778 
1779  // Per GW scalar
1781  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1783  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1785 
1786  // Per GW scatter
1787  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
1789  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1791  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1793  }
1794  }
1795 }
1796 
1797 void
1799  VoipCodec_t codec,
1800  NodeContainer gwUsers,
1801  NodeContainer utUsers,
1802  Time startTime,
1803  Time stopTime,
1804  Time startDelay,
1805  double percentage)
1806 {
1807  NS_LOG_FUNCTION(this << direction << codec << startTime << stopTime << startDelay
1808  << percentage);
1809 
1810  // Filter UT users to keep only a given percentage on which installing the application
1811  Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1812  NodeContainer utUsersUpdated;
1813  for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1814  {
1815  if (rng->GetValue(0.0, 1.0) < percentage)
1816  {
1817  utUsersUpdated.Add(utUsers.Get(i));
1818  }
1819  }
1820 
1821  AddVoipTraffic(direction, codec, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1822 }
1823 
1824 void
1826  std::string interval,
1827  uint32_t packetSize,
1828  NodeContainer gwUsers,
1829  NodeContainer utUsers,
1830  Time startTime,
1831  Time stopTime,
1832  Time startDelay)
1833 {
1834  NS_LOG_FUNCTION(this << direction << interval << packetSize << startTime << stopTime
1835  << startDelay);
1836 
1837  if (gwUsers.GetN() == 0)
1838  {
1839  NS_LOG_WARN("Gateway users container is empty");
1840  return;
1841  }
1842  if (utUsers.GetN() == 0)
1843  {
1844  NS_LOG_WARN("UT users container is empty");
1845  return;
1846  }
1847 
1848  std::string socketFactory = "ns3::UdpSocketFactory";
1849  uint16_t port = 9;
1850 
1851  PacketSinkHelper sinkHelper(socketFactory, Address());
1852 
1853  ObjectFactory factory;
1854  factory.SetTypeId("ns3::CbrApplication");
1855  factory.Set("Protocol", StringValue(socketFactory));
1856  ApplicationContainer sinkContainer;
1857  ApplicationContainer cbrContainer;
1858 
1859  // create CBR applications from GWs to UT users
1860  for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1861  {
1862  for (uint32_t i = 0; i < utUsers.GetN(); i++)
1863  {
1864  if (direction == RTN_LINK)
1865  {
1866  InetSocketAddress gwUserAddr =
1867  InetSocketAddress(m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1868  if (!HasSinkInstalled(gwUsers.Get(j), port))
1869  {
1870  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
1871  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
1872  }
1873 
1874  factory.Set("Interval", TimeValue(Time(interval)));
1875  factory.Set("PacketSize", UintegerValue(packetSize));
1876  factory.Set("Remote", AddressValue(Address(gwUserAddr)));
1877  Ptr<CbrApplication> p_app = factory.Create<CbrApplication>();
1878  utUsers.Get(i)->AddApplication(p_app);
1879  auto app = ApplicationContainer(p_app).Get(0);
1880  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1881  cbrContainer.Add(app);
1882  }
1883  else if (direction == FWD_LINK)
1884  {
1885  InetSocketAddress utUserAddr =
1886  InetSocketAddress(m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1887  if (!HasSinkInstalled(utUsers.Get(i), port))
1888  {
1889  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
1890  sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
1891  }
1892 
1893  factory.Set("Interval", TimeValue(Time(interval)));
1894  factory.Set("PacketSize", UintegerValue(packetSize));
1895  factory.Set("Remote", AddressValue(Address(utUserAddr)));
1896  Ptr<CbrApplication> p_app = factory.Create<CbrApplication>();
1897  gwUsers.Get(j)->AddApplication(p_app);
1898  auto app = ApplicationContainer(p_app).Get(0);
1899  app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1900  cbrContainer.Add(app);
1901  }
1902  }
1903  }
1904 
1905  sinkContainer.Start(startTime);
1906  sinkContainer.Stop(stopTime);
1907 
1908  m_last_custom_application.application = cbrContainer;
1909  m_last_custom_application.start = startTime;
1910  m_last_custom_application.stop = stopTime;
1912 
1914  {
1915  // Add throuhgput statistics
1916  if (direction == FWD_LINK)
1917  {
1918  // Global scalar
1919  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1921  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1923  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1925 
1926  // Global scatter
1927  m_satStatsHelperContainer->AddGlobalFwdAppThroughput(
1929  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1931  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1933 
1934  // Per UT scalar
1936  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1938  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1940 
1941  // Per UT scatter
1942  m_satStatsHelperContainer->AddPerUtFwdAppThroughput(
1944  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1946  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1948 
1949  // Per GW scalar
1951  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1953  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1955 
1956  // Per GW scatter
1957  m_satStatsHelperContainer->AddPerGwFwdAppThroughput(
1959  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1961  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1963  }
1964  else if (direction == RTN_LINK)
1965  {
1966  // Global scalar
1967  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1969  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1971  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1973 
1974  // Global scatter
1975  m_satStatsHelperContainer->AddGlobalRtnAppThroughput(
1977  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1979  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1981 
1982  // Per UT scalar
1984  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1986  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1988 
1989  // Per UT scatter
1990  m_satStatsHelperContainer->AddPerUtRtnAppThroughput(
1992  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1994  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1996 
1997  // Per GW scalar
1999  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
2001  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
2003 
2004  // Per GW scatter
2005  m_satStatsHelperContainer->AddPerGwRtnAppThroughput(
2007  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
2009  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
2011  }
2012  }
2013 }
2014 
2015 void
2016 SatTrafficHelper::ChangeCustomTraffic(Time delay, std::string interval, uint32_t packetSize)
2017 {
2018  NS_LOG_FUNCTION(this << delay << interval << packetSize);
2019 
2021  {
2022  NS_FATAL_ERROR("No custom traffic created when calling the method "
2023  "SatTrafficHelper::ChangeCustomTraffic for the first time.");
2024  }
2026  {
2027  NS_FATAL_ERROR("Custom traffic updated after its stop time.");
2028  }
2029  for (auto i = m_last_custom_application.application.Begin();
2031  ++i)
2032  {
2033  Ptr<CbrApplication> app = (dynamic_cast<CbrApplication*>(PeekPointer(*i)));
2034  Simulator::Schedule(m_last_custom_application.start + delay,
2036  this,
2037  app,
2038  interval,
2039  packetSize);
2040  }
2041 }
2042 
2043 void
2044 SatTrafficHelper::UpdateAttribute(Ptr<CbrApplication> application,
2045  std::string interval,
2046  uint32_t packetSize)
2047 {
2048  NS_LOG_FUNCTION(this << application << interval << packetSize);
2049 
2050  application->SetInterval(Time(interval));
2051  application->SetPacketSize(packetSize);
2052 }
2053 
2054 bool
2055 SatTrafficHelper::HasSinkInstalled(Ptr<Node> node, uint16_t port)
2056 {
2057  NS_LOG_FUNCTION(this << node->GetId() << port);
2058 
2059  for (uint32_t i = 0; i < node->GetNApplications(); i++)
2060  {
2061  auto sink = DynamicCast<PacketSink>(node->GetApplication(i));
2062  if (sink != nullptr)
2063  {
2064  AddressValue av;
2065  sink->GetAttribute("Local", av);
2066  if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
2067  {
2068  return true;
2069  }
2070  }
2071  }
2072  return false;
2073 }
2074 
2075 void
2077 {
2078  NS_LOG_FUNCTION(this);
2079 
2080  NS_ASSERT_MSG(m_trafficHelper != nullptr, "Traffic helper must be defined");
2081 
2082  for (const std::pair<const std::string, SatTrafficHelperConf::TrafficConfiguration_t>&
2083  trafficModel : m_trafficModel)
2084  {
2086  if (trafficModel.first == "LoraCbr")
2087  {
2088  modelName = SatTrafficHelper::LORA_PERIODIC;
2089  }
2090  else if (trafficModel.first == "LoraPeriodic")
2091  {
2092  modelName = SatTrafficHelper::LORA_CBR;
2093  }
2094  else if (trafficModel.first == "Cbr")
2095  {
2096  modelName = SatTrafficHelper::CBR;
2097  }
2098  else if (trafficModel.first == "OnOff")
2099  {
2100  modelName = SatTrafficHelper::ONOFF;
2101  }
2102  else if (trafficModel.first == "Http")
2103  {
2104  modelName = SatTrafficHelper::HTTP;
2105  }
2106  else if (trafficModel.first == "Nrtv")
2107  {
2108  modelName = SatTrafficHelper::NRTV;
2109  }
2110  else if (trafficModel.first == "Poisson")
2111  {
2112  modelName = SatTrafficHelper::POISSON;
2113  }
2114  else if (trafficModel.first == "Voip")
2115  {
2116  modelName = SatTrafficHelper::VOIP;
2117  }
2118  else
2119  {
2120  NS_FATAL_ERROR("Unknown traffic model has been configured: " << trafficModel.first);
2121  }
2122 
2123  std::vector<SatTrafficHelper::TransportLayerProtocol_t> protocols;
2124  switch (trafficModel.second.m_protocol)
2125  {
2127  protocols.push_back(SatTrafficHelper::UDP);
2128  break;
2129  }
2131  protocols.push_back(SatTrafficHelper::TCP);
2132  break;
2133  }
2135  protocols.push_back(SatTrafficHelper::TCP);
2136  protocols.push_back(SatTrafficHelper::UDP);
2137  break;
2138  }
2139  default: {
2140  NS_FATAL_ERROR("Unknown traffic protocol");
2141  }
2142  }
2143 
2144  std::vector<SatTrafficHelper::TrafficDirection_t> directions;
2145  switch (trafficModel.second.m_direction)
2146  {
2148  directions.push_back(SatTrafficHelper::RTN_LINK);
2149  break;
2150  }
2152  directions.push_back(SatTrafficHelper::FWD_LINK);
2153  break;
2154  }
2156  directions.push_back(SatTrafficHelper::FWD_LINK);
2157  directions.push_back(SatTrafficHelper::RTN_LINK);
2158  break;
2159  }
2160  default: {
2161  NS_FATAL_ERROR("Unknown traffic protocol");
2162  }
2163  }
2164 
2165  if (trafficModel.second.m_percentage > 0.0)
2166  {
2167  SatTrafficHelperConf::TrafficConfiguration_t conf = trafficModel.second;
2168  Time startTime = conf.m_startTime;
2169  if (startTime > m_simTime)
2170  {
2171  NS_FATAL_ERROR("Traffic model "
2172  << trafficModel.first
2173  << " configured to start after the simulation ended");
2174  }
2175 
2176  Time stopTime = conf.m_stopTime;
2177  if (stopTime == Seconds(0))
2178  {
2179  stopTime = m_simTime + Seconds(1);
2180  }
2181  if (stopTime < startTime)
2182  {
2183  NS_FATAL_ERROR("Traffic model " << trafficModel.first
2184  << " configured to stop before it is started");
2185  }
2186 
2187  NodeContainer gws = Singleton<SatTopology>::Get()->GetGwUserNodes();
2188  NodeContainer uts;
2189  if (modelName == SatTrafficHelper::LORA_PERIODIC)
2190  {
2191  uts = Singleton<SatTopology>::Get()->GetUtNodes();
2192  }
2193  else
2194  {
2195  uts = Singleton<SatTopology>::Get()->GetUtUserNodes();
2196  }
2197 
2198  for (SatTrafficHelper::TransportLayerProtocol_t& protocol : protocols)
2199  {
2200  for (SatTrafficHelper::TrafficDirection_t& direction : directions)
2201  {
2202  switch (modelName)
2203  {
2205  m_trafficHelper->AddLoraPeriodicTraffic(conf.m_interval,
2206  conf.m_packetSize,
2207  uts,
2208  startTime,
2209  stopTime,
2210  conf.m_startDelay,
2211  conf.m_percentage);
2212  break;
2213  }
2215  m_trafficHelper->AddLoraCbrTraffic(conf.m_interval,
2216  conf.m_packetSize,
2217  gws,
2218  uts,
2219  startTime,
2220  stopTime,
2221  conf.m_startDelay,
2222  conf.m_percentage);
2223  break;
2224  }
2225  case SatTrafficHelper::CBR: {
2226  m_trafficHelper->AddCbrTraffic(direction,
2227  protocol,
2228  conf.m_interval,
2229  conf.m_packetSize,
2230  gws,
2231  uts,
2232  startTime,
2233  stopTime,
2234  conf.m_startDelay,
2235  conf.m_percentage);
2236  break;
2237  }
2238  case SatTrafficHelper::ONOFF: {
2239  m_trafficHelper->AddOnOffTraffic(direction,
2240  protocol,
2241  conf.m_dataRate,
2242  conf.m_packetSize,
2243  gws,
2244  uts,
2245  conf.m_onTimePattern,
2246  conf.m_offTimePattern,
2247  startTime,
2248  stopTime,
2249  conf.m_startDelay,
2250  conf.m_percentage);
2251  break;
2252  }
2253  case SatTrafficHelper::HTTP: {
2254  m_trafficHelper->AddHttpTraffic(direction,
2255  gws,
2256  uts,
2257  startTime,
2258  stopTime,
2259  conf.m_startDelay,
2260  conf.m_percentage);
2261  break;
2262  }
2263  case SatTrafficHelper::NRTV: {
2264  m_trafficHelper->AddNrtvTraffic(direction,
2265  gws,
2266  uts,
2267  startTime,
2268  stopTime,
2269  conf.m_startDelay,
2270  conf.m_percentage);
2271  break;
2272  }
2274  m_trafficHelper->AddPoissonTraffic(direction,
2275  conf.m_onTime,
2276  conf.m_offTime,
2277  conf.m_dataRate,
2278  conf.m_packetSize,
2279  gws,
2280  uts,
2281  startTime,
2282  stopTime,
2283  conf.m_startDelay,
2284  conf.m_percentage);
2285  break;
2286  }
2287  case SatTrafficHelper::VOIP: {
2288  m_trafficHelper->AddVoipTraffic(direction,
2289  conf.m_codec,
2290  gws,
2291  uts,
2292  startTime,
2293  stopTime,
2294  conf.m_startDelay,
2295  conf.m_percentage);
2296  break;
2297  }
2298  default:
2299  NS_FATAL_ERROR("Unknown traffic model has been configured: " << modelName);
2300  }
2301  }
2302  }
2303  }
2304  }
2305 }
2306 
2307 } // namespace ns3
A helper to make it easier to instantiate an ns3::SatOnOffApplication on a set of nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::SatOnOffApplication on each node of the input container configured with all the attri...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
virtual ~SatTrafficHelperConf()
Destructor.
SatTrafficHelperConf()
Default constructor.
TypeId GetInstanceTypeId(void) const
Derived from Object.
void InstallTrafficModels()
Install traffic models from configuration files.
static TypeId GetTypeId(void)
Derived from Object.
Ptr< SatTrafficHelper > m_trafficHelper
std::map< std::string, TrafficConfiguration_t > m_trafficModel
Creates pre-defined trafics.
void AddNrtvTraffic(TrafficDirection_t direction, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new TCP/NRTV traffic between chosen GWs and UTs.
void AddCustomTraffic(TrafficDirection_t direction, std::string interval, uint32_t packetSize, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new CBR traffic between chosen GWs and UTs that can be customized.
SatTrafficHelper()
Default constructor.
void ChangeCustomTraffic(Time delay, std::string interval, uint32_t packetSize)
Change the parameters of the last custom traffic created.
CustomTrafficInfo_s m_last_custom_application
void AddCbrTraffic(TrafficDirection_t direction, TransportLayerProtocol_t protocol, Time interval, uint32_t packetSize, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new CBR traffic between chosen GWs and UTs.
bool HasSinkInstalled(Ptr< Node > node, uint16_t port)
Check if node has a PacketSink installed at certain port.
void AddOnOffTraffic(TrafficDirection_t direction, TransportLayerProtocol_t protocol, DataRate dataRate, uint32_t packetSize, NodeContainer gwUsers, NodeContainer utUsers, std::string onTimePattern, std::string offTimePattern, Time startTime, Time stopTime, Time startDelay)
Add a new ONOFF traffic between chosen GWs and UTs.
static TypeId GetTypeId(void)
Get the type ID.
void AddPoissonTraffic(TrafficDirection_t direction, Time onTime, Time offTimeExpMean, DataRate rate, uint32_t packetSize, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new Poisson traffic between chosen GWs and UTs.
void AddVoipTraffic(TrafficDirection_t direction, VoipCodec_t codec, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new Poisson traffic between chosen GWs and UTs.
TypeId GetInstanceTypeId(void) const
Get the type ID of object instance.
TrafficType_t
List of available traffics.
Ptr< SatStatsHelperContainer > m_satStatsHelperContainer
void AddHttpTraffic(TrafficDirection_t direction, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add a new TCP/HTTP traffic between chosen GWs and UTs.
void AddLoraPeriodicTraffic(Time interval, uint32_t packetSize, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add Lora periodic traffic between chosen GWs and UTs.
void UpdateAttribute(Ptr< CbrApplication > application, std::string interval, uint32_t packetSize)
Update the chosen attribute of a custom traffic.
void AddLoraCbrTraffic(Time interval, uint32_t packetSize, NodeContainer gwUsers, NodeContainer utUsers, Time startTime, Time stopTime, Time startDelay)
Add Lora CBR traffic between chosen GWs and UTs.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
#define SIM_ADD_TRAFFIC_MODEL_PERCENTAGE_ATTRIBUTE(index, value)
#define SIM_ADD_TRAFFIC_MODEL_PACKET_SIZE_ATTRIBUTE(index, value)
#define SIM_ADD_TRAFFIC_MODEL_START_DELAY_ATTRIBUTE(index, value)
#define SIM_ADD_TRAFFIC_MODEL_STOP_TIME_ATTRIBUTE(index, value)
#define SIM_ADD_TRAFFIC_MODEL_OFF_TIME_ATTRIBUTE(index, value)
#define SIM_ADD_TRAFFIC_MODEL_DATA_RATE_ATTRIBUTE(index, value)