A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rta-tig-mobile-gaming-test-suite.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
9#include "ns3/application-container.h"
10#include "ns3/application-helper.h"
11#include "ns3/config.h"
12#include "ns3/double.h"
13#include "ns3/inet-socket-address.h"
14#include "ns3/internet-stack-helper.h"
15#include "ns3/ipv4-address-helper.h"
16#include "ns3/ipv4-address.h"
17#include "ns3/ipv4-interface-container.h"
18#include "ns3/ipv4-l3-protocol.h"
19#include "ns3/ipv4-list-routing-helper.h"
20#include "ns3/node-container.h"
21#include "ns3/node.h"
22#include "ns3/nstime.h"
23#include "ns3/packet-sink-helper.h"
24#include "ns3/packet-sink.h"
25#include "ns3/packet-socket-address.h"
26#include "ns3/pointer.h"
27#include "ns3/rng-seed-manager.h"
28#include "ns3/rta-tig-mobile-gaming.h"
29#include "ns3/simple-net-device-helper.h"
30#include "ns3/string.h"
31#include "ns3/test.h"
32#include "ns3/traced-callback.h"
33
34#include <algorithm>
35#include <numeric>
36#include <string>
37#include <vector>
38
39using namespace ns3;
40
41NS_LOG_COMPONENT_DEFINE("RtaTigMobileGamingTest");
42
43/**
44 * @ingroup applications-test
45 * @ingroup tests
46 *
47 * RT mobile gaming traffic test.
48 *
49 * The test consider traffic values for the two models presented in IEEE 802.11 Real Time
50 * Applications TIG Report (Section 4.1.4: Traffic model) and for both downlink and uplink.
51 *
52 * The test generates traffic between two nodes and keeps track of generated TX packets (size,
53 * timestamp and current stage). The test verifies the correct transition to stages, it checks the
54 * average sizes of generated packets for each stage match with the settings of the random
55 * variables, and it validates the average inter-arrival between generated gaming packets against
56 * the expected one based on the settings of the random variable.
57 */
59{
60 public:
61 /// Information about gaming parameters
63 {
64 uint32_t minInitialPacketSize{}; //!< Minimum size in bytes for initial packet payload
65 uint32_t maxInitialPacketSize{}; //!< Maximum size in bytes for initial packet payload
66 uint32_t minEndPacketSize{}; //!< Minimum size in bytes for end packet payload
67 uint32_t maxEndPacketSize{}; //!< Maximum size in bytes for end packet payload
68 uint32_t packetSizeLevLocation{}; //!< Location of largest extreme value distribution used
69 //!< to calculate packet sizes
70 double packetSizeLevScale{}; //!< Scale of largest extreme value distribution used to
71 //!< calculate packet sizes
72 Time packetArrivalLevLocation{}; //!< Location of largest extreme value distribution used to
73 //!< calculate packet arrivals
74 Time packetArrivalLevScale{}; //!< Scale of largest extreme value distribution used to
75 //!< calculate packet arrivals
76 };
77
78 /**
79 * Constructor
80 * @param name the name of the test to run
81 * @param params the VoIP parameters to use for the test, default parameters are used if not
82 * provided
83 */
84 RtaTigMobileGamingTestCase(const std::string& name, const GamingParams& params);
85
86 private:
87 void DoSetup() override;
88 void DoRun() override;
89
90 /**
91 * Record a packets successfully sent
92 * @param packet the transmitted packet
93 * @param stage the gaming traffic model stage of the packet
94 */
96
97 /**
98 * Record a packet successfully received
99 * @param context the context
100 * @param p the packet
101 * @param addr the sender's address
102 */
103 void ReceiveRx(std::string context, Ptr<const Packet> p, const Address& addr);
104
105 /// Information about transmitted packet
106 struct TxInfo
107 {
108 uint32_t length{0}; //!< length of the packet in bytes
109 Time tstamp{Time()}; //!< timestamp at which the packet is transmitted
112 //!< packet is transmitted
113 };
114
115 std::vector<TxInfo> m_sent; //!< transmitted gaming packets
116 uint64_t m_received{0}; //!< number of bytes received
117
118 GamingParams m_params; //!< parameters of the model
119};
120
122 const GamingParams& params)
123 : TestCase{name},
124 m_params{params}
125{
126}
127
128void
131{
132 const auto now = Simulator::Now();
133 NS_LOG_FUNCTION(this << packet << packet->GetSize() << now << stage);
134 m_sent.push_back({packet->GetSize(), now, stage});
135}
136
137void
139{
140 NS_LOG_FUNCTION(this << p << addr << p->GetSize());
141 m_received += p->GetSize();
142}
143
144void
146{
147 NS_LOG_FUNCTION(this);
148 // LogComponentEnable("RtaTigMobileGamingTest", LOG_LEVEL_ALL);
149 // LogComponentEnable("RtaTigMobileGaming", LOG_LEVEL_ALL);
150 // LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
151
154
155 const auto simulationTime = Seconds(60);
156 uint16_t port = 90;
157
158 auto sender = CreateObject<Node>();
159 auto receiver = CreateObject<Node>();
160
162 nodes.Add(sender);
163 nodes.Add(receiver);
164
165 SimpleNetDeviceHelper simpleHelper;
166 auto devices = simpleHelper.Install(nodes);
167
168 InternetStackHelper internet;
169 internet.Install(nodes);
170
171 Ipv4AddressHelper ipv4Helper;
172 ipv4Helper.SetBase("10.11.12.0", "255.255.255.0");
173 auto interfaces = ipv4Helper.Assign(devices);
174
176 auto remoteAddress = InetSocketAddress(interfaces.GetAddress(1), port);
177 sourceHelper.SetAttribute("Remote", AddressValue(remoteAddress));
178
180 "Min",
181 DoubleValue(m_params.minInitialPacketSize),
182 "Max",
183 DoubleValue(m_params.maxInitialPacketSize));
184 sourceHelper.SetAttribute("CustomInitialPacketSize", PointerValue(ips));
185
186 auto eps =
188 DoubleValue(m_params.minEndPacketSize),
189 "Max",
190 DoubleValue(m_params.maxEndPacketSize));
191 sourceHelper.SetAttribute("CustomEndPacketSize", PointerValue(eps));
192
194 "Location",
195 DoubleValue(m_params.packetSizeLevLocation),
196 "Scale",
197 DoubleValue(m_params.packetSizeLevScale));
198 sourceHelper.SetAttribute("CustomPacketSizeLev", PointerValue(psl));
199
201 "Location",
202 DoubleValue(m_params.packetArrivalLevLocation.GetMicroSeconds()),
203 "Scale",
204 DoubleValue(m_params.packetArrivalLevScale.GetMicroSeconds()));
205 sourceHelper.SetAttribute("CustomPacketArrivalLev", PointerValue(pal));
206
207 auto sourceApp = sourceHelper.Install(sender);
208 const auto startAppTime = Seconds(1.0);
209 sourceApp.Start(startAppTime);
210 sourceApp.Stop(startAppTime + simulationTime);
211
212 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
214 auto sinkApp = sinkHelper.Install(receiver);
215 sinkApp.Start(Seconds(0.0));
216 sinkApp.Stop(Seconds(2.0) + simulationTime);
217
218 int64_t streamNumber = 100;
219 sourceHelper.AssignStreams(nodes, streamNumber);
220
222 "/NodeList/*/$ns3::Node/ApplicationList/*/$ns3::RtaTigMobileGaming/TxWithStage",
224
225 Config::Connect("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
227}
228
229void
231{
234
235 const auto totalTx =
236 std::accumulate(m_sent.cbegin(), m_sent.cend(), 0ULL, [](auto sum, const auto& tx) {
237 return sum + tx.length;
238 });
239 NS_TEST_ASSERT_MSG_EQ(totalTx, m_received, "Did not receive all transmitted gaming packets");
240
241 NS_TEST_ASSERT_MSG_EQ(m_sent.cbegin()->stage,
243 "First received packet is not an initial packet");
244 NS_TEST_ASSERT_MSG_EQ(m_sent.crbegin()->stage,
246 "Last received packet is not an ending packet");
247 const auto allGamingPackets =
248 std::all_of(m_sent.cbegin() + 1, m_sent.cend() - 1, [](const auto& tx) {
249 return tx.stage == RtaTigMobileGaming::TrafficModelStage::GAMING;
250 });
251 NS_TEST_ASSERT_MSG_EQ(allGamingPackets, true, "Incorrectly reported stage during gaming stage");
252
253 NS_TEST_ASSERT_MSG_GT_OR_EQ(m_sent.cbegin()->length,
254 m_params.minInitialPacketSize,
255 "Size of initial packet is lower than expected");
256 NS_TEST_ASSERT_MSG_LT_OR_EQ(m_sent.cbegin()->length,
257 m_params.maxInitialPacketSize,
258 "Size of initial packet is higher than expected");
259
260 NS_TEST_ASSERT_MSG_GT_OR_EQ(m_sent.crbegin()->length,
261 m_params.minEndPacketSize,
262 "Size of end packet is lower than expected");
263 NS_TEST_ASSERT_MSG_LT_OR_EQ(m_sent.crbegin()->length,
264 m_params.maxEndPacketSize,
265 "Size of end packet is higher than expected");
266
267 const auto totalGamingTx =
268 std::accumulate(m_sent.cbegin() + 1, m_sent.cend() - 1, 0.0, [](auto sum, const auto& tx) {
269 return sum + tx.length;
270 });
271 const auto averageGamingPacketSize = totalGamingTx / (m_sent.size() - 2);
272 const auto expectedAverageGamingPacketSize =
274 m_params.packetSizeLevScale);
275 NS_TEST_EXPECT_MSG_EQ_TOL(averageGamingPacketSize,
276 expectedAverageGamingPacketSize,
277 0.5,
278 "Unexpected average gaming packet size");
279
280 std::vector<Time> packetArrivals;
281 std::transform(m_sent.cbegin(),
282 m_sent.cend() - 1,
283 m_sent.cbegin() + 1,
284 std::back_inserter(packetArrivals),
285 [](const auto& lhs, const auto& rhs) { return (rhs.tstamp - lhs.tstamp); });
286 const auto totalPacketArrivals =
287 std::accumulate(packetArrivals.cbegin(),
288 packetArrivals.cend(),
289 Time(),
290 [](auto sum, const auto t) { return sum + t; });
291 const auto averagePacketArrivalUs =
292 static_cast<double>(totalPacketArrivals.GetMicroSeconds()) / packetArrivals.size();
293 const auto expectedAveragePacketArrivalUs = LargestExtremeValueRandomVariable::GetMean(
294 m_params.packetArrivalLevLocation.GetMicroSeconds(),
295 m_params.packetArrivalLevScale.GetMicroSeconds());
296 NS_TEST_EXPECT_MSG_EQ_TOL(averagePacketArrivalUs,
297 expectedAveragePacketArrivalUs,
298 0.01 * expectedAveragePacketArrivalUs,
299 "Unexpected average packet arrival");
300}
301
302/**
303 * @ingroup applications-test
304 * @ingroup tests
305 *
306 * @brief RtaTigMobileGaming TestSuite
307 */
309{
310 public:
312};
313
315 : TestSuite("applications-rta-tig-mobile-gaming", Type::UNIT)
316{
318 "Check real-time mobile gaming traffic for DL status-sync",
319 {0, 20, 500, 600, 50, 11.0, MilliSeconds(13), MicroSeconds(3700)}),
322 "Check real-time mobile gaming traffic for UL status-sync",
323 {0, 20, 400, 550, 38, 3.7, MilliSeconds(15), MicroSeconds(5700)}),
326 "Check real-time mobile gaming traffic for DL lockstep",
327 {0, 80, 1400, 1500, 210, 35.0, MilliSeconds(28), MicroSeconds(4200)}),
330 "Check real-time mobile gaming traffic for UL lockstep",
331 {0, 80, 500, 600, 92, 38.0, MilliSeconds(22), MicroSeconds(3400)}),
333}
334
336 g_RtaTigMobileGamingTestSuite; //!< Static variable for test initialization
uint64_t m_received
number of bytes received
void ReceiveRx(std::string context, Ptr< const Packet > p, const Address &addr)
Record a packet successfully received.
GamingParams m_params
parameters of the model
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
RtaTigMobileGamingTestCase(const std::string &name, const GamingParams &params)
Constructor.
std::vector< TxInfo > m_sent
transmitted gaming packets
void PacketTx(Ptr< const Packet > packet, RtaTigMobileGaming::TrafficModelStage stage)
Record a packets successfully sent.
a polymophic address class
Definition address.h:114
AttributeValue implementation for Address.
Definition address.h:329
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
A helper to make it easier to instantiate an application on a set of nodes.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assigns a unique (monotonically increasing) stream number to all applications that match the configur...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
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.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static Ipv4Address GetAny()
double GetMean() const
Returns the mean value for the Largest Extreme Value distribution returned by this RNG stream.
keep track of a set of node pointers.
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 void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static TypeId GetTypeId()
Get the type ID.
TrafficModelStage
Traffic model stages.
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
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
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition config.cc:946
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:133
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition test.h:499
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
Definition test.h:739
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition test.h:904
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1307
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static RtaTigMobileGamingTestSuite g_RtaTigMobileGamingTestSuite
Static variable for test initialization.
Time packetArrivalLevLocation
Location of largest extreme value distribution used to calculate packet arrivals.
Time packetArrivalLevScale
Scale of largest extreme value distribution used to calculate packet arrivals.
uint32_t maxEndPacketSize
Maximum size in bytes for end packet payload.
uint32_t maxInitialPacketSize
Maximum size in bytes for initial packet payload.
double packetSizeLevScale
Scale of largest extreme value distribution used to calculate packet sizes.
uint32_t minInitialPacketSize
Minimum size in bytes for initial packet payload.
uint32_t minEndPacketSize
Minimum size in bytes for end packet payload.
uint32_t packetSizeLevLocation
Location of largest extreme value distribution used to calculate packet sizes.
Time tstamp
timestamp at which the packet is transmitted
RtaTigMobileGaming::TrafficModelStage stage
traffic model stage when the packet is transmitted
uint32_t length
length of the packet in bytes