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:
57
59 {
60 }
61
62 /**
63 * Number of arguments passed to callback.
64 *
65 * Since the sink function is outside the invoking class we can't use
66 * the test macros directly. Instead, we cache success
67 * in the \c m_nArgs public value, then inspect it
68 * in the CheckType() method.
69 */
70 static std::size_t m_nArgs;
71
72 private:
73 /** Callback checkers. */
74 template <typename... Ts>
75 class Checker;
76
77 void DoRun() override;
78
79}; // TracedCallbackTypedefTestCase
80
81/*
82 --------------------------------------------------------------------
83 Support functions and classes
84 --------------------------------------------------------------------
85*/
86
87namespace
88{
89
90/**
91 * \ingroup system-tests-traced
92 *
93 * Record typedefs which are identical to previously declared.
94 * \return a container of strings representing the duplicates.
95 */
96std::set<std::string>
98{
99 std::set<std::string> dupes;
100
101 dupes.insert("LteRlc::NotifyTxTracedCallback");
102 dupes.insert("LteRlc::ReceiveTracedCallback");
103 dupes.insert("LteUeRrc::ImsiCidRntiTracedCallback");
104 dupes.insert("LteUeRrc::MibSibHandoverTracedCallback");
105 dupes.insert("WifiPhyStateHelper::RxEndErrorTracedCallback");
106
107 return dupes;
108}
109
110/**
111 * \ingroup system-tests-traced
112 *
113 * Container for duplicate types.
114 */
115std::set<std::string> g_dupes = Duplicates();
116
117/**
118 * \ingroup system-tests-traced
119 *
120 * Stringify the known TracedCallback type names.
121 *
122 * \tparam T \explicit The typedef name.
123 * \param [in] N The number of arguments expected.
124 * \returns The \c TracedCallback type name.
125 */
126template <typename T>
127inline std::string
129{
130 return "unknown";
131}
132
133/**
134 * \ingroup system-tests-traced
135 *
136 * Returns a string representing the type of a class.
137 */
138#define TYPENAME(T) \
139 template <> \
140 inline std::string TypeName<T>(int N) \
141 { \
142 std::stringstream ss; \
143 ss << #T << "(" << N << ")"; \
144 return ss.str(); \
145 }
146
147/**
148 * \ingroup system-tests-traced
149 *
150 * \name Stringify known typename.
151 */
152/**
153 * @{
154 * \brief Stringify a known typename
155 */
211/** @} */
212#undef TYPENAME
213
214/**
215 * \ingroup system-tests-traced
216 *
217 * Log that a callback was invoked.
218 *
219 * We can't actually do anything with any of the arguments,
220 * but the fact we got called is what's important.
221 *
222 * \param [in] N The number of arguments passed to the callback.
223 */
224void
225SinkIt(std::size_t N)
226{
227 std::cout << "with " << N << " args." << std::endl;
229}
230
231/**
232 * \ingroup system-tests-traced
233 *
234 * Sink functions.
235 */
236template <typename... Ts>
238{
239 public:
240 /**
241 * \brief Sink function, called by a TracedCallback.
242 * \tparam Ts parameters of the TracedCallback.
243 */
244 static void Sink(Ts...)
245 {
246 const std::size_t n = sizeof...(Ts);
247 SinkIt(n);
248 }
249};
250
251} // unnamed namespace
252
253/*
254 --------------------------------------------------------------------
255 Class TracedCallbackTypedefTestCase implementation
256
257 We put the template implementations here to break a dependency cycle
258 from the Checkers() to TracedCbSink<> to SinkIt()
259 --------------------------------------------------------------------
260*/
261
263
264template <typename... Ts>
266{
267 /// TracedCallback to be called.
269
270 public:
272 ~Checker() override{};
273
274 /// Arguments of the TracedCallback.
275 std::tuple<std::remove_pointer_t<std::remove_cvref_t<Ts>>...> m_items;
276
277 /// Number of arguments of the TracedCallback.
278 const std::size_t m_nItems = sizeof...(Ts);
279
280 /**
281 * Invoke a TracedCallback.
282 */
283 template <typename U>
284 void Invoke()
285 {
286 U sink = TracedCbSink<Ts...>::Sink;
287 Callback<void, Ts...> cb = MakeCallback(sink);
288
289 std::cout << TypeName<U>(m_nItems) << " invoked ";
291 std::apply(m_cb, m_items);
292 Cleanup();
293 }
294
295 /**
296 * Cleanup the test.
297 */
298 void Cleanup()
299 {
300 if (m_nArgs == 0)
301 {
302 std::cout << std::endl;
303 }
305 "failed, m_nArgs: " << m_nArgs << " N: " << m_nItems);
306 m_nArgs = 0;
307 }
308};
309
311 : TestCase("Check basic TracedCallback operation")
312{
313}
314
315/**
316 * \ingroup system-tests-traced
317 *
318 * Check the TracedCallback duplicate by checking if it matches the TracedCallback
319 * it is supposed to be equal to.
320 */
321#define DUPE(U, T1) \
322 if (g_dupes.find(#U) == g_dupes.end()) \
323 { \
324 NS_TEST_ASSERT_MSG_NE(0, 1, "expected to find " << #U << " in dupes."); \
325 } \
326 if (TypeName<U>(0) == TypeName<T1>(0)) \
327 { \
328 std::cout << #U << " matches " << #T1 << std::endl; \
329 } \
330 else \
331 { \
332 NS_TEST_ASSERT_MSG_EQ(TypeName<U>(0), \
333 TypeName<T1>(0), \
334 "the typedef " \
335 << #U << " used to match the typedef " << #T1 \
336 << " but no longer does. Please add a new CHECK call."); \
337 }
338
339/**
340 * \ingroup system-tests-traced
341 *
342 * Check the TracedCallback by calling its Invoke function.
343 */
344#define CHECK(U, ...) CreateObject<Checker<__VA_ARGS__>>()->Invoke<U>()
345
346void
348{
350
352
354 const Ipv4Header&,
357 Ptr<Ipv4>,
358 uint32_t);
359
361
363
365 const Ipv6Header&,
368 Ptr<Ipv6>,
369 uint32_t);
370
372
374
376
378
380 Time,
383
385 uint32_t,
386 uint32_t,
387 uint16_t,
388 uint8_t,
389 uint16_t,
390 uint8_t,
391 uint16_t,
392 uint8_t);
393
394 CHECK(LteEnbMac::UlSchedulingTracedCallback, uint32_t, uint32_t, uint16_t, uint8_t, uint16_t);
395
396 CHECK(LteEnbPhy::ReportUeSinrTracedCallback, uint16_t, uint16_t, double, uint8_t);
397
399
400 CHECK(LteEnbRrc::ConnectionHandoverTracedCallback, uint64_t, uint16_t, uint16_t);
401
402 CHECK(LteEnbRrc::HandoverStartTracedCallback, uint64_t, uint16_t, uint16_t, uint16_t);
403
404 CHECK(LteEnbRrc::NewUeContextTracedCallback, uint16_t, uint16_t);
405
407 uint64_t,
408 uint16_t,
409 uint16_t,
411
412 CHECK(LtePdcp::PduRxTracedCallback, uint16_t, uint8_t, uint32_t, uint64_t);
413
414 CHECK(LtePdcp::PduTxTracedCallback, uint16_t, uint8_t, uint32_t);
415
417
419
420 CHECK(LteUePhy::RsrpSinrTracedCallback, uint16_t, uint16_t, double, double, uint8_t);
421
423
424 CHECK(LteUeRrc::CellSelectionTracedCallback, uint64_t, uint16_t);
425
427
429
431 uint64_t,
432 uint16_t,
433 uint16_t,
436
438
440
442 const olsr::PacketHeader&,
443 const olsr::MessageList&);
444
446
448
450
452
454
456
458
460
462
464
469 uint32_t);
470
474 uint32_t);
475
479 double);
480
482
484
486
488
490
492
494
496 uint64_t,
497 uint16_t,
498 uint16_t,
501
503
505
508 double,
509 WifiMode,
511
513
515
517
519}
520
521/**
522 * \ingroup system-tests-traced
523 *
524 * \brief TracedCallback typedef TestSuite
525 */
531
533 : TestSuite("traced-callback-typedef", Type::SYSTEM)
534{
535 AddTestCase(new TracedCallbackTypedefTestCase, TestCase::Duration::QUICK);
536}
537
538/// 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:88
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:344
void(* CellSelectionTracedCallback)(uint64_t imsi, uint16_t cellId)
TracedCallback signature for imsi, cellId and rnti events.
Definition lte-ue-rrc.h:324
void(* ImsiCidRntiTracedCallback)(uint64_t imsi, uint16_t cellId, uint16_t rnti)
TracedCallback signature for imsi, cellId and rnti events.
Definition lte-ue-rrc.h:333
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:358
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
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.
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.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
void(* OutputTracedCallback)(const double now, const double data)
TracedCallback signature for output trace.
Forward calls to a chain of Callback.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
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:188
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:204
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:40
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:64
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