author | Tom Henderson <tomh@tomh.org> |
Sun, 18 Oct 2009 22:11:29 -0700 | |
changeset 5431 | 01a657b8d1ef |
parent 5426 | 7b36d173c490 |
child 6031 | 18776ed87c60 |
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:: |
5426 | 19 |
* Tracing implementation details:: |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
@end menu |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
|
5426 | 22 |
@node Tracing Motivation |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
@section Motivation |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
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
|
26 |
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
|
27 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
@verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
#include <iostream> |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
... |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
int main () |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
{ |
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 |
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
|
35 |
... |
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 |
@end verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
@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
|
51 |
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
|
52 |
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
|
53 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
simple use scenarios. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
@node Overview |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
@section Overview |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
or models of the simulator. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
95 |
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
|
96 |
@code{ns-3} @code{Callback}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
functions. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
@subsection The Simplest Example |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
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
|
115 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
116 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
117 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
#include ``ns3/object.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
#include ``ns3/uinteger.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
#include ``ns3/traced-value.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
#include ``ns3/trace-source-accessor.h'' |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
#include <iostream> |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
using namespace ns3; |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
126 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
127 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
@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
|
133 |
that obeys value semantics. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
operator--, operator+, operator==, etc. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
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
|
143 |
made using those operators. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
145 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
146 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
class MyObject : public Object |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
148 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
public: |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
150 |
static TypeId GetTypeId (void) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
static TypeId tid = TypeId ("MyObject") |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
.SetParent (Object::GetTypeId ()) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
.AddConstructor<MyObject> () |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
.AddTraceSource ("MyInteger", |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
"An integer value to trace.", |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
MakeTraceSourceAccessor (&MyObject::m_myInt)) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
return tid; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
} |
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 |
MyObject () {} |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
TracedValue<uint32_t> m_myInt; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
}; |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
165 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
166 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
the @code{TracedValue} declaration. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
process. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
178 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
179 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
void |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
IntTrace (Int oldValue, Int newValue) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
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
|
184 |
} |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
185 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
186 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
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
|
189 |
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
|
190 |
@code{TracedValue} is executed. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
192 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
193 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
int |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
195 |
main (int argc, char *argv[]) |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
196 |
{ |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
197 |
Ptr<MyObject> myObject = CreateObject<MyObject> (); |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
198 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
199 |
myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback(&IntTrace)); |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
200 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
201 |
myObject->m_myInt = 1234; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
202 |
} |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
203 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
204 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
205 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
206 |
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
|
207 |
in which the trace source lives. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
@code{TraceConnectWithoutContext}, takes a string parameter that provides |
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
216 |
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
|
217 |
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
|
218 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
Finally, the line, |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
220 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
221 |
@verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
222 |
myObject->m_myInt = 1234; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
223 |
@end verbatim |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
224 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
@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
|
241 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
called a @emph{config path}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
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
|
248 |
(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
|
249 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
250 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
251 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
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
|
253 |
|
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 |
Config::ConnectWithoutContext ( |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
257 |
"/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
|
258 |
MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
259 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
260 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
261 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
being provided. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
266 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
@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
|
271 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
272 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
273 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
274 |
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
|
275 |
|
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 |
|
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
278 |
theObject->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
279 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
280 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
281 |
|
5197
0401d439763e
silly typos and add disclaimer
Craig Dowell <craigdo@ee.washington.edu>
parents:
5188
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
@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
|
286 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
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
|
291 |
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
|
292 |
an @code{ns3::Object}. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
293 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
@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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
@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
|
305 |
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
|
306 |
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
|
307 |
simulation. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
308 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
|
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
313 |
@smallformat |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
314 |
@example |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
315 |
object->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndTracer)); |
5431
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
316 |
@end example |
01a657b8d1ef
some cleanup of part 1 of manual
Tom Henderson <tomh@tomh.org>
parents:
5426
diff
changeset
|
317 |
@end smallformat |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
318 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
of the TCP congestion window. |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
326 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
327 |
@node Using the Tracing API |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
328 |
@section Using the Tracing API |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
329 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
330 |
There |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
331 |
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
|
332 |
|
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
333 |
@itemize @bullet |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
334 |
@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
|
335 |
@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
|
336 |
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
|
337 |
core of the simulator; |
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
338 |
@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
|
339 |
sinks. |
5231 | 340 |
@end itemize |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
341 |
|
5426 | 342 |
@node Tracing implementation details |
5188
799fdd8fc54a
add some words about tracing to the manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
343 |
@section Implementation details |