Tracing of channel variables

33 views
Skip to first unread message

Kalle Tuulos

unread,
Aug 23, 2019, 7:53:08 AM8/23/19
to ns-3-users
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

Kalle Tuulos

unread,
Aug 26, 2019, 4:23:05 AM8/26/19
to ns-3-users
Ok, I found the solution. The key was, that Config::Connect should be mapped to "ChannelList".

Attached is ns-3.29 patch with necessary modifications to enable tracing. WireState traces are printed to screen from the csma-ping.cc examle. There is also patch to ping to print packet sizes properly.

BR,
  Kalle
csma-tracing.txt
Reply all
Reply to author
Forward
0 new messages