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));
90 simulationHelper->LoadScenario(
"geo-33E");
93 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
97 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
98 NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
101 Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable>();
103 NodeContainer utCbrUsers;
104 NodeContainer utOnOffUsers;
141 uint8_t onOffTos(0x28);
142 uint8_t cbrTos(0xB8);
145 for (NodeContainer::Iterator i = utUsers.Begin(); i != utUsers.End(); i++)
148 if (rand->GetValue() < cbrProbability)
155 utOnOffUsers.Add(*i);
159 NS_LOG_INFO(
"Number of created CBR users: " << utCbrUsers.GetN()
160 <<
", On-Off users: " << utOnOffUsers.GetN());
162 ApplicationContainer gwCbrApps;
163 ApplicationContainer gwOnOffApps;
164 ApplicationContainer utCbrSinkApps;
165 ApplicationContainer utOnOffSinkApps;
169 NS_LOG_INFO(
"Creating CBR applications and sinks");
172 Time startDelay = appStartTime;
173 uint32_t cbrGwUserId(0);
174 uint32_t onOffGwUserId(1);
176 if (utCbrUsers.GetN() > 0)
179 PacketSinkHelper cbrSinkHelper(
180 "ns3::UdpSocketFactory",
181 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
182 CbrHelper cbrHelper(
"ns3::UdpSocketFactory",
183 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
184 cbrHelper.SetAttribute(
"Interval", StringValue(interval));
185 cbrHelper.SetAttribute(
"PacketSize", UintegerValue(packetSize));
188 for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
191 InetSocketAddress cbrDest(helper->GetUserAddress(utCbrUsers.Get(i)), port);
193 cbrHelper.SetAttribute(
"Remote", AddressValue(Address(cbrDest)));
194 cbrHelper.SetAttribute(
"Tos", UintegerValue(cbrTos));
195 cbrSinkHelper.SetAttribute(
"Local", AddressValue(Address(cbrDest)));
197 gwCbrApps.Add(cbrHelper.Install(gwUsers.Get(cbrGwUserId)));
198 utCbrSinkApps.Add(cbrSinkHelper.Install(utCbrUsers.Get(i)));
200 startDelay += Seconds(0.001);
203 gwCbrApps.Get(i)->SetStartTime(Seconds(0.1));
204 gwCbrApps.Get(i)->SetStopTime(appStopTime);
205 utCbrSinkApps.Get(i)->SetStartTime(startDelay);
206 utCbrSinkApps.Get(i)->SetStopTime(appStopTime);
213 if (utOnOffUsers.GetN() > 0)
215 NS_LOG_INFO(
"Creating OnOff applications and sinks");
217 std::string dataRate =
"100kb/s";
218 std::string onTime =
"2.0";
219 std::string offTime =
"2.0";
221 Config::SetDefault(
"ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
222 Config::SetDefault(
"ns3::OnOffApplication::DataRate", StringValue(dataRate));
223 Config::SetDefault(
"ns3::OnOffApplication::OnTime",
224 StringValue(
"ns3::ConstantRandomVariable[Constant=" + onTime +
"]"));
225 Config::SetDefault(
"ns3::OnOffApplication::OffTime",
226 StringValue(
"ns3::ConstantRandomVariable[Constant=" + offTime +
"]"));
230 PacketSinkHelper onOffSinkHelper(
231 "ns3::UdpSocketFactory",
232 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
233 OnOffHelper onOffHelper(
"ns3::UdpSocketFactory",
234 InetSocketAddress(helper->GetUserAddress(utCbrUsers.Get(0)), port));
236 startDelay = appStartTime;
239 for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
242 InetSocketAddress onOffDest(helper->GetUserAddress(utOnOffUsers.Get(i)), port);
245 onOffHelper.SetAttribute(
"Remote", AddressValue(Address(onOffDest)));
246 onOffHelper.SetAttribute(
"Tos", UintegerValue(onOffTos));
247 onOffSinkHelper.SetAttribute(
"Local", AddressValue(Address(onOffDest)));
249 gwOnOffApps.Add(onOffHelper.Install(gwUsers.Get(onOffGwUserId)));
250 utOnOffSinkApps.Add(onOffSinkHelper.Install(utOnOffUsers.Get(i)));
252 startDelay += Seconds(0.001);
254 gwOnOffApps.Get(i)->SetStartTime(Seconds(0.1));
255 gwOnOffApps.Get(i)->SetStopTime(appStopTime);
256 utOnOffSinkApps.Get(i)->SetStartTime(startDelay);
257 utOnOffSinkApps.Get(i)->SetStopTime(appStopTime);
264 NS_LOG_INFO(
"--- sat-multi-application-fwd-example ---");
265 NS_LOG_INFO(
" Packet size in bytes: " << packetSize);
266 NS_LOG_INFO(
" Packet sending interval: " << interval);
267 NS_LOG_INFO(
" Simulation length: " << simLength);
268 NS_LOG_INFO(
" Number of UTs: " << utsPerBeam);
269 NS_LOG_INFO(
" Number of end users per UT: " << endUsersPerUt);
272 simulationHelper->RunSimulation();
ErrorModel
Error model enum.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.