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 = Singleton<SatTopology>::Get()->GetUtNode(node);
68 NodeContainer nodeUsers;
72 nodeUsers = Singleton<SatTopology>::Get()->GetUtUserNodes(utNode);
74 << Singleton<SatIdMapper>::Get()->GetUtIdWithMac(
75 Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode))
80 nodeUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
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(Singleton<SatTopology>::Get()->GetGwUserNodes(),
160 Singleton<SatTopology>::Get()->GetUtUserNodes());
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!!!");
302 simulationHelper->LoadScenario(
"geo-33E");
305 Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
307 NS_LOG_INFO(
"--- Creating scenario: " << scenario <<
" ---");
311 NS_LOG_INFO(
"--- Add sink to each users ---");
314 uint16_t multicastPort = 9;
317 NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
318 NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
320 if (scenario ==
"larger")
322 uint32_t currentGroup = preDefinedGroup;
324 if (preDefinedGroup == ALL_GROUPS)
329 for (uint32_t i = currentGroup; i < END_OF_GROUP; i++)
331 groupReceivers = NodeContainer();
338 groupSource = gwUsers.Get(0);
339 groupReceivers.Add(utUsers.Get(0));
340 groupReceivers.Add(utUsers.Get(1));
341 groupReceivers.Add(utUsers.Get(2));
342 groupReceivers.Add(utUsers.Get(3));
343 groupReceivers.Add(utUsers.Get(4));
349 groupSource = gwUsers.Get(0);
350 groupReceivers.Add(utUsers.Get(1));
351 groupReceivers.Add(utUsers.Get(2));
352 groupReceivers.Add(utUsers.Get(4));
358 groupSource = utUsers.Get(0);
359 groupReceivers.Add(utUsers.Get(1));
360 groupReceivers.Add(utUsers.Get(2));
361 groupReceivers.Add(utUsers.Get(4));
366 groupSource = utUsers.Get(1);
367 groupReceivers.Add(utUsers.Get(2));
368 groupReceivers.Add(utUsers.Get(4));
373 groupSource = utUsers.Get(0);
374 groupReceivers.Add(utUsers.Get(3));
375 groupReceivers.Add(utUsers.Get(4));
380 groupSource = utUsers.Get(1);
381 groupReceivers.Add(utUsers.Get(2));
382 groupReceivers.Add(gwUsers.Get(0));
387 groupSource = utUsers.Get(0);
388 groupReceivers.Add(gwUsers.Get(0));
393 groupSource = utUsers.Get(1);
394 groupReceivers.Add(utUsers.Get(2));
399 groupSource = utUsers.Get(0);
400 groupReceivers.Add(gwUsers.Get(0));
401 groupReceivers.Add(utUsers.Get(4));
406 groupSource = utUsers.Get(0);
407 groupReceivers.Add(utUsers.Get(3));
412 groupSource = utUsers.Get(0);
413 groupReceivers.Add(utUsers.Get(4));
418 groupSource = utUsers.Get(0);
419 groupReceivers.Add(utUsers.Get(2));
423 NS_FATAL_ERROR(
"Not supported pre-defined group!!!");
427 NS_LOG_INFO(
"--- Creating multicast pre-defined group " << preDefinedGroup <<
" ---");
431 std::stringstream groupAddress;
432 groupAddress <<
"225.1." << i <<
".1";
433 Ipv4Address multicastGroup(groupAddress.str().c_str());
446 NS_LOG_INFO(
"--- Creating multicast group in full scenario ---");
449 NodeContainer users = NodeContainer(gwUsers, utUsers);
452 std::vector<uint32_t> sources;
453 sources.push_back(std::rand() % gwUsers.GetN());
454 sources.push_back((std::rand() % utUsers.GetN()) + gwUsers.GetN());
457 for (uint32_t i = 0; i < sources.size(); i++)
459 std::vector<uint32_t> ids;
461 for (uint32_t j = 0; j < users.GetN(); j++)
471 std::random_shuffle(ids.begin(), ids.end());
474 groupSource = users.Get(sources[i]);
477 groupReceivers = NodeContainer();
479 for (uint32_t j = 0; ((j < fullScenarioReceivers) && (j < ids.size())); j++)
481 groupReceivers.Add(users.Get(ids.at(j)));
484 std::stringstream groupAddress;
485 groupAddress <<
"225.1." << i <<
".1";
486 Ipv4Address multicastGroup(groupAddress.str().c_str());
498 NS_LOG_INFO(
"--- Running simulation ---");
500 simulationHelper->RunSimulation();
502 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.