27 #include <ns3/cbr-helper.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>
42 NS_LOG_COMPONENT_DEFINE(
"SatelliteTrafficHelper");
47 NS_OBJECT_ENSURE_REGISTERED(SatTrafficHelperConf);
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", \
62 MakeEnumAccessor<SatTrafficHelperConf::TransportLayerProtocol_t>( \
63 &SatTrafficHelperConf::SetTraffic##index##Protocol, \
64 &SatTrafficHelperConf::GetTraffic##index##Protocol), \
65 MakeEnumChecker(SatTrafficHelperConf::PROTOCOL_UDP, \
67 SatTrafficHelperConf::PROTOCOL_TCP, \
69 SatTrafficHelperConf::PROTOCOL_BOTH, \
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", \
76 MakeEnumAccessor<SatTrafficHelperConf::TrafficDirection_t>( \
77 &SatTrafficHelperConf::SetTraffic##index##Direction, \
78 &SatTrafficHelperConf::GetTraffic##index##Direction), \
79 MakeEnumChecker(SatTrafficHelperConf::RTN_LINK, \
81 SatTrafficHelperConf::FWD_LINK, \
83 SatTrafficHelperConf::BOTH_LINK, \
86 #define SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(index, value) \
87 AddAttribute("Traffic" TOSTRING(index) "Interval", \
88 "Interval between packets", \
90 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##Interval, \
91 &SatTrafficHelperConf::GetTraffic##index##Interval), \
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())
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>())
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), \
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), \
126 #define SIM_ADD_TRAFFIC_MODEL_ON_TIME_ATTRIBUTE(index, value) \
127 AddAttribute("Traffic" TOSTRING(index) "OnTime", \
128 "On time value for Poisson traffic", \
130 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##OnTime, \
131 &SatTrafficHelperConf::GetTraffic##index##OnTime), \
134 #define SIM_ADD_TRAFFIC_MODEL_OFF_TIME_ATTRIBUTE(index, value) \
135 AddAttribute("Traffic" TOSTRING(index) "OffTime", \
136 "Off time value for Poisson traffic", \
138 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##OffTime, \
139 &SatTrafficHelperConf::GetTraffic##index##OffTime), \
142 #define SIM_ADD_TRAFFIC_MODEL_CODEC_ATTRIBUTE(index, value) \
143 AddAttribute("Traffic" TOSTRING(index) "Codec", \
144 "Codec used for VoIP traffic", \
146 MakeEnumAccessor<SatTrafficHelper::VoipCodec_t>( \
147 &SatTrafficHelperConf::SetTraffic##index##Codec, \
148 &SatTrafficHelperConf::GetTraffic##index##Codec), \
149 MakeEnumChecker(SatTrafficHelper::G_711_1, \
151 SatTrafficHelper::G_711_2, \
153 SatTrafficHelper::G_723_1, \
155 SatTrafficHelper::G_729_2, \
157 SatTrafficHelper::G_729_3, \
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", \
164 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StartTime, \
165 &SatTrafficHelperConf::GetTraffic##index##StartTime), \
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.", \
173 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StopTime, \
174 &SatTrafficHelperConf::GetTraffic##index##StopTime), \
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", \
181 MakeTimeAccessor(&SatTrafficHelperConf::SetTraffic##index##StartDelay, \
182 &SatTrafficHelperConf::GetTraffic##index##StartDelay), \
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))
197 TypeId(
"ns3::SatTrafficHelperConf")
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))
207 .SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(LoraCbr, Seconds(1))
209 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(LoraCbr, Seconds(0.1))
216 .SIM_ADD_TRAFFIC_MODEL_INTERVAL_ATTRIBUTE(Cbr, Seconds(1))
218 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Cbr, Seconds(0.1))
225 .SIM_ADD_TRAFFIC_MODEL_DATA_RATE_ATTRIBUTE(OnOff, DataRate(
"500kb/s"))
227 .SIM_ADD_TRAFFIC_MODEL_ON_TIME_PATTERN_ATTRIBUTE(
229 "ns3::ConstantRandomVariable[Constant=1000]")
230 .SIM_ADD_TRAFFIC_MODEL_OFF_TIME_PATTERN_ATTRIBUTE(
232 "ns3::ConstantRandomVariable[Constant=0]")
233 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(OnOff, Seconds(0.1))
239 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Http, Seconds(0.1))
245 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Nrtv, Seconds(0.1))
251 .SIM_ADD_TRAFFIC_MODEL_ON_TIME_ATTRIBUTE(Poisson, Seconds(1))
255 .SIM_ADD_TRAFFIC_MODEL_START_TIME_ATTRIBUTE(Poisson, Seconds(0.1))
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))
273 NS_LOG_FUNCTION(
this);
279 : m_simTime(Seconds(0)),
280 m_trafficHelper(nullptr)
282 NS_LOG_FUNCTION(
this);
284 NS_FATAL_ERROR(
"Default constructor not in use");
288 : m_simTime(simTime),
289 m_trafficHelper(trafficHelper)
291 NS_LOG_FUNCTION(
this << simTime << trafficHelper);
296 NS_LOG_FUNCTION(
this);
305 TypeId(
"ns3::SatTrafficHelper")
307 .AddConstructor<SatTrafficHelper>()
308 .AddAttribute(
"EnableDefaultStatistics",
309 "Enable outputing values from stats helpers",
312 MakeBooleanChecker());
319 NS_LOG_FUNCTION(
this);
325 : m_satHelper(nullptr),
326 m_satStatsHelperContainer(nullptr)
328 NS_FATAL_ERROR(
"Default constructor of SatTrafficHelper cannot be used.");
332 Ptr<SatStatsHelperContainer> satStatsHelperContainer)
333 : m_satHelper(satHelper),
334 m_satStatsHelperContainer(satStatsHelperContainer),
335 m_enableDefaultStatistics(false)
348 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay);
352 NS_LOG_WARN(
"UT container is empty");
356 PacketSinkHelper sinkHelper(
"ns3::UdpSocketFactory", Address());
357 CbrHelper cbrHelper(
"ns3::UdpSocketFactory", Address());
358 ApplicationContainer sinkContainer;
359 ApplicationContainer cbrContainer;
364 for (uint32_t i = 0; i < uts.GetN(); i++)
367 Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
369 app->SetInterval(interval);
370 NS_LOG_DEBUG(
"Created an application with interval = " << interval.GetHours() <<
" hours");
372 app->SetStartTime(startTime + (i + 1) * startDelay);
373 app->SetStopTime(stopTime);
374 app->SetPacketSize(packetSize);
377 node->AddApplication(app);
390 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay
394 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
395 NodeContainer utsUpdated;
396 for (uint32_t i = 0; i < uts.GetN(); ++i)
398 if (rng->GetValue(0.0, 1.0) < percentage)
400 utsUpdated.Add(uts.Get(i));
410 NodeContainer gwUsers,
411 NodeContainer utUsers,
416 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay);
418 if (gwUsers.GetN() == 0)
420 NS_LOG_WARN(
"Gateway users container is empty");
423 if (utUsers.GetN() == 0)
425 NS_LOG_WARN(
"UT users container is empty");
431 PacketSinkHelper sinkHelper(
"ns3::UdpSocketFactory", Address());
432 CbrHelper cbrHelper(
"ns3::UdpSocketFactory", Address());
433 ApplicationContainer sinkContainer;
434 ApplicationContainer cbrContainer;
437 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
439 for (uint32_t i = 0; i < utUsers.GetN(); i++)
441 InetSocketAddress gwUserAddr =
442 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
445 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
446 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
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);
457 sinkContainer.Start(startTime);
458 sinkContainer.Stop(stopTime);
464 NodeContainer gwUsers,
465 NodeContainer utUsers,
471 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay
475 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
476 NodeContainer utUsersUpdated;
477 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
479 if (rng->GetValue(0.0, 1.0) < percentage)
481 utUsersUpdated.Add(utUsers.Get(i));
499 NodeContainer gwUsers,
500 NodeContainer utUsers,
505 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay);
507 if (gwUsers.GetN() == 0)
509 NS_LOG_WARN(
"Gateway users container is empty");
512 if (utUsers.GetN() == 0)
514 NS_LOG_WARN(
"UT users container is empty");
518 std::string socketFactory =
522 PacketSinkHelper sinkHelper(socketFactory, Address());
523 CbrHelper cbrHelper(socketFactory, Address());
524 ApplicationContainer sinkContainer;
525 ApplicationContainer cbrContainer;
528 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
530 for (uint32_t i = 0; i < utUsers.GetN(); i++)
534 InetSocketAddress gwUserAddr =
535 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
538 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
539 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
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);
550 InetSocketAddress utUserAddr =
551 InetSocketAddress(
m_satHelper->GetUserAddress(utUsers.Get(i)), port);
554 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
555 sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
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);
567 sinkContainer.Start(startTime);
568 sinkContainer.Stop(stopTime);
677 NodeContainer gwUsers,
678 NodeContainer utUsers,
684 NS_LOG_FUNCTION(
this << interval << packetSize << startTime << stopTime << startDelay
688 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
689 NodeContainer utUsersUpdated;
690 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
692 if (rng->GetValue(0.0, 1.0) < percentage)
694 utUsersUpdated.Add(utUsers.Get(i));
714 NodeContainer gwUsers,
715 NodeContainer utUsers,
716 std::string onTimePattern,
717 std::string offTimePattern,
722 NS_LOG_FUNCTION(
this << dataRate << packetSize << onTimePattern << offTimePattern << startTime
723 << stopTime << startDelay);
725 if (gwUsers.GetN() == 0)
727 NS_LOG_WARN(
"Gateway users container is empty");
730 if (utUsers.GetN() == 0)
732 NS_LOG_WARN(
"UT users container is empty");
736 std::string socketFactory =
740 PacketSinkHelper sinkHelper(socketFactory, Address());
742 ApplicationContainer sinkContainer;
743 ApplicationContainer onOffContainer;
745 onOffHelper.
SetAttribute(
"OnTime", StringValue(onTimePattern));
746 onOffHelper.
SetAttribute(
"OffTime", StringValue(offTimePattern));
747 onOffHelper.
SetAttribute(
"DataRate", DataRateValue(dataRate));
748 onOffHelper.
SetAttribute(
"PacketSize", UintegerValue(packetSize));
751 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
753 for (uint32_t i = 0; i < utUsers.GetN(); i++)
757 InetSocketAddress gwUserAddr =
758 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
761 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
762 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
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);
772 InetSocketAddress utUserAddr =
773 InetSocketAddress(
m_satHelper->GetUserAddress(utUsers.Get(i)), port);
776 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
777 sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
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);
788 sinkContainer.Start(startTime);
789 sinkContainer.Stop(stopTime);
898 NodeContainer gwUsers,
899 NodeContainer utUsers,
900 std::string onTimePattern,
901 std::string offTimePattern,
907 NS_LOG_FUNCTION(
this << dataRate << packetSize << onTimePattern << offTimePattern << startTime
908 << stopTime << startDelay << percentage);
911 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
912 NodeContainer utUsersUpdated;
913 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
915 if (rng->GetValue(0.0, 1.0) < percentage)
917 utUsersUpdated.Add(utUsers.Get(i));
936 NodeContainer gwUsers,
937 NodeContainer utUsers,
942 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay);
944 if (gwUsers.GetN() == 0)
946 NS_LOG_WARN(
"Gateway users container is empty");
949 if (utUsers.GetN() == 0)
951 NS_LOG_WARN(
"UT users container is empty");
955 ThreeGppHttpHelper httpHelper;
958 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
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);
968 for (uint32_t i = 0; i < utUsers.GetN(); i++)
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);
1101 NodeContainer gwUsers,
1102 NodeContainer utUsers,
1108 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay << percentage);
1111 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1112 NodeContainer utUsersUpdated;
1113 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1115 if (rng->GetValue(0.0, 1.0) < percentage)
1117 utUsersUpdated.Add(utUsers.Get(i));
1121 AddHttpTraffic(direction, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1126 NodeContainer gwUsers,
1127 NodeContainer utUsers,
1132 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay);
1134 if (gwUsers.GetN() == 0)
1136 NS_LOG_WARN(
"Gateway users container is empty");
1139 if (utUsers.GetN() == 0)
1141 NS_LOG_WARN(
"UT users container is empty");
1145 std::string socketFactory =
"ns3::TcpSocketFactory";
1147 NrtvHelper nrtvHelper(TypeId::LookupByName(socketFactory));
1150 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
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);
1160 for (uint32_t i = 0; i < utUsers.GetN(); i++)
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);
1273 NodeContainer gwUsers,
1274 NodeContainer utUsers,
1280 NS_LOG_FUNCTION(
this << direction << startTime << stopTime << startDelay << percentage);
1283 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1284 NodeContainer utUsersUpdated;
1285 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1287 if (rng->GetValue(0.0, 1.0) < percentage)
1289 utUsersUpdated.Add(utUsers.Get(i));
1293 AddNrtvTraffic(direction, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1299 Time offTimeExpMean,
1301 uint32_t packetSize,
1302 NodeContainer gwUsers,
1303 NodeContainer utUsers,
1308 NS_LOG_FUNCTION(
this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
1309 << stopTime << startDelay);
1311 if (gwUsers.GetN() == 0)
1313 NS_LOG_WARN(
"Gateway users container is empty");
1316 if (utUsers.GetN() == 0)
1318 NS_LOG_WARN(
"UT users container is empty");
1322 std::string socketFactory =
"ns3::UdpSocketFactory";
1326 PacketSinkHelper sinkHelper(socketFactory, Address());
1328 ApplicationContainer sinkContainer;
1329 ApplicationContainer onOffContainer;
1332 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1334 for (uint32_t i = 0; i < utUsers.GetN(); i++)
1338 InetSocketAddress gwUserAddr =
1339 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1343 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
1344 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
1348 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
1349 std::to_string(onTime.GetSeconds()) +
"]"));
1351 StringValue(
"ns3::ExponentialRandomVariable[Mean=" +
1352 std::to_string(offTimeExpMean.GetSeconds()) +
1354 onOffHelper.
SetAttribute(
"DataRate", DataRateValue(rate));
1355 onOffHelper.
SetAttribute(
"PacketSize", UintegerValue(packetSize));
1356 onOffHelper.
SetAttribute(
"Remote", AddressValue(Address(gwUserAddr)));
1358 auto app = onOffHelper.
Install(utUsers.Get(i)).Get(0);
1359 app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1360 onOffContainer.Add(app);
1364 InetSocketAddress utUserAddr =
1365 InetSocketAddress(
m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1369 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
1370 sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
1374 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
1375 std::to_string(onTime.GetSeconds()) +
"]"));
1377 StringValue(
"ns3::ExponentialRandomVariable[Mean=" +
1378 std::to_string(offTimeExpMean.GetSeconds()) +
1380 onOffHelper.
SetAttribute(
"DataRate", DataRateValue(rate));
1381 onOffHelper.
SetAttribute(
"PacketSize", UintegerValue(packetSize));
1382 onOffHelper.
SetAttribute(
"Remote", AddressValue(Address(utUserAddr)));
1384 auto app = onOffHelper.
Install(gwUsers.Get(j)).Get(0);
1385 app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1386 onOffContainer.Add(app);
1390 sinkContainer.Start(startTime);
1391 sinkContainer.Stop(stopTime);
1498 Time offTimeExpMean,
1500 uint32_t packetSize,
1501 NodeContainer gwUsers,
1502 NodeContainer utUsers,
1508 NS_LOG_FUNCTION(
this << direction << onTime << offTimeExpMean << rate << packetSize << startTime
1509 << stopTime << startDelay << percentage);
1512 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1513 NodeContainer utUsersUpdated;
1514 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1516 if (rng->GetValue(0.0, 1.0) < percentage)
1518 utUsersUpdated.Add(utUsers.Get(i));
1537 NodeContainer gwUsers,
1538 NodeContainer utUsers,
1543 NS_LOG_FUNCTION(
this << direction << codec << startTime << stopTime << startDelay);
1545 if (gwUsers.GetN() == 0)
1547 NS_LOG_WARN(
"Gateway users container is empty");
1550 if (utUsers.GetN() == 0)
1552 NS_LOG_WARN(
"UT users container is empty");
1556 std::string socketFactory =
"ns3::UdpSocketFactory";
1562 uint32_t packetSize;
1597 NS_FATAL_ERROR(
"VoIP codec does not exist or is not implemented");
1600 PacketSinkHelper sinkHelper(socketFactory, Address());
1602 ApplicationContainer sinkContainer;
1603 ApplicationContainer onOffContainer;
1606 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1608 for (uint32_t i = 0; i < utUsers.GetN(); i++)
1612 InetSocketAddress gwUserAddr =
1613 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1617 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
1618 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
1622 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
1623 std::to_string(onTime) +
"]"));
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)));
1631 auto app = onOffHelper.
Install(utUsers.Get(i)).Get(0);
1632 app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1633 onOffContainer.Add(app);
1637 InetSocketAddress utUserAddr =
1638 InetSocketAddress(
m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1642 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
1643 sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
1647 StringValue(
"ns3::ConstantRandomVariable[Constant=" +
1648 std::to_string(onTime) +
"]"));
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)));
1656 auto app = onOffHelper.
Install(gwUsers.Get(j)).Get(0);
1657 app->SetStartTime(startTime + (i + j * gwUsers.GetN() + 1) * startDelay);
1658 onOffContainer.Add(app);
1662 sinkContainer.Start(startTime);
1663 sinkContainer.Stop(stopTime);
1800 NodeContainer gwUsers,
1801 NodeContainer utUsers,
1807 NS_LOG_FUNCTION(
this << direction << codec << startTime << stopTime << startDelay
1811 Ptr<UniformRandomVariable> rng = CreateObject<UniformRandomVariable>();
1812 NodeContainer utUsersUpdated;
1813 for (uint32_t i = 0; i < utUsers.GetN(); ++i)
1815 if (rng->GetValue(0.0, 1.0) < percentage)
1817 utUsersUpdated.Add(utUsers.Get(i));
1821 AddVoipTraffic(direction, codec, gwUsers, utUsersUpdated, startTime, stopTime, startDelay);
1826 std::string interval,
1827 uint32_t packetSize,
1828 NodeContainer gwUsers,
1829 NodeContainer utUsers,
1834 NS_LOG_FUNCTION(
this << direction << interval << packetSize << startTime << stopTime
1837 if (gwUsers.GetN() == 0)
1839 NS_LOG_WARN(
"Gateway users container is empty");
1842 if (utUsers.GetN() == 0)
1844 NS_LOG_WARN(
"UT users container is empty");
1848 std::string socketFactory =
"ns3::UdpSocketFactory";
1851 PacketSinkHelper sinkHelper(socketFactory, Address());
1853 ObjectFactory factory;
1854 factory.SetTypeId(
"ns3::CbrApplication");
1855 factory.Set(
"Protocol", StringValue(socketFactory));
1856 ApplicationContainer sinkContainer;
1857 ApplicationContainer cbrContainer;
1860 for (uint32_t j = 0; j < gwUsers.GetN(); j++)
1862 for (uint32_t i = 0; i < utUsers.GetN(); i++)
1866 InetSocketAddress gwUserAddr =
1867 InetSocketAddress(
m_satHelper->GetUserAddress(gwUsers.Get(j)), port);
1870 sinkHelper.SetAttribute(
"Local", AddressValue(Address(gwUserAddr)));
1871 sinkContainer.Add(sinkHelper.Install(gwUsers.Get(j)));
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);
1885 InetSocketAddress utUserAddr =
1886 InetSocketAddress(
m_satHelper->GetUserAddress(utUsers.Get(i)), port);
1889 sinkHelper.SetAttribute(
"Local", AddressValue(Address(utUserAddr)));
1890 sinkContainer.Add(sinkHelper.Install(utUsers.Get(i)));
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);
1905 sinkContainer.Start(startTime);
1906 sinkContainer.Stop(stopTime);
2018 NS_LOG_FUNCTION(
this << delay << interval << packetSize);
2022 NS_FATAL_ERROR(
"No custom traffic created when calling the method "
2023 "SatTrafficHelper::ChangeCustomTraffic for the first time.");
2027 NS_FATAL_ERROR(
"Custom traffic updated after its stop time.");
2033 Ptr<CbrApplication> app = (
dynamic_cast<CbrApplication*
>(PeekPointer(*i)));
2045 std::string interval,
2046 uint32_t packetSize)
2048 NS_LOG_FUNCTION(
this << application << interval << packetSize);
2050 application->SetInterval(Time(interval));
2051 application->SetPacketSize(packetSize);
2057 NS_LOG_FUNCTION(
this << node->GetId() << port);
2059 for (uint32_t i = 0; i < node->GetNApplications(); i++)
2061 auto sink = DynamicCast<PacketSink>(node->GetApplication(i));
2062 if (sink !=
nullptr)
2065 sink->GetAttribute(
"Local", av);
2066 if (InetSocketAddress::ConvertFrom(av.Get()).GetPort() == port)
2078 NS_LOG_FUNCTION(
this);
2080 NS_ASSERT_MSG(
m_trafficHelper !=
nullptr,
"Traffic helper must be defined");
2082 for (
const std::pair<const std::string, SatTrafficHelperConf::TrafficConfiguration_t>&
2086 if (trafficModel.first ==
"LoraCbr")
2090 else if (trafficModel.first ==
"LoraPeriodic")
2094 else if (trafficModel.first ==
"Cbr")
2098 else if (trafficModel.first ==
"OnOff")
2102 else if (trafficModel.first ==
"Http")
2106 else if (trafficModel.first ==
"Nrtv")
2110 else if (trafficModel.first ==
"Poisson")
2114 else if (trafficModel.first ==
"Voip")
2120 NS_FATAL_ERROR(
"Unknown traffic model has been configured: " << trafficModel.first);
2123 std::vector<SatTrafficHelper::TransportLayerProtocol_t> protocols;
2124 switch (trafficModel.second.m_protocol)
2140 NS_FATAL_ERROR(
"Unknown traffic protocol");
2144 std::vector<SatTrafficHelper::TrafficDirection_t> directions;
2145 switch (trafficModel.second.m_direction)
2161 NS_FATAL_ERROR(
"Unknown traffic protocol");
2165 if (trafficModel.second.m_percentage > 0.0)
2167 SatTrafficHelperConf::TrafficConfiguration_t conf = trafficModel.second;
2168 Time startTime = conf.m_startTime;
2171 NS_FATAL_ERROR(
"Traffic model "
2172 << trafficModel.first
2173 <<
" configured to start after the simulation ended");
2176 Time stopTime = conf.m_stopTime;
2177 if (stopTime == Seconds(0))
2181 if (stopTime < startTime)
2183 NS_FATAL_ERROR(
"Traffic model " << trafficModel.first
2184 <<
" configured to stop before it is started");
2187 NodeContainer gws = Singleton<SatTopology>::Get()->GetGwUserNodes();
2191 uts = Singleton<SatTopology>::Get()->GetUtNodes();
2195 uts = Singleton<SatTopology>::Get()->GetUtUserNodes();
2245 conf.m_onTimePattern,
2246 conf.m_offTimePattern,
2299 NS_FATAL_ERROR(
"Unknown traffic model has been configured: " << modelName);
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.
Ptr< SatHelper > m_satHelper
bool m_enableDefaultStatistics
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)
ApplicationContainer application