A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rta-tig-mobile-gaming-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006,2007 INRIA
3 * Copyright (c) 2016 Magister Solutions
4 * Copyright (c) 2025 Tom Henderson
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 * Borrows from examples/wireless/wifi-ap.cc for overall Wi-Fi network setup pattern
9 * Borrows from src/applications/examples/three-gpp-http-example.cc for overall simulation flow
10 */
11
12/**
13 * @file rta-tig-mobile-gaming-example.cc
14 * @brief A simple real-time mobile gaming traffic generator example over Wi-Fi
15 *
16 * This example demonstrates how to set up a basic ns-3 simulation with real-time
17 * mobile gaming traffic over a Wi-Fi network. Real-time mobile gaming is characterized
18 * by small packets (30-500 bytes) sent frequently (every 30-60ms) with low latency
19 * requirements.
20 *
21 * The simulation consists of:
22 * - A simple Wi-Fi network with one AP (Access Point) and one STA (Station)
23 * - Gaming traffic with three stages: Initial, Gaming, and Ending
24 * - Application-level tracing to observe gaming packets and stage transitions
25 *
26 * The traffic model follows IEEE 802.11-18/2009r6 RTA TIG Report (Section 4.1.4):
27 * - Two synchronization mechanisms: Status Sync and Frame Lockstep Sync
28 * - Packet sizes and arrivals follow Largest Extreme Value distribution
29 * - Initial and end packets follow Uniform distribution
30 *
31 * Traffic model presets:
32 * - Status Sync DL: a=13ms, b=3.7ms arrivals; a=50, b=11 bytes sizes
33 * - Status Sync UL: a=15ms, b=5.7ms arrivals; a=38, b=3.7 bytes sizes
34 * - Lockstep DL: a=28ms, b=4.2ms arrivals; a=210, b=35 bytes sizes
35 * - Lockstep UL: a=22ms, b=3.4ms arrivals; a=92, b=38 bytes sizes
36 *
37 * To run with default (status-sync DL): ./ns3 run rta-tig-mobile-gaming-example
38 * To run status-sync UL: ./ns3 run "rta-tig-mobile-gaming-example --model=status-sync-ul"
39 * To run lockstep DL: ./ns3 run "rta-tig-mobile-gaming-example --model=lockstep-dl"
40 * To run lockstep UL: ./ns3 run "rta-tig-mobile-gaming-example --model=lockstep-ul"
41 *
42 * To disable verbose logging: ./ns3 run "rta-tig-mobile-gaming-example --verbose=false"
43 */
44
45#include "ns3/applications-module.h"
46#include "ns3/core-module.h"
47#include "ns3/internet-module.h"
48#include "ns3/mobility-module.h"
49#include "ns3/network-module.h"
50#include "ns3/wifi-module.h"
51
52using namespace ns3;
53
54NS_LOG_COMPONENT_DEFINE("RtaTigMobileGamingExample");
55
56/**
57 * Callback invoked when a gaming packet is transmitted
58 * @param context The context string
59 * @param packet The transmitted packet
60 * @param stage The traffic model stage
61 */
62void GamingPacketSent(std::string context,
63 Ptr<const Packet> packet,
65
66/**
67 * Callback invoked when the PacketSink receives a packet
68 * @param context The context string
69 * @param packet The received packet
70 * @param address The sender's address
71 */
72void PacketReceived(std::string context, Ptr<const Packet> packet, const Address& address);
73
74int
75main(int argc, char* argv[])
76{
77 Time duration{Seconds(10)}; // Simulation time in seconds
78 std::string model{"status-sync-dl"}; // Traffic model preset
79 bool verbose = true; // Enable/disable verbose logging
80
81 CommandLine cmd(__FILE__);
82 cmd.Usage("Real-time mobile gaming traffic example");
83 cmd.AddValue("duration", "Duration of traffic flow, in seconds", duration);
84 cmd.AddValue("model",
85 "Traffic model preset (status-sync-dl, status-sync-ul, lockstep-dl, lockstep-ul). "
86 "Default: status-sync-dl",
87 model);
88 cmd.AddValue("verbose",
89 "Enable verbose logging of RtaTigMobileGaming, PacketSink, and this program",
90 verbose);
91 cmd.Parse(argc, argv);
92
93 if (verbose)
94 {
96 "RtaTigMobileGamingExample",
99 "RtaTigMobileGaming",
102 "PacketSink",
104 }
105
106 NodeContainer wifiNodes;
107 wifiNodes.Create(2); // Create 2 nodes: one will be AP, one will be STA
108
109 Ptr<Node> apNode = wifiNodes.Get(0);
110 Ptr<Node> staNode = wifiNodes.Get(1);
111
114 phy.SetChannel(channel.Create());
115
118 wifi.SetStandard(WIFI_STANDARD_80211ax);
119
122
123 // Configure AP
124 Ssid ssid = Ssid("gaming-network");
125 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
126 apDevices = wifi.Install(phy, mac, apNode);
127
128 // Configure STA
129 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
130 staDevices = wifi.Install(phy, mac, staNode);
131
133 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
134 "MinX",
135 DoubleValue(0.0),
136 "MinY",
137 DoubleValue(0.0),
138 "DeltaX",
139 DoubleValue(5.0),
140 "DeltaY",
141 DoubleValue(5.0),
142 "GridWidth",
143 UintegerValue(2),
144 "LayoutType",
145 StringValue("RowFirst"));
146 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
147 mobility.Install(wifiNodes);
148
150 internet.Install(wifiNodes);
151
153 ipv4.SetBase("10.1.1.0", "255.255.255.0");
154
155 NetDeviceContainer allDevices;
156 allDevices.Add(apDevices);
157 allDevices.Add(staDevices);
158 Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign(allDevices);
159
160 NS_LOG_INFO("AP address: " << ipv4Interfaces.GetAddress(0));
161 NS_LOG_INFO("STA address: " << ipv4Interfaces.GetAddress(1));
162
163 // Gaming uses UDP as specified
164 std::string protocolFactory = "ns3::UdpSocketFactory";
165 uint16_t port = 5000;
166
168 sourceHelper.SetAttribute("Protocol", TypeIdValue(TypeId::LookupByName(protocolFactory)));
169
170 // Configure traffic model parameters based on preset
171 // Parameters from IEEE 802.11-18/2009r6 Tables 4-3 and 4-4
172 Ptr<Node> sourceNode;
173 Ptr<Node> sinkNode;
174 std::string remoteAddress;
175
176 if (model == "status-sync-dl")
177 {
178 // Downlink: AP -> STA
179 sourceNode = apNode;
180 sinkNode = staNode;
181 remoteAddress = "10.1.1.2";
182
183 // Status-sync DL parameters (defaults)
184 // Initial: [0, 20], End: [500, 600]
185 // Arrivals: LEV(13ms, 3.7ms), Sizes: LEV(50, 11)
186 NS_LOG_INFO("Using Status-Sync Downlink model (default parameters)");
187 }
188 else if (model == "status-sync-ul")
189 {
190 // Uplink: STA -> AP
191 sourceNode = staNode;
192 sinkNode = apNode;
193 remoteAddress = "10.1.1.1";
194
195 // Status-sync UL parameters
197 DoubleValue(0),
198 "Max",
199 DoubleValue(20));
200 sourceHelper.SetAttribute("InitialPacketSize", PointerValue(ips));
201
203 DoubleValue(400),
204 "Max",
205 DoubleValue(550));
206 sourceHelper.SetAttribute("EndPacketSize", PointerValue(eps));
207
209 "Location",
210 DoubleValue(15000), // 15ms in us
211 "Scale",
212 DoubleValue(5700)); // 5.7ms in us
213 sourceHelper.SetAttribute("PacketArrivalLev", PointerValue(pal));
214
216 DoubleValue(38),
217 "Scale",
218 DoubleValue(3.7));
219 sourceHelper.SetAttribute("PacketSizeLev", PointerValue(psl));
220
221 NS_LOG_INFO("Using Status-Sync Uplink model");
222 }
223 else if (model == "lockstep-dl")
224 {
225 // Downlink: AP -> STA
226 sourceNode = apNode;
227 sinkNode = staNode;
228 remoteAddress = "10.1.1.2";
229
230 // Lockstep DL parameters
232 DoubleValue(0),
233 "Max",
234 DoubleValue(80));
235 sourceHelper.SetAttribute("InitialPacketSize", PointerValue(ips));
236
238 DoubleValue(1400),
239 "Max",
240 DoubleValue(1500));
241 sourceHelper.SetAttribute("EndPacketSize", PointerValue(eps));
242
244 "Location",
245 DoubleValue(28000), // 28ms in us
246 "Scale",
247 DoubleValue(4200)); // 4.2ms in us
248 sourceHelper.SetAttribute("PacketArrivalLev", PointerValue(pal));
249
251 DoubleValue(210),
252 "Scale",
253 DoubleValue(35));
254 sourceHelper.SetAttribute("PacketSizeLev", PointerValue(psl));
255
256 NS_LOG_INFO("Using Frame Lockstep Downlink model");
257 }
258 else if (model == "lockstep-ul")
259 {
260 // Uplink: STA -> AP
261 sourceNode = staNode;
262 sinkNode = apNode;
263 remoteAddress = "10.1.1.1";
264
265 // Lockstep UL parameters
267 DoubleValue(0),
268 "Max",
269 DoubleValue(80));
270 sourceHelper.SetAttribute("InitialPacketSize", PointerValue(ips));
271
273 DoubleValue(500),
274 "Max",
275 DoubleValue(600));
276 sourceHelper.SetAttribute("EndPacketSize", PointerValue(eps));
277
279 "Location",
280 DoubleValue(22000), // 22ms in us
281 "Scale",
282 DoubleValue(3400)); // 3.4ms in us
283 sourceHelper.SetAttribute("PacketArrivalLev", PointerValue(pal));
284
286 DoubleValue(92),
287 "Scale",
288 DoubleValue(38));
289 sourceHelper.SetAttribute("PacketSizeLev", PointerValue(psl));
290
291 NS_LOG_INFO("Using Frame Lockstep Uplink model");
292 }
293 else
294 {
296 "Invalid model: "
297 << model
298 << ". Use 'status-sync-dl', 'status-sync-ul', 'lockstep-dl', or 'lockstep-ul'.");
299 }
300
302 sourceHelper.SetAttribute("Remote", AddressValue(remoteAddr));
303
304 auto sourceApps = sourceHelper.Install(sourceNode);
305 sourceApps.Start(Seconds(1.0));
306 sourceApps.Stop(Seconds(1.0) + duration);
307
308 PacketSinkHelper sinkHelper(protocolFactory, InetSocketAddress(Ipv4Address::GetAny(), port));
309 auto sinkApps = sinkHelper.Install(sinkNode);
310 sinkApps.Start(Seconds(0.0));
311 sinkApps.Stop(Seconds(2.0) + duration);
312
313 // Connect to gaming TX with stage trace
314 Config::Connect("/NodeList/*/ApplicationList/*/$ns3::RtaTigMobileGaming/TxWithStage",
316
317 // Connect to RX trace
318 Config::Connect("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
320
321 NS_LOG_INFO("Starting simulation for traffic duration: " << duration.As(Time::S));
322 NS_LOG_INFO("Traffic model: " << model);
323
324 Simulator::Stop(Seconds(2) + duration);
326
327 // Get statistics from packet sink
329 if (sink)
330 {
331 uint32_t bytesRx = sink->GetTotalRx();
332 NS_LOG_INFO("Total bytes received: " << bytesRx);
333 }
334
336
337 return 0;
338}
339
340void
341GamingPacketSent(std::string context,
342 Ptr<const Packet> packet,
344{
345 NS_LOG_INFO("Gaming TX [" << context << "]: Packet size (bytes): " << packet->GetSize()
346 << " Stage: " << stage);
347}
348
349void
350PacketReceived(std::string context, Ptr<const Packet> packet, const Address& address)
351{
352 NS_LOG_INFO("Packet RX [" << context << "]: Size(bytes): " << packet->GetSize());
353}
a polymophic address class
Definition address.h:114
AttributeValue implementation for Address.
Definition address.h:329
A helper to make it easier to instantiate an application on a set of nodes.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
AttributeValue implementation for Pointer.
Definition pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static TypeId GetTypeId()
Get the type ID.
TrafficModelStage
Traffic model stages.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
AttributeValue implementation for Ssid.
Definition ssid.h:85
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:408
@ S
second
Definition nstime.h:106
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:870
AttributeValue implementation for TypeId.
Definition type-id.h:649
Hold an unsigned integer type.
Definition uinteger.h:34
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Make it easy to create and manage PHY objects for the YANS model.
uint16_t port
Definition dsdv-manet.cc:33
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:970
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
@ WIFI_STANDARD_80211ax
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition log.cc:279
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:605
LogLevel
Logging severity classes and levels.
Definition log.h:86
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:108
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Definition log.h:110
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
Definition log.h:111
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
Definition log.h:112
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:96
staDevices
Definition third.py:87
ssid
Definition third.py:82
channel
Definition third.py:77
mac
Definition third.py:81
wifi
Definition third.py:84
apDevices
Definition third.py:90
mobility
Definition third.py:92
phy
Definition third.py:78
bool verbose
void PacketReceived(std::string context, Ptr< const Packet > packet, const Address &address)
Callback invoked when the PacketSink receives a packet.
void GamingPacketSent(std::string context, Ptr< const Packet > packet, RtaTigMobileGaming::TrafficModelStage stage)
Callback invoked when a gaming packet is transmitted.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44