A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rta-tig-mobile-gaming.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 DERONNE SOFTWARE ENGINEERING
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
10
11#include "ns3/double.h"
12#include "ns3/enum.h"
13#include "ns3/inet-socket-address.h"
14#include "ns3/inet6-socket-address.h"
15#include "ns3/log.h"
16#include "ns3/node.h"
17#include "ns3/nstime.h"
18#include "ns3/packet-socket-address.h"
19#include "ns3/packet.h"
20#include "ns3/pointer.h"
21#include "ns3/random-variable-stream.h"
22#include "ns3/simulator.h"
23#include "ns3/socket-factory.h"
24#include "ns3/socket.h"
25#include "ns3/string.h"
26#include "ns3/udp-socket-factory.h"
27
28#include <cmath>
29
30namespace ns3
31{
32
33NS_LOG_COMPONENT_DEFINE("RtaTigMobileGaming");
34
36
39{
40 static TypeId tid =
41 TypeId("ns3::RtaTigMobileGaming")
43 .SetGroupName("Applications")
44 .AddConstructor<RtaTigMobileGaming>()
45 .AddAttribute("ModelPresets",
46 "The model presets to use (Custom for custom settings)",
48 TypeId::ATTR_CONSTRUCT, // prevent setting after construction
52 "Custom",
54 "StatusSyncDl",
56 "StatusSyncUl",
58 "LockstepDl",
60 "LockstepUl"))
61 .AddAttribute(
62 "Protocol",
63 "The type of protocol to use. This should be a subclass of ns3::SocketFactory",
67 .AddAttribute(
68 "CustomInitialPacketSize",
69 "A uniform random variable to generate size in bytes for initial packet payload.",
70 StringValue("ns3::UniformRandomVariable[Min=0|Max=20]"),
73 .AddAttribute(
74 "CustomEndPacketSize",
75 "A uniform random variable to generate size in bytes for end packet payload.",
76 StringValue("ns3::UniformRandomVariable[Min=500|Max=600]"),
79 .AddAttribute(
80 "CustomPacketSizeLev",
81 "A largest extreme value random variable to calculate packet sizes in bytes.",
82 StringValue("ns3::LargestExtremeValueRandomVariable[Location=50|Scale=11.0]"),
85 .AddAttribute(
86 "CustomPacketArrivalLev",
87 "A largest extreme value random variable to calculate packet packet arrivals in "
88 "microseconds.",
89 StringValue("ns3::LargestExtremeValueRandomVariable[Location=13000|Scale=3700]"),
92 .AddTraceSource("TxWithStage",
93 "A packet is sent, this trace also reports the current stage",
95 "ns3::RtaTigMobileGaming::TxTracedCallback");
96 return tid;
97}
98
103
108
109int64_t
111{
112 NS_LOG_FUNCTION(this << stream);
113 auto currentStream = stream;
114 m_initialSizeUniform->SetStream(currentStream++);
115 m_endSizeUniform->SetStream(currentStream++);
116 m_levArrivals->SetStream(currentStream++);
117 m_levSizes->SetStream(currentStream++);
118 return (currentStream - stream);
119}
120
121void
123{
124 NS_LOG_FUNCTION(this);
126
128 {
129 // Load model presets
130 switch (m_modelPresets)
131 {
133 m_initialSizeUniform->SetAttribute("Min", DoubleValue(0));
134 m_initialSizeUniform->SetAttribute("Max", DoubleValue(20));
135 m_endSizeUniform->SetAttribute("Min", DoubleValue(500));
136 m_endSizeUniform->SetAttribute("Max", DoubleValue(600));
137 m_levSizes->SetAttribute("Location", DoubleValue(50.0));
138 m_levSizes->SetAttribute("Scale", DoubleValue(11.0));
139 m_levArrivals->SetAttribute("Location", DoubleValue(13000.0));
140 m_levArrivals->SetAttribute("Scale", DoubleValue(3700.0));
141 break;
143 m_initialSizeUniform->SetAttribute("Min", DoubleValue(0));
144 m_initialSizeUniform->SetAttribute("Max", DoubleValue(20));
145 m_endSizeUniform->SetAttribute("Min", DoubleValue(400));
146 m_endSizeUniform->SetAttribute("Max", DoubleValue(550));
147 m_levSizes->SetAttribute("Location", DoubleValue(38.0));
148 m_levSizes->SetAttribute("Scale", DoubleValue(3.7));
149 m_levArrivals->SetAttribute("Location", DoubleValue(15000.0));
150 m_levArrivals->SetAttribute("Scale", DoubleValue(5700.0));
151 break;
153 m_initialSizeUniform->SetAttribute("Min", DoubleValue(0));
154 m_initialSizeUniform->SetAttribute("Max", DoubleValue(80));
155 m_endSizeUniform->SetAttribute("Min", DoubleValue(1400));
156 m_endSizeUniform->SetAttribute("Max", DoubleValue(1500));
157 m_levSizes->SetAttribute("Location", DoubleValue(210.0));
158 m_levSizes->SetAttribute("Scale", DoubleValue(35.0));
159 m_levArrivals->SetAttribute("Location", DoubleValue(28000.0));
160 m_levArrivals->SetAttribute("Scale", DoubleValue(4200.0));
161 break;
163 m_initialSizeUniform->SetAttribute("Min", DoubleValue(0));
164 m_initialSizeUniform->SetAttribute("Max", DoubleValue(80));
165 m_endSizeUniform->SetAttribute("Min", DoubleValue(500));
166 m_endSizeUniform->SetAttribute("Max", DoubleValue(600));
167 m_levSizes->SetAttribute("Location", DoubleValue(92.0));
168 m_levSizes->SetAttribute("Scale", DoubleValue(38.0));
169 m_levArrivals->SetAttribute("Location", DoubleValue(22000.0));
170 m_levArrivals->SetAttribute("Scale", DoubleValue(3400.0));
171 break;
173 default:
174 break;
175 }
176 }
177}
178
179void
181{
182 NS_LOG_FUNCTION(this);
183
184 m_socket->SetAllowBroadcast(true);
185 m_socket->ShutdownRecv();
186
188
189 if (m_connected)
190 {
191 ScheduleNext();
192 }
193}
194
195void
201
202void
204{
205 NS_LOG_FUNCTION(this);
207 {
208 // handled once ending packet is transmitted
209 return;
210 }
211 m_txEvent.Cancel();
212}
213
214void
216{
217 NS_LOG_FUNCTION(this);
218 NS_ASSERT(!m_txEvent.IsPending());
219 const auto delay = MicroSeconds(m_levArrivals->GetValue());
221}
222
223void
225{
226 NS_LOG_FUNCTION(this);
227
229 const auto stage{m_currentStage};
230 switch (stage)
231 {
233 packetSize = m_initialSizeUniform->GetInteger();
234 break;
236 packetSize = m_endSizeUniform->GetInteger();
237 break;
239 default:
240 packetSize = std::round(m_levSizes->GetValue());
241 break;
242 }
243 auto packet = Create<Packet>(packetSize);
244
245 const auto actualSize = static_cast<uint32_t>(m_socket->Send(packet));
246 NS_ABORT_MSG_IF(actualSize != packetSize,
247 "Sent size " << actualSize << " does not match expected size " << packetSize);
248 m_txTrace(packet);
249 m_txStageTrace(packet, stage);
250
252 {
253 NS_LOG_INFO("At time " << Simulator::Now().As(Time::S) << " gaming traffic source sent "
254 << packetSize << " bytes during stage " << stage << " to "
255 << InetSocketAddress::ConvertFrom(m_peer).GetIpv4() << " port "
257 }
259 {
260 NS_LOG_INFO("At time " << Simulator::Now().As(Time::S) << " gaming traffic source sent "
261 << packetSize << " bytes during stage " << stage << " to "
262 << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6() << " port "
264 }
265
267 {
269 CancelEvents();
270 CloseSocket();
271 }
272 else
273 {
275 {
277 }
278 ScheduleNext();
279 }
280}
281
282void
288
289std::ostream&
291{
292 switch (stage)
293 {
295 os << "Initial stage";
296 break;
298 os << "Gaming stage";
299 break;
301 os << "Ending stage";
302 break;
303 default:
304 NS_FATAL_ERROR("Unknown gaming traffic model stage");
305 }
306 return os;
307}
308
309} // Namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:437
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Generate RT mobile gaming traffic.
void DoStartApplication() override
Application specific startup code for child subclasses.
TracedCallback< Ptr< const Packet >, TrafficModelStage > m_txStageTrace
Traced Callback: transmitted packets and their stage.
void CancelEvents() override
Cancel all pending events.
EventId m_txEvent
Event ID of pending TX event scheduling.
Ptr< UniformRandomVariable > m_endSizeUniform
Uniform random variable to generate the end packet size.
TrafficModelStage m_currentStage
Hold the current stage.
void DoInitialize() override
Initialize() implementation.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this Application object.
void SendPacket()
Transmit one initial, gaming or ending packet.
Ptr< LargestExtremeValueRandomVariable > m_levArrivals
Largest extreme value random variable to generate packet arrival times.
static TypeId GetTypeId()
Get the type ID.
ModelPresets m_modelPresets
Model presets to use to configure the traffic generator.
void ScheduleNext()
Schedule the next packet transmission.
Ptr< LargestExtremeValueRandomVariable > m_levSizes
Largest extreme value random variable to generate packet sizes.
TrafficModelStage
Traffic model stages.
void DoConnectionSucceeded(Ptr< Socket > socket) override
Application specific code for child subclasses upon a Connection Succeed event.
void DoStopApplication() override
Application specific shutdown code for child subclasses.
Ptr< UniformRandomVariable > m_initialSizeUniform
Uniform random variable to generate the initial packet size.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
TypeId m_protocolTid
Protocol TypeId value.
SourceApplication(bool allowPacketSocket=true)
Constructor.
Ptr< Socket > m_socket
Socket.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
bool m_connected
flag whether socket is connected
Address m_peer
Peer address.
bool CloseSocket()
Close the socket.
Hold variables of type string.
Definition string.h:45
@ S
second
Definition nstime.h:106
a unique identifier for an interface.
Definition type-id.h:50
@ ATTR_GET
The attribute can be read.
Definition type-id.h:55
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition type-id.h:57
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
AttributeValue implementation for TypeId.
Definition type-id.h:649
static TypeId GetTypeId()
Get the type ID.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition enum.h:223
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:250
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:273
Ptr< const AttributeChecker > MakeTypeIdChecker()
Definition type-id.cc:1333
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition type-id.h:649
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1307
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:181
static const uint32_t packetSize
Packet size generated at the AP.