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-fwd-example");
50 main(
int argc,
char* argv[])
55 LogComponentEnable(
"sat-multi-application-fwd-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);
67 auto simulationHelper = CreateObject<SimulationHelper>(
"example-multi-application-fwd");
68 Config::SetDefault(
"ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(
true));
69 Config::SetDefault(
"ns3::SatHelper::PacketTraceEnabled", BooleanValue(
true));
73 cmd.AddValue(
"endUsersPerUt",
"Number of end users per UT", endUsersPerUt);
74 cmd.AddValue(
"utsPerBeam",
"Number of UTs per spot-beam", utsPerBeam);
75 cmd.AddValue(
"cbrProbability",
"Probability of CBR end users", cbrProbability);
76 cmd.AddValue(
"simLength",
"Simulation length in seconds", simLength);
77 simulationHelper->AddDefaultUiArguments(cmd);
78 cmd.Parse(argc, argv);
80 simulationHelper->SetUserCountPerUt(endUsersPerUt);
81 simulationHelper->SetUtCountPerBeam(utsPerBeam);
82 simulationHelper->SetBeamSet({12, 22});
83 simulationHelper->SetSimulationTime(simLength);
87 Config::SetDefault(
"ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
88 Config::SetDefault(
"ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
94 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
98 NodeContainer utUsers = helper->GetUtUsers();
99 NodeContainer gwUsers = helper->GetGwUsers();
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 gwCbrApps;
164 ApplicationContainer gwOnOffApps;
165 ApplicationContainer utCbrSinkApps;
166 ApplicationContainer utOnOffSinkApps;
170 NS_LOG_INFO(
"Creating CBR applications and sinks");
173 Time startDelay = appStartTime;
174 uint32_t cbrGwUserId(0);
175 uint32_t onOffGwUserId(1);
177 if (utCbrUsers.GetN() > 0)
180 PacketSinkHelper cbrSinkHelper(
181 "ns3::UdpSocketFactory",
182 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
183 CbrHelper cbrHelper(
"ns3::UdpSocketFactory",
184 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
185 cbrHelper.SetAttribute(
"Interval", StringValue(interval));
186 cbrHelper.SetAttribute(
"PacketSize", UintegerValue(packetSize));
189 for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
192 InetSocketAddress cbrDest(helper->GetUserAddress(utCbrUsers.Get(i)), port);
193 cbrDest.SetTos(cbrTos);
195 cbrHelper.SetAttribute(
"Remote", AddressValue(Address(cbrDest)));
196 cbrSinkHelper.SetAttribute(
"Local", AddressValue(Address(cbrDest)));
198 gwCbrApps.Add(cbrHelper.Install(gwUsers.Get(cbrGwUserId)));
199 utCbrSinkApps.Add(cbrSinkHelper.Install(utCbrUsers.Get(i)));
201 startDelay += Seconds(0.001);
204 gwCbrApps.Get(i)->SetStartTime(Seconds(0.1));
205 gwCbrApps.Get(i)->SetStopTime(appStopTime);
206 utCbrSinkApps.Get(i)->SetStartTime(startDelay);
207 utCbrSinkApps.Get(i)->SetStopTime(appStopTime);
214 if (utOnOffUsers.GetN() > 0)
216 NS_LOG_INFO(
"Creating OnOff applications and sinks");
218 std::string dataRate =
"100kb/s";
219 std::string onTime =
"2.0";
220 std::string offTime =
"2.0";
222 Config::SetDefault(
"ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
223 Config::SetDefault(
"ns3::OnOffApplication::DataRate", StringValue(dataRate));
224 Config::SetDefault(
"ns3::OnOffApplication::OnTime",
225 StringValue(
"ns3::ConstantRandomVariable[Constant=" + onTime +
"]"));
226 Config::SetDefault(
"ns3::OnOffApplication::OffTime",
227 StringValue(
"ns3::ConstantRandomVariable[Constant=" + offTime +
"]"));
231 PacketSinkHelper onOffSinkHelper(
232 "ns3::UdpSocketFactory",
233 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
234 OnOffHelper onOffHelper(
"ns3::UdpSocketFactory",
235 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
237 startDelay = appStartTime;
240 for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
243 InetSocketAddress onOffDest(helper->GetUserAddress(utOnOffUsers.Get(i)), port);
244 onOffDest.SetTos(onOffTos);
247 onOffHelper.SetAttribute(
"Remote", AddressValue(Address(onOffDest)));
248 onOffSinkHelper.SetAttribute(
"Local", AddressValue(Address(onOffDest)));
250 gwOnOffApps.Add(onOffHelper.Install(gwUsers.Get(onOffGwUserId)));
251 utOnOffSinkApps.Add(onOffSinkHelper.Install(utOnOffUsers.Get(i)));
253 startDelay += Seconds(0.001);
255 gwOnOffApps.Get(i)->SetStartTime(Seconds(0.1));
256 gwOnOffApps.Get(i)->SetStopTime(appStopTime);
257 utOnOffSinkApps.Get(i)->SetStartTime(startDelay);
258 utOnOffSinkApps.Get(i)->SetStopTime(appStopTime);
265 NS_LOG_INFO(
"--- sat-multi-application-fwd-example ---");
266 NS_LOG_INFO(
" Packet size in bytes: " << packetSize);
267 NS_LOG_INFO(
" Packet sending interval: " << interval);
268 NS_LOG_INFO(
" Simulation length: " << simLength);
269 NS_LOG_INFO(
" Number of UTs: " << utsPerBeam);
270 NS_LOG_INFO(
" Number of end users per UT: " << endUsersPerUt);
273 simulationHelper->RunSimulation();
ErrorModel
Error model enum.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.