Question in short: how can channel variables, e.g. Wirestate, be traced?
I'm using the "src/csma/examples/csma-ping.cc" as an example. In this example, 4 Csma devices connect to the same Csma channel. According to manual's Tracing chapter, steps would be:
First, modify the "csma-channel.h" file. Add following:
#include "ns3/traced-value.h"
#include "ns3/trace-source-accessor.h"
Modify the definition of m_state to be:
TracedValue<WireState> m_state;
Then, add trace source. For this, edit the "csma-channel.cc", GetTypeId function.
.AddTraceSource ("ChannelState", "Channel state",
MakeTraceSourceAccessor (&CsmaChannel::m_state))
Then, create a tracing function. This will be added to "csma-ping.cc" file.
static void
ChannelStateTrace ( WireState oldValue, SatelWireState newValue )
{
std::string filename = "channel_state_trace.txt";
std::ofstream outFile;
outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!outFile.is_open ())
{
NS_LOG_ERROR ("Can't open file " << filename);
return;
}
outFile << Simulator::Now() << " Old value " << oldValue << " New " << newValue << std::endl;
}
But after this, I don't know, how I can activate the tracing. The manual suggests to use myObject->TraceConnectWithoutContext () but the csma-ping.cc's main function is not aware of CsmaChannel object, thus it can't call its TraceConnectWithoutContext function.
So, back to the question: how channel's activity can be traced?
Thanks and best regards,
Kalle
xx