Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(640)

Unified Diff: doc/tutorial/tweaking.texi

Issue 196058: Redo ASCII and pcap Traces
Patch Set: Created 14 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: doc/tutorial/tweaking.texi
===================================================================
--- a/doc/tutorial/tweaking.texi
+++ b/doc/tutorial/tweaking.texi
@@ -812,32 +812,30 @@
@cindex tracing packets
Let's just jump right in and add some ASCII tracing output to our
-@code{scratch/myfirst.cc} script.
-
-The first thing you need to do is to add the following include to the top of
-the script just after the GNU GPL comment:
+@code{scratch/myfirst.cc} script. Right before the call to
+@code{Simulator::Run ()}, add the following line of code:
@verbatim
- #include <fstream>
+ pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("myfirst.tr"));
@end verbatim
-Then, right before the call to @code{Simulator::Run ()}, add the
-following lines of code:
+This line of code contains two nested method calls. The inside method,
+@code{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. We'll 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
+``myfirst.tr'' and passing it into @code{ns-3}. You are telling @code{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++ ofstream
+objects relating to copy constructors.
-@verbatim
- std::ofstream ascii;
- ascii.open ("myfirst.tr");
- PointToPointHelper::EnableAsciiAll (ascii);
-@end verbatim
+The outside call, to @code{EnableAsciiAll()}, tells the helper that you
+want to enable ASCII tracing on all point-to-point devices in your simulation;
+and you want the (provided) trace sinks to write out information about packet
+movement in ASCII format.
-The first two lines are just vanilla C++ code to open a stream that will be
-written to a file named ``myfirst.tr''. See your favorite C++ tutorial if you
-are unfamiliar with this code. The last line of code in the snippet above
-tells @command{ns-3} that you want to enable ASCII tracing on all
-point-to-point devices in your simulation; and you want the (provided) trace
-sinks to write out information about packet movement in ASCII format to the
-stream provided. For those familiar with @command{ns-2}, the traced events are
-equivalent to the popular trace points that log "+", "-", "d", and "r" events.
+For those familiar with @command{ns-2}, the traced events are equivalent to
+the popular trace points that log "+", "-", "d", and "r" events.
You can now build the script and run it from the command line:
@@ -984,7 +982,7 @@
The code used to enable pcap tracing is a one-liner.
@verbatim
- PointToPointHelper::EnablePcapAll ("myfirst");
+ pointToPoint.EnablePcapAll ("myfirst");
@end verbatim
Go ahead and insert this line of code after the ASCII tracing code we just
@@ -993,7 +991,7 @@
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.
+and a ``.pcap'' suffix.
In our example script, we will eventually see files named ``myfirst-0-0.pcap''
and ``myfirst-1-0.pcap'' which are the pcap traces for node 0-device 0 and

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b