24 #include <ns3/cbr-helper.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>
34 NS_LOG_COMPONENT_DEFINE(
"SatelliteTrafficHelper");
39 NS_OBJECT_ENSURE_REGISTERED(SatTrafficHelper);
45 TypeId(
"ns3::SatTrafficHelper").SetParent<Object>().AddConstructor<SatTrafficHelper>();
52 NS_LOG_FUNCTION(
this);
59 m_satStatsHelperContainer(NULL)
61 NS_FATAL_ERROR(
"Default constructor of SatTrafficHelper cannot be used.");
65 Ptr<SatStatsHelperContainer> satStatsHelperContainer)
66 : m_satHelper(satHelper),
67 m_satStatsHelperContainer(satStatsHelperContainer)
82 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay);
86 NS_LOG_WARN(
"Gateway container is empty");
91 NS_LOG_WARN(
"UT container is empty");
95 std::string socketFactory =
"ns3::UdpSocketFactory";
98 PacketSinkHelper sinkHelper(socketFactory, Address());
99 CbrHelper cbrHelper(socketFactory, Address());
100 ApplicationContainer sinkContainer;
101 ApplicationContainer cbrContainer;
104 for (uint32_t j = 0; j < gws.GetN(); j++)
106 for (uint32_t i = 0; i < uts.GetN(); i++)
110 InetSocketAddress gwUserAddr =
111 InetSocketAddress(
m_satHelper->GetUserAddress(gws.Get(j)), port);
114 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
115 sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
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);
126 InetSocketAddress utUserAddr =
127 InetSocketAddress(
m_satHelper->GetUserAddress(uts.Get(i)), port);
130 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
131 sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
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);
143 sinkContainer.Start(startTime);
144 sinkContainer.Stop(stopTime);
241 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay);
245 NS_LOG_WARN(
"Gateway container is empty");
250 NS_LOG_WARN(
"UT container is empty");
254 ThreeGppHttpHelper httpHelper;
257 for (uint32_t j = 0; j < gws.GetN(); j++)
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);
267 for (uint32_t i = 0; i < uts.GetN(); i++)
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);
391 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay);
395 NS_LOG_WARN(
"Gateway container is empty");
400 NS_LOG_WARN(
"UT container is empty");
404 std::string socketFactory =
"ns3::TcpSocketFactory";
406 NrtvHelper nrtvHelper(TypeId::LookupByName(socketFactory));
409 for (uint32_t j = 0; j < gws.GetN(); j++)
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);
419 for (uint32_t i = 0; i < uts.GetN(); i++)
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);
527 NS_LOG_FUNCTION(
this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
528 << stopTime << startDelay);
532 NS_LOG_WARN(
"Gateway container is empty");
537 NS_LOG_WARN(
"UT container is empty");
541 std::string socketFactory =
"ns3::UdpSocketFactory";
545 PacketSinkHelper sinkHelper(socketFactory, Address());
547 ApplicationContainer sinkContainer;
548 ApplicationContainer onOffContainer;
551 for (uint32_t j = 0; j < gws.GetN(); j++)
553 for (uint32_t i = 0; i < uts.GetN(); i++)
557 InetSocketAddress gwUserAddr =
558 InetSocketAddress(
m_satHelper->GetUserAddress(gws.Get(j)), port);
562 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
563 sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
567 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
568 std::to_string(onTime.GetSeconds()) +
"]"));
570 StringValue(
"ns3::ExponentialRandomVariable[Mean=" +
571 std::to_string(offTimeExpMean.GetSeconds()) +
573 onOffHelper.
SetAttribute(
"DataRate", DataRateValue(rate));
574 onOffHelper.
SetAttribute(
"PacketSize", UintegerValue(packetSize));
575 onOffHelper.
SetAttribute(
"Remote", AddressValue(Address(gwUserAddr)));
577 auto app = onOffHelper.
Install(uts.Get(i)).Get(0);
578 app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
579 onOffContainer.Add(app);
583 InetSocketAddress utUserAddr =
584 InetSocketAddress(
m_satHelper->GetUserAddress(uts.Get(i)), port);
588 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
589 sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
593 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
594 std::to_string(onTime.GetSeconds()) +
"]"));
596 StringValue(
"ns3::ExponentialRandomVariable[Mean=" +
597 std::to_string(offTimeExpMean.GetSeconds()) +
599 onOffHelper.
SetAttribute(
"DataRate", DataRateValue(rate));
600 onOffHelper.
SetAttribute(
"PacketSize", UintegerValue(packetSize));
601 onOffHelper.
SetAttribute(
"Remote", AddressValue(Address(utUserAddr)));
603 auto app = onOffHelper.
Install(gws.Get(j)).Get(0);
604 app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
605 onOffContainer.Add(app);
609 sinkContainer.Start(startTime);
610 sinkContainer.Stop(stopTime);
708 NS_LOG_FUNCTION(
this << direction << codec << startTime << stopTime << startDelay);
712 NS_LOG_WARN(
"Gateway container is empty");
717 NS_LOG_WARN(
"UT container is empty");
721 std::string socketFactory =
"ns3::UdpSocketFactory";
762 NS_FATAL_ERROR(
"VoIP codec does not exist or is not implemented");
765 PacketSinkHelper sinkHelper(socketFactory, Address());
767 ApplicationContainer sinkContainer;
768 ApplicationContainer onOffContainer;
771 for (uint32_t j = 0; j < gws.GetN(); j++)
773 for (uint32_t i = 0; i < uts.GetN(); i++)
777 InetSocketAddress gwUserAddr =
778 InetSocketAddress(
m_satHelper->GetUserAddress(gws.Get(j)), port);
782 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
783 sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
787 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
788 std::to_string(onTime) +
"]"));
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)));
796 auto app = onOffHelper.
Install(uts.Get(i)).Get(0);
797 app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
798 onOffContainer.Add(app);
802 InetSocketAddress utUserAddr =
803 InetSocketAddress(
m_satHelper->GetUserAddress(uts.Get(i)), port);
807 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
808 sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
812 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
813 std::to_string(onTime) +
"]"));
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)));
821 auto app = onOffHelper.
Install(gws.Get(j)).Get(0);
822 app->SetStartTime(startTime + (i + j * gws.GetN() + 1) * startDelay);
823 onOffContainer.Add(app);
827 sinkContainer.Start(startTime);
828 sinkContainer.Stop(stopTime);
949 std::string interval,
957 NS_LOG_FUNCTION(
this << direction << interval << packetSize << startTime << stopTime
962 NS_LOG_WARN(
"Gateway container is empty");
967 NS_LOG_WARN(
"UT container is empty");
971 std::string socketFactory =
"ns3::UdpSocketFactory";
974 PacketSinkHelper sinkHelper(socketFactory, Address());
976 ObjectFactory factory;
977 factory.SetTypeId(
"ns3::CbrApplication");
978 factory.Set(
"Protocol", StringValue(socketFactory));
979 ApplicationContainer sinkContainer;
980 ApplicationContainer cbrContainer;
983 for (uint32_t j = 0; j < gws.GetN(); j++)
985 for (uint32_t i = 0; i < uts.GetN(); i++)
989 InetSocketAddress gwUserAddr =
990 InetSocketAddress(
m_satHelper->GetUserAddress(gws.Get(j)), port);
993 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
994 sinkContainer.Add(sinkHelper.Install(gws.Get(j)));
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);
1008 InetSocketAddress utUserAddr =
1009 InetSocketAddress(
m_satHelper->GetUserAddress(uts.Get(i)), port);
1012 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
1013 sinkContainer.Add(sinkHelper.Install(uts.Get(i)));
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);
1028 sinkContainer.Start(startTime);
1029 sinkContainer.Stop(stopTime);
1126 NS_LOG_FUNCTION(
this << delay << interval << packetSize);
1130 NS_FATAL_ERROR(
"No custom traffic created when calling the method "
1131 "SatTrafficHelper::ChangeCustomTraffic for the first time.");
1135 NS_FATAL_ERROR(
"Custom traffic updated after its stop time.");
1141 Ptr<CbrApplication> app = (
dynamic_cast<CbrApplication*
>(PeekPointer(*i)));
1153 std::string interval,
1154 uint32_t packetSize)
1156 NS_LOG_FUNCTION(
this << application << interval << packetSize);
1158 application->SetInterval(Time(interval));
1159 application->SetPacketSize(packetSize);
1165 NS_LOG_FUNCTION(
this << node->GetId() << port);
1167 for (uint32_t i = 0; i < node->GetNApplications(); i++)
1169 auto sink = DynamicCast<PacketSink>(node->GetApplication(i));
1173 sink->GetAttribute(
"Local", av);
1174 if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
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.
Ptr< SatHelper > m_satHelper
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.
ApplicationContainer application