22 #include "ns3/applications-module.h"
23 #include "ns3/core-module.h"
24 #include "ns3/ipv4-l3-protocol.h"
25 #include "ns3/network-module.h"
26 #include "ns3/satellite-module.h"
27 #include "ns3/traffic-module.h"
47 NS_LOG_COMPONENT_DEFINE(
"sat-multi-application-rtn-example");
50 main(
int argc,
char* argv[])
55 LogComponentEnable(
"sat-multi-application-rtn-example", LOG_LEVEL_INFO);
57 uint32_t endUsersPerUt(3);
58 uint32_t utsPerBeam(3);
59 double cbrProbability(0.5);
60 uint32_t packetSize = 512;
61 std::string interval =
"1s";
62 double simLength(15.0);
64 Time appStartTime = Seconds(0.001);
65 Time appStopTime = Seconds(10.0);
68 auto simulationHelper = CreateObject<SimulationHelper>(
"example-multi-application-rtn");
69 Config::SetDefault(
"ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(
true));
70 Config::SetDefault(
"ns3::SatHelper::PacketTraceEnabled", BooleanValue(
true));
74 cmd.AddValue(
"endUsersPerUt",
"Number of end users per UT", endUsersPerUt);
75 cmd.AddValue(
"utsPerBeam",
"Number of UTs per spot-beam", utsPerBeam);
76 cmd.AddValue(
"cbrProbability",
"Probability of CBR end users", cbrProbability);
77 cmd.AddValue(
"simLength",
"Simulation length in seconds", simLength);
78 simulationHelper->AddDefaultUiArguments(cmd);
79 cmd.Parse(argc, argv);
81 simulationHelper->SetUtCountPerBeam(1);
82 simulationHelper->SetUserCountPerUt(1);
83 simulationHelper->SetBeamSet({12, 22});
84 simulationHelper->SetSimulationTime(simLength);
88 Config::SetDefault(
"ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
89 Config::SetDefault(
"ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
91 simulationHelper->LoadScenario(
"geo-33E");
94 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
98 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
99 NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
102 Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable>();
104 NodeContainer utCbrUsers;
105 NodeContainer utOnOffUsers;
142 uint8_t onOffTos(0x28);
143 uint8_t cbrTos(0xB8);
146 for (NodeContainer::Iterator i = utUsers.Begin(); i != utUsers.End(); i++)
149 if (rand->GetValue() < cbrProbability)
156 utOnOffUsers.Add(*i);
160 NS_LOG_INFO(
"Number of created CBR users: " << utCbrUsers.GetN()
161 <<
", On-Off users: " << utOnOffUsers.GetN());
163 ApplicationContainer gwCbrSinkApps;
164 ApplicationContainer gwOnOffSinkApps;
165 ApplicationContainer utCbrApps;
166 ApplicationContainer utOnOffApps;
170 NS_LOG_INFO(
"Creating CBR applications and sinks");
173 Time startDelay = appStartTime;
175 uint32_t cbrGwUserId(0);
176 uint32_t onOffGwUserId(1);
178 if (utCbrUsers.GetN() > 0)
181 PacketSinkHelper cbrSinkHelper(
182 "ns3::UdpSocketFactory",
183 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
185 "ns3::UdpSocketFactory",
186 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
187 cbrHelper.SetAttribute(
"Interval", StringValue(interval));
188 cbrHelper.SetAttribute(
"PacketSize", UintegerValue(packetSize));
189 cbrHelper.SetAttribute(
"Tos", UintegerValue(cbrTos));
192 InetSocketAddress cbrDest(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port);
195 gwCbrSinkApps.Add(cbrSinkHelper.Install(gwUsers.Get(cbrGwUserId)));
196 gwCbrSinkApps.Get(0)->SetStartTime(Seconds(0.1));
197 gwCbrSinkApps.Get(0)->SetStopTime(appStopTime);
199 for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
201 cbrHelper.SetAttribute(
"Remote", AddressValue(Address(cbrDest)));
202 cbrSinkHelper.SetAttribute(
"Local", AddressValue(Address(cbrDest)));
204 utCbrApps.Add(cbrHelper.Install(utCbrUsers.Get(i)));
206 startDelay += Seconds(0.001);
209 utCbrApps.Get(i)->SetStartTime(startDelay);
210 utCbrApps.Get(i)->SetStopTime(appStopTime);
217 if (utOnOffUsers.GetN() > 0)
219 NS_LOG_INFO(
"Creating OnOff applications and sinks");
221 std::string dataRate =
"100kb/s";
222 std::string onTime =
"2.0";
223 std::string offTime =
"2.0";
225 Config::SetDefault(
"ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
226 Config::SetDefault(
"ns3::OnOffApplication::DataRate", StringValue(dataRate));
227 Config::SetDefault(
"ns3::OnOffApplication::OnTime",
228 StringValue(
"ns3::ConstantRandomVariable[Constant=" + onTime +
"]"));
229 Config::SetDefault(
"ns3::OnOffApplication::OffTime",
230 StringValue(
"ns3::ConstantRandomVariable[Constant=" + offTime +
"]"));
234 PacketSinkHelper onOffSinkHelper(
235 "ns3::UdpSocketFactory",
236 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
237 OnOffHelper onOffHelper(
"ns3::UdpSocketFactory",
238 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
240 startDelay = appStartTime;
243 InetSocketAddress onOffDest(helper->GetUserAddress(gwUsers.Get(onOffGwUserId)), port);
246 gwOnOffSinkApps.Add(onOffSinkHelper.Install(gwUsers.Get(onOffGwUserId)));
247 gwOnOffSinkApps.Get(0)->SetStartTime(Seconds(0.1));
248 gwOnOffSinkApps.Get(0)->SetStopTime(appStopTime);
250 for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
252 onOffHelper.SetAttribute(
"Remote", AddressValue(Address(onOffDest)));
253 onOffHelper.SetAttribute(
"Tos", UintegerValue(onOffTos));
254 onOffSinkHelper.SetAttribute(
"Local", AddressValue(Address(onOffDest)));
256 utOnOffApps.Add(onOffHelper.Install(utOnOffUsers.Get(i)));
258 startDelay += Seconds(0.001);
260 utOnOffApps.Get(i)->SetStartTime(startDelay);
261 utOnOffApps.Get(i)->SetStopTime(appStopTime);
268 NS_LOG_INFO(
"--- sat-multi-application-rtn-example ---");
269 NS_LOG_INFO(
" Packet size in bytes: " << packetSize);
270 NS_LOG_INFO(
" Packet sending interval: " << interval);
271 NS_LOG_INFO(
" Simulation length: " << simLength);
272 NS_LOG_INFO(
" Number of UTs: " << utsPerBeam);
273 NS_LOG_INFO(
" Number of end users per UT: " << endUsersPerUt);
276 simulationHelper->RunSimulation();
ErrorModel
Error model enum.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.