A Discrete-Event Network Simulator
API
traced-callback-typedef-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2015 Lawrence Livermore National Laboratory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19 */
20
21#include <iostream>
22#include <sstream>
23#include <set>
24#include <string>
25#include "ns3/test.h"
26#include "ns3/core-module.h"
27#include "ns3/dsr-module.h" // DsrOPtionSRHeader
28#include "ns3/internet-module.h" // Ipv4, Ipv4L3Protocol, Ipv4PacketProbe
29 // Ipv6L3Protocol, Ipv6PacketProbe
30#include "ns3/lr-wpan-mac.h" // LrWpanMac
31#include "ns3/lte-module.h" // PhyReceptionStatParameters,
32 // PhyTransmissionStatParameters,
33 // LteUePowerControl
34#include "ns3/mesh-module.h" // PeerManagementProtocol
35#include "ns3/mobility-module.h" // MobilityModel
36#include "ns3/network-module.h" // Packet, PacketBurst
37#include "ns3/olsr-module.h" // olsr::RoutingProtocol
38#include "ns3/sixlowpan-module.h" // SixLowPanNetDevice
39#include "ns3/spectrum-module.h" // SpectrumValue
40#include "ns3/stats-module.h" // TimeSeriesAdapter
41#include "ns3/uan-module.h" // UanPhy
42#include "ns3/wifi-phy-state-helper.h"
43#include "ns3/wifi-mac-header.h"
44
45using namespace ns3;
46
65{
66public:
69 {
70 }
71
80 static std::size_t m_nArgs;
81
82private:
83
85 template <typename... Ts>
86 class Checker;
87
88 virtual void DoRun (void);
89
90}; // TracedCallbackTypedefTestCase
91
92/*
93 --------------------------------------------------------------------
94 Support functions and classes
95 --------------------------------------------------------------------
96*/
97
98namespace {
99
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
125std::set<std::string> g_dupes = Duplicates ();
126
127
137template <typename T>
138inline
139std::string TypeName (int N)
140{
141 return "unknown";
142}
143
149#define TYPENAME(T) \
150 template <> \
151 inline std::string \
152 TypeName < T > (int N) \
153 { \
154 std::stringstream ss; \
155 ss << # T << "(" << N << ")"; \
156 return ss.str (); \
157 }
158
168TYPENAME (dsr::DsrOptionSRHeader::TracedCallback);
169TYPENAME (EpcUeNas::StateTracedCallback);
170TYPENAME (Ipv4L3Protocol::DropTracedCallback);
171TYPENAME (Ipv4L3Protocol::SentTracedCallback);
172TYPENAME (Ipv4L3Protocol::TxRxTracedCallback);
173TYPENAME (Ipv6L3Protocol::DropTracedCallback);
174TYPENAME (Ipv6L3Protocol::SentTracedCallback);
175TYPENAME (Ipv6L3Protocol::TxRxTracedCallback);
176TYPENAME (LrWpanMac::SentTracedCallback);
177TYPENAME (LrWpanMac::StateTracedCallback);
178TYPENAME (LrWpanPhy::StateTracedCallback);
179TYPENAME (LteEnbMac::DlSchedulingTracedCallback);
180TYPENAME (LteEnbMac::UlSchedulingTracedCallback);
181TYPENAME (LteEnbPhy::ReportInterferenceTracedCallback);
182TYPENAME (LteEnbPhy::ReportUeSinrTracedCallback);
183TYPENAME (LteEnbRrc::ConnectionHandoverTracedCallback);
184TYPENAME (LteEnbRrc::HandoverStartTracedCallback);
185TYPENAME (LteEnbRrc::NewUeContextTracedCallback);
186TYPENAME (LteEnbRrc::ReceiveReportTracedCallback);
187TYPENAME (LtePdcp::PduRxTracedCallback);
188TYPENAME (LtePdcp::PduTxTracedCallback);
189TYPENAME (LteUePhy::StateTracedCallback);
190TYPENAME (LteUePhy::RsrpSinrTracedCallback);
191TYPENAME (LteUeRrc::CellSelectionTracedCallback);
192TYPENAME (LteUeRrc::StateTracedCallback);
193TYPENAME (Mac48Address::TracedCallback);
194TYPENAME (MobilityModel::TracedCallback);
195TYPENAME (olsr::RoutingProtocol::PacketTxRxTracedCallback);
196TYPENAME (olsr::RoutingProtocol::TableChangeTracedCallback);
197TYPENAME (Packet::AddressTracedCallback);
198TYPENAME (Packet::Mac48AddressTracedCallback);
199TYPENAME (Packet::SinrTracedCallback);
200TYPENAME (Packet::SizeTracedCallback);
201TYPENAME (Packet::TracedCallback);
202TYPENAME (PacketBurst::TracedCallback);
203TYPENAME (dot11s::PeerManagementProtocol::LinkOpenCloseTracedCallback);
204TYPENAME (PhyReceptionStatParameters::TracedCallback);
205TYPENAME (PhyTransmissionStatParameters::TracedCallback);
206TYPENAME (SixLowPanNetDevice::DropTracedCallback);
207TYPENAME (SixLowPanNetDevice::RxTxTracedCallback);
208TYPENAME (SpectrumChannel::LossTracedCallback);
209TYPENAME (SpectrumValue::TracedCallback);
210TYPENAME (TimeSeriesAdaptor::OutputTracedCallback);
211TYPENAME (UanMac::PacketModeTracedCallback);
212TYPENAME (UanMacCw::QueueTracedCallback);
213TYPENAME (UanMacRc::QueueTracedCallback);
214TYPENAME (UanNetDevice::RxTxTracedCallback);
215TYPENAME (UanPhy::TracedCallback);
216TYPENAME (UeManager::StateTracedCallback);
217TYPENAME (WifiMacHeader::TracedCallback);
218TYPENAME (WifiPhyStateHelper::RxOkTracedCallback);
219TYPENAME (WifiPhyStateHelper::StateTracedCallback);
220TYPENAME (WifiPhyStateHelper::TxTracedCallback);
221TYPENAME (WifiRemoteStationManager::PowerChangeTracedCallback);
222TYPENAME (WifiRemoteStationManager::RateChangeTracedCallback);
224#undef TYPENAME
225
226
237void SinkIt (std::size_t N)
238{
239 std::cout << "with " << N << " args." << std::endl;
241}
242
248template <typename... Ts>
250{
251public:
256 static void Sink (Ts...)
257 {
258 const std::size_t n = sizeof...(Ts);
259 SinkIt (n);
260 }
261};
262
263
264} // unnamed namespace
265
266
267/*
268 --------------------------------------------------------------------
269 Class TracedCallbackTypedefTestCase implementation
270
271 We put the template implementations here to break a dependency cycle
272 from the Checkers() to TracedCbSink<> to SinkIt()
273 --------------------------------------------------------------------
274*/
275
277
278template <typename... Ts>
280{
283public:
284 Checker () {};
285 virtual ~Checker () {};
286
288 std::tuple<typename TypeTraits<Ts>::BaseType...> m_items;
289
291 const std::size_t m_nItems = sizeof...(Ts);
292
296 template <typename U>
297 void Invoke (void)
298 {
299 U sink = TracedCbSink<Ts...>::Sink;
300 Callback<void, Ts...> cb = MakeCallback (sink);
301
302 std::cout << TypeName<U> (m_nItems) << " invoked ";
304 std::apply(m_cb, m_items);
305 Cleanup ();
306 }
307
311 void Cleanup ()
312 {
313 if (m_nArgs == 0)
314 {
315 std::cout << std::endl;
316 }
317 NS_ASSERT_MSG (m_nArgs && m_nArgs == m_nItems, "failed, m_nArgs: " << m_nArgs << " N: " << m_nItems);
318 m_nArgs = 0;
319 }
320
321};
322
323
325 : TestCase ("Check basic TracedCallback operation")
326{
327}
328
335#define DUPE(U, T1) \
336 if (g_dupes.find ( # U ) == g_dupes.end ()) { \
337 NS_TEST_ASSERT_MSG_NE (0, 1, \
338 "expected to find " << # U << " in dupes."); } \
339 if (TypeName<U> (0) == TypeName<T1> (0)) { \
340 std::cout << # U << " matches " << # T1 << std::endl; } \
341 else \
342 NS_TEST_ASSERT_MSG_EQ \
343 (TypeName<U> (0), TypeName<T1> (0), \
344 "the typedef " << # U << \
345 " used to match the typedef " << # T1 << \
346 " but no longer does. Please add a new CHECK call.")
347
348
354#define CHECK(U, ...) \
355 CreateObject< Checker< __VA_ARGS__ > > ()->Invoke<U> ()
356
357
358void
360{
361
362 CHECK (dsr::DsrOptionSRHeader::TracedCallback,
363 const dsr::DsrOptionSRHeader &);
364
365 CHECK (EpcUeNas::StateTracedCallback,
367
368 CHECK (Ipv4L3Protocol::DropTracedCallback,
371
372 CHECK (Ipv4L3Protocol::SentTracedCallback,
374
375 CHECK (Ipv4L3Protocol::TxRxTracedCallback,
377
378 CHECK (Ipv6L3Protocol::DropTracedCallback,
381
382 CHECK (Ipv6L3Protocol::SentTracedCallback,
384
385 CHECK (Ipv6L3Protocol::TxRxTracedCallback,
387
388 CHECK (LrWpanMac::SentTracedCallback,
389 Ptr<const Packet>, uint8_t, uint8_t);
390
391 CHECK (LrWpanMac::StateTracedCallback,
393
394 CHECK (LrWpanPhy::StateTracedCallback,
396
397 CHECK (LteEnbMac::DlSchedulingTracedCallback,
398 uint32_t, uint32_t, uint16_t,
399 uint8_t, uint16_t, uint8_t, uint16_t, uint8_t);
400
401 CHECK (LteEnbMac::UlSchedulingTracedCallback,
402 uint32_t, uint32_t, uint16_t, uint8_t, uint16_t);
403
404 CHECK (LteEnbPhy::ReportUeSinrTracedCallback,
405 uint16_t, uint16_t, double, uint8_t);
406
407 CHECK (LteEnbPhy::ReportInterferenceTracedCallback,
408 uint16_t, Ptr<SpectrumValue>);
409
410 CHECK (LteEnbRrc::ConnectionHandoverTracedCallback,
411 uint64_t, uint16_t, uint16_t);
412
413 CHECK (LteEnbRrc::HandoverStartTracedCallback,
414 uint64_t, uint16_t, uint16_t, uint16_t);
415
416 CHECK (LteEnbRrc::NewUeContextTracedCallback,
417 uint16_t, uint16_t);
418
419 CHECK (LteEnbRrc::ReceiveReportTracedCallback,
420 uint64_t, uint16_t, uint16_t, LteRrcSap::MeasurementReport);
421
422 CHECK (LtePdcp::PduRxTracedCallback,
423 uint16_t, uint8_t, uint32_t, uint64_t);
424
425 CHECK (LtePdcp::PduTxTracedCallback,
426 uint16_t, uint8_t, uint32_t);
427
428 DUPE (LteRlc::NotifyTxTracedCallback, LtePdcp::PduTxTracedCallback);
429
430 DUPE (LteRlc::ReceiveTracedCallback, LtePdcp::PduRxTracedCallback);
431
432 CHECK (LteUePhy::RsrpSinrTracedCallback,
433 uint16_t, uint16_t, double, double, uint8_t);
434
435 CHECK (LteUePhy::StateTracedCallback,
436 uint16_t, uint16_t, LteUePhy::State, LteUePhy::State);
437
438 CHECK (LteUeRrc::CellSelectionTracedCallback,
439 uint64_t, uint16_t);
440
441 DUPE (LteUeRrc::ImsiCidRntiTracedCallback, LteEnbRrc::ConnectionHandoverTracedCallback);
442
443 DUPE (LteUeRrc::MibSibHandoverTracedCallback, LteEnbRrc::HandoverStartTracedCallback);
444
445 CHECK (LteUeRrc::StateTracedCallback,
446 uint64_t, uint16_t, uint16_t, LteUeRrc::State, LteUeRrc::State);
447
448 CHECK (Mac48Address::TracedCallback,
450
451 CHECK (MobilityModel::TracedCallback,
453
454 CHECK (olsr::RoutingProtocol::PacketTxRxTracedCallback,
455 const olsr::PacketHeader &, const olsr::MessageList &);
456
457 CHECK (olsr::RoutingProtocol::TableChangeTracedCallback,
458 uint32_t);
459
460 CHECK (Packet::AddressTracedCallback,
461 Ptr<const Packet>, const Address &);
462
463 CHECK (Packet::Mac48AddressTracedCallback,
465
466 CHECK (Packet::SinrTracedCallback,
467 Ptr<const Packet>, double);
468
469 CHECK (Packet::SizeTracedCallback,
471
472 CHECK (Packet::TracedCallback,
474
475 CHECK (PacketBurst::TracedCallback,
477
478 CHECK (dot11s::PeerManagementProtocol::LinkOpenCloseTracedCallback,
480
481 CHECK (PhyReceptionStatParameters::TracedCallback,
483
484 CHECK (PhyTransmissionStatParameters::TracedCallback,
486
487 CHECK (SixLowPanNetDevice::DropTracedCallback,
490
491 CHECK (SixLowPanNetDevice::RxTxTracedCallback,
493
494 CHECK (SpectrumChannel::LossTracedCallback,
496
497 CHECK (SpectrumValue::TracedCallback,
499
500 CHECK (TimeSeriesAdaptor::OutputTracedCallback,
501 double, double);
502
503 CHECK (UanMac::PacketModeTracedCallback,
505
506 CHECK (UanMacCw::QueueTracedCallback,
507 Ptr<const Packet>, uint16_t);
508
509 CHECK (UanMacRc::QueueTracedCallback,
511
512 CHECK (UanNetDevice::RxTxTracedCallback,
514
515 CHECK (UanPhy::TracedCallback,
517
518 CHECK (UeManager::StateTracedCallback,
519 uint64_t, uint16_t, uint16_t, UeManager::State, UeManager::State);
520
521 CHECK (WifiMacHeader::TracedCallback,
522 const WifiMacHeader &);
523
524 CHECK (WifiPhyStateHelper::RxEndErrorTracedCallback,
525 Ptr<const Packet>, double);
526
527 CHECK (WifiPhyStateHelper::RxOkTracedCallback,
529
530 CHECK (WifiPhyStateHelper::StateTracedCallback,
532
533 CHECK (WifiPhyStateHelper::TxTracedCallback,
535
536 CHECK (WifiRemoteStationManager::PowerChangeTracedCallback,
537 double, double, Mac48Address);
538
539 CHECK (WifiRemoteStationManager::RateChangeTracedCallback,
541}
542
549{
550public:
552};
553
555 : TestSuite ("traced-callback-typedef", SYSTEM)
556{
557 AddTestCase (new TracedCallbackTypedefTestCase, TestCase::QUICK);
558}
559
TracedCallback< Ts... > m_cb
TracedCallback to be called.
std::tuple< typename TypeTraits< Ts >::BaseType... > m_items
Arguments of the TracedCallback.
const std::size_t m_nItems
Number of arguments of the TracedCallback.
static std::size_t m_nArgs
Number of arguments passed to callback.
virtual void DoRun(void)
Implementation to actually run this TestCase.
a polymophic address class
Definition: address.h:91
Callback template class.
Definition: callback.h:1279
Class for representing data rates.
Definition: data-rate.h:89
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition: epc-ue-nas.h:163
Packet header for IPv4.
Definition: ipv4-header.h:34
DropReason
Reason why a packet has been dropped.
Packet header for IPv6.
Definition: ipv6-header.h:36
DropReason
Reason why a packet has been dropped.
State
The states of the UE PHY entity.
Definition: lte-ue-phy.h:67
State
The states of the UE RRC entity.
Definition: lte-ue-rrc.h:106
an EUI-48 address
Definition: mac48-address.h:44
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
A base class which provides memory management and object aggregation.
Definition: object.h:88
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Forward calls to a chain of Callback.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
State
The state of the UeManager at the eNB RRC.
Definition: lte-enb-rrc.h:87
Implements the IEEE 802.11 MAC header.
represent a single transmission mode
Definition: wifi-mode.h:48
Source Route (SR) Message Format.
#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:88
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:70
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:106
#define CHECK(U,...)
Check the TracedCallback by calling its Invoke function.
#define DUPE(U, T1)
Check the TracedCallback duplicate by checking if it maches the TracedCallback it is supposed to be e...
std::set< std::string > g_dupes
Container for duplicate types.
#define TYPENAME(T)
Returns a sting representing the type of a class.
std::string TypeName(int N)
Stringify the known TracedCallback type names.
std::set< std::string > Duplicates(void)
Record typedefs which are identical to previously declared.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
std::vector< MessageHeader > MessageList
Definition: olsr-header.h:695
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
MeasurementReport structure.
Definition: lte-rrc-sap.h:902
PhyReceptionStatParameters structure.
Definition: lte-common.h:213
PhyTransmissionStatParameters structure.
Definition: lte-common.h:187
static TracedCallbackTypedefTestSuite tracedCallbackTypedefTestSuite
Static variable for test initialization.
WifiPhyState
The state of the PHY layer.
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56