22 #include "ns3/applications-module.h"
23 #include "ns3/core-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/network-module.h"
26 #include "ns3/satellite-module.h"
27 #include "ns3/traffic-module.h"
43 NS_LOG_COMPONENT_DEFINE(
"sat-multicast-example");
51 SinkReceive(std::string context, Ptr<const Packet>,
const Address&)
53 NS_LOG_INFO(
" Packet received from/by: " << context);
67 Ptr<Node> utNode = helper->GetUserHelper()->GetUtNode(node);
68 NodeContainer nodeUsers;
72 nodeUsers = helper->GetUserHelper()->GetUtUsers(utNode);
74 << Singleton<SatIdMapper>::Get()->GetUtIdWithMac(
75 Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode))
80 nodeUsers = helper->GetUserHelper()->GetGwUsers();
84 uint32_t userIndex = 0;
86 for (uint32_t j = 0; ((j < nodeUsers.GetN()) && (userIndex == 0)); j++)
88 if (nodeUsers.Get(j) == node)
123 NodeContainer groupReceivers,
124 Ipv4Address groupAddress,
129 Time time = startTime;
131 NS_LOG_INFO(
"--- Create multicast group " << groupAddress <<
" ---");
133 helper->SetMulticastGroupRoutes(source,
135 helper->GetUserAddress(source),
138 NS_LOG_INFO(
"--- Creating traffic generator for " << groupAddress <<
" ---");
141 CbrHelper cbrHelper(
"ns3::UdpSocketFactory", InetSocketAddress(groupAddress, port));
142 cbrHelper.SetAttribute(
"Interval", StringValue(
"0.4s"));
143 cbrHelper.SetAttribute(
"PacketSize", UintegerValue(512));
145 ApplicationContainer cbr = cbrHelper.Install(source);
146 cbr.Start(startTime + Seconds(0.4));
147 cbr.Stop(startTime + Seconds(1.0));
149 NS_LOG_INFO(
"--- Group " << groupAddress <<
" source: " <<
GetUserInfo(helper, source)
152 ApplicationContainer sink;
154 std::stringstream receiverInfo;
155 receiverInfo <<
"--- Group " << groupAddress <<
" receivers: ";
159 NodeContainer users = NodeContainer(helper->GetUserHelper()->GetGwUsers(),
160 helper->GetUserHelper()->GetUtUsers());
162 PacketSinkHelper sinkHelperGroup(
"ns3::UdpSocketFactory",
163 InetSocketAddress(groupAddress, port));
166 for (uint32_t i = 0; i < users.GetN(); i++)
168 sink.Add(sinkHelperGroup.Install(users.Get(i)));
170 std::string nodeName =
GetUserInfo(helper, users.Get(i));
171 std::stringstream context;
172 context << groupAddress <<
"/" << nodeName;
174 DynamicCast<PacketSink>(sink.Get(i))
175 ->TraceConnect(
"Rx", context.str(), MakeCallback(&
SinkReceive));
179 for (uint32_t i = 0; i < groupReceivers.GetN(); i++)
181 std::string nodeName =
GetUserInfo(helper, groupReceivers.Get(i));
182 receiverInfo << nodeName <<
" ";
187 PacketSinkHelper sinkHelperGroup(
"ns3::UdpSocketFactory",
188 InetSocketAddress(groupAddress, port));
191 for (uint32_t i = 0; i < groupReceivers.GetN(); i++)
193 sink.Add(sinkHelperGroup.Install(groupReceivers.Get(i)));
195 std::string nodeName =
GetUserInfo(helper, groupReceivers.Get(i));
196 receiverInfo << nodeName <<
" ";
198 std::stringstream context;
199 context << groupAddress <<
"/" << nodeName;
201 DynamicCast<PacketSink>(sink.Get(i))
202 ->TraceConnect(
"Rx", context.str(), MakeCallback(&
SinkReceive));
206 receiverInfo <<
"---";
207 NS_LOG_INFO(receiverInfo.str());
209 sink.Start(startTime);
210 sink.Stop(startTime + Seconds(2));
212 Simulator::Schedule(startTime + Seconds(1.41), &
LogEmptyLine);
214 return startTime + Seconds(1);
218 main(
int argc,
char* argv[])
221 LogComponentEnable(
"CbrApplication", LOG_LEVEL_INFO);
222 LogComponentEnable(
"PacketSink", LOG_LEVEL_INFO);
223 LogComponentEnable(
"sat-multicast-example", LOG_LEVEL_INFO);
225 NS_LOG_INFO(
"--- Starting sat-multicast-example ---");
245 uint32_t preDefinedGroup = (uint32_t)GROUP_1;
246 uint32_t fullScenarioReceivers = 10;
247 std::string scenario =
"larger";
249 bool sinkToAll =
false;
252 Ptr<Node> groupSource;
253 NodeContainer groupReceivers;
256 auto simulationHelper = CreateObject<SimulationHelper>(
"example-multicast");
257 Config::SetDefault(
"ns3::SatHelper::ScenarioCreationTraceEnabled", BooleanValue(
true));
258 Config::SetDefault(
"ns3::SatHelper::PacketTraceEnabled", BooleanValue(
true));
262 cmd.AddValue(
"scenario",
"Test scenario to use. (larger or full", scenario);
263 cmd.AddValue(
"preDefinedGroup",
264 "Pre-defined multicast group for larger scenario. (0 = all)",
266 cmd.AddValue(
"fullScenarioReceivers",
267 "Number of the receivers in full scenario",
268 fullScenarioReceivers);
269 cmd.AddValue(
"sinkToAll",
"Add multicast sink to all users.", sinkToAll);
270 simulationHelper->AddDefaultUiArguments(cmd);
271 cmd.Parse(argc, argv);
274 Config::SetDefault(
"ns3::SatUserHelper::BackboneNetworkType",
276 Config::SetDefault(
"ns3::SatUserHelper::SubscriberNetworkType",
279 Time startTime = Seconds(1.2);
280 simulationHelper->SetOutputTag(scenario);
281 simulationHelper->SetSimulationTime(startTime + Seconds(3.0));
283 if (scenario ==
"larger")
287 else if (scenario ==
"full")
293 NS_FATAL_ERROR(satScenario <<
" not supported!!!");
306 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
308 NS_LOG_INFO(
"--- Creating scenario: " << scenario <<
" ---");
312 NS_LOG_INFO(
"--- Add sink to each users ---");
315 uint16_t multicastPort = 9;
318 NodeContainer utUsers = helper->GetUtUsers();
319 NodeContainer gwUsers = helper->GetGwUsers();
321 if (scenario ==
"larger")
323 uint32_t currentGroup = preDefinedGroup;
325 if (preDefinedGroup == ALL_GROUPS)
330 for (uint32_t i = currentGroup; i < END_OF_GROUP; i++)
332 groupReceivers = NodeContainer();
339 groupSource = gwUsers.Get(0);
340 groupReceivers.Add(utUsers.Get(0));
341 groupReceivers.Add(utUsers.Get(1));
342 groupReceivers.Add(utUsers.Get(2));
343 groupReceivers.Add(utUsers.Get(3));
344 groupReceivers.Add(utUsers.Get(4));
350 groupSource = gwUsers.Get(0);
351 groupReceivers.Add(utUsers.Get(1));
352 groupReceivers.Add(utUsers.Get(2));
353 groupReceivers.Add(utUsers.Get(4));
359 groupSource = utUsers.Get(0);
360 groupReceivers.Add(utUsers.Get(1));
361 groupReceivers.Add(utUsers.Get(2));
362 groupReceivers.Add(utUsers.Get(4));
367 groupSource = utUsers.Get(1);
368 groupReceivers.Add(utUsers.Get(2));
369 groupReceivers.Add(utUsers.Get(4));
374 groupSource = utUsers.Get(0);
375 groupReceivers.Add(utUsers.Get(3));
376 groupReceivers.Add(utUsers.Get(4));
381 groupSource = utUsers.Get(1);
382 groupReceivers.Add(utUsers.Get(2));
383 groupReceivers.Add(gwUsers.Get(0));
388 groupSource = utUsers.Get(0);
389 groupReceivers.Add(gwUsers.Get(0));
394 groupSource = utUsers.Get(1);
395 groupReceivers.Add(utUsers.Get(2));
400 groupSource = utUsers.Get(0);
401 groupReceivers.Add(gwUsers.Get(0));
402 groupReceivers.Add(utUsers.Get(4));
407 groupSource = utUsers.Get(0);
408 groupReceivers.Add(utUsers.Get(3));
413 groupSource = utUsers.Get(0);
414 groupReceivers.Add(utUsers.Get(4));
419 groupSource = utUsers.Get(0);
420 groupReceivers.Add(utUsers.Get(2));
424 NS_FATAL_ERROR(
"Not supported pre-defined group!!!");
428 NS_LOG_INFO(
"--- Creating multicast pre-defined group " << preDefinedGroup <<
" ---");
432 std::stringstream groupAddress;
433 groupAddress <<
"225.1." << i <<
".1";
434 Ipv4Address multicastGroup(groupAddress.str().c_str());
447 NS_LOG_INFO(
"--- Creating multicast group in full scenario ---");
450 NodeContainer users = NodeContainer(gwUsers, utUsers);
453 std::vector<uint32_t> sources;
454 sources.push_back(std::rand() % gwUsers.GetN());
455 sources.push_back((std::rand() % utUsers.GetN()) + gwUsers.GetN());
458 for (uint32_t i = 0; i < sources.size(); i++)
460 std::vector<uint32_t> ids;
462 for (uint32_t j = 0; j < users.GetN(); j++)
472 std::random_shuffle(ids.begin(), ids.end());
475 groupSource = users.Get(sources[i]);
478 groupReceivers = NodeContainer();
480 for (uint32_t j = 0; ((j < fullScenarioReceivers) && (j < ids.size())); j++)
482 groupReceivers.Add(users.Get(ids.at(j)));
485 std::stringstream groupAddress;
486 groupAddress <<
"225.1." << i <<
".1";
487 Ipv4Address multicastGroup(groupAddress.str().c_str());
499 NS_LOG_INFO(
"--- Running simulation ---");
501 simulationHelper->RunSimulation();
503 NS_LOG_INFO(
"--- Finished ---");
PreDefinedScenario_t
Values for pre-defined scenarios to be used by helper when building satellite network topology base.
@ LARGER
LARGER Larger scenario used as base.
@ FULL
FULL Full scenario used as base.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static std::string GetUserInfo(Ptr< SatHelper > helper, Ptr< Node > node)
Construct information of the given user node.
static Time EstablishMulticastGroup(Ptr< SatHelper > helper, Ptr< Node > source, NodeContainer groupReceivers, Ipv4Address groupAddress, uint16_t port, Time startTime, bool sinkToAll)
Establish multicast group and generate traffic in that group.
static void SinkReceive(std::string context, Ptr< const Packet >, const Address &)
Receive RX traces from packet sinks.
static void LogEmptyLine()
Log empty line.