What is tracing ?
After running simulation if we want to analyze the behavior of the network we need to analyze certain events that are occurring. Tracing means noting each and every event happening at every instance of time. Tracing analysis is helpful to provide proof for any new research, experiment. So ns-3 provides following two types of tracing.
1. ASCII tracing
ns-3 provides helper functionality that wraps the low-level tracing system to help you with the details involved in configuring some easily understood packet traces. If you enable this functionality, you will see output in a ASCII files thus the name. For those familiar with ns-2 output, this type of trace is analogous to the out.tr generated by many scripts. Right before the call to Simulator::Run (), add the following lines of code:
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("filename.tr"));
Like in many other ns-3 idioms, this code uses a helper object to help create ASCII traces. The second line contains two nested method calls. The inside method, CreateFileStream() uses an unnamed object idiom to create a file stream object on the stack (without an object name) and pass it down to the called method. Well go into this more in the future, but all you have to know at this point is that you are creating an object representing a file named filename.tr and passing it into ns-3. You are telling ns-3 to deal with the lifetime issues of the created object and also to deal with problems caused by a little-known (intentional) limitation of C++ offstream objects relating to copy constructors. The outside call, to EnableAsciiAll(), tells the helper that you want to enable ASCII tracing on all devices in your simulation; and you want the (provided) trace sinks to write out information about packet movement in ASCII format.
2. pcap tracing:
The ns-3 device helpers can be used to create trace les in the .pcap format. The acronym pcap (usually written in lower case) stands for packet capture, and is actually an API that includes the definition of a .pcap file format. The most popular program that can read and display this format is Wireshark (formerly called Ethereal).
However, there are many trac trace analyzers that use this packet format. The code used to enable pcap tracing is a one-liner.
pointToPoint.EnablePcapAll (“filename”);
Go ahead and insert this line of code after the ASCII tracing code. Notice that only passed the string is filename, and not filename.pcap or something similar. This is because the parameter is a prefix, not a complete file name. The helper will actually create a trace file for every point-to-point device in the simulation. The file names will be built using the prefix, the node number, the device number and a .pcap suffix. Once you have added the line of code to enable pcap tracing, you can run the script in the usual way:
./waf --run scratch/filename
- Reading output with tcpdump
The easiest thing to do at this point will be to use tcpdump to look at the pcap files.
tcpdump -nn -tt -r filename-0-0.pcap reading from le filename-0-0.pcap, link-type PPP (PPP) 2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024 tcpdump -nn -tt -r filename-1-0.pcap reading from le filename-1-0.pcap, link-type PPP (PPP) 2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024
You can see in the dump of filename-0-0.pcap (the client device) that the echo packet is sent at 2 seconds into the simulation. If you look at the second dump (filename-1-0.pcap) you can see that packet being received at 2.257324 seconds. You see the packet being echoed back at 2.257324 seconds in the second dump, and finally, you see the packet being received back at the client in the first dump at 2.514648 seconds.
2. Reading output with Wireshark :
If you are unfamiliar with Wireshark, there is a web site available from which you can download programs and documentation. Wireshark is a graphical user interface which can be used for displaying these trace files. If you have Wireshark available, you can open each of the trace files and display the contents as if you had captured the packets using a packet sniffer.
Visit again for more updates thanks…..