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 
24 #include <ns3/cbr-helper.h>
25 #include <ns3/log.h>
26 #include <ns3/nrtv-helper.h>
27 #include <ns3/packet-sink-helper.h>
28 #include <ns3/packet-sink.h>
29 #include <ns3/satellite-on-off-helper.h>
30 #include <ns3/simulation-helper.h>
31 #include <ns3/three-gpp-http-satellite-helper.h>
32 #include <ns3/type-id.h>
33 
34 NS_LOG_COMPONENT_DEFINE("SatelliteTrafficHelper");
35 
36 namespace ns3
37 {
38 
39 NS_OBJECT_ENSURE_REGISTERED(SatTrafficHelper);
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::SatTrafficHelper").SetParent<Object>().AddConstructor<SatTrafficHelper>();
46  return tid;
47 }
48 
49 TypeId
51 {
52  NS_LOG_FUNCTION(this);
53 
54  return GetTypeId();
55 }
56 
58  : m_satHelper(NULL),
59  m_satStatsHelperContainer(NULL)
60 {
61  NS_FATAL_ERROR("Default constructor of SatTrafficHelper cannot be used.");
62 }
63 
64 SatTrafficHelper::SatTrafficHelper(Ptr<SatHelper> satHelper,
65  Ptr<SatStatsHelperContainer> satStatsHelperContainer)
66  : m_satHelper(satHelper),
67  m_satStatsHelperContainer(satStatsHelperContainer)
68 {
70 }
71 
72 void
74  std::string interval,
75  uint32_t packetSize,
76  NodeContainer gws,
77  NodeContainer uts,
78  Time startTime,
79  Time stopTime,
80  Time startDelay)
81 {
82  NS_LOG_FUNCTION(this << interval << packetSize << startTime << stopTime << startDelay);
83 
84  if (gws.GetN() == 0)
85  {
86  NS_LOG_WARN("Gateway container is empty");
87  return;
88  }
89  if (uts.GetN() == 0)
90  {
91  NS_LOG_WARN("UT container is empty");
92  return;
93  }
94 
95  std::string socketFactory = "ns3::UdpSocketFactory";
96  uint16_t port = 9;
97 
98  PacketSinkHelper sinkHelper(socketFactory, Address());
99  CbrHelper cbrHelper(socketFactory, Address());
100  ApplicationContainer sinkContainer;
101  ApplicationContainer cbrContainer;
102 
103  // create CBR applications from GWs to UT users
104  for (uint32_t j = 0; j < gws.GetN(); j++)
105  {
106  for (uint32_t i = 0; i < uts.GetN(); i++)
107  {
108  if (direction == RTN_LINK)
109  {
110  InetSocketAddress gwUserAddr =
111  InetSocketAddress(m_satHelper->GetUserAddress(gws.Get(j)), port);
112  if (!HasSinkInstalled(gws.Get(j), port))
113  {
114  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
115  sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
116  }
117 
118  cbrHelper.SetConstantTraffic(Time(interval), packetSize);
119  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
120  auto app = cbrHelper.Install(uts.Get(i)).Get(0);
121  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
122  cbrContainer.Add(app);
123  }
124  else if (direction == FWD_LINK)
125  {
126  InetSocketAddress utUserAddr =
127  InetSocketAddress(m_satHelper->GetUserAddress(uts.Get(i)), port);
128  if (!HasSinkInstalled(uts.Get(i), port))
129  {
130  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
131  sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
132  }
133 
134  cbrHelper.SetConstantTraffic(Time(interval), packetSize);
135  cbrHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
136  auto app = cbrHelper.Install(gws.Get(j)).Get(0);
137  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
138  cbrContainer.Add(app);
139  }
140  }
141  }
142 
143  sinkContainer.Start(startTime);
144  sinkContainer.Stop(stopTime);
145 
146  // Add throuhgput statistics
147  if (direction == FWD_LINK)
148  {
149  // Global scalar
151  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
153  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
155 
156  // Global scatter
158  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
160  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
162 
163  // Per UT scalar
165  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
167  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
168 
169  // Per UT scatter
171  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
173  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
175 
176  // Per GW scalar
178  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
180  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
181 
182  // Per GW scatter
184  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
186  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
188  }
189  else if (direction == RTN_LINK)
190  {
191  // Global scalar
193  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
195  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
197 
198  // Global scatter
200  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
202  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
204 
205  // Per UT scalar
207  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
209  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
210 
211  // Per UT scatter
213  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
215  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
217 
218  // Per GW scalar
220  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
222  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
223 
224  // Per GW scatter
226  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
228  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
230  }
231 }
232 
233 void
235  NodeContainer gws,
236  NodeContainer uts,
237  Time startTime,
238  Time stopTime,
239  Time startDelay)
240 {
241  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay);
242 
243  if (gws.GetN() == 0)
244  {
245  NS_LOG_WARN("Gateway container is empty");
246  return;
247  }
248  if (uts.GetN() == 0)
249  {
250  NS_LOG_WARN("UT container is empty");
251  return;
252  }
253 
254  ThreeGppHttpHelper httpHelper;
255  if (direction == FWD_LINK)
256  {
257  for (uint32_t j = 0; j < gws.GetN(); j++)
258  {
259  auto app = httpHelper.InstallUsingIpv4(gws.Get(j), uts).Get(1);
260  app->SetStartTime(startTime + (j + 1) * startDelay);
261  httpHelper.GetServer().Start(startTime);
262  httpHelper.GetServer().Stop(stopTime);
263  }
264  }
265  else if (direction == RTN_LINK)
266  {
267  for (uint32_t i = 0; i < uts.GetN(); i++)
268  {
269  auto app = httpHelper.InstallUsingIpv4(uts.Get(i), gws).Get(1);
270  app->SetStartTime(startTime + (i + 1) * startDelay);
271  httpHelper.GetServer().Start(startTime);
272  httpHelper.GetServer().Stop(stopTime);
273  }
274  }
275 
276  // Add PLT statistics
277  if (direction == FWD_LINK)
278  {
285  }
286  else if (direction == RTN_LINK)
287  {
294  }
295 
296  // Add throuhgput statistics
297  if (direction == FWD_LINK)
298  {
299  // Global scalar
301  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
303  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
305 
306  // Global scatter
308  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
310  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
312 
313  // Per UT scalar
315  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
317  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
318 
319  // Per UT scatter
321  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
323  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
325 
326  // Per GW scalar
328  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
330  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
331 
332  // Per GW scatter
334  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
336  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
338  }
339  else if (direction == RTN_LINK)
340  {
341  // Global scalar
343  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
345  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
347 
348  // Global scatter
350  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
352  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
354 
355  // Per UT scalar
357  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
359  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
360 
361  // Per UT scatter
363  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
365  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
367 
368  // Per GW scalar
370  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
372  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
373 
374  // Per GW scatter
376  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
378  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
380  }
381 }
382 
383 void
385  NodeContainer gws,
386  NodeContainer uts,
387  Time startTime,
388  Time stopTime,
389  Time startDelay)
390 {
391  NS_LOG_FUNCTION(this << direction << startTime << stopTime << startDelay);
392 
393  if (gws.GetN() == 0)
394  {
395  NS_LOG_WARN("Gateway container is empty");
396  return;
397  }
398  if (uts.GetN() == 0)
399  {
400  NS_LOG_WARN("UT container is empty");
401  return;
402  }
403 
404  std::string socketFactory = "ns3::TcpSocketFactory";
405 
406  NrtvHelper nrtvHelper(TypeId::LookupByName(socketFactory));
407  if (direction == FWD_LINK)
408  {
409  for (uint32_t j = 0; j < gws.GetN(); j++)
410  {
411  auto app = nrtvHelper.InstallUsingIpv4(gws.Get(j), uts).Get(1);
412  app->SetStartTime(startTime + (j + 1) * startDelay);
413  nrtvHelper.GetServer().Start(startTime);
414  nrtvHelper.GetServer().Stop(stopTime);
415  }
416  }
417  else if (direction == RTN_LINK)
418  {
419  for (uint32_t i = 0; i < uts.GetN(); i++)
420  {
421  auto app = nrtvHelper.InstallUsingIpv4(uts.Get(i), gws).Get(1);
422  app->SetStartTime(startTime + (i + 1) * startDelay);
423  nrtvHelper.GetServer().Start(startTime);
424  nrtvHelper.GetServer().Stop(stopTime);
425  }
426  }
427 
428  // Add throuhgput statistics
429  if (direction == FWD_LINK)
430  {
431  // Global scalar
433  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
435  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
437 
438  // Global scatter
440  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
442  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
444 
445  // Per UT scalar
447  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
449  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
450 
451  // Per UT scatter
453  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
455  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
457 
458  // Per GW scalar
460  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
462  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
463 
464  // Per GW scatter
466  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
468  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
470  }
471  else if (direction == RTN_LINK)
472  {
473  // Global scalar
475  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
477  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
479 
480  // Global scatter
482  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
484  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
486 
487  // Per UT scalar
489  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
491  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
492 
493  // Per UT scatter
495  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
497  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
499 
500  // Per GW scalar
502  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
504  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
505 
506  // Per GW scatter
508  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
510  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
512  }
513 }
514 
515 void
517  Time onTime,
518  Time offTimeExpMean,
519  std::string rate,
520  uint32_t packetSize,
521  NodeContainer gws,
522  NodeContainer uts,
523  Time startTime,
524  Time stopTime,
525  Time startDelay)
526 {
527  NS_LOG_FUNCTION(this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
528  << stopTime << startDelay);
529 
530  if (gws.GetN() == 0)
531  {
532  NS_LOG_WARN("Gateway container is empty");
533  return;
534  }
535  if (uts.GetN() == 0)
536  {
537  NS_LOG_WARN("UT container is empty");
538  return;
539  }
540 
541  std::string socketFactory = "ns3::UdpSocketFactory";
542 
543  uint16_t port = 9;
544 
545  PacketSinkHelper sinkHelper(socketFactory, Address());
546  SatOnOffHelper onOffHelper(socketFactory, Address());
547  ApplicationContainer sinkContainer;
548  ApplicationContainer onOffContainer;
549 
550  // create CBR applications from GWs to UT users
551  for (uint32_t j = 0; j < gws.GetN(); j++)
552  {
553  for (uint32_t i = 0; i < uts.GetN(); i++)
554  {
555  if (direction == RTN_LINK)
556  {
557  InetSocketAddress gwUserAddr =
558  InetSocketAddress(m_satHelper->GetUserAddress(gws.Get(j)), port);
559 
560  if (!HasSinkInstalled(gws.Get(j), port))
561  {
562  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
563  sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
564  }
565 
566  onOffHelper.SetAttribute("OnTime",
567  StringValue("ns3::ConstantRandomVariable[Constant=" +
568  std::to_string(onTime.GetSeconds()) + "]"));
569  onOffHelper.SetAttribute("OffTime",
570  StringValue("ns3::ExponentialRandomVariable[Mean=" +
571  std::to_string(offTimeExpMean.GetSeconds()) +
572  "]"));
573  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
574  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
575  onOffHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
576 
577  auto app = onOffHelper.Install(uts.Get(i)).Get(0);
578  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
579  onOffContainer.Add(app);
580  }
581  else if (direction == FWD_LINK)
582  {
583  InetSocketAddress utUserAddr =
584  InetSocketAddress(m_satHelper->GetUserAddress(uts.Get(i)), port);
585 
586  if (!HasSinkInstalled(uts.Get(i), port))
587  {
588  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
589  sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
590  }
591 
592  onOffHelper.SetAttribute("OnTime",
593  StringValue("ns3::ConstantRandomVariable[Constant=" +
594  std::to_string(onTime.GetSeconds()) + "]"));
595  onOffHelper.SetAttribute("OffTime",
596  StringValue("ns3::ExponentialRandomVariable[Mean=" +
597  std::to_string(offTimeExpMean.GetSeconds()) +
598  "]"));
599  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
600  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
601  onOffHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
602 
603  auto app = onOffHelper.Install(gws.Get(j)).Get(0);
604  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
605  onOffContainer.Add(app);
606  }
607  }
608  }
609  sinkContainer.Start(startTime);
610  sinkContainer.Stop(stopTime);
611 
612  // Add throuhgput statistics
613  if (direction == FWD_LINK)
614  {
615  // Global scalar
617  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
619  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
621 
622  // Global scatter
624  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
626  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
628 
629  // Per UT scalar
631  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
633  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
634 
635  // Per UT scatter
637  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
639  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
641 
642  // Per GW scalar
644  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
646  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
647 
648  // Per GW scatter
650  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
652  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
654  }
655  else if (direction == RTN_LINK)
656  {
657  // Global scalar
659  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
661  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
663 
664  // Global scatter
666  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
668  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
670 
671  // Per UT scalar
673  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
675  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
676 
677  // Per UT scatter
679  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
681  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
683 
684  // Per GW scalar
686  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
688  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
689 
690  // Per GW scatter
692  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
694  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
696  }
697 }
698 
699 void
701  VoipCodec_t codec,
702  NodeContainer gws,
703  NodeContainer uts,
704  Time startTime,
705  Time stopTime,
706  Time startDelay)
707 {
708  NS_LOG_FUNCTION(this << direction << codec << startTime << stopTime << startDelay);
709 
710  if (gws.GetN() == 0)
711  {
712  NS_LOG_WARN("Gateway container is empty");
713  return;
714  }
715  if (uts.GetN() == 0)
716  {
717  NS_LOG_WARN("UT container is empty");
718  return;
719  }
720 
721  std::string socketFactory = "ns3::UdpSocketFactory";
722  uint16_t port = 9;
723 
724  double onTime;
725  double offTime;
726  std::string rate;
727  uint32_t packetSize;
728 
729  switch (codec)
730  {
731  case G_711_1:
732  onTime = 0.5;
733  offTime = 0.05;
734  rate = "70kbps"; // 64kbps globally
735  packetSize = 80;
736  break;
737  case G_711_2:
738  onTime = 0.5;
739  offTime = 0.05;
740  rate = "70kbps"; // 64kbps globally
741  packetSize = 160;
742  break;
743  case G_723_1:
744  onTime = 0.5;
745  offTime = 0.05;
746  rate = "6864bps"; // 6240bps globally
747  packetSize = 30;
748  break;
749  case G_729_2:
750  onTime = 0.5;
751  offTime = 0.05;
752  rate = "8800bps"; // 8kbps globally
753  packetSize = 20;
754  break;
755  case G_729_3:
756  onTime = 0.5;
757  offTime = 0.05;
758  rate = "7920bps"; // 7200bps globally
759  packetSize = 30;
760  break;
761  default:
762  NS_FATAL_ERROR("VoIP codec does not exist or is not implemented");
763  }
764 
765  PacketSinkHelper sinkHelper(socketFactory, Address());
766  SatOnOffHelper onOffHelper(socketFactory, Address());
767  ApplicationContainer sinkContainer;
768  ApplicationContainer onOffContainer;
769 
770  // create CBR applications from GWs to UT users
771  for (uint32_t j = 0; j < gws.GetN(); j++)
772  {
773  for (uint32_t i = 0; i < uts.GetN(); i++)
774  {
775  if (direction == RTN_LINK)
776  {
777  InetSocketAddress gwUserAddr =
778  InetSocketAddress(m_satHelper->GetUserAddress(gws.Get(j)), port);
779 
780  if (!HasSinkInstalled(gws.Get(j), port))
781  {
782  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
783  sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
784  }
785 
786  onOffHelper.SetAttribute("OnTime",
787  StringValue("ns3::ConstantRandomVariable[Constant=" +
788  std::to_string(onTime) + "]"));
789  onOffHelper.SetAttribute("OffTime",
790  StringValue("ns3::ConstantRandomVariable[Constant=" +
791  std::to_string(offTime) + "]"));
792  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
793  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
794  onOffHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
795 
796  auto app = onOffHelper.Install(uts.Get(i)).Get(0);
797  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
798  onOffContainer.Add(app);
799  }
800  else if (direction == FWD_LINK)
801  {
802  InetSocketAddress utUserAddr =
803  InetSocketAddress(m_satHelper->GetUserAddress(uts.Get(i)), port);
804 
805  if (!HasSinkInstalled(uts.Get(i), port))
806  {
807  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
808  sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
809  }
810 
811  onOffHelper.SetAttribute("OnTime",
812  StringValue("ns3::ConstantRandomVariable[Constant=" +
813  std::to_string(onTime) + "]"));
814  onOffHelper.SetAttribute("OffTime",
815  StringValue("ns3::ConstantRandomVariable[Constant=" +
816  std::to_string(offTime) + "]"));
817  onOffHelper.SetAttribute("DataRate", DataRateValue(rate));
818  onOffHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
819  onOffHelper.SetAttribute("Remote", AddressValue(Address(utUserAddr)));
820 
821  auto app = onOffHelper.Install(gws.Get(j)).Get(0);
822  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
823  onOffContainer.Add(app);
824  }
825  }
826  }
827  sinkContainer.Start(startTime);
828  sinkContainer.Stop(stopTime);
829 
830  // Add jitter statistics
831  if (direction == FWD_LINK)
832  {
833  // Global
836 
837  // Per UT
840 
841  // Per GW
844  }
845  else if (direction == RTN_LINK)
846  {
847  // Global
850 
851  // Per UT
854 
855  // Per GW
858  }
859 
860  // Add throuhgput statistics
861  if (direction == FWD_LINK)
862  {
863  // Global scalar
865  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
867  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
869 
870  // Global scatter
872  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
874  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
876 
877  // Per UT scalar
879  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
881  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
882 
883  // Per UT scatter
885  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
887  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
889 
890  // Per GW scalar
892  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
894  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
895 
896  // Per GW scatter
898  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
900  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
902  }
903  else if (direction == RTN_LINK)
904  {
905  // Global scalar
907  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
909  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
911 
912  // Global scatter
914  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
916  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
918 
919  // Per UT scalar
921  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
923  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
924 
925  // Per UT scatter
927  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
929  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
931 
932  // Per GW scalar
934  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
936  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
937 
938  // Per GW scatter
940  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
942  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
944  }
945 }
946 
947 void
949  std::string interval,
950  uint32_t packetSize,
951  NodeContainer gws,
952  NodeContainer uts,
953  Time startTime,
954  Time stopTime,
955  Time startDelay)
956 {
957  NS_LOG_FUNCTION(this << direction << interval << packetSize << startTime << stopTime
958  << startDelay);
959 
960  if (gws.GetN() == 0)
961  {
962  NS_LOG_WARN("Gateway container is empty");
963  return;
964  }
965  if (uts.GetN() == 0)
966  {
967  NS_LOG_WARN("UT container is empty");
968  return;
969  }
970 
971  std::string socketFactory = "ns3::UdpSocketFactory";
972  uint16_t port = 9;
973 
974  PacketSinkHelper sinkHelper(socketFactory, Address());
975 
976  ObjectFactory factory;
977  factory.SetTypeId("ns3::CbrApplication");
978  factory.Set("Protocol", StringValue(socketFactory));
979  ApplicationContainer sinkContainer;
980  ApplicationContainer cbrContainer;
981 
982  // create CBR applications from GWs to UT users
983  for (uint32_t j = 0; j < gws.GetN(); j++)
984  {
985  for (uint32_t i = 0; i < uts.GetN(); i++)
986  {
987  if (direction == RTN_LINK)
988  {
989  InetSocketAddress gwUserAddr =
990  InetSocketAddress(m_satHelper->GetUserAddress(gws.Get(j)), port);
991  if (!HasSinkInstalled(gws.Get(j), port))
992  {
993  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
994  sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
995  }
996 
997  factory.Set("Interval", TimeValue(Time(interval)));
998  factory.Set("PacketSize", UintegerValue(packetSize));
999  factory.Set("Remote", AddressValue(Address(gwUserAddr)));
1000  Ptr<CbrApplication> p_app = factory.Create<CbrApplication>();
1001  uts.Get(i)->AddApplication(p_app);
1002  auto app = ApplicationContainer(p_app).Get(0);
1003  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
1004  cbrContainer.Add(app);
1005  }
1006  else if (direction == FWD_LINK)
1007  {
1008  InetSocketAddress utUserAddr =
1009  InetSocketAddress(m_satHelper->GetUserAddress(uts.Get(i)), port);
1010  if (!HasSinkInstalled(uts.Get(i), port))
1011  {
1012  sinkHelper.SetAttribute("Local", AddressValue(Address(utUserAddr)));
1013  sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
1014  }
1015 
1016  factory.Set("Interval", TimeValue(Time(interval)));
1017  factory.Set("PacketSize", UintegerValue(packetSize));
1018  factory.Set("Remote", AddressValue(Address(utUserAddr)));
1019  Ptr<CbrApplication> p_app = factory.Create<CbrApplication>();
1020  gws.Get(j)->AddApplication(p_app);
1021  auto app = ApplicationContainer(p_app).Get(0);
1022  app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
1023  cbrContainer.Add(app);
1024  }
1025  }
1026  }
1027 
1028  sinkContainer.Start(startTime);
1029  sinkContainer.Stop(stopTime);
1030 
1031  m_last_custom_application.application = cbrContainer;
1032  m_last_custom_application.start = startTime;
1033  m_last_custom_application.stop = stopTime;
1035 
1036  // Add throuhgput statistics
1037  if (direction == FWD_LINK)
1038  {
1039  // Global scalar
1041  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1043  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1045 
1046  // Global scatter
1048  m_satStatsHelperContainer->AddGlobalFwdFeederMacThroughput(
1050  m_satStatsHelperContainer->AddGlobalFwdUserMacThroughput(
1052 
1053  // Per UT scalar
1055  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1057  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
1058 
1059  // Per UT scatter
1061  m_satStatsHelperContainer->AddPerUtFwdFeederMacThroughput(
1063  m_satStatsHelperContainer->AddPerUtFwdUserMacThroughput(
1065 
1066  // Per GW scalar
1068  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1070  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
1071 
1072  // Per GW scatter
1074  m_satStatsHelperContainer->AddPerGwFwdFeederMacThroughput(
1076  m_satStatsHelperContainer->AddPerGwFwdUserMacThroughput(
1078  }
1079  else if (direction == RTN_LINK)
1080  {
1081  // Global scalar
1083  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1085  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1087 
1088  // Global scatter
1090  m_satStatsHelperContainer->AddGlobalRtnFeederMacThroughput(
1092  m_satStatsHelperContainer->AddGlobalRtnUserMacThroughput(
1094 
1095  // Per UT scalar
1097  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1099  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
1100 
1101  // Per UT scatter
1103  m_satStatsHelperContainer->AddPerUtRtnFeederMacThroughput(
1105  m_satStatsHelperContainer->AddPerUtRtnUserMacThroughput(
1107 
1108  // Per GW scalar
1110  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1112  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(SatStatsHelper::OUTPUT_SCALAR_FILE);
1113 
1114  // Per GW scatter
1116  m_satStatsHelperContainer->AddPerGwRtnFeederMacThroughput(
1118  m_satStatsHelperContainer->AddPerGwRtnUserMacThroughput(
1120  }
1121 }
1122 
1123 void
1124 SatTrafficHelper::ChangeCustomTraffic(Time delay, std::string interval, uint32_t packetSize)
1125 {
1126  NS_LOG_FUNCTION(this << delay << interval << packetSize);
1127 
1129  {
1130  NS_FATAL_ERROR("No custom traffic created when calling the method "
1131  "SatTrafficHelper::ChangeCustomTraffic for the first time.");
1132  }
1134  {
1135  NS_FATAL_ERROR("Custom traffic updated after its stop time.");
1136  }
1137  for (auto i = m_last_custom_application.application.Begin();
1139  ++i)
1140  {
1141  Ptr<CbrApplication> app = (dynamic_cast<CbrApplication*>(PeekPointer(*i)));
1142  Simulator::Schedule(m_last_custom_application.start + delay,
1144  this,
1145  app,
1146  interval,
1147  packetSize);
1148  }
1149 }
1150 
1151 void
1152 SatTrafficHelper::UpdateAttribute(Ptr<CbrApplication> application,
1153  std::string interval,
1154  uint32_t packetSize)
1155 {
1156  NS_LOG_FUNCTION(this << application << interval << packetSize);
1157 
1158  application->SetInterval(Time(interval));
1159  application->SetPacketSize(packetSize);
1160 }
1161 
1162 bool
1163 SatTrafficHelper::HasSinkInstalled(Ptr<Node> node, uint16_t port)
1164 {
1165  NS_LOG_FUNCTION(this << node->GetId() << port);
1166 
1167  for (uint32_t i = 0; i < node->GetNApplications(); i++)
1168  {
1169  auto sink = DynamicCast<PacketSink>(node->GetApplication(i));
1170  if (sink != NULL)
1171  {
1172  AddressValue av;
1173  sink->GetAttribute("Local", av);
1174  if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
1175  {
1176  return true;
1177  }
1178  }
1179  }
1180  return false;
1181 }
1182 
1183 } // 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.
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
bool HasSinkInstalled(Ptr< Node > node, uint16_t port)
Check if node has a PacketSink installed at certain port.
void AddNrtvTraffic(TrafficDirection_t direction, NodeContainer gws, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add a new TCP/NRTV traffic between chosen GWs and UTs.
void AddHttpTraffic(TrafficDirection_t direction, NodeContainer gws, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add a new TCP/HTTP traffic between chosen GWs and UTs.
static TypeId GetTypeId(void)
Get the type ID.
void AddCustomTraffic(TrafficDirection_t direction, std::string interval, uint32_t packetSize, NodeContainer gws, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add a new CBR traffic between chosen GWs and UTs that can be customized.
void AddCbrTraffic(TrafficDirection_t direction, std::string interval, uint32_t packetSize, NodeContainer gws, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add a new UDP/CBR traffic between chosen GWs and UTs.
void AddVoipTraffic(TrafficDirection_t direction, VoipCodec_t codec, NodeContainer gws, NodeContainer uts, 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.
void AddPoissonTraffic(TrafficDirection_t direction, Time onTime, Time offTimeExpMean, std::string rate, uint32_t packetSize, NodeContainer gws, NodeContainer uts, Time startTime, Time stopTime, Time startDelay)
Add a new Poisson traffic between chosen GWs and UTs.
Ptr< SatStatsHelperContainer > m_satStatsHelperContainer
void UpdateAttribute(Ptr< CbrApplication > application, std::string interval, uint32_t packetSize)
Update the chosen attribute of a custom traffic.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.