Generating pcap files

382 views
Skip to first unread message

Shashank Solomon

unread,
Jun 10, 2014, 7:23:22 AM6/10/14
to ns-3-...@googlegroups.com

  I added this line in my example program :
          stdma.StdmaHelper::EnablePcapInternal("simple-stdma", stdmaDevices.Get(0),false,false);
  EnablePcapInternal is defined in stdma-helper as follows :
 
void
StdmaHelper::EnablePcapInternal (std::string prefix, ns3::Ptr<ns3::NetDevice> nd, bool promiscuous, bool explicitFilename)
{
 
  ns3::PcapHelper pcapHelper;
  ns3::Ptr<StdmaNetDevice> device = nd->GetObject<StdmaNetDevice> ();
  std::string filename;
  if (explicitFilename)
    {
      filename = prefix;
    }
  else
    {
      filename = pcapHelper.GetFilenameFromDevice (prefix, device);
    }

  ns3::Ptr<ns3::PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out,
                                                     ns3::PcapHelper::DLT_NULL);
  pcapHelper.HookDefaultSink<StdmaNetDevice> (device, "Sniffer", file);
}
  
On running, i get this error message - assert failed. cond="result == true", msg="PcapHelper::HookDefaultSink():  Unable to hook "Sniffer"", file=./ns3/trace-helper.h, line=99
terminate called without an active exception

What does unable to hook Sniffer mean? Im new to ns3 and this is my first try at writing a Pcap trace. Any help would be much appreciated

PS . I have attached the example code and the stdma-helper.cc and stdma-helper.h files
simple-stdma-example.cc
stdma-helper.cc
stdma-helper.h

Konstantinos

unread,
Jun 10, 2014, 7:46:00 AM6/10/14
to ns-3-...@googlegroups.com
This is not the proper way to call a member function from a class.
 stdma.StdmaHelper::EnablePcapInternal("simple-stdma", stdmaDevices.Get(0),false,false);

Also, the name of the method (EnablePcapInternal), seems like a private class that should not be accessed outside the StdmaHelper.
Also, in your stdma-helper.h you have commented out the inheritance from PcapHelperForDevice.

Have you defined a StdmaNetDevice? I see it using in throughout your helper but not in the files you send.
 ns3::Ptr<StdmaNetDevice> device = nd->GetObject<StdmaNetDevice> ();

Does this NetDevice have a tracesource "Sniffer" which is actually what is required here?

 pcapHelper.HookDefaultSink<StdmaNetDevice> (device, "Sniffer", file);


Shashank Solomon

unread,
Jun 10, 2014, 11:07:48 PM6/10/14
to ns-3-...@googlegroups.com
Thanks for your quick reply. I checked my StdmaNetDevice class - the trace source wasn't defined. I will add it and run

Shashank Solomon

unread,
Jun 11, 2014, 12:21:36 AM6/11/14
to ns-3-...@googlegroups.com
 I was able to generate a pcap file but I dont know how to add data like source and destination to it. Can someone advise me?

I added my trace hook to StdmaNetDevice::ForwardUp . Is this enough?

 i will attach the files required
stdma-helper.cc
stdma-helper.h
simple-stdma-example.cc
stdma-net-device.cc
stdma-net-device.h
simple-stdma-0-0.pcap

Konstantinos

unread,
Jun 11, 2014, 5:28:53 AM6/11/14
to ns-3-...@googlegroups.com
Please do not post the same question over and over again. 

The Sniffer trace source should be triggered both on Tx and on Rx events. 
Taking for example the CsmaNetDevice, its sniffertrace is called in SendFrom, Transmit, Receive.
Reply all
Reply to author
Forward
0 new messages