How to enable PCAP tracing in a test

1,015 views
Skip to first unread message

Matt

unread,
Sep 1, 2014, 11:18:06 AM9/1/14
to ns-3-...@googlegroups.com
Hi,

I have a very simple network composed of one node and 2 hosts. I would
like to generate a PCAP file of the communication at both hosts to
debug my code. I've had a look at the documentation (with the website
crashing from times to times :) ) and from what I understood, I should
use a device helper such as PontToPoint etc.. that inherit from
PcapHelperForNetDevice.

Thing is I set my devices manually (rather I modified the tcp-test.cc)
so using the PointToPointHelper doesn't seem like a good idea.
Any advice on how to do it ?

IIRC, I also need to launch test.py with specific flags to prevent my
pcap from being garbage collected at the end of the test.

I am using ns3.19.

Regards

Matt

Konstantinos

unread,
Sep 1, 2014, 11:38:31 AM9/1/14
to ns-3-...@googlegroups.com
Dear Matt,

IMHO, there is no need to inherit the helper, just create an object of PcapHelper and then enable PCAP for your device by hooking the DefaultSink.
Just look how the helper implements that function

76 void
77 PointToPointHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
78 {
79  //
80  // All of the Pcap enable functions vector through here including the ones
81  // that are wandering through all of devices on perhaps all of the nodes in
82  // the system. We can only deal with devices of type PointToPointNetDevice.
83  //
84  Ptr<PointToPointNetDevice> device = nd->GetObject<PointToPointNetDevice> ();
85  if (device == 0)
86  {
87  NS_LOG_INFO ("PointToPointHelper::EnablePcapInternal(): Device " << device << " not of type ns3::PointToPointNetDevice");
88  return;
89  }
90 
91  PcapHelper pcapHelper;
92 
93  std::string filename;
94  if (explicitFilename)
95  {
96  filename = prefix;
97  }
98  else
99  {
100  filename = pcapHelper.GetFilenameFromDevice (prefix, device);
101  }
102 
103  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out,
105  pcapHelper.HookDefaultSink<PointToPointNetDevice> (device, "PromiscSniffer", file);
106 }

Matt Anonyme

unread,
Sep 1, 2014, 6:13:08 PM9/1/14
to ns-3-...@googlegroups.com
Indeed it looks like the way to go. It is strange to have to create an object for a function that stores no state (it could be a template function or a static member).

I've compiled my code with that and ran my test.  (Basically I've added the following code at the end of TcpTestCase::SetupDefaultSim() :
=====
PointToPointHelper helper;
helper.EnablePcapAll("test",true);
=====
My test fails and then I can't find any Pcap even though I run ./test.py with the "-r " flag. I can see the results.xml in the correct subfolder of testpy-output but no trace of a pcap file (looked with $find . -iname test.pcap).

Any idea why ? It is possible that it does not get saved because the test fails.

Thanks

Matt

unread,
Sep 2, 2014, 5:39:19 AM9/2/14
to ns-3-...@googlegroups.com
I enabled logging for the tracing helpers and saw:
"[INFO ] PointToPointHelper::EnablePcapInternal(): Device 0 not of
type ns3::PointToPointNetDevice" and indeed tcp-test.cc installs
SimpleNetDevice which don't have helpers for Pcap capture. I will try
to upgrade it with PointToPointDevice.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ns-3-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ns-3-users/IFuLMwhPodU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ns-3-users+...@googlegroups.com.
> To post to this group, send email to ns-3-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ns-3-users.
> For more options, visit https://groups.google.com/d/optout.

Tommaso Pecorella

unread,
Sep 2, 2014, 1:18:29 PM9/2/14
to ns-3-...@googlegroups.com
Hi Matt,

if you're writing tests for the Internet module, please avoid using PointToPoint (or CSMA). The only "safe" NetDevice to use in tests is SimpleNetDevice (which doesn't support yet pcap traces).
If you want we can extend SimpleNetDevice to have pcap traces too, but they shouldn't be really needed in TCP tests.
Pcap traces are usually used in regression tests, but keeping a "perfect" pcap trace is often more a hassle than anything. E.g., you change how IP id is handled, new traces. You add ARP jitter, new traces, and so on.

From my experience... just find another way to assess that everything works as intended.

Cheers,

T.

Matt

unread,
Sep 3, 2014, 9:59:28 AM9/3/14
to ns-3-...@googlegroups.com
2014-09-02 19:18 GMT+02:00 Tommaso Pecorella <tomm...@gmail.com>:
> Hi Matt,
>
> if you're writing tests for the Internet module, please avoid using
> PointToPoint (or CSMA). The only "safe" NetDevice to use in tests is
> SimpleNetDevice (which doesn't support yet pcap traces).
Thanks for the warning. I will change it to SimpleNetDevice
afterwards, I am time-limited now. Being able to generate pcaps look
important even for testings. In case a test fails with ns3 valinna one
can send a pcap to the main team (even if that should not happen).
I should be doing my debugging in the scratchpad but as I use a
slighty modifed tcp test it was easier to do it as a test. Having the
PCAP allows me to benefit from wireshark colored output (would be nice
to have the same in the NS3 logger :D ) and its TCP understanding.

I have not the time yet to propose a solution but this is strange to
have to create an object (PoinToPointDeviceHelper) to be able to
enable Pcap. The member function does not use any variables from the
object. It could be left as a static function or even a template
function specialized later on:
template<T>
EnablePcap(Ptr<T> )
{
.....NS_FATAL_ERROR("Not Implemented yet");
}


template<>
EnablePcap(Ptr<PointToPointDevice> )
{
....actual code
}

Regards

Tommaso Pecorella

unread,
Sep 3, 2014, 12:19:02 PM9/3/14
to ns-3-...@googlegroups.com
Hi Matt,

it's already a template:
template <typename T> void
PcapHelper::HookDefaultSink (Ptr<T> object, std::string tracename, Ptr<PcapFileWrapper> file)
{
 
bool result =
   
object->TraceConnectWithoutContext (tracename.c_str (), MakeBoundCallback (&DefaultSink, file));
  NS_ASSERT_MSG
(result == true, "PcapHelper::HookDefaultSink():  Unable to hook \"" << tracename << "\"");
}

The problem may be to use it outside of the helper. Purely because the Helper is inheriting from the PcapHelper class, while the NetDevice isn't.
Why? It's a design pattern... or call it a design choice.

About having tests generating PCAPs, I don't agree. I'd rather have a "companion" example. It is more readable, can generate PCAPs, can use the NetDevices it wants, and so on.
I do undertand that you're short on time, but I'd restrict the test to specific functionalities and the more complex scenario... an example.

Anyway, this goes beyond your original question. You have a need, and you needed to find a solution. When you'll have time and you'll want to submit code for review... we'll iron out the little things.

Cheers,

T.
Reply all
Reply to author
Forward
0 new messages