Manage ASCII trace files for device models. More...
#include <trace-helper.h>
Public Member Functions | |
AsciiTraceHelper () | |
Create an ascii trace helper. | |
~AsciiTraceHelper () | |
Destroy an ascii trace helper. | |
Ptr< OutputStreamWrapper > | CreateFileStream (std::string filename, std::ios::openmode filemode=std::ios::out) |
Create and initialize an output stream object we'll use to write the traced bits. | |
std::string | GetFilenameFromDevice (std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true) |
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated with a device. | |
std::string | GetFilenameFromInterfacePair (std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true) |
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated with a node. | |
template<typename T > | |
void | HookDefaultDequeueSinkWithContext (Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default dequeue operation trace sink that does accept and log a trace context. | |
template<typename T > | |
void | HookDefaultDequeueSinkWithoutContext (Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default dequeue operation trace sink that does not accept nor log a trace context. | |
template<typename T > | |
void | HookDefaultDropSinkWithContext (Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default drop operation trace sink that does accept and log a trace context. | |
template<typename T > | |
void | HookDefaultDropSinkWithoutContext (Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace context. | |
template<typename T > | |
void | HookDefaultEnqueueSinkWithContext (Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default enqueue operation trace sink that does accept and log a trace context. | |
template<typename T > | |
void | HookDefaultEnqueueSinkWithoutContext (Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default enqueue operation trace sink that does not accept nor log a trace context. | |
template<typename T > | |
void | HookDefaultReceiveSinkWithContext (Ptr< T > object, std::string context, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default receive operation trace sink that does accept and log a trace context. | |
template<typename T > | |
void | HookDefaultReceiveSinkWithoutContext (Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream) |
Hook a trace source to the default receive operation trace sink that does not accept nor log a trace context. |
Static Public Member Functions | |
static void | DefaultDequeueSinkWithContext (Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p) |
static void | DefaultDequeueSinkWithoutContext (Ptr< OutputStreamWrapper > file, Ptr< const Packet > p) |
static void | DefaultDropSinkWithContext (Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p) |
static void | DefaultDropSinkWithoutContext (Ptr< OutputStreamWrapper > file, Ptr< const Packet > p) |
static void | DefaultEnqueueSinkWithContext (Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p) |
static void | DefaultEnqueueSinkWithoutContext (Ptr< OutputStreamWrapper > file, Ptr< const Packet > p) |
static void | DefaultReceiveSinkWithContext (Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p) |
static void | DefaultReceiveSinkWithoutContext (Ptr< OutputStreamWrapper > file, Ptr< const Packet > p) |
Manage ASCII trace files for device models.
Handling ascii trace files is a common operation for ns-3 devices. It is useful to provide a common base class for dealing with these ops.
Definition at line 109 of file trace-helper.h.
ns3::AsciiTraceHelper::AsciiTraceHelper | ( | ) |
Create an ascii trace helper.
Definition at line 173 of file trace-helper.cc.
References NS_LOG_FUNCTION_NOARGS.
ns3::AsciiTraceHelper::~AsciiTraceHelper | ( | ) |
Destroy an ascii trace helper.
Definition at line 178 of file trace-helper.cc.
References NS_LOG_FUNCTION_NOARGS.
Ptr< OutputStreamWrapper > ns3::AsciiTraceHelper::CreateFileStream | ( | std::string | filename, |
std::ios::openmode | filemode = std::ios::out |
||
) |
Create and initialize an output stream object we'll use to write the traced bits.
One of the common issues users run into when trying to use tracing in ns-3 is actually a design decision made in the C++ stream library. It is not widely known that copy and assignment of iostreams is forbidden by std::basic_ios<>. This is because it is not possible to predict the semantics of the stream desired by a user.
The tempting ns-3 idiom when tracing to a file is to create a bound callback with an ofstream as the bound object. Unfortunately, this implies a copy construction in order to get the ofstream object into the callback. This operation, as mentioned above, is forbidden by the STL. You could use a global ostream and pass a pointer to it, but that is pretty ugly. You could create an ostream on the stack and pass a pointer to it, but you may run into object lifetime issues. Ns-3 has a nice reference counted object that can solve the problem so we use one of those to carry the stream around and deal with the lifetime issues.
Definition at line 184 of file trace-helper.cc.
References NS_LOG_FUNCTION.
Referenced by DsdvManetExample::CreateDevices(), MobilityTraceTestCase::DoRun(), Ns3TcpLossTestCase::DoRun(), ns3::FdNetDeviceHelper::EnableAsciiInternal(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), ns3::YansWifiPhyHelper::EnableAsciiInternal(), ns3::WimaxHelper::EnableAsciiInternal(), ns3::InternetStackHelper::EnableAsciiIpv4Internal(), ns3::InternetStackHelper::EnableAsciiIpv6Internal(), ns3::SpectrumAnalyzerHelper::Install(), and main().
|
static |
Definition at line 363 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by ns3::WimaxHelper::EnableAsciiForConnection(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), and HookDefaultDequeueSinkWithContext().
|
static |
Definition at line 356 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by HookDefaultDequeueSinkWithoutContext().
|
static |
Definition at line 336 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by ns3::WimaxHelper::EnableAsciiForConnection(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), ns3::InternetStackHelper::EnableAsciiIpv4Internal(), and HookDefaultDropSinkWithContext().
|
static |
Definition at line 329 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by HookDefaultDropSinkWithoutContext().
|
static |
Definition at line 310 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by ns3::WimaxHelper::EnableAsciiForConnection(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), and HookDefaultEnqueueSinkWithContext().
|
static |
Definition at line 303 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by HookDefaultEnqueueSinkWithoutContext().
|
static |
Definition at line 387 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by ns3::FdNetDeviceHelper::EnableAsciiInternal(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), and HookDefaultReceiveSinkWithContext().
|
static |
Definition at line 380 of file trace-helper.cc.
References ns3::Time::GetSeconds(), ns3::OutputStreamWrapper::GetStream(), ns3::Now(), and NS_LOG_FUNCTION.
Referenced by HookDefaultReceiveSinkWithoutContext().
std::string ns3::AsciiTraceHelper::GetFilenameFromDevice | ( | std::string | prefix, |
Ptr< NetDevice > | device, | ||
bool | useObjectNames = true |
||
) |
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated with a device.
Definition at line 205 of file trace-helper.cc.
References ns3::Names::FindName(), ns3::Node::GetId(), ns3::NetDevice::GetIfIndex(), ns3::NetDevice::GetNode(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
Referenced by ns3::FdNetDeviceHelper::EnableAsciiInternal(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), ns3::YansWifiPhyHelper::EnableAsciiInternal(), ns3::WimaxHelper::EnableAsciiInternal(), and ns3::SpectrumAnalyzerHelper::Install().
std::string ns3::AsciiTraceHelper::GetFilenameFromInterfacePair | ( | std::string | prefix, |
Ptr< Object > | object, | ||
uint32_t | interface, | ||
bool | useObjectNames = true |
||
) |
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated with a node.
Definition at line 250 of file trace-helper.cc.
References ns3::Names::FindName(), ns3::Node::GetId(), ns3::Object::GetObject(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
Referenced by ns3::InternetStackHelper::EnableAsciiIpv4Internal(), and ns3::InternetStackHelper::EnableAsciiIpv6Internal().
void ns3::AsciiTraceHelper::HookDefaultDequeueSinkWithContext | ( | Ptr< T > | object, |
std::string | context, | ||
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default dequeue operation trace sink that does accept and log a trace context.
Definition at line 285 of file trace-helper.h.
References DefaultDequeueSinkWithContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
void ns3::AsciiTraceHelper::HookDefaultDequeueSinkWithoutContext | ( | Ptr< T > | object, |
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default dequeue operation trace sink that does not accept nor log a trace context.
Definition at line 276 of file trace-helper.h.
References DefaultDequeueSinkWithoutContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
Referenced by ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), and ns3::CsmaHelper::EnableAsciiInternal().
void ns3::AsciiTraceHelper::HookDefaultDropSinkWithContext | ( | Ptr< T > | object, |
std::string | context, | ||
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default drop operation trace sink that does accept and log a trace context.
Definition at line 263 of file trace-helper.h.
References DefaultDropSinkWithContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
void ns3::AsciiTraceHelper::HookDefaultDropSinkWithoutContext | ( | Ptr< T > | object, |
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace context.
Definition at line 254 of file trace-helper.h.
References DefaultDropSinkWithoutContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
Referenced by ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), ns3::CsmaHelper::EnableAsciiInternal(), and ns3::InternetStackHelper::EnableAsciiIpv4Internal().
void ns3::AsciiTraceHelper::HookDefaultEnqueueSinkWithContext | ( | Ptr< T > | object, |
std::string | context, | ||
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default enqueue operation trace sink that does accept and log a trace context.
Definition at line 241 of file trace-helper.h.
References DefaultEnqueueSinkWithContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
void ns3::AsciiTraceHelper::HookDefaultEnqueueSinkWithoutContext | ( | Ptr< T > | object, |
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default enqueue operation trace sink that does not accept nor log a trace context.
Definition at line 232 of file trace-helper.h.
References DefaultEnqueueSinkWithoutContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
Referenced by ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), and ns3::CsmaHelper::EnableAsciiInternal().
void ns3::AsciiTraceHelper::HookDefaultReceiveSinkWithContext | ( | Ptr< T > | object, |
std::string | context, | ||
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default receive operation trace sink that does accept and log a trace context.
Definition at line 307 of file trace-helper.h.
References DefaultReceiveSinkWithContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
void ns3::AsciiTraceHelper::HookDefaultReceiveSinkWithoutContext | ( | Ptr< T > | object, |
std::string | traceName, | ||
Ptr< OutputStreamWrapper > | stream | ||
) |
Hook a trace source to the default receive operation trace sink that does not accept nor log a trace context.
Definition at line 298 of file trace-helper.h.
References DefaultReceiveSinkWithoutContext(), ns3::MakeBoundCallback(), and NS_ASSERT_MSG.
Referenced by ns3::FdNetDeviceHelper::EnableAsciiInternal(), ns3::EmuHelper::EnableAsciiInternal(), ns3::PointToPointHelper::EnableAsciiInternal(), and ns3::CsmaHelper::EnableAsciiInternal().