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));
95 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
99 NodeContainer utUsers = helper->GetUtUsers();
100 NodeContainer gwUsers = helper->GetGwUsers();
103 Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable>();
105 NodeContainer utCbrUsers;
106 NodeContainer utOnOffUsers;
143 uint8_t onOffTos(0x28);
144 uint8_t cbrTos(0xB8);
147 for (NodeContainer::Iterator i = utUsers.Begin(); i != utUsers.End(); i++)
150 if (rand->GetValue() < cbrProbability)
157 utOnOffUsers.Add(*i);
161 NS_LOG_INFO(
"Number of created CBR users: " << utCbrUsers.GetN()
162 <<
", On-Off users: " << utOnOffUsers.GetN());
164 ApplicationContainer gwCbrSinkApps;
165 ApplicationContainer gwOnOffSinkApps;
166 ApplicationContainer utCbrApps;
167 ApplicationContainer utOnOffApps;
171 NS_LOG_INFO(
"Creating CBR applications and sinks");
174 Time startDelay = appStartTime;
176 uint32_t cbrGwUserId(0);
177 uint32_t onOffGwUserId(1);
179 if (utCbrUsers.GetN() > 0)
182 PacketSinkHelper cbrSinkHelper(
183 "ns3::UdpSocketFactory",
184 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
186 "ns3::UdpSocketFactory",
187 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
188 cbrHelper.SetAttribute(
"Interval", StringValue(interval));
189 cbrHelper.SetAttribute(
"PacketSize", UintegerValue(packetSize));
192 InetSocketAddress cbrDest(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port);
193 cbrDest.SetTos(cbrTos);
196 gwCbrSinkApps.Add(cbrSinkHelper.Install(gwUsers.Get(cbrGwUserId)));
197 gwCbrSinkApps.Get(0)->SetStartTime(Seconds(0.1));
198 gwCbrSinkApps.Get(0)->SetStopTime(appStopTime);
200 for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
202 cbrHelper.SetAttribute(
"Remote", AddressValue(Address(cbrDest)));
203 cbrSinkHelper.SetAttribute(
"Local", AddressValue(Address(cbrDest)));
205 utCbrApps.Add(cbrHelper.Install(utCbrUsers.Get(i)));
207 startDelay += Seconds(0.001);
210 utCbrApps.Get(i)->SetStartTime(startDelay);
211 utCbrApps.Get(i)->SetStopTime(appStopTime);
218 if (utOnOffUsers.GetN() > 0)
220 NS_LOG_INFO(
"Creating OnOff applications and sinks");
222 std::string dataRate =
"100kb/s";
223 std::string onTime =
"2.0";
224 std::string offTime =
"2.0";
226 Config::SetDefault(
"ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
227 Config::SetDefault(
"ns3::OnOffApplication::DataRate", StringValue(dataRate));
228 Config::SetDefault(
"ns3::OnOffApplication::OnTime",
229 StringValue(
"ns3::ConstantRandomVariable[Constant=" + onTime +
"]"));
230 Config::SetDefault(
"ns3::OnOffApplication::OffTime",
231 StringValue(
"ns3::ConstantRandomVariable[Constant=" + offTime +
"]"));
235 PacketSinkHelper onOffSinkHelper(
236 "ns3::UdpSocketFactory",
237 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
238 OnOffHelper onOffHelper(
"ns3::UdpSocketFactory",
239 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
241 startDelay = appStartTime;
244 InetSocketAddress onOffDest(helper->GetUserAddress(gwUsers.Get(onOffGwUserId)), port);
245 onOffDest.SetTos(onOffTos);
248 gwOnOffSinkApps.Add(onOffSinkHelper.Install(gwUsers.Get(onOffGwUserId)));
249 gwOnOffSinkApps.Get(0)->SetStartTime(Seconds(0.1));
250 gwOnOffSinkApps.Get(0)->SetStopTime(appStopTime);
252 for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
254 onOffHelper.SetAttribute(
"Remote", AddressValue(Address(onOffDest)));
255 onOffSinkHelper.SetAttribute(
"Local", AddressValue(Address(onOffDest)));
257 utOnOffApps.Add(onOffHelper.Install(utOnOffUsers.Get(i)));
259 startDelay += Seconds(0.001);
261 utOnOffApps.Get(i)->SetStartTime(startDelay);
262 utOnOffApps.Get(i)->SetStopTime(appStopTime);
269 NS_LOG_INFO(
"--- sat-multi-application-rtn-example ---");
270 NS_LOG_INFO(
" Packet size in bytes: " << packetSize);
271 NS_LOG_INFO(
" Packet sending interval: " << interval);
272 NS_LOG_INFO(
" Simulation length: " << simLength);
273 NS_LOG_INFO(
" Number of UTs: " << utsPerBeam);
274 NS_LOG_INFO(
" Number of end users per UT: " << endUsersPerUt);
277 simulationHelper->RunSimulation();
ErrorModel
Error model enum.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.