author | Craig Dowell <craigdo@ee.washington.edu> |
Fri, 12 Feb 2010 21:02:49 -0800 | |
changeset 6051 | b988174aa30b |
parent 6031 | 18776ed87c60 |
child 6053 | b17ea72acee9 |
permissions | -rw-r--r-- |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
@node Tracing |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
@chapter Tracing |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
4 |
The tracing subsystem is one of the most important mechanisms to understand in |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
@command{ns-3}. In most cases, @command{ns-3} users will have a brilliant idea |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
for some new and improved networking feature. In order to verify that this |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
idea works, the researcher will make changes to an existing system and then run |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
8 |
experiments to see how the new feature behaves by gathering statistics |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
9 |
that capture the behavior of the feature. |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
In other words, the whole point of running a simulation is to generate output for |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
further study. In @command{ns-3}, the subsystem that enables a researcher to do |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
this is the tracing subsystem. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
@menu |
5426 | 16 |
* Tracing Motivation:: |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
* Overview:: |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
* Using the Tracing API:: |
6031 | 19 |
* Using the Tracing Helpers:: |
5426 | 20 |
* Tracing implementation details:: |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
@end menu |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
|
5426 | 23 |
@node Tracing Motivation |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
@section Motivation |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
There are many ways to get information out of a program. The most straightforward |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
way is to just directly print the information to the standard output, as in, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
@verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
#include <iostream> |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
int main () |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
std::cout << ``The value of x is `` << x << std::endl; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
@end verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
This is workable in small environments, but as your simulations get more and more |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
41 |
complicated, you end up with more and more prints and the task of parsing and |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
performing computations on the output begins to get harder and harder. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
Another thing to consider is that every time a new tidbit is needed, the software |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
core must be edited and another print introduced. There is no standardized way |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
to control all of this output, so the amount of output tends to grow without |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
bounds. Eventually, the bandwidth required for simply outputting this information |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
begins to limit the running time of the simulation. The output files grow to |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
enormous sizes and parsing them becomes a problem. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
@command{ns-3} provides a simple mechanism for logging and providing some control |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
over output via @emph{Log Components}, but the level of control is not very fine |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
grained at all. The logging module is a relatively blunt instrument. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
It is desirable to have a facility that allows one to reach into the core system |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
and only get the information required without having to change and recompile the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
core system. Even better would be a system that notified the user when an item |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
of interest changed or an interesting event happened. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
The @command{ns-3} tracing system is designed to work along those lines and is |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
well-integrated with the Attribute and Config substems allowing for relatively |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
simple use scenarios. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
@node Overview |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
@section Overview |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
The tracing subsystem relies heavily on the @code{ns-3} Callback and Attribute |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
mechanisms. You should read and understand the corresponding sections of the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
manual before attempting to understand the tracing system. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
The ns-3 tracing system is built on the concepts of independent tracing sources |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
and tracing sinks; along with a uniform mechanism for connecting sources to sinks. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
Trace sources are entities that can signal events that happen in a simulation and |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
provide access to interesting underlying data. For example, a trace source could |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
indicate when a packet is received by a net device and provide access to the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
packet contents for interested trace sinks. A trace source might also indicate |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
78 |
when an interesting state change happens in a model. For example, the congestion |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
window of a TCP model is a prime candidate for a trace source. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
Trace sources are not useful by themselves; they must be connected to other pieces |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
of code that actually do something useful with the information provided by the source. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
The entities that consume trace information are called trace sinks. Trace sources |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
are generators of events and trace sinks are consumers. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
This explicit division allows for large numbers of trace sources to be scattered |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
around the system in places which model authors believe might be useful. Unless |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
a user connects a trace sink to one of these sources, nothing is output. This |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
arrangement allows relatively unsophisticated users to attach new types of sinks |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
to existing tracing sources, without requiring editing and recompiling the core |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
or models of the simulator. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
There can be zero or more consumers of trace events generated by a trace source. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
One can think of a trace source as a kind of point-to-multipoint information link. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
96 |
The ``transport protocol'' for this conceptual point-to-multipoint link is an |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
@code{ns-3} @code{Callback}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
Recall from the Callback Section that callback facility is a way to allow two |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
modules in the system to communicate via function calls while at the same time |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
decoupling the calling function from the called class completely. This is the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
same requirement as outlined above for the tracing system. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
104 |
Basically, a trace source @emph{is} a callback to which multiple |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
105 |
functions may be registered. When a trace sink expresses |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
interest in receiving trace events, it adds a callback to a list of callbacks |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
held by the trace source. When an interesting event happens, the trace source |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
invokes its @code{operator()} providing zero or more parameters. This tells |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
the source to go through its list of callbacks invoking each one in turn. In |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
this way, the parameter(s) are communicated to the trace sinks, which are just |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
functions. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
@subsection The Simplest Example |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
It will be useful to go walk a quick example just to reinforce what we've said. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
117 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
118 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
#include ``ns3/object.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
#include ``ns3/uinteger.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
#include ``ns3/traced-value.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
#include ``ns3/trace-source-accessor.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
#include <iostream> |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
using namespace ns3; |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
127 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
128 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
The first thing to do is include the required files. As mentioned above, the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
trace system makes heavy use of the Object and Attribute systems. The first |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
two includes bring in the declarations for those systems. The file, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
@code{traced-value.h} brings in the required declarations for tracing data |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
that obeys value semantics. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
In general, value semantics just means that you can pass the object around, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
not an address. In order to use value semantics at all you have to have an |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
object with an associated copy constructor and assignment operator |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
available. We extend the requirements to talk about the set of operators |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
that are pre-defined for plain-old-data (POD) types. Operator=, operator++, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
operator--, operator+, operator==, etc. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
What this all means is that you will be able to trace changes to an object |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
made using those operators. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
146 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
147 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
class MyObject : public Object |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
public: |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
static TypeId GetTypeId (void) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
static TypeId tid = TypeId ("MyObject") |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
.SetParent (Object::GetTypeId ()) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
.AddConstructor<MyObject> () |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
.AddTraceSource ("MyInteger", |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
"An integer value to trace.", |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
MakeTraceSourceAccessor (&MyObject::m_myInt)) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
return tid; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
MyObject () {} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
TracedValue<uint32_t> m_myInt; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
}; |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
166 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
167 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
169 |
Since the tracing system is integrated with Attributes, and Attributes work |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
with Objects, there must be an @command{ns-3} @code{Object} for the trace source |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
171 |
to live in. The two important lines of code are the @code{.AddTraceSource} and |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
the @code{TracedValue} declaration. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
The @code{.AddTraceSource} provides the ``hooks'' used for connecting the trace |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
source to the outside world. The @code{TracedValue} declaration provides the |
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
176 |
infrastructure that overloads the operators mentioned above and drives the callback |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
process. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
179 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
180 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
void |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
IntTrace (Int oldValue, Int newValue) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
std::cout << ``Traced `` << oldValue << `` to `` << newValue << std::endl; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
} |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
186 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
187 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
This is the definition of the trace sink. It corresponds directly to a callback |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
function. This function will be called whenever one of the operators of the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
@code{TracedValue} is executed. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
193 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
194 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
195 |
int |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
196 |
main (int argc, char *argv[]) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
197 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
Ptr<MyObject> myObject = CreateObject<MyObject> (); |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
199 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
200 |
myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback(&IntTrace)); |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
myObject->m_myInt = 1234; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
203 |
} |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
204 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
205 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
206 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
207 |
In this snippet, the first thing that needs to be done is to create the object |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
in which the trace source lives. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
210 |
The next step, the @code{TraceConnectWithoutContext}, forms the connection |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
211 |
between the trace source and the trace sink. Notice the @code{MakeCallback} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
212 |
template function. Recall from the Callback section that this creates the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
213 |
specialized functor responsible for providing the overloaded @code{operator()} |
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
214 |
used to ``fire'' the callback. The overloaded operators (++, --, etc.) will |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
215 |
use this @code{operator()} to actually invoke the callback. The |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
216 |
@code{TraceConnectWithoutContext}, takes a string parameter that provides |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
217 |
the name of the Attribute assigned to the trace source. Let's ignore the bit |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
218 |
about context for now since it is not important yet. |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
Finally, the line, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
@verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
223 |
myObject->m_myInt = 1234; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
224 |
@end verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
225 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
226 |
should be interpreted as an invocation of @code{operator=} on the member |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
227 |
variable @code{m_myInt} with the integer @code{1234} passed as a parameter. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
228 |
It turns out that this operator is defined (by @code{TracedValue}) to execute |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
229 |
a callback that returns void and takes two integer values as parameters -- |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
230 |
an old value and a new value for the integer in question. That is exactly |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
231 |
the function signature for the callback function we provided -- @code{IntTrace}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
232 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
To summarize, a trace source is, in essence, a variable that holds a list of |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
callbacks. A trace sink is a function used as the target of a callback. The |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
Attribute and object type information systems are used to provide a way to |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
connect trace sources to trace sinks. The act of ``hitting'' a trace source |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
is executing an operator on the trace source which fires callbacks. This |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
results in the trace sink callbacks registering interest in the source being |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
called with the parameters provided by the source. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
@subsection Using the Config Subsystem to Connect to Trace Sources |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
243 |
The @code{TraceConnectWithoutContext} call shown above in the simple example is |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
244 |
actually very rarely used in the system. More typically, the @code{Config} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
subsystem is used to allow selecting a trace source in the system using what is |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
called a @emph{config path}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
For example, one might find something that looks like the following in the system |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
(taken from @code{examples/tcp-large-transfer.cc}) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
251 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
252 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
253 |
void CwndTracer (uint32_t oldval, uint32_t newval) {} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
256 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
257 |
Config::ConnectWithoutContext ( |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
258 |
"/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
259 |
MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
260 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
261 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
262 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
263 |
This should look very familiar. It is the same thing as the previous example, |
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
264 |
except that a static member function of class @code{Config} is being called instead |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
265 |
of a method on @code{Object}; and instead of an @code{Attribute} name, a path is |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
266 |
being provided. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
267 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
268 |
The first thing to do is to read the path backward. The last segment of the path |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
269 |
must be an @code{Attribute} of an @code{Object}. In fact, if you had a pointer to |
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
270 |
the @code{Object} that has the ``CongestionWindow'' @code{Attribute} handy (call it |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
271 |
@code{theObject}), you could write this just like the previous example: |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
272 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
273 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
274 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
275 |
void CwndTracer (uint32_t oldval, uint32_t newval) {} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
276 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
277 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
278 |
|
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
279 |
theObject->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
280 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
281 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
282 |
|
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
283 |
It turns out that the code for @code{Config::ConnectWithoutContext} does exactly that. |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
284 |
This function takes a path that represents a chain of @code{Object} pointers and follows |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
285 |
them until it gets to the end of the path and interprets the last segment as an |
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
286 |
@code{Attribute} on the last object. Let's walk through what happens. |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
287 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
288 |
The leading ``/'' character in the path refers to a so-called namespace. One of the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
289 |
predefined namespaces in the config system is ``NodeList'' which is a list of all of |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
290 |
the nodes in the simulation. Items in the list are referred to by indices into the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
291 |
list, so ``/NodeList/0'' refers to the zeroth node in the list of nodes created by |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
292 |
the simulation. This node is actually a @code{Ptr<Node>} and so is a subclass of |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
293 |
an @code{ns3::Object}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
294 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
295 |
As described in the Object Model section, @code{ns-3} supports an object aggregation |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
296 |
model. The next path segment begins with the ``$'' character which indicates a |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
297 |
@code{GetObject} call should be made looking for the type that follows. When a |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
298 |
node is initialized by an @code{InternetStackHelper} a number of interfaces are |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
299 |
aggregated to the node. One of these is the TCP level four protocol. The runtime |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
300 |
type of this protocol object is ``ns3::TcpL4Protocol''. When the @code{GetObject} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
301 |
is executed, it returns a pointer to the object of this type. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
302 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
303 |
The @code{TcpL4Protocol} class defines an Attribute called ``SocketList'' which is |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
304 |
a list of sockets. Each socket is actually an @code{ns3::Object} with its own |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
305 |
@code{Attributes}. The items in the list of sockets are referred to by index just |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
306 |
as in the NodeList, so ``SocketList/0'' refers to the zeroth socket in the list |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
307 |
of sockets on the zeroth node in the NodeList -- the first node constructed in the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
308 |
simulation. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
309 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
310 |
This socket, the type of which turns out to be an @code{ns3::TcpSocketImpl} defines |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
311 |
an attribute called ``CongestionWindow'' which is a @code{TracedValue<uint32_t>}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
312 |
The @code{Config::ConnectWithoutContext} now does a, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
313 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
314 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
315 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
316 |
object->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
317 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
318 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
319 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
320 |
using the object pointer from ``SocketList/0'' which makes the connection between |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
321 |
the trace source defined in the socket to the callback -- @code{CwndTracer}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
322 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
323 |
Now, whenever a change is made to the @code{TracedValue<uint32_t>} representing the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
324 |
congestion window in the TCP socket, the registered callback will be executed and |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
325 |
the function @code{CwndTracer} will be called printing out the old and new values |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
326 |
of the TCP congestion window. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
327 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
328 |
@node Using the Tracing API |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
329 |
@section Using the Tracing API |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
330 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
331 |
There |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
332 |
are three levels of interaction with the tracing system: |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
333 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
334 |
@itemize @bullet |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
335 |
@item Beginning user can easily control which objects are participating in tracing; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
336 |
@item Intermediate users can extend the tracing system to modify the output format |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
337 |
generated or use existing trace sources in different ways, without modifying the |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
338 |
core of the simulator; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
339 |
@item Advanced users can modify the simulator core to add new tracing sources and |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
340 |
sinks. |
5231 | 341 |
@end itemize |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
342 |
|
6031 | 343 |
@node Using the Tracing Helpers |
344 |
@section Using the Tracing Helpers |
|
345 |
||
346 |
The @code{ns-3} trace helpers provide a rich environment for configuring and |
|
347 |
selecting different trace events and writing them to files. In previous |
|
348 |
sections, primarily ``Building Topologies,'' we have seen several varieties |
|
349 |
of the trace helper methods designed for use inside other (device) helpers. |
|
350 |
||
351 |
Perhaps you will recall seeing some of these variations: |
|
352 |
||
353 |
@verbatim |
|
354 |
pointToPoint.EnablePcapAll ("second"); |
|
355 |
pointToPoint.EnablePcap ("second", p2pNodes.Get (0)->GetId (), 0); |
|
356 |
csma.EnablePcap ("third", csmaDevices.Get (0), true); |
|
357 |
pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("myfirst.tr")); |
|
358 |
@end verbatim |
|
359 |
||
360 |
What may not be obvious, though, is that there is a consistent model for all of |
|
361 |
the trace-related methods found in the system. We will now take a little time |
|
362 |
and take a look at the ``big picture''. |
|
363 |
||
364 |
There are currently two primary use cases of the tracing helpers in @code{ns-3}: |
|
365 |
Device helpers and protocol helpers. Device helpers look at the problem |
|
366 |
of specifying which traces should be enabled through a node, device pair. For |
|
367 |
example, you may want to specify that pcap tracing should be enabled on a |
|
368 |
particular device on a specific node. This follows from the @code{ns-3} device |
|
369 |
conceptual model, and also the conceptual models of the various device helpers. |
|
370 |
Following naturallyu from this, the files created follow a |
|
371 |
<prefix>-<node>-<device> naming convention. |
|
372 |
||
373 |
Protocol helpers look at the problem of specifying which traces should be |
|
374 |
enabled through a protocol and interface pair. This follows from the @code{ns-3} |
|
375 |
protocol stack conceptual model, and also the conceptual models of internet |
|
376 |
stack helpers. Naturally, the trace files should follow a |
|
377 |
<prefix>-<protocol>-<interface> naming convention. |
|
378 |
||
379 |
The trace helpers therefore fall naturally into a two-dimensional taxonomy. |
|
380 |
There are subtleties that prevent all four classes from behaving identically, |
|
381 |
but we do strive to make them all work as similarly as possible; and whenever |
|
382 |
possible there are analogs for all methods in all classes. |
|
383 |
||
384 |
@verbatim |
|
385 |
| pcap | ascii | |
|
386 |
-----------------+------+-------| |
|
387 |
Device Helper | | | |
|
388 |
-----------------+------+-------| |
|
389 |
Protocol Helper | | | |
|
390 |
-----------------+------+-------| |
|
391 |
@end verbatim |
|
392 |
||
393 |
Let say at this point that @code{mixins} would probably be the best way to |
|
394 |
approach the kind of class hierarchy found in @code{src/helper/trace-helper.h} |
|
395 |
but our Python bindings generator does not support multiple inheritance and so |
|
396 |
this choice is excluded for now. We were forced to linearize the inheritance |
|
397 |
tree and use single inheritance for the trace functionality. This results in a |
|
398 |
somewhat odd arrangement of classes, an unusual naming convention and implies |
|
399 |
a hierarchy of functionality avialable in those classes. This isn't really a |
|
400 |
concern for users of this functionality, but it does make our discussion here |
|
401 |
a bit more difficult in some cases. |
|
402 |
||
403 |
Let's take a quick look at all four of these cases. |
|
404 |
||
405 |
@subsection Pcap Tracing Device Helpers |
|
406 |
||
407 |
The goal of these helpers is to make it easy to add a consistent pcap trace |
|
408 |
facility to an @code{ns-3} device. We want all of the various flavors of |
|
409 |
pcap tracing to work the same across all devices, so the methods of these |
|
410 |
helpers are inherited by device helpers. Take a look at |
|
411 |
@code{src/helper/trace-helper.h} if you want to follow the discussion while |
|
412 |
looking at real code. |
|
413 |
||
414 |
The class @code{PcapHelperForDevice} provides the high level functionality |
|
415 |
for using pcap tracing in an @code{ns-3} device. Every device must implement a |
|
416 |
single virtual method inherited from this class. |
|
417 |
||
418 |
@verbatim |
|
419 |
virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous) = 0; |
|
420 |
@end verbatim |
|
421 |
||
422 |
The signature of this method reflects the device-centric view of the situation |
|
423 |
at this level. All of the public methods inherited from class |
|
424 |
2@code{PcapUserHelperForDevice} reduce to calling this single device-dependent |
|
425 |
implementation method. For example, the lowest level pcap method, |
|
426 |
||
427 |
@verbatim |
|
428 |
void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false); |
|
429 |
@verbatim |
|
430 |
||
431 |
will call the device implementation of @code{EnablePcapInternal} directly. All |
|
432 |
other public pcap tracing methods build on this implementation to provide |
|
433 |
additional user-level functionality. What this means to the user is that all |
|
434 |
device helpers in the system will have all of the pcap trace methods available; |
|
435 |
and these methods will all work in the same way across devices if the device |
|
436 |
implements @code{EnablePcapInternal} correctly. |
|
437 |
||
438 |
@subsubsection Pcap Tracing Device Helper Methods |
|
439 |
||
440 |
@verbatim |
|
441 |
void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false); |
|
442 |
void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false); |
|
443 |
void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false); |
|
444 |
void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false); |
|
445 |
void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false); |
|
446 |
void EnablePcapAll (std::string prefix, bool promiscuous = false); |
|
447 |
@end verbatim |
|
448 |
||
449 |
You are encouraged to peruse the Doxygen for class @code{PcapHelperForDevice} |
|
450 |
to find the details of these methods; but to summarize ... |
|
451 |
||
452 |
You can enable pcap tracing on a particular node/net-device pair by providing a |
|
453 |
@code{Ptr<NetDevice>} to an @code{EnablePcap} method. The @code{Ptr<Node>} is |
|
454 |
implicit since the net device must belong to exactly one @code{Node}. |
|
455 |
For example, |
|
456 |
||
457 |
@verbatim |
|
458 |
Ptr<NetDevice> nd; |
|
459 |
... |
|
460 |
helper.EnablePcap ("prefix", nd); |
|
461 |
@end verbatim |
|
462 |
||
463 |
You can enable pcap tracing on a particular node/net-device pair by providing a |
|
464 |
@code{std::string} representing an object name service string to an |
|
465 |
@code{EnablePcap} method. The @code{Ptr<NetDevice>} is looked up from the name |
|
466 |
string. Again, the @code<Node> is implicit since the named net device must |
|
467 |
belong to exactly one @code{Node}. For example, |
|
468 |
||
469 |
@verbatim |
|
470 |
Names::Add ("server" ...); |
|
471 |
Names::Add ("server/eth0" ...); |
|
472 |
... |
|
473 |
helper.EnablePcap ("prefix", "server/ath0"); |
|
474 |
@end verbatim |
|
475 |
||
476 |
You can enable pcap tracing on a collection of node/net-device pairs by |
|
477 |
providing a @code{NetDeviceContainer}. For each @code{NetDevice} in the container |
|
478 |
the type is checked. For each device of the proper type (the same type as is |
|
479 |
managed by the device helper), tracing is enabled. Again, the @code<Node> is |
|
480 |
implicit since the found net device must belong to exactly one @code{Node}. |
|
481 |
For example, |
|
482 |
||
483 |
@verbatim |
|
484 |
NetDeviceContainer d = ...; |
|
485 |
... |
|
486 |
helper.EnablePcap ("prefix", d); |
|
487 |
@end verbatim |
|
488 |
||
489 |
You can enable pcap tracing on a collection of node/net-device pairs by |
|
490 |
providing a @code{NodeContainer}. For each @code{Node} in the @code{NodeContainer} |
|
491 |
its attached @code{NetDevices} are iterated. For each @code{NetDevice} attached |
|
492 |
to each node in the container, the type of that device is checked. For each |
|
493 |
device of the proper type (the same type as is managed by the device helper), |
|
494 |
tracing is enabled. |
|
495 |
||
496 |
@verbatim |
|
497 |
NodeContainer n; |
|
498 |
... |
|
499 |
helper.EnablePcap ("prefix", n); |
|
500 |
@end verbatim |
|
501 |
||
502 |
You can enable pcap tracing on the basis of node ID and device ID as well as |
|
503 |
with explicit @code{Ptr}. Each @code{Node} in the system has an integer node ID |
|
504 |
and each device connected to a node has an integer device ID. |
|
505 |
||
506 |
@verbatim |
|
507 |
helper.EnablePcap ("prefix", 21, 1); |
|
508 |
@end verbatim |
|
509 |
||
510 |
Finally, you can enable pcap tracing for all devices in the system, with the |
|
511 |
same type as that managed by the device helper. |
|
512 |
||
513 |
@verbatim |
|
514 |
helper.EnablePcapAll ("prefix"); |
|
515 |
@end verbatim |
|
516 |
||
517 |
In each of these cases, there is an additional parameter that defaults to false. |
|
518 |
This parameter indicates that the trace should not be gathered in promiscuous |
|
519 |
mode. If you do want your traces to include all traffic seen by the device |
|
520 |
(and the device supports promiscuous mode) simply add a true parameter to any |
|
521 |
of the calls above. For example, |
|
522 |
||
523 |
@verbatim |
|
524 |
Ptr<NetDevice> nd; |
|
525 |
... |
|
526 |
helper.EnablePcap ("prefix", nd, true); |
|
527 |
@end verbatim |
|
528 |
||
529 |
will enable promiscuous mode captures on the @code{NetDevice} specified by @code{nd}. |
|
530 |
||
531 |
@subsubsection Pcap Tracing Device Helper Filename Selection |
|
532 |
||
533 |
Implicit in all of the method descriptions above is the construction of the |
|
534 |
complete filenames by the implementation method. By convention, pcap traces |
|
535 |
in the @code{ns-3} system are of the form ``<prefix>-<node id>-<device id>.pcap'' |
|
536 |
||
537 |
As previously mentioned, every node in the system will have a system-assigned |
|
538 |
node id; and every device will have an interface index (also called a device id) |
|
539 |
relative to its node. By default, then, a pcap trace file created as a result |
|
540 |
of enabling tracing on the first device of node 21 using the prefix ``prefix'' |
|
541 |
would be ``prefix-21-1.pcap''. |
|
542 |
||
543 |
You can always use the @code{ns-3} object name service to make this more clear. |
|
544 |
For example, if you use the object name service to assign the name ``server'' |
|
545 |
to node 21, the resulting pcap trace file name will automatically become, |
|
546 |
``prefix-server-1.pcap'' and if you also assign the name ``eth0'' to the |
|
547 |
device, your pcap file name will automatically pick this up and be called |
|
548 |
``prefix-server-eth0.pcap''. |
|
549 |
||
550 |
@subsection Ascii Tracing Device Helpers |
|
551 |
||
552 |
The behavior of the ascii trace helpers is substantially similar to the pcap |
|
553 |
case. Take a look at @code{src/helper/trace-helper.h} if you want to |
|
554 |
follow the discussion while looking at real code. |
|
555 |
||
556 |
The class @code{TraceHelperForDevice} adds the high level functionality for |
|
557 |
using ascii tracing to class @code{PcapHelperForDevice}. If a device helper |
|
558 |
inherits from class @code{TraceHelperForDevice} it gets both pcap and ascii |
|
559 |
tracing powers. Along with the internal pcap function, every device must |
|
560 |
also implement a single virtual method inherited from the ascii trace additions |
|
561 |
to this class. |
|
562 |
||
563 |
@verbatim |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
564 |
virtual void EnableAsciiInternal (Ptr<OutputStreamKeeper> stream, std::string prefix, Ptr<NetDevice> nd) = 0; |
6031 | 565 |
@end verbatim |
566 |
||
567 |
The signature of this method reflects the device-centric view of the situation |
|
568 |
at this level; and also the fact that the helper may be writing to a shared |
|
569 |
output stream. All of the public ascii-trace-related methods inherited from |
|
570 |
class @code{TraceHelperForDevice} reduce to calling this single device- |
|
571 |
dependent implementation method. For example, the lowest level ascii trace |
|
572 |
methods, |
|
573 |
||
574 |
@verbatim |
|
575 |
void EnableAscii (std::string prefix, Ptr<NetDevice> nd); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
576 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, Ptr<NetDevice> nd); |
6031 | 577 |
@verbatim |
578 |
||
579 |
will call the device implementation of @code{EnableAsciiInternal} directly, |
|
580 |
providing either a valid prefix or stream. All other public ascii tracing |
|
581 |
methods will build on these low-level functions to provide additional user-level |
|
582 |
functionality. What this means to the user is that all device helpers in the |
|
583 |
system will have all of the ascii trace methods available; and these methods |
|
584 |
will all work in the same way across devices if the devices implement |
|
585 |
@code{EnablAsciiInternal} correctly. |
|
586 |
||
587 |
@subsubsection Ascii Tracing Device Helper Methods |
|
588 |
||
589 |
@verbatim |
|
590 |
void EnableAscii (std::string prefix, Ptr<NetDevice> nd); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
591 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, Ptr<NetDevice> nd); |
6031 | 592 |
|
593 |
void EnableAscii (std::string prefix, std::string ndName); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
594 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, std::string ndName); |
6031 | 595 |
|
596 |
void EnableAscii (std::string prefix, NetDeviceContainer d); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
597 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, NetDeviceContainer d); |
6031 | 598 |
|
599 |
void EnableAscii (std::string prefix, NodeContainer n); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
600 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, NodeContainer n); |
6031 | 601 |
|
602 |
void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
603 |
void EnableAscii (Ptr<OutputStreamKeeper> stream, uint32_t nodeid, uint32_t deviceid); |
6031 | 604 |
|
605 |
void EnableAsciiAll (std::string prefix); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
606 |
void EnableAsciiAll (Ptr<OutputStreamKeeper> stream); |
6031 | 607 |
@end verbatim |
608 |
||
609 |
You are encouraged to peruse the Doxygen for class @code{TraceHelperForDevice} |
|
610 |
to find the details of these methods; but to summarize ... |
|
611 |
||
612 |
There are twice as many methods available for ascii tracing as there were for |
|
613 |
pcap tracing. This is because, in addition to the pcap-style model where traces |
|
614 |
from each unique node/device pair are written to a unique file, we support a model |
|
615 |
in which trace information for many node/device pairs is written to a common file. |
|
616 |
This means that the <prefix>-<node>-<device> file name generation mechanism is |
|
617 |
replaced by a mechanism to refer to a common file; and the number of API methods |
|
618 |
is doubled to allow all combinations. |
|
619 |
||
620 |
Just as in pcap tracing, you can enable ascii tracing on a particular |
|
621 |
node/net-device pair by providing a @code{Ptr<NetDevice>} to an @code{EnableAscii} |
|
622 |
method. The @code{Ptr<Node>} is implicit since the net device must belong to |
|
623 |
exactly one @code{Node}. For example, |
|
624 |
||
625 |
@verbatim |
|
626 |
Ptr<NetDevice> nd; |
|
627 |
... |
|
628 |
helper.EnableAscii ("prefix", nd); |
|
629 |
@end verbatim |
|
630 |
||
631 |
In this case, no trace contexts are written to the ascii trace file since they |
|
632 |
would be redundant. The system will pick the file name to be created using |
|
633 |
the same rules as described in the pcap section, except that the file will |
|
634 |
have the suffix ``.tr'' instead of ``.pcap''. |
|
635 |
||
636 |
If you want to enable ascii tracing on more than one net device and have all |
|
637 |
traces sent to a single file, you can do that as well by using an object to |
|
638 |
refer to a single file. We have already seen this in the ``cwnd'' example |
|
639 |
above: |
|
640 |
||
641 |
@verbatim |
|
642 |
Ptr<NetDevice> nd1; |
|
643 |
Ptr<NetDevice> nd2; |
|
644 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
645 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 646 |
... |
647 |
helper.EnableAscii (stream, nd1); |
|
648 |
helper.EnableAscii (stream, nd2); |
|
649 |
@verbatim |
|
650 |
||
651 |
In this case, trace contexts are written to the ascii trace file since they |
|
652 |
are required to disambiguate traces from the two devices. Note that since the |
|
653 |
user is completely specifying the file name, the string should include the ``,tr'' |
|
654 |
for consistency. |
|
655 |
||
656 |
You can enable ascii tracing on a particular node/net-device pair by providing a |
|
657 |
@code{std::string} representing an object name service string to an |
|
658 |
@code{EnablePcap} method. The @code{Ptr<NetDevice>} is looked up from the name |
|
659 |
string. Again, the @code<Node> is implicit since the named net device must |
|
660 |
belong to exactly one @code{Node}. For example, |
|
661 |
||
662 |
@verbatim |
|
663 |
Names::Add ("client" ...); |
|
664 |
Names::Add ("client/eth0" ...); |
|
665 |
Names::Add ("server" ...); |
|
666 |
Names::Add ("server/eth0" ...); |
|
667 |
... |
|
668 |
helper.EnableAscii ("prefix", "client/eth0"); |
|
669 |
helper.EnableAscii ("prefix", "server/eth0"); |
|
670 |
@end verbatim |
|
671 |
||
672 |
This would result in two files named ``prefix-client-eth0.tr'' and |
|
673 |
``prefix-server-eth0.tr'' with traces for each device in the respective trace |
|
674 |
file. Since all of the EnableAscii functions are overloaded to take a stream object, |
|
675 |
you can use that form as well: |
|
676 |
||
677 |
@verbatim |
|
678 |
Names::Add ("client" ...); |
|
679 |
Names::Add ("client/eth0" ...); |
|
680 |
Names::Add ("server" ...); |
|
681 |
Names::Add ("server/eth0" ...); |
|
682 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
683 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 684 |
... |
685 |
helper.EnableAscii (stream, "client/eth0"); |
|
686 |
helper.EnableAscii (stream, "server/eth0"); |
|
687 |
@end verbatim |
|
688 |
||
689 |
This would result in a single trace file called ``trace-file-name.tr'' that |
|
690 |
contains all of the trace events for both devices. The events would be |
|
691 |
disambiguated by trace context strings. |
|
692 |
||
693 |
You can enable ascii tracing on a collection of node/net-device pairs by |
|
694 |
providing a @code{NetDeviceContainer}. For each @code{NetDevice} in the container |
|
695 |
the type is checked. For each device of the proper type (the same type as is |
|
696 |
managed by the device helper), tracing is enabled. Again, the @code<Node> is |
|
697 |
implicit since the found net device must belong to exactly one @code{Node}. |
|
698 |
For example, |
|
699 |
||
700 |
@verbatim |
|
701 |
NetDeviceContainer d = ...; |
|
702 |
... |
|
703 |
helper.EnableAscii ("prefix", d); |
|
704 |
@end verbatim |
|
705 |
||
706 |
This would result in a number of ascii trace files being created, each of which |
|
707 |
follows the <prefix>-<node id>-<device id>.tr convention. Combining all of the |
|
708 |
traces into a single file is accomplished similarly to the examples above: |
|
709 |
||
710 |
@verbatim |
|
711 |
NetDeviceContainer d = ...; |
|
712 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
713 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 714 |
... |
715 |
helper.EnableAscii (stream, d); |
|
716 |
@end verbatim |
|
717 |
||
718 |
You can enable ascii tracing on a collection of node/net-device pairs by |
|
719 |
providing a @code{NodeContainer}. For each @code{Node} in the @code{NodeContainer} |
|
720 |
its attached @code{NetDevices} are iterated. For each @code{NetDevice} attached |
|
721 |
to each node in the container, the type of that device is checked. For each |
|
722 |
device of the proper type (the same type as is managed by the device helper), |
|
723 |
tracing is enabled. |
|
724 |
||
725 |
@verbatim |
|
726 |
NodeContainer n; |
|
727 |
... |
|
728 |
helper.EnableAscii ("prefix", n); |
|
729 |
@end verbatim |
|
730 |
||
731 |
This would result in a number of ascii trace files being created, each of which |
|
732 |
follows the <prefix>-<node id>-<device id>.tr convention. Combining all of the |
|
733 |
traces into a single file is accomplished similarly to the examples above: |
|
734 |
||
735 |
You can enable pcap tracing on the basis of node ID and device ID as well as |
|
736 |
with explicit @code{Ptr}. Each @code{Node} in the system has an integer node ID |
|
737 |
and each device connected to a node has an integer device ID. |
|
738 |
||
739 |
@verbatim |
|
740 |
helper.EnableAscii ("prefix", 21, 1); |
|
741 |
@end verbatim |
|
742 |
||
743 |
Of course, the traces can be combined into a single file as shown above. |
|
744 |
||
745 |
Finally, you can enable pcap tracing for all devices in the system, with the |
|
746 |
same type as that managed by the device helper. |
|
747 |
||
748 |
@verbatim |
|
749 |
helper.EnableAsciiAll ("prefix"); |
|
750 |
@end verbatim |
|
751 |
||
752 |
This would result in a number of ascii trace files being created, one for |
|
753 |
every device in the system of the type managed by the helper. All of these |
|
754 |
files will follow the <prefix>-<node id>-<device id>.tr convention. Combining |
|
755 |
all of the traces into a single file is accomplished similarly to the examples |
|
756 |
above. |
|
757 |
||
758 |
@subsubsection Ascii Tracing Device Helper Filename Selection |
|
759 |
||
760 |
Implicit in the prefix-style method descriptions above is the construction of the |
|
761 |
complete filenames by the implementation method. By convention, ascii traces |
|
762 |
in the @code{ns-3} system are of the form ``<prefix>-<node id>-<device id>.tr'' |
|
763 |
||
764 |
As previously mentioned, every node in the system will have a system-assigned |
|
765 |
node id; and every device will have an interface index (also called a device id) |
|
766 |
relative to its node. By default, then, an ascii trace file created as a result |
|
767 |
of enabling tracing on the first device of node 21, using the prefix ``prefix'', |
|
768 |
would be ``prefix-21-1.tr''. |
|
769 |
||
770 |
You can always use the @code{ns-3} object name service to make this more clear. |
|
771 |
For example, if you use the object name service to assign the name ``server'' |
|
772 |
to node 21, the resulting ascii trace file name will automatically become, |
|
773 |
``prefix-server-1.tr'' and if you also assign the name ``eth0'' to the |
|
774 |
device, your ascii trace file name will automatically pick this up and be called |
|
775 |
``prefix-server-eth0.tr''. |
|
776 |
||
777 |
@subsection Pcap Tracing Protocol Helpers |
|
778 |
||
779 |
The goal of these helpers is to make it easy to add a consistent pcap trace |
|
780 |
facility to protocols. We want all of the various flavors of pcap tracing to |
|
781 |
work the same across all protocols, so the methods of these helpers are |
|
782 |
inherited by stack helpers. Take a look at @code{src/helper/trace-helper.h} |
|
783 |
if you want to follow the discussion while looking at real code. |
|
784 |
||
785 |
In this section we will be illustrating the methods as applied to the protocol |
|
786 |
@code{Ipv4}. To specify traces in similar protocols, just substitute the |
|
787 |
appropriate type. For example, use a @code{Ptr<Ipv6>} instead of a |
|
788 |
@code{Ptr<Ipv4>} and call @code{EnablePcapIpv6} instead of @code{EnablePcapIpv4}. |
|
789 |
||
790 |
The class @code{PcapHelperForIpv4} provides the high level functionality for |
|
791 |
using pcap tracing in the @code{Ipv4} protocol. Every protocol enabling these |
|
792 |
methods must implement a single virtual method inherited from this class. There |
|
793 |
will be a separate implementation for @code{Ipv6}, for example, but the only |
|
794 |
difference will be in the method names and signatures. Different method names |
|
795 |
are required to disambiguate class @code{Ipv4} from @coe{Ipv6} which are both |
|
796 |
derived from class @code{Object}, and methods that share the same signature. |
|
797 |
||
798 |
@verbatim |
|
799 |
virtual void EnablePcapIpv4Internal (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface) = 0; |
|
800 |
@end verbatim |
|
801 |
||
802 |
The signature of this method reflects the protocol and interface-centric view |
|
803 |
of the situation at this level. All of the public methods inherited from class |
|
804 |
@code{PcapHelperForIpv4} reduce to calling this single device-dependent |
|
805 |
implementation method. For example, the lowest level pcap method, |
|
806 |
||
807 |
@verbatim |
|
808 |
void EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface); |
|
809 |
@verbatim |
|
810 |
||
811 |
will call the device implementation of @code{EnablePcapIpv4Internal} directly. |
|
812 |
All other public pcap tracing methods build on this implementation to provide |
|
813 |
additional user-level functionality. What this means to the user is that all |
|
814 |
protocol helpers in the system will have all of the pcap trace methods |
|
815 |
available; and these methods will all work in the same way across |
|
816 |
protocols if the helper implements @code{EnablePcapIpv4Internal} correctly. |
|
817 |
||
818 |
@subsubsection Pcap Tracing Protocol Helper Methods |
|
819 |
||
820 |
These methods are designed to be in one-to-one correspondence with the @code{Node}- |
|
821 |
and @code{NetDevice}- centric versions of the device versions. Instead of |
|
822 |
@code{Node} and @code{NetDevice} pair constraints, we use protocol and interface |
|
823 |
constraints. |
|
824 |
||
825 |
Note that just like in the device version, there are six methods: |
|
826 |
||
827 |
@verbatim |
|
828 |
void EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface); |
|
829 |
void EnablePcapIpv4 (std::string prefix, std::string ipv4Name, uint32_t interface); |
|
830 |
void EnablePcapIpv4 (std::string prefix, Ipv4InterfaceContainer c); |
|
831 |
void EnablePcapIpv4 (std::string prefix, NodeContainer n); |
|
832 |
void EnablePcapIpv4 (std::string prefix, uint32_t nodeid, uint32_t interface); |
|
833 |
void EnablePcapIpv4All (std::string prefix); |
|
834 |
@end verbatim |
|
835 |
||
836 |
You are encouraged to peruse the Doxygen for class @code{PcapHelperForIpv4} |
|
837 |
to find the details of these methods; but to summarize ... |
|
838 |
||
839 |
You can enable pcap tracing on a particular protocol/interface pair by providing a |
|
840 |
@code{Ptr<Ipv4>} and @code{interface} to an @code{EnablePcap} method. For example, |
|
841 |
||
842 |
@verbatim |
|
843 |
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
|
844 |
... |
|
845 |
helper.EnablePcapIpv4 ("prefix", ipv4, 0); |
|
846 |
@end verbatim |
|
847 |
||
848 |
You can enable pcap tracing on a particular node/net-device pair by providing a |
|
849 |
@code{std::string} representing an object name service string to an |
|
850 |
@code{EnablePcap} method. The @code{Ptr<Ipv4>} is looked up from the name |
|
851 |
string. For example, |
|
852 |
||
853 |
@verbatim |
|
854 |
Names::Add ("serverIPv4" ...); |
|
855 |
... |
|
856 |
helper.EnablePcapIpv4 ("prefix", "serverIpv4", 1); |
|
857 |
@end verbatim |
|
858 |
||
859 |
You can enable pcap tracing on a collection of protocol/interface pairs by |
|
860 |
providing an @code{Ipv4InterfaceContainer}. For each @code{Ipv4} / interface |
|
861 |
pair in the container the protocol type is checked. For each protocol of the |
|
862 |
proper type (the same type as is managed by the device helper), tracing is |
|
863 |
enabled for the corresponding interface. For example, |
|
864 |
||
865 |
@verbatim |
|
866 |
NodeContainer nodes; |
|
867 |
... |
|
868 |
NetDeviceContainer devices = deviceHelper.Install (nodes); |
|
869 |
... |
|
870 |
Ipv4AddressHelper ipv4; |
|
871 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
872 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
|
873 |
... |
|
874 |
helper.EnablePcapIpv4 ("prefix", interfaces); |
|
875 |
@end verbatim |
|
876 |
||
877 |
You can enable pcap tracing on a collection of protocol/interface pairs by |
|
878 |
providing a @code{NodeContainer}. For each @code{Node} in the @code{NodeContainer} |
|
879 |
the appropriate protocol is found. For each protocol, its interfaces are |
|
880 |
enumerated and tracing is enabled on the resulting pairs. For example, |
|
881 |
||
882 |
@verbatim |
|
883 |
NodeContainer n; |
|
884 |
... |
|
885 |
helper.EnablePcapIpv4 ("prefix", n); |
|
886 |
@end verbatim |
|
887 |
||
888 |
You can enable pcap tracing on the basis of node ID and interface as well. In |
|
889 |
this case, the node-id is translated to a @code{Ptr{Node} and the appropriate |
|
890 |
protocol is looked up in the node. The resulting protocol and interface are |
|
891 |
used to specify the resulting trace source. |
|
892 |
||
893 |
@verbatim |
|
894 |
helper.EnablePcapIpv4 ("prefix", 21, 1); |
|
895 |
@end verbatim |
|
896 |
||
897 |
Finally, you can enable pcap tracing for all interfaces in the system, with |
|
898 |
associated protocol being the same type as that managed by the device helper. |
|
899 |
||
900 |
@verbatim |
|
901 |
helper.EnablePcapIpv4All ("prefix"); |
|
902 |
@end verbatim |
|
903 |
||
904 |
@subsubsection Pcap Tracing Protocol Helper Filename Selection |
|
905 |
||
906 |
Implicit in all of the method descriptions above is the construction of the |
|
907 |
complete filenames by the implementation method. By convention, pcap traces |
|
908 |
taken for devices in the @code{ns-3} system are of the form |
|
909 |
``<prefix>-<node id>-<device id>.pcap''. In the case of protocol traces, |
|
910 |
there is a one-to-one correspondence between protocols and @code{Nodes}. |
|
911 |
This is because protocol @code{Objects} are aggregated to @code{Node Objects}. |
|
912 |
Since there is no global protocol id in the system, we use the corresponding |
|
913 |
node id in file naming. Threfore there is a possibility for file name |
|
914 |
collisions in automatically chosen trace file names. For this reason, the |
|
915 |
file name convention is changed for protocol traces. |
|
916 |
||
917 |
As previously mentioned, every node in the system will have a system-assigned |
|
918 |
node id. Since there is a one-to-one correspondence between protocol instances |
|
919 |
and node instances we use the node id. Each interface has an interface id |
|
920 |
relative to its protocol. We use the convention |
|
921 |
"<prefix>-n<node id>-i<interface id>.pcap" for trace file naming in protocol |
|
922 |
helpers. |
|
923 |
||
924 |
Therefore, by default, a pcap trace file created as a result of enabling tracing |
|
925 |
on interface 1 of the Ipv4 protocol of node 21 using the prefix ``prefix'' |
|
926 |
would be ``prefix-n21-i1.pcap''. |
|
927 |
||
928 |
You can always use the @code{ns-3} object name service to make this more clear. |
|
929 |
For example, if you use the object name service to assign the name ``serverIpv4'' |
|
930 |
to the Ptr<Ipv4> on node 21, the resulting pcap trace file name will |
|
931 |
automatically become, ``prefix-nserverIpv4-i1.pcap''. |
|
932 |
||
933 |
@subsection Ascii Tracing Protocol Helpers |
|
934 |
||
935 |
The behavior of the ascii trace helpers is substantially similar to the pcap |
|
936 |
case. Take a look at @code{src/helper/trace-helper.h} if you want to |
|
937 |
follow the discussion while looking at real code. |
|
938 |
||
939 |
In this section we will be illustrating the methods as applied to the protocol |
|
940 |
@code{Ipv4}. To specify traces in similar protocols, just substitute the |
|
941 |
appropriate type. For example, use a @code{Ptr<Ipv6>} instead of a |
|
942 |
@code{Ptr<Ipv4>} and call @code{EnableAsciiIpv6} instead of @code{EnableAsciiIpv4}. |
|
943 |
||
944 |
The class @code{PcapAndAsciiHelperForIpv4} adds the high level functionality |
|
945 |
for using ascii tracing to the PcapHelperForIpv4. Every protocol must |
|
946 |
additionally implement a single virtual method inherited from this class. |
|
947 |
||
948 |
@verbatim |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
949 |
virtual void EnableAsciiIpv4Internal (Ptr<OutputStreamKeeper> stream, std::string prefix, |
6031 | 950 |
Ptr<Ipv4> ipv4, uint32_t interface) = 0; |
951 |
@end verbatim |
|
952 |
||
953 |
The signature of this method reflects the protocol- and interface-centric view |
|
954 |
of the situation at this level; and also the fact that the helper may be writing |
|
955 |
to a shared output stream. All of the public methods inherited from class |
|
956 |
@code{PcapAndAsciiTraceHelperForIpv4} reduce to calling this single device- |
|
957 |
dependent implementation method. For example, the lowest level ascii trace |
|
958 |
methods, |
|
959 |
||
960 |
@verbatim |
|
961 |
void EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
962 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, Ptr<Ipv4> ipv4, uint32_t interface); |
6031 | 963 |
@verbatim |
964 |
||
965 |
will call the device implementation of @code{EnableAsciiIpv4Internal} directly, |
|
966 |
providing either the prefix or the stream. All other public ascii tracing |
|
967 |
methods will build on these low-level functions to provide additional user-level |
|
968 |
functionality. What this means to the user is that all device helpers in the |
|
969 |
system will have all of the ascii trace methods available; and these methods |
|
970 |
will all work in the same way across protocols if the protocols implement |
|
971 |
@code{EnablAsciiIpv4Internal} correctly. |
|
972 |
||
973 |
@subsubsection Ascii Tracing Device Helper Methods |
|
974 |
||
975 |
@verbatim |
|
976 |
void EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
977 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, Ptr<Ipv4> ipv4, uint32_t interface); |
6031 | 978 |
|
979 |
void EnableAsciiIpv4 (std::string prefix, std::string ipv4Name, uint32_t interface); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
980 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, std::string ipv4Name, uint32_t interface); |
6031 | 981 |
|
982 |
void EnableAsciiIpv4 (std::string prefix, Ipv4InterfaceContainer c); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
983 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, Ipv4InterfaceContainer c); |
6031 | 984 |
|
985 |
void EnableAsciiIpv4 (std::string prefix, NodeContainer n); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
986 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, NodeContainer n); |
6031 | 987 |
|
988 |
void EnableAsciiIpv4 (std::string prefix, uint32_t nodeid, uint32_t deviceid); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
989 |
void EnableAsciiIpv4 (Ptr<OutputStreamKeeper> stream, uint32_t nodeid, uint32_t interface); |
6031 | 990 |
|
991 |
void EnableAsciiIpv4All (std::string prefix); |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
992 |
void EnableAsciiIpv4All (Ptr<OutputStreamKeeper> stream); |
6031 | 993 |
@end verbatim |
994 |
||
995 |
You are encouraged to peruse the Doxygen for class @code{PcapAndAsciiHelperForIpv4} |
|
996 |
to find the details of these methods; but to summarize ... |
|
997 |
||
998 |
There are twice as many methods available for ascii tracing as there were for |
|
999 |
pcap tracing. This is because, in addition to the pcap-style model where traces |
|
1000 |
from each unique protocol/interface pair are written to a unique file, we |
|
1001 |
support a model in which trace information for many protocol/interface pairs is |
|
1002 |
written to a common file. This means that the <prefix>-n<node id>-<interface> |
|
1003 |
file name generation mechanism is replaced by a mechanism to refer to a common |
|
1004 |
file; and the number of API methods is doubled to allow all combinations. |
|
1005 |
||
1006 |
Just as in pcap tracing, you can enable ascii tracing on a particular |
|
1007 |
protocol/interface pair by providing a @code{Ptr<Ipv4>} and an @code{interface} |
|
1008 |
to an @code{EnableAscii} method. |
|
1009 |
For example, |
|
1010 |
||
1011 |
@verbatim |
|
1012 |
Ptr<Ipv4> ipv4; |
|
1013 |
... |
|
1014 |
helper.EnableAsciiIpv4 ("prefix", ipv4, 1); |
|
1015 |
@end verbatim |
|
1016 |
||
1017 |
In this case, no trace contexts are written to the ascii trace file since they |
|
1018 |
would be redundant. The system will pick the file name to be created using |
|
1019 |
the same rules as described in the pcap section, except that the file will |
|
1020 |
have the suffix ``.tr'' instead of ``.pcap''. |
|
1021 |
||
1022 |
If you want to enable ascii tracing on more than one interface and have all |
|
1023 |
traces sent to a single file, you can do that as well by using an object to |
|
1024 |
refer to a single file. We have already something similar to this in the |
|
1025 |
``cwnd'' example above: |
|
1026 |
||
1027 |
@verbatim |
|
1028 |
Ptr<Ipv4> protocol1 = node1->GetObject<Ipv4> (); |
|
1029 |
Ptr<Ipv4> protocol2 = node2->GetObject<Ipv4> (); |
|
1030 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
1031 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 1032 |
... |
1033 |
helper.EnableAsciiIpv4 (stream, protocol1, 1); |
|
1034 |
helper.EnableAsciiIpv4 (stream, protocol2, 1); |
|
1035 |
@verbatim |
|
1036 |
||
1037 |
In this case, trace contexts are written to the ascii trace file since they |
|
1038 |
are required to disambiguate traces from the two interfaces. Note that since |
|
1039 |
the user is completely specifying the file name, the string should include the |
|
1040 |
``,tr'' for consistency. |
|
1041 |
||
1042 |
You can enable ascii tracing on a particular protocol by providing a |
|
1043 |
@code{std::string} representing an object name service string to an |
|
1044 |
@code{EnablePcap} method. The @code{Ptr<Ipv4>} is looked up from the name |
|
1045 |
string. The @code<Node> in the resulting filenames is implicit since there |
|
1046 |
is a one-to-one correspondence between protocol instances and nodes, |
|
1047 |
For example, |
|
1048 |
||
1049 |
@verbatim |
|
1050 |
Names::Add ("node1Ipv4" ...); |
|
1051 |
Names::Add ("node2Ipv4" ...); |
|
1052 |
... |
|
1053 |
helper.EnableAsciiIpv4 ("prefix", "node1Ipv4", 1); |
|
1054 |
helper.EnableAsciiIpv4 ("prefix", "node2Ipv4", 1); |
|
1055 |
@end verbatim |
|
1056 |
||
1057 |
This would result in two files named ``prefix-nnode1Ipv4-i1.tr'' and |
|
1058 |
``prefix-nnode2Ipv4-i1.tr'' with traces for each interface in the respective |
|
1059 |
trace file. Since all of the EnableAscii functions are overloaded to take a |
|
1060 |
stream object, you can use that form as well: |
|
1061 |
||
1062 |
@verbatim |
|
1063 |
Names::Add ("node1Ipv4" ...); |
|
1064 |
Names::Add ("node2Ipv4" ...); |
|
1065 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
1066 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 1067 |
... |
1068 |
helper.EnableAsciiIpv4 (stream, "node1Ipv4", 1); |
|
1069 |
helper.EnableAsciiIpv4 (stream, "node2Ipv4", 1); |
|
1070 |
@end verbatim |
|
1071 |
||
1072 |
This would result in a single trace file called ``trace-file-name.tr'' that |
|
1073 |
contains all of the trace events for both interfaces. The events would be |
|
1074 |
disambiguated by trace context strings. |
|
1075 |
||
1076 |
You can enable ascii tracing on a collection of protocol/interface pairs by |
|
1077 |
providing an @code{Ipv4InterfaceContainer}. For each protocol of the proper |
|
1078 |
type (the same type as is managed by the device helper), tracing is enabled |
|
1079 |
for the corresponding interface. Again, the @code<Node> is implicit since |
|
1080 |
there is a one-to-one correspondence between each protocol and its node. |
|
1081 |
For example, |
|
1082 |
||
1083 |
@verbatim |
|
1084 |
NodeContainer nodes; |
|
1085 |
... |
|
1086 |
NetDeviceContainer devices = deviceHelper.Install (nodes); |
|
1087 |
... |
|
1088 |
Ipv4AddressHelper ipv4; |
|
1089 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
1090 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
|
1091 |
... |
|
1092 |
... |
|
1093 |
helper.EnableAsciiIpv4 ("prefix", interfaces); |
|
1094 |
@end verbatim |
|
1095 |
||
1096 |
This would result in a number of ascii trace files being created, each of which |
|
1097 |
follows the <prefix>-n<node id>-i<interface>.tr convention. Combining all of the |
|
1098 |
traces into a single file is accomplished similarly to the examples above: |
|
1099 |
||
1100 |
@verbatim |
|
1101 |
NodeContainer nodes; |
|
1102 |
... |
|
1103 |
NetDeviceContainer devices = deviceHelper.Install (nodes); |
|
1104 |
... |
|
1105 |
Ipv4AddressHelper ipv4; |
|
1106 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
1107 |
Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
|
1108 |
... |
|
6051
b988174aa30b
OutputStreamObject to OutputStreamKeeper
Craig Dowell <craigdo@ee.washington.edu>
parents:
6031
diff
changeset
|
1109 |
Ptr<OutputStreamKeeper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr"); |
6031 | 1110 |
... |
1111 |
helper.EnableAsciiIpv4 (stream, interfaces); |
|
1112 |
@end verbatim |
|
1113 |
||
1114 |
You can enable ascii tracing on a collection of protocol/interface pairs by |
|
1115 |
providing a @code{NodeContainer}. For each @code{Node} in the @code{NodeContainer} |
|
1116 |
the appropriate protocol is found. For each protocol, its interfaces are |
|
1117 |
enumerated and tracing is enabled on the resulting pairs. For example, |
|
1118 |
||
1119 |
@verbatim |
|
1120 |
NodeContainer n; |
|
1121 |
... |
|
1122 |
helper.EnableAsciiIpv4 ("prefix", n); |
|
1123 |
@end verbatim |
|
1124 |
||
1125 |
This would result in a number of ascii trace files being created, each of which |
|
1126 |
follows the <prefix>-<node id>-<device id>.tr convention. Combining all of the |
|
1127 |
traces into a single file is accomplished similarly to the examples above: |
|
1128 |
||
1129 |
You can enable pcap tracing on the basis of node ID and device ID as well. In |
|
1130 |
this case, the node-id is translated to a @code{Ptr{Node} and the appropriate |
|
1131 |
protocol is looked up in the node. The resulting protocol and interface are |
|
1132 |
used to specify the resulting trace source. |
|
1133 |
||
1134 |
@verbatim |
|
1135 |
helper.EnableAsciiIpv4 ("prefix", 21, 1); |
|
1136 |
@end verbatim |
|
1137 |
||
1138 |
Of course, the traces can be combined into a single file as shown above. |
|
1139 |
||
1140 |
Finally, you can enable ascii tracing for all interfaces in the system, with |
|
1141 |
associated protocol being the same type as that managed by the device helper. |
|
1142 |
||
1143 |
@verbatim |
|
1144 |
helper.EnableAsciiIpv4All ("prefix"); |
|
1145 |
@end verbatim |
|
1146 |
||
1147 |
This would result in a number of ascii trace files being created, one for |
|
1148 |
every interface in the system related to a protocol of the type managed by the |
|
1149 |
helper. All of these files will follow the <prefix>-n<node id>-i<interface.tr |
|
1150 |
convention. Combining all of the traces into a single file is accomplished |
|
1151 |
similarly to the examples above. |
|
1152 |
||
1153 |
@subsubsection Ascii Tracing Device Helper Filename Selection |
|
1154 |
||
1155 |
Implicit in the prefix-style method descriptions above is the construction of the |
|
1156 |
complete filenames by the implementation method. By convention, ascii traces |
|
1157 |
in the @code{ns-3} system are of the form ``<prefix>-<node id>-<device id>.tr'' |
|
1158 |
||
1159 |
As previously mentioned, every node in the system will have a system-assigned |
|
1160 |
node id. Since there is a one-to-one correspondence between protocols and nodes |
|
1161 |
we use to node-id to identify the protocol identity. Every interface on a |
|
1162 |
given rotocol will have an interface index (also called simply an interface) |
|
1163 |
relative to its protocol. By default, then, an ascii trace file created as a result |
|
1164 |
of enabling tracing on the first device of node 21, using the prefix ``prefix'', |
|
1165 |
would be ``prefix-n21-i1.tr''. Use the prefix to disambiguate multiple protocols |
|
1166 |
per node. |
|
1167 |
||
1168 |
You can always use the @code{ns-3} object name service to make this more clear. |
|
1169 |
For example, if you use the object name service to assign the name ``serverIpv4'' |
|
1170 |
to the protocol on node 21, and also specify interface one, the resulting ascii |
|
1171 |
trace file name will automatically become, ``prefix-nserverIpv4-1.tr''. |
|
1172 |
||
5426 | 1173 |
@node Tracing implementation details |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1174 |
@section Implementation details |