A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
traced-callback-typedef-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Lawrence Livermore National Laboratory
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7 */
8
9#include "ns3/core-module.h"
10#include "ns3/dsr-module.h" // DsrOPtionSRHeader
11#include "ns3/internet-module.h" // Ipv4, Ipv4L3Protocol, Ipv4PacketProbe
12#include "ns3/test.h"
13
14#include <iostream>
15#include <set>
16#include <sstream>
17#include <string>
18#include <type_traits>
19// Ipv6L3Protocol, Ipv6PacketProbe
20#include "ns3/lr-wpan-mac.h" // LrWpanMac
21#include "ns3/lte-module.h" // PhyReceptionStatParameters,
22 // PhyTransmissionStatParameters,
23 // LteUePowerControl
24#include "ns3/mesh-module.h" // PeerManagementProtocol
25#include "ns3/mobility-module.h" // MobilityModel
26#include "ns3/network-module.h" // Packet, PacketBurst
27#include "ns3/olsr-module.h" // olsr::RoutingProtocol
28#include "ns3/sixlowpan-module.h" // SixLowPanNetDevice
29#include "ns3/spectrum-module.h" // SpectrumValue
30#include "ns3/stats-module.h" // TimeSeriesAdapter
31#include "ns3/uan-module.h" // UanPhy
32#include "ns3/wifi-mac-header.h"
33#include "ns3/wifi-phy-state-helper.h"
34
35using namespace ns3;
36
37/**
38 * @file
39 * @ingroup system-tests-traced
40 *
41 * TracedCallback tests to verify if they are called with
42 * the right type and number of arguments.
43 */
44
45/**
46 * @ingroup system-tests-traced
47 *
48 * TracedCallback Testcase.
49 *
50 * This test verifies that the TracedCallback is called with
51 * the right type and number of arguments.
52 */
54{
55 public:
56 /// @return the TypeId for the callback checkers
58 {
59 static TypeId tid = TypeId("ns3::TracedCallbackTypedefTestCaseChecker")
61 .SetGroupName("Test")
62 .HideFromDocumentation();
63 return tid;
64 }
65
67
69 {
70 }
71
72 /**
73 * Number of arguments passed to callback.
74 *
75 * Since the sink function is outside the invoking class we can't use
76 * the test macros directly. Instead, we cache success
77 * in the \c m_nArgs public value, then inspect it
78 * in the CheckType() method.
79 */
80 static std::size_t m_nArgs;
81
82 private:
83 /** Callback checkers. */
84 template <typename... Ts>
85 class Checker;
86
87 void DoRun() override;
88
89}; // TracedCallbackTypedefTestCase
90
91/*
92 --------------------------------------------------------------------
93 Support functions and classes
94 --------------------------------------------------------------------
95*/
96
97namespace
98{
99
100/**
101 * @ingroup system-tests-traced
102 *
103 * Record typedefs which are identical to previously declared.
104 * @return a container of strings representing the duplicates.
105 */
106std::set<std::string>
108{
109 std::set<std::string> dupes;
110
111 dupes.insert("LteRlc::NotifyTxTracedCallback");
112 dupes.insert("LteRlc::ReceiveTracedCallback");
113 dupes.insert("LteUeRrc::ImsiCidRntiTracedCallback");
114 dupes.insert("LteUeRrc::MibSibHandoverTracedCallback");
115 dupes.insert("WifiPhyStateHelper::RxEndErrorTracedCallback");
116
117 return dupes;
118}
119
120/**
121 * @ingroup system-tests-traced
122 *
123 * Container for duplicate types.
124 */
125std::set<std::string> g_dupes = Duplicates();
126
127/**
128 * @ingroup system-tests-traced
129 *
130 * Stringify the known TracedCallback type names.
131 *
132 * @tparam T \explicit The typedef name.
133 * @param [in] N The number of arguments expected.
134 * @returns The \c TracedCallback type name.
135 */
136template <typename T>
137inline std::string
139{
140 return "unknown";
141}
142
143/**
144 * @ingroup system-tests-traced
145 *
146 * Returns a string representing the type of a class.
147 */
148#define TYPENAME(T) \
149 template <> \
150 inline std::string TypeName<T>(int N) \
151 { \
152 std::stringstream ss; \
153 ss << #T << "(" << N << ")"; \
154 return ss.str(); \
155 }
156
157/**
158 * @ingroup system-tests-traced
159 *
160 * @name Stringify known typename.
161 */
162/**
163 * @{
164 * @brief Stringify a known typename
165 */
221/** @} */
222#undef TYPENAME
223
224/**
225 * @ingroup system-tests-traced
226 *
227 * Log that a callback was invoked.
228 *
229 * We can't actually do anything with any of the arguments,
230 * but the fact we got called is what's important.
231 *
232 * @param [in] N The number of arguments passed to the callback.
233 */
234void
235SinkIt(std::size_t N)
236{
237 std::cout << "with " << N << " args." << std::endl;
239}
240
241/**
242 * @ingroup system-tests-traced
243 *
244 * Sink functions.
245 */
246template <typename... Ts>
248{
249 public:
250 /**
251 * @brief Sink function, called by a TracedCallback.
252 * @tparam Ts parameters of the TracedCallback.
253 */
254 static void Sink(Ts...)
255 {
256 const std::size_t n = sizeof...(Ts);
257 SinkIt(n);
258 }
259};
260
261} // unnamed namespace
262
263/*
264 --------------------------------------------------------------------
265 Class TracedCallbackTypedefTestCase implementation
266
267 We put the template implementations here to break a dependency cycle
268 from the Checkers() to TracedCbSink<> to SinkIt()
269 --------------------------------------------------------------------
270*/
271
273
274template <typename... Ts>
276{
277 /// TracedCallback to be called.
279
280 public:
281 /// @return the TypeId for this checker
286
288 {
289 }
290
291 ~Checker() override
292 {
293 }
294
295 /// Arguments of the TracedCallback.
296 std::tuple<std::remove_pointer_t<std::remove_cvref_t<Ts>>...> m_items;
297
298 /// Number of arguments of the TracedCallback.
299 const std::size_t m_nItems = sizeof...(Ts);
300
301 /**
302 * Invoke a TracedCallback.
303 */
304 template <typename U>
305 void Invoke()
306 {
307 U sink = TracedCbSink<Ts...>::Sink;
308 Callback<void, Ts...> cb = MakeCallback(sink);
309
310 std::cout << TypeName<U>(m_nItems) << " invoked ";
311 m_cb.ConnectWithoutContext(cb);
312 std::apply(m_cb, m_items);
313 Cleanup();
314 }
315
316 /**
317 * Cleanup the test.
318 */
319 void Cleanup()
320 {
321 if (m_nArgs == 0)
322 {
323 std::cout << std::endl;
324 }
326 "failed, m_nArgs: " << m_nArgs << " N: " << m_nItems);
327 m_nArgs = 0;
328 }
329};
330
332 : TestCase("Check basic TracedCallback operation")
333{
334}
335
336/**
337 * @ingroup system-tests-traced
338 *
339 * Check the TracedCallback duplicate by checking if it matches the TracedCallback
340 * it is supposed to be equal to.
341 */
342#define DUPE(U, T1) \
343 if (g_dupes.find(#U) == g_dupes.end()) \
344 { \
345 NS_TEST_ASSERT_MSG_NE(0, 1, "expected to find " << #U << " in dupes."); \
346 } \
347 if (TypeName<U>(0) == TypeName<T1>(0)) \
348 { \
349 std::cout << #U << " matches " << #T1 << std::endl; \
350 } \
351 else \
352 { \
353 NS_TEST_ASSERT_MSG_EQ(TypeName<U>(0), \
354 TypeName<T1>(0), \
355 "the typedef " \
356 << #U << " used to match the typedef " << #T1 \
357 << " but no longer does. Please add a new CHECK call."); \
358 }
359
360/**
361 * @ingroup system-tests-traced
362 *
363 * Check the TracedCallback by calling its Invoke function.
364 */
365#define CHECK(U, ...) CreateObject<Checker<__VA_ARGS__>>()->Invoke<U>()
366
367void
369{
371
373
375 const Ipv4Header&,
378 Ptr<Ipv4>,
379 uint32_t);
380
382
384
386 const Ipv6Header&,
389 Ptr<Ipv6>,
390 uint32_t);
391
393
395
397
399
401 Time,
404
406 uint32_t,
407 uint32_t,
408 uint16_t,
409 uint8_t,
410 uint16_t,
411 uint8_t,
412 uint16_t,
413 uint8_t);
414
415 CHECK(LteEnbMac::UlSchedulingTracedCallback, uint32_t, uint32_t, uint16_t, uint8_t, uint16_t);
416
417 CHECK(LteEnbPhy::ReportUeSinrTracedCallback, uint16_t, uint16_t, double, uint8_t);
418
420
421 CHECK(LteEnbRrc::ConnectionHandoverTracedCallback, uint64_t, uint16_t, uint16_t);
422
423 CHECK(LteEnbRrc::HandoverStartTracedCallback, uint64_t, uint16_t, uint16_t, uint16_t);
424
425 CHECK(LteEnbRrc::NewUeContextTracedCallback, uint16_t, uint16_t);
426
428 uint64_t,
429 uint16_t,
430 uint16_t,
432
433 CHECK(LtePdcp::PduRxTracedCallback, uint16_t, uint8_t, uint32_t, uint64_t);
434
435 CHECK(LtePdcp::PduTxTracedCallback, uint16_t, uint8_t, uint32_t);
436
438
440
441 CHECK(LteUePhy::RsrpSinrTracedCallback, uint16_t, uint16_t, double, double, uint8_t);
442
444
445 CHECK(LteUeRrc::CellSelectionTracedCallback, uint64_t, uint16_t);
446
448
450
452 uint64_t,
453 uint16_t,
454 uint16_t,
457
459
461
463 const olsr::PacketHeader&,
464 const olsr::MessageList&);
465
467
469
471
473
475
477
479
481
483
485
490 uint32_t);
491
495 uint32_t);
496
500 double);
501
503
505
507
509
511
513
515
517 uint64_t,
518 uint16_t,
519 uint16_t,
522
524
526
529 double,
530 WifiMode,
532
534
536
538
540}
541
542/**
543 * @ingroup system-tests-traced
544 *
545 * @brief TracedCallback typedef TestSuite
546 */
552
558
559/// Static variable for test initialization
TracedCallback< Ts... > m_cb
TracedCallback to be called.
std::tuple< std::remove_pointer_t< std::remove_cvref_t< Ts > >... > m_items
Arguments of the TracedCallback.
const std::size_t m_nItems
Number of arguments of the TracedCallback.
void DoRun() override
Implementation to actually run this TestCase.
static std::size_t m_nArgs
Number of arguments passed to callback.
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
Class for representing data rates.
Definition data-rate.h:78
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition epc-ue-nas.h:151
void(* StateTracedCallback)(const State oldState, const State newState)
TracedCallback signature for state change events.
Definition epc-ue-nas.h:171
Packet header for IPv4.
Definition ipv4-header.h:23
DropReason
Reason why a packet has been dropped.
void(* DropTracedCallback)(const Ipv4Header &header, Ptr< const Packet > packet, DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
TracedCallback signature for packet drop events.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
void(* SentTracedCallback)(const Ipv4Header &header, Ptr< const Packet > packet, uint32_t interface)
TracedCallback signature for packet send, forward, or local deliver events.
Packet header for IPv6.
Definition ipv6-header.h:24
void(* SentTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, uint32_t interface)
TracedCallback signature for packet sent, forwarded or local-delivered events.
DropReason
Reason why a packet has been dropped.
void(* DropTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet drop events.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
void(* DlSchedulingTracedCallback)(const uint32_t frame, const uint32_t subframe, const uint16_t rnti, const uint8_t mcs0, const uint16_t tbs0Size, const uint8_t mcs1, const uint16_t tbs1Size, const uint8_t ccId)
TracedCallback signature for DL scheduling events.
void(* UlSchedulingTracedCallback)(const uint32_t frame, const uint32_t subframe, const uint16_t rnti, const uint8_t mcs, const uint16_t tbsSize)
TracedCallback signature for UL scheduling events.
void(* ReportUeSinrTracedCallback)(uint16_t cellId, uint16_t rnti, double sinrLinear, uint8_t componentCarrierId)
TracedCallback signature for the linear average of SRS SINRs.
void(* ReportInterferenceTracedCallback)(uint16_t cellId, Ptr< SpectrumValue > spectrumValue)
TracedCallback signature for the linear average of SRS SINRs.
void(* ReceiveReportTracedCallback)(const uint64_t imsi, const uint16_t cellId, const uint16_t rnti, const LteRrcSap::MeasurementReport report)
TracedCallback signature for receive measurement report events.
void(* HandoverStartTracedCallback)(const uint64_t imsi, const uint16_t cellId, const uint16_t rnti, const uint16_t targetCid)
TracedCallback signature for handover start events.
void(* ConnectionHandoverTracedCallback)(const uint64_t imsi, const uint16_t cellId, const uint16_t rnti)
TracedCallback signature for connection and handover end events.
void(* NewUeContextTracedCallback)(const uint16_t cellId, const uint16_t rnti)
TracedCallback signature for new Ue Context events.
void(* PduRxTracedCallback)(const uint16_t rnti, const uint8_t lcid, const uint32_t size, const uint64_t delay)
TracedCallback signature for PDU receive event.
Definition lte-pdcp.h:128
void(* PduTxTracedCallback)(uint16_t rnti, uint8_t lcid, uint32_t size)
TracedCallback for PDU transmission event.
Definition lte-pdcp.h:117
void(* ReceiveTracedCallback)(uint16_t rnti, uint8_t lcid, uint32_t bytes, uint64_t delay)
TracedCallback signature for.
Definition lte-rlc.h:120
void(* NotifyTxTracedCallback)(uint16_t rnti, uint8_t lcid, uint32_t bytes)
TracedCallback signature for NotifyTxOpportunity events.
Definition lte-rlc.h:109
void(* StateTracedCallback)(uint16_t cellId, uint16_t rnti, State oldState, State newState)
TracedCallback signature for state transition events.
Definition lte-ue-phy.h:289
State
The states of the UE PHY entity.
Definition lte-ue-phy.h:52
void(* RsrpSinrTracedCallback)(uint16_t cellId, uint16_t rnti, double rsrp, double sinr, uint8_t componentCarrierId)
TracedCallback signature for cell RSRP and SINR report.
Definition lte-ue-phy.h:303
State
The states of the UE RRC entity.
Definition lte-ue-rrc.h:71
void(* MibSibHandoverTracedCallback)(uint64_t imsi, uint16_t cellId, uint16_t rnti, uint16_t otherCid)
TracedCallback signature for MIBReceived, Sib1Received and HandoverStart events.
Definition lte-ue-rrc.h:328
void(* CellSelectionTracedCallback)(uint64_t imsi, uint16_t cellId)
TracedCallback signature for imsi, cellId and rnti events.
Definition lte-ue-rrc.h:308
void(* ImsiCidRntiTracedCallback)(uint64_t imsi, uint16_t cellId, uint16_t rnti)
TracedCallback signature for imsi, cellId and rnti events.
Definition lte-ue-rrc.h:317
void(* StateTracedCallback)(uint64_t imsi, uint16_t cellId, uint16_t rnti, State oldState, State newState)
TracedCallback signature for state transition events.
Definition lte-ue-rrc.h:342
an EUI-48 address
void(* TracedCallback)(Mac48Address value)
TracedCallback signature for Mac48Address.
A class used for addressing MAC8 MAC's.
void(* TracedCallback)(Ptr< const MobilityModel > model)
TracedCallback signature.
A base class which provides memory management and object aggregation.
Definition object.h:78
Object()
Constructor.
Definition object.cc:96
void(* TracedCallback)(Ptr< const PacketBurst > burst)
TracedCallback signature for Ptr<PacketBurst>
void(* SizeTracedCallback)(uint32_t oldSize, uint32_t newSize)
TracedCallback signature for changes in packet size.
Definition packet.h:748
void(* Mac48AddressTracedCallback)(Ptr< const Packet > packet, Mac48Address mac)
TracedCallback signature for packet and Mac48Address.
Definition packet.h:740
void(* AddressTracedCallback)(Ptr< const Packet > packet, const Address &address)
TracedCallback signature for packet and Address.
Definition packet.h:721
void(* SinrTracedCallback)(Ptr< const Packet > packet, double sinr)
TracedCallback signature for packet and SINR.
Definition packet.h:756
void(* TracedCallback)(Ptr< const Packet > packet)
TracedCallback signature for Ptr<Packet>
Definition packet.h:713
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
void(* DropTracedCallback)(DropReason reason, Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet drop events.
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
void(* RxTxTracedCallback)(Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet send/receive events.
void(* LossTracedCallback)(Ptr< const SpectrumPhy > txPhy, Ptr< const SpectrumPhy > rxPhy, double lossDb)
TracedCallback signature for path loss calculation events.
void(* TracedCallback)(Ptr< SpectrumValue > value)
TracedCallback signature for SpectrumValue.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1055
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1274
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
static constexpr auto SYSTEM
Definition test.h:1293
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
void(* OutputTracedCallback)(const double now, const double data)
TracedCallback signature for output trace.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition uan-mac-cw.h:96
void(* PacketModeTracedCallback)(Ptr< const Packet > packet, UanTxMode mode)
TracedCallback signature for packet reception/enqueue/dequeue events.
Definition uan-mac.h:113
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint32_t proto)
TracedCallback signature for dequeue of a packet.
Definition uan-mac-rc.h:189
void(* RxTxTracedCallback)(Ptr< const Packet > packet, Mac8Address address)
TracedCallback signature for MAC send/receive events.
void(* TracedCallback)(Ptr< const Packet > pkt, double sinr, UanTxMode mode)
TracedCallback signature for UanPhy packet send/receive events.
Definition uan-phy.h:208
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
State
The state of the UeManager at the eNB RRC.
Definition lte-enb-rrc.h:67
void(* StateTracedCallback)(const uint64_t imsi, const uint16_t cellId, const uint16_t rnti, const State oldState, const State newState)
TracedCallback signature for state transition events.
Implements the IEEE 802.11 MAC header.
void(* TracedCallback)(const WifiMacHeader &header)
TracedCallback signature for WifiMacHeader.
represent a single transmission mode
Definition wifi-mode.h:38
void(* TxTracedCallback)(Ptr< const Packet > packet, WifiMode mode, WifiPreamble preamble, uint8_t power)
TracedCallback signature for transmit event.
void(* StateTracedCallback)(Time start, Time duration, WifiPhyState state)
TracedCallback signature for state changes.
void(* RxEndErrorTracedCallback)(Ptr< const Packet > packet, double snr)
TracedCallback signature for receive end error event.
void(* RxOkTracedCallback)(Ptr< const Packet > packet, double snr, WifiMode mode, WifiPreamble preamble)
TracedCallback signature for receive end OK event.
void(* PowerChangeTracedCallback)(double oldPower, double newPower, Mac48Address remoteAddress)
TracedCallback signature for power change events.
void(* RateChangeTracedCallback)(DataRate oldRate, DataRate newRate, Mac48Address remoteAddress)
TracedCallback signature for rate change events.
void(* LinkOpenCloseTracedCallback)(Mac48Address src, const Mac48Address dst)
TracedCallback signature for link open/close events.
Header of Dsr Option Source Route.
void(* TracedCallback)(const DsrOptionSRHeader &header)
TracedCallback signature for DsrOptionSrHeader.
void(* StateTracedCallback)(MacState oldState, MacState newState)
TracedCallback signature for MacState change events.
void(* SentTracedCallback)(Ptr< const Packet > packet, uint8_t retries, uint8_t backoffs)
TracedCallback signature for sent packets.
void(* StateTracedCallback)(Time time, PhyEnumeration oldState, PhyEnumeration newState)
TracedCallback signature for Trx state change events.
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers):
Definition olsr-header.h:68
void(* PacketTxRxTracedCallback)(const PacketHeader &header, const MessageList &messages)
TracedCallback signature for Packet transmit and receive events.
void(* TableChangeTracedCallback)(uint32_t size)
TracedCallback signature for routing table computation.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
MacState
MAC states.
Definition lr-wpan-mac.h:65
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
#define CHECK(U,...)
Check the TracedCallback by calling its Invoke function.
#define DUPE(U, T1)
Check the TracedCallback duplicate by checking if it matches the TracedCallback it is supposed to be ...
std::set< std::string > g_dupes
Container for duplicate types.
std::set< std::string > Duplicates()
Record typedefs which are identical to previously declared.
#define TYPENAME(T)
Returns a string representing the type of a class.
std::string TypeName(int N)
Stringify the known TracedCallback type names.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
std::vector< MessageHeader > MessageList
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
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:684
MeasurementReport structure.
PhyReceptionStatParameters structure.
Definition lte-common.h:201
void(* TracedCallback)(const PhyReceptionStatParameters params)
TracedCallback signature.
Definition lte-common.h:221
PhyTransmissionStatParameters structure.
Definition lte-common.h:177
void(* TracedCallback)(const PhyTransmissionStatParameters params)
TracedCallback signature.
Definition lte-common.h:196
static TracedCallbackTypedefTestSuite tracedCallbackTypedefTestSuite
Static variable for test initialization.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44