author | Craig Dowell <craigdo@ee.washington.edu> |
Wed, 01 Jul 2009 23:08:07 -0700 | |
changeset 4634 | 46687cc0acb6 |
parent 4533 | f4d74e20ad78 |
child 5404 | 930965240183 |
permissions | -rw-r--r-- |
3332 | 1 |
|
2 |
@c ======================================================================== |
|
3 |
@c Begin document body here |
|
4 |
@c ======================================================================== |
|
5 |
||
6 |
@c ======================================================================== |
|
3340 | 7 |
@c PART: Tweaking ns-3 |
3332 | 8 |
@c ======================================================================== |
3340 | 9 |
@c The below chapters are under the major heading "Tweaking ns-3" |
3332 | 10 |
@c This is similar to the Latex \part command |
11 |
@c |
|
12 |
@c ======================================================================== |
|
3340 | 13 |
@c Tweaking ns-3 |
3332 | 14 |
@c ======================================================================== |
3340 | 15 |
@node Tweaking ns-3 |
16 |
@chapter Tweaking ns-3 |
|
3332 | 17 |
|
18 |
@menu |
|
19 |
* Using the Logging Module:: |
|
20 |
* Using Command Line Arguments:: |
|
21 |
* Using the Tracing System:: |
|
22 |
@end menu |
|
23 |
||
24 |
@c ======================================================================== |
|
25 |
@c Using the Logging Module |
|
26 |
@c ======================================================================== |
|
27 |
@node Using the Logging Module |
|
28 |
@section Using the Logging Module |
|
29 |
||
30 |
@cindex logging |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
31 |
We have already taken a brief look at the @command{ns-3} logging module while |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
32 |
going over the @code{first.cc} script. We will now take a closer look and |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
33 |
see what kind of use-cases the logging subsystem was designed to cover. |
3332 | 34 |
|
3342
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
35 |
@node Logging Overview |
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
36 |
@subsection Logging Overview |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
37 |
Many large systems support some kind of message logging facility, and |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
38 |
@command{ns-3} is not an exception. In some cases, only error messages are |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
39 |
logged to the ``operator console'' (which is typically @code{stderr} in Unix- |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
40 |
based systems). In other systems, warning messages may be output as well as |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
41 |
more detailed informational messages. In some cases, logging facilities are |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
42 |
used to output debug messages which can quickly turn the output into a blur. |
3332 | 43 |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
44 |
@command{Ns-3} takes the view that all of these verbosity levels are useful |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
45 |
and we provide a selectable, multi-level approach to message logging. Logging |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
46 |
can be disabled completely, enabled on a component-by-component basis, or |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
47 |
enabled globally; and it provides selectable verbosity levels. The |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
48 |
@command{ns-3} log module provides a straightforward, relatively easy to use |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
49 |
way to get useful information out of your simulation. |
3332 | 50 |
|
51 |
You should understand that we do provide a general purpose mechanism --- |
|
52 |
tracing --- to get data out of your models which should be preferred for |
|
53 |
simulation output (see the tutorial section Using the Tracing System for |
|
54 |
more details on our tracing system). Logging should be preferred for |
|
55 |
debugging information, warnings, error messages, or any time you want to |
|
56 |
easily get a quick message out of your scripts or models. |
|
57 |
||
58 |
There are currently seven levels of log messages of increasing verbosity |
|
59 |
defined in the system. |
|
60 |
||
61 |
@itemize @bullet |
|
62 |
@item NS_LOG_ERROR --- Log error messages; |
|
63 |
@item NS_LOG_WARN --- Log warning messages; |
|
64 |
@item NS_LOG_DEBUG --- Log relatively rare, ad-hoc debugging messages; |
|
65 |
@item NS_LOG_INFO --- Log informational messages about program progress; |
|
66 |
@item NS_LOG_FUNCTION --- Log a message describing each function called; |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
67 |
@item NS_LOG_LOGIC -- Log messages describing logical flow within a function; |
3332 | 68 |
@item NS_LOG_ALL --- Log everything. |
69 |
@end itemize |
|
70 |
||
71 |
We also provide an unconditional logging level that is always displayed, |
|
72 |
irrespective of logging levels or component selection. |
|
73 |
||
74 |
@itemize @bullet |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
75 |
@item NS_LOG_UNCOND -- Log the associated message unconditionally. |
3332 | 76 |
@end itemize |
77 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
78 |
Each level can be requested singly or cumulatively; and logging can be set |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
79 |
up using a shell environment variable (NS_LOG) or by logging system function |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
80 |
call. As was seen earlier in the tutorial, the logging system has Doxygen |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
81 |
documentation and now would be a good time to peruse the Logging Module |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
82 |
documentation if you have not done so. |
3332 | 83 |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
84 |
Now that you have read the documentation in great detail, let's use some of |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
85 |
that knowledge to get some interesting information out of the |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
86 |
@code{scratch/myfirst.cc} example script you have already built. |
3332 | 87 |
|
3342
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
88 |
@node Enabling Logging |
3356
be3532c51a37
Tutorial TOC tweaks
Craig Dowell <craigdo@ee.washington.edu>
parents:
3355
diff
changeset
|
89 |
@subsection Enabling Logging |
3332 | 90 |
@cindex NS_LOG |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
91 |
Let's use the NS_LOG environment variable to turn on some more logging, but |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
92 |
first, just to get our bearings, go ahead and run the last script just as you |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
93 |
did previously, |
3332 | 94 |
|
95 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
96 |
./waf --run scratch/myfirst |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
97 |
@end verbatim |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
98 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
99 |
You should see the now familiar output of the first @command{ns-3} example |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
100 |
program |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
101 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
102 |
@verbatim |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
103 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
104 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
105 |
'build' finished successfully (0.413s) |
3332 | 106 |
Sent 1024 bytes to 10.1.1.2 |
107 |
Received 1024 bytes from 10.1.1.1 |
|
108 |
Received 1024 bytes from 10.1.1.2 |
|
109 |
@end verbatim |
|
110 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
111 |
It turns out that the ``Sent'' and ``Received'' messages you see above are |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
112 |
actually logging messages from the @code{UdpEchoClientApplication} and |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
113 |
@code{UdpEchoServerApplication}. We can ask the client application, for |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
114 |
example, to print more information by setting its logging level via the |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
115 |
NS_LOG environment variable. |
3332 | 116 |
|
4533 | 117 |
I am going to assume from here on that you are using an sh-like shell that uses |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
118 |
the``VARIABLE=value'' syntax. If you are using a csh-like shell, then you |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
119 |
will have to convert my examples to the ``setenv VARIABLE value'' syntax |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
120 |
required by those shells. |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
121 |
|
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
122 |
Right now, the UDP echo client application is responding to the following line |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
123 |
of code in @code{scratch/myfirst.cc}, |
3332 | 124 |
|
125 |
@verbatim |
|
126 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); |
|
127 |
@end verbatim |
|
128 |
||
129 |
This line of code enables the @code{LOG_LEVEL_INFO} level of logging. When |
|
130 |
we pass a logging level flag, we are actually enabling the given level and |
|
131 |
all lower levels. In this case, we have enabled @code{NS_LOG_INFO}, |
|
132 |
@code{NS_LOG_DEBUG}, @code{NS_LOG_WARN} and @code{NS_LOG_ERROR}. We can |
|
133 |
increase the logging level and get more information without changing the |
|
134 |
script and recompiling by setting the NS_LOG environment variable like this: |
|
135 |
||
136 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
137 |
export NS_LOG=UdpEchoClientApplication=level_all |
3332 | 138 |
@end verbatim |
139 |
||
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
140 |
This sets the shell environment variable @code{NS_LOG} to the string, |
3332 | 141 |
|
142 |
@verbatim |
|
143 |
UdpEchoClientApplication=level_all |
|
144 |
@end verbatim |
|
145 |
||
146 |
The left hand side of the assignment is the name of the logging component we |
|
147 |
want to set, and the right hand side is the flag we want to use. In this case, |
|
148 |
we are going to turn on all of the debugging levels for the application. If |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
149 |
you run the script with NS_LOG set this way, the @command{ns-3} logging |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
150 |
system will pick up the change and you should see the following output: |
3332 | 151 |
|
152 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
153 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
154 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
155 |
'build' finished successfully (0.404s) |
3332 | 156 |
UdpEchoClientApplication:UdpEchoClient() |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
157 |
UdpEchoClientApplication:SetDataSize(1024) |
3332 | 158 |
UdpEchoClientApplication:StartApplication() |
159 |
UdpEchoClientApplication:ScheduleTransmit() |
|
160 |
UdpEchoClientApplication:Send() |
|
161 |
Sent 1024 bytes to 10.1.1.2 |
|
162 |
Received 1024 bytes from 10.1.1.1 |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
163 |
UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20) |
3332 | 164 |
Received 1024 bytes from 10.1.1.2 |
165 |
UdpEchoClientApplication:StopApplication() |
|
166 |
UdpEchoClientApplication:DoDispose() |
|
167 |
UdpEchoClientApplication:~UdpEchoClient() |
|
168 |
@end verbatim |
|
169 |
||
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
170 |
The additional debug information provided by the application is from |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
171 |
the NS_LOG_FUNCTION level. This shows every time a function in the application |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
172 |
is called during script execution. Note that there are no requirements in the |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
173 |
@command{ns-3} system that models must support any particular logging |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
174 |
functionality. The decision regarding how much information is logged |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
175 |
is left to the individual model developer. In the case of the echo |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
176 |
applications, a good deal of log output is available. |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
177 |
|
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
178 |
You can now see a log of the function calls that were made to the application. |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
179 |
If you look closely you will notice a single colon between the string |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
180 |
@code{UdpEchoClientApplication} and the method name where you might have |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
181 |
expected a C++ scope operator (@code{::}). This is intentional. |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
182 |
|
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
183 |
The name is not actually a class name, it is a logging component name. When |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
184 |
there is a one-to-one correspondence between a source file and a class, this |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
185 |
will generally be the class name but you should understand that it is not |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
186 |
actually a class name, and there is a single colon there instead of a double |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
187 |
colon to remind you in a relatively subtle way to conceptually separate the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
188 |
logging component name from the class name. |
3332 | 189 |
|
3771
21f40ccb03b3
tutorial typos fixed (bug 379)
Tom Henderson <tomh@tomh.org>
parents:
3382
diff
changeset
|
190 |
It turns out that in some cases, it can be hard to determine which method |
3332 | 191 |
actually generates a log message. If you look in the text above, you may |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
192 |
wonder where the string ``@code{Received 1024 bytes from 10.1.1.2}'' comes |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
193 |
from. You can resolve this by OR'ing the @code{prefix_func} level into the |
3332 | 194 |
@code{NS_LOG} environment variable. Try doing the following, |
195 |
||
196 |
@verbatim |
|
197 |
export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func' |
|
198 |
@end verbatim |
|
199 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
200 |
Note that the quotes are required since the vertical bar we use to indicate an |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
201 |
OR operation is also a Unix pipe connector. |
3332 | 202 |
|
203 |
Now, if you run the script you will see that the logging system makes sure |
|
204 |
that every message from the given log component is prefixed with the component |
|
205 |
name. |
|
206 |
||
207 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
208 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
209 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
210 |
'build' finished successfully (0.417s) |
3332 | 211 |
UdpEchoClientApplication:UdpEchoClient() |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
212 |
UdpEchoClientApplication:SetDataSize(1024) |
3332 | 213 |
UdpEchoClientApplication:StartApplication() |
214 |
UdpEchoClientApplication:ScheduleTransmit() |
|
215 |
UdpEchoClientApplication:Send() |
|
216 |
UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2 |
|
217 |
Received 1024 bytes from 10.1.1.1 |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
218 |
UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20) |
3332 | 219 |
UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2 |
220 |
UdpEchoClientApplication:StopApplication() |
|
221 |
UdpEchoClientApplication:DoDispose() |
|
222 |
UdpEchoClientApplication:~UdpEchoClient() |
|
223 |
@end verbatim |
|
224 |
||
225 |
You can now see all of the messages coming from the UDP echo client application |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
226 |
are identified as such. The message ``Received 1024 bytes from 10.1.1.2'' is |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
227 |
now clearly identified as coming from the echo client application. The |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
228 |
remaining message must be coming from the UDP echo server application. We |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
229 |
can enable that component by entering a colon separated list of components in |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
230 |
the NS_LOG environment variable. |
3332 | 231 |
|
232 |
@verbatim |
|
233 |
export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func: |
|
234 |
UdpEchoServerApplication=level_all|prefix_func' |
|
235 |
@end verbatim |
|
236 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
237 |
Warning: You will need to remove the newline after the @code{:} in the |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
238 |
example text above which is only there for document formatting purposes. |
3332 | 239 |
|
240 |
Now, if you run the script you will see all of the log messages from both the |
|
241 |
echo client and server applications. You may see that this can be very useful |
|
242 |
in debugging problems. |
|
243 |
||
244 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
245 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
246 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
247 |
'build' finished successfully (0.406s) |
3332 | 248 |
UdpEchoServerApplication:UdpEchoServer() |
249 |
UdpEchoClientApplication:UdpEchoClient() |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
250 |
UdpEchoClientApplication:SetDataSize(1024) |
3332 | 251 |
UdpEchoServerApplication:StartApplication() |
252 |
UdpEchoClientApplication:StartApplication() |
|
253 |
UdpEchoClientApplication:ScheduleTransmit() |
|
254 |
UdpEchoClientApplication:Send() |
|
255 |
UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2 |
|
256 |
UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1 |
|
257 |
UdpEchoServerApplication:HandleRead(): Echoing packet |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
258 |
UdpEchoClientApplication:HandleRead(0x624920, 0x625160) |
3332 | 259 |
UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2 |
260 |
UdpEchoServerApplication:StopApplication() |
|
261 |
UdpEchoClientApplication:StopApplication() |
|
262 |
UdpEchoClientApplication:DoDispose() |
|
263 |
UdpEchoServerApplication:DoDispose() |
|
264 |
UdpEchoClientApplication:~UdpEchoClient() |
|
265 |
UdpEchoServerApplication:~UdpEchoServer() |
|
266 |
@end verbatim |
|
267 |
||
268 |
It is also sometimes useful to be able to see the simulation time at which a |
|
269 |
log message is generated. You can do this by ORing in the prefix_time bit. |
|
270 |
||
271 |
@verbatim |
|
272 |
export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time: |
|
273 |
UdpEchoServerApplication=level_all|prefix_func|prefix_time' |
|
274 |
@end verbatim |
|
275 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
276 |
Again, you will have to remove the newline above. If you run the script now, |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
277 |
you should see the following output: |
3332 | 278 |
|
279 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
280 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
281 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
282 |
'build' finished successfully (0.418s) |
4207
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
283 |
0s UdpEchoServerApplication:UdpEchoServer() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
284 |
0s UdpEchoClientApplication:UdpEchoClient() |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
285 |
0s UdpEchoClientApplication:SetDataSize(1024) |
4207
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
286 |
1s UdpEchoServerApplication:StartApplication() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
287 |
2s UdpEchoClientApplication:StartApplication() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
288 |
2s UdpEchoClientApplication:ScheduleTransmit() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
289 |
2s UdpEchoClientApplication:Send() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
290 |
2s UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2 |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
291 |
2.00369s UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1 |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
292 |
2.00369s UdpEchoServerApplication:HandleRead(): Echoing packet |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
293 |
2.00737s UdpEchoClientApplication:HandleRead(0x624290, 0x624ad0) |
4207
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
294 |
2.00737s UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2 |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
295 |
10s UdpEchoServerApplication:StopApplication() |
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
296 |
10s UdpEchoClientApplication:StopApplication() |
3332 | 297 |
UdpEchoClientApplication:DoDispose() |
298 |
UdpEchoServerApplication:DoDispose() |
|
299 |
UdpEchoClientApplication:~UdpEchoClient() |
|
300 |
UdpEchoServerApplication:~UdpEchoServer() |
|
301 |
@end verbatim |
|
302 |
||
303 |
You can see that the constructor for the UdpEchoServer was called at a |
|
4207
11043ba9a122
tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents:
4032
diff
changeset
|
304 |
simulation time of 0 seconds. This is actually happening before the |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
305 |
simulation starts, but the time is displayed as zero seconds. The same is true |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
306 |
for the UdpEchoClient constructor message. |
3332 | 307 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
308 |
Recall that the @code{scratch/first.cc} script started the echo server |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
309 |
application at one second into the simulation. You can now see that the |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
310 |
@code{StartApplication} method of the server is, in fact, called at one second. |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
311 |
You can also see that the echo client application is started at a simulation |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
312 |
time of two seconds as we requested in the script. |
3332 | 313 |
|
314 |
You can now follow the progress of the simulation from the |
|
315 |
@code{ScheduleTransmit} call in the client that calls @code{Send} to the |
|
316 |
@code{HandleRead} callback in the echo server application. Note that the |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
317 |
elapsed time for the packet to be sent across the point-to-point link is 3.69 |
3332 | 318 |
milliseconds. You see the echo server logging a message telling you that it |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
319 |
has echoed the packet and then, after another channel delay, you see the echo |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
320 |
client receive the echoed packet in its @code{HandleRead} method. |
3332 | 321 |
|
322 |
There is a lot that is happening under the covers in this simulation that you |
|
323 |
are not seeing as well. You can very easily follow the entire process by |
|
324 |
turning on all of the logging components in the system. Try setting the |
|
325 |
@code{NS_LOG} variable to the following, |
|
326 |
||
327 |
@verbatim |
|
328 |
export 'NS_LOG=*=level_all|prefix_func|prefix_time' |
|
329 |
@end verbatim |
|
330 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
331 |
The asterisk above is the logging component wildcard. This will turn on all |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
332 |
of the logging in all of the components used in the simulation. I won't |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
333 |
reproduce the output here (as of this writing it produces 1265 lines of output |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
334 |
for the single packet echo) but you can redirect this information into a file |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
335 |
and look through it with your favorite editor if you like, |
3332 | 336 |
|
337 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
338 |
./waf --run scratch/myfirst > log.out 2>&1 |
3332 | 339 |
@end verbatim |
340 |
||
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
341 |
I personally use this extremely verbose version of logging when I am presented |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
342 |
with a problem and I have no idea where things are going wrong. I can follow the |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
343 |
progress of the code quite easily without having to set breakpoints and step |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
344 |
through code in a debugger. I can just edit up the output in my favorite editor |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
345 |
and search around for things I expect, and see things happening that I don't |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
346 |
expect. When I have a general idea about what is going wrong, I transition into |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
347 |
a debugger for a fine-grained examination of the problem. This kind of output |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
348 |
can be especially useful when your script does something completely unexpected. |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
349 |
If you are stepping using a debugger you may miss an unexpected excursion |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
350 |
completely. Logging the excursion makes it quickly visible. |
3332 | 351 |
|
3342
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
352 |
@node Adding Logging to your Code |
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
353 |
@subsection Adding Logging to your Code |
3332 | 354 |
@cindex NS_LOG |
355 |
You can add new logging to your simulations by making calls to the log |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
356 |
component via several macros. Let's do so in the @code{myfirst.cc} script we |
3332 | 357 |
have in the @code{scratch} directory. |
358 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
359 |
Recall that we have defined a logging component in that script: |
3332 | 360 |
|
361 |
@verbatim |
|
362 |
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); |
|
363 |
@end verbatim |
|
364 |
||
365 |
You now know that you can enable all of the logging for this component by |
|
366 |
setting the @code{NS_LOG} environment variable to the various levels. Let's |
|
4533 | 367 |
go ahead and add some logging to the script. The macro used to add an |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
368 |
informational level log message is @code{NS_LOG_INFO}. Go ahead and add one |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
369 |
(just before we start creating the nodes) that tells you that the script is |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
370 |
``Creating Topology.'' This is done as in this code snippet, |
3332 | 371 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
372 |
Open @code{scratch/myfirst.cc} in your favorite editor and add the line, |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
373 |
|
3332 | 374 |
@verbatim |
375 |
NS_LOG_INFO ("Creating Topology"); |
|
376 |
@end verbatim |
|
377 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
378 |
right before the lines, |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
379 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
380 |
@verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
381 |
NodeContainer nodes; |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
382 |
nodes.Create (2); |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
383 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
384 |
|
3332 | 385 |
Now build the script using waf and clear the @code{NS_LOG} variable to turn |
386 |
off the torrent of logging we previously enabled: |
|
387 |
||
388 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
389 |
./waf |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
390 |
export NS_LOG= |
3332 | 391 |
@end verbatim |
392 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
393 |
Now, if you run the script, |
3332 | 394 |
|
395 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
396 |
./waf --run scratch/myfirst |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
397 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
398 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
399 |
you will @emph{not} see your new message since its associated logging |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
400 |
component (@code{FirstScriptExample}) has not been enabled. In order to see your |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
401 |
message you will have to enable the @code{FirstScriptExample} logging component |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
402 |
with a level greater than or equal to @code{NS_LOG_INFO}. If you just want to |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
403 |
see this particular level of logging, you can enable it by, |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
404 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
405 |
@verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
406 |
export NS_LOG=FirstScriptExample=info |
3332 | 407 |
@end verbatim |
408 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
409 |
If you now run the script you will see your new ``Creating Topology'' log |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
410 |
message, |
3332 | 411 |
|
412 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
413 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
414 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
415 |
'build' finished successfully (0.404s) |
3332 | 416 |
Creating Topology |
417 |
Sent 1024 bytes to 10.1.1.2 |
|
418 |
Received 1024 bytes from 10.1.1.1 |
|
419 |
Received 1024 bytes from 10.1.1.2 |
|
420 |
@end verbatim |
|
421 |
||
422 |
@c ======================================================================== |
|
423 |
@c Using Command Line Arguments |
|
424 |
@c ======================================================================== |
|
425 |
@node Using Command Line Arguments |
|
426 |
@section Using Command Line Arguments |
|
427 |
||
3342
8762b90e6f7e
formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents:
3340
diff
changeset
|
428 |
@subsection Overriding Default Attributes |
3339
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
429 |
@cindex command line arguments |
3349
e6259dcffada
more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3348
diff
changeset
|
430 |
Another way you can change how @command{ns-3} scripts behave without editing |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
431 |
and building is via @emph{command line arguments.} We provide a mechanism to |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
432 |
parse command line arguments and automatically set local and global variables |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
433 |
based on those arguments. |
3332 | 434 |
|
435 |
The first step in using the command line argument system is to declare the |
|
436 |
command line parser. This is done quite simply (in your main program) as |
|
437 |
in the following code, |
|
438 |
||
439 |
@verbatim |
|
440 |
int |
|
441 |
main (int argc, char *argv[]) |
|
442 |
{ |
|
443 |
... |
|
444 |
||
445 |
CommandLine cmd; |
|
446 |
cmd.Parse (argc, argv); |
|
447 |
||
448 |
... |
|
449 |
} |
|
450 |
@end verbatim |
|
451 |
||
452 |
This simple two line snippet is actually very useful by itself. It opens the |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
453 |
door to the @command{ns-3} global variable and @code{Attribute} systems. Go |
4533 | 454 |
ahead and add that two lines of code to the @code{scratch/myfirst.cc} script at |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
455 |
the start of @code{main}. Go ahead and build the script and run it, but ask |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
456 |
the script for help in the following way, |
3332 | 457 |
|
458 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
459 |
./waf --run "scratch/myfirst --PrintHelp" |
3332 | 460 |
@end verbatim |
461 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
462 |
This will ask Waf to run the @code{scratch/myfirst} script and pass the command |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
463 |
line argument @code{--PrintHelp} to the script. The quotes are required to |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
464 |
sort out which program gets which argument. The command line parser will |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
465 |
now see the @code{--PrintHelp} argument and respond with, |
3332 | 466 |
|
467 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
468 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
469 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
470 |
'build' finished successfully (0.413s) |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
471 |
TcpL4Protocol:TcpStateMachine() |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
472 |
CommandLine:HandleArgument(): Handle arg name=PrintHelp value= |
3332 | 473 |
--PrintHelp: Print this help message. |
474 |
--PrintGroups: Print the list of groups. |
|
475 |
--PrintTypeIds: Print all TypeIds. |
|
476 |
--PrintGroup=[group]: Print all TypeIds of group. |
|
477 |
--PrintAttributes=[typeid]: Print all attributes of typeid. |
|
478 |
--PrintGlobals: Print the list of globals. |
|
479 |
@end verbatim |
|
480 |
||
481 |
Let's focus on the @code{--PrintAttributes} option. We have already hinted |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
482 |
at the @command{ns-3} @code{Attribute} system while walking through the |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
483 |
@code{first.cc} script. We looked at the following lines of code, |
3332 | 484 |
|
485 |
@verbatim |
|
486 |
PointToPointHelper pointToPoint; |
|
3382
d5f8e5fae1c6
fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3356
diff
changeset
|
487 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
d5f8e5fae1c6
fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3356
diff
changeset
|
488 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
3332 | 489 |
@end verbatim |
490 |
||
491 |
and mentioned that @code{DataRate} was actually an @code{Attribute} of the |
|
492 |
@code{PointToPointNetDevice}. Let's use the command line argument parser |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
493 |
to take a look at the @code{Attributes} of the PointToPointNetDevice. The help |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
494 |
listing says that we should provide a @code{TypeId}. This corresponds to the |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
495 |
class name of the class to which the @code{Attributes} belong. In this case it |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
496 |
will be @code{ns3::PointToPointNetDevice}. Let's go ahead and type in, |
3332 | 497 |
|
498 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
499 |
./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointNetDevice" |
3332 | 500 |
@end verbatim |
501 |
||
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
502 |
The system will print out all of the @code{Attributes} of this kind of net device. |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
503 |
Among the @code{Attributes} you will see listed is, |
3332 | 504 |
|
505 |
@verbatim |
|
506 |
--ns3::PointToPointNetDevice::DataRate=[32768bps]: |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
507 |
The default data rate for point to point links |
3332 | 508 |
@end verbatim |
509 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
510 |
This is the default value that will be used when a @code{PointToPointNetDevice} |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
511 |
is created in the system. We overrode this default with the @code{Attribute} |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
512 |
setting in the @code{PointToPointHelper} above. Let's use the default values |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
513 |
for the point-to-point devices and channels by deleting the |
3382
d5f8e5fae1c6
fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents:
3356
diff
changeset
|
514 |
@code{SetDeviceAttribute} call and the @code{SetChannelAttribute} call from |
4533 | 515 |
the @code{myfirst.cc} we have in the scratch directory. |
3332 | 516 |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
517 |
Your script should now just declare the @code{PointToPointHelper} and not do |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
518 |
any @code{set} operations as in the following example, |
3332 | 519 |
|
520 |
@verbatim |
|
521 |
... |
|
522 |
||
523 |
NodeContainer nodes; |
|
524 |
nodes.Create (2); |
|
525 |
||
526 |
PointToPointHelper pointToPoint; |
|
527 |
||
528 |
NetDeviceContainer devices; |
|
529 |
devices = pointToPoint.Install (nodes); |
|
530 |
||
531 |
... |
|
532 |
@end verbatim |
|
533 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
534 |
Go ahead and build the new script with Waf (@code{./waf}) and let's go back |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
535 |
and enable some logging from the UDP echo server application and turn on the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
536 |
time prefix. |
3332 | 537 |
|
538 |
@verbatim |
|
539 |
export 'NS_LOG=UdpEchoServerApplication=level_all|prefix_time' |
|
540 |
@end verbatim |
|
541 |
||
542 |
If you run the script, you should now see the following output, |
|
543 |
||
544 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
545 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
546 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
547 |
'build' finished successfully (0.405s) |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
548 |
0s UdpEchoServerApplication:UdpEchoServer() |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
549 |
1s UdpEchoServerApplication:StartApplication() |
3332 | 550 |
Sent 1024 bytes to 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
551 |
2.25732s Received 1024 bytes from 10.1.1.1 |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
552 |
2.25732s Echoing packet |
3332 | 553 |
Received 1024 bytes from 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
554 |
10s UdpEchoServerApplication:StopApplication() |
3332 | 555 |
UdpEchoServerApplication:DoDispose() |
556 |
UdpEchoServerApplication:~UdpEchoServer() |
|
557 |
@end verbatim |
|
558 |
||
559 |
Recall that the last time we looked at the simulation time at which the packet |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
560 |
was received by the echo server, it was at 2.00369 seconds. |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
561 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
562 |
@verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
563 |
2.00369s UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1 |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
564 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
565 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
566 |
Now it is receiving the packet at 2.25732 seconds. This is because we just dropped |
3332 | 567 |
the data rate of the @code{PointToPointNetDevice} down to its default of |
568 |
32768 bits per second from five megabits per second. |
|
569 |
||
570 |
If we were to provide a new @code{DataRate} using the command line, we could |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
571 |
speed our simulation up again. We do this in the following way, according to |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
572 |
the formula implied by the help item: |
3332 | 573 |
|
574 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
575 |
./waf --run "scratch/myfirst --ns3::PointToPointNetDevice::DataRate=5Mbps" |
3332 | 576 |
@end verbatim |
577 |
||
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
578 |
This will set the default value of the @code{DataRate} @code{Attribute} back to |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
579 |
five megabits per second. Are you surprised by the result? It turns out that |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
580 |
in order to get the original behavior of the script back, we will have to set |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
581 |
the speed-of-light delay of the channel as well. We can ask the command line |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
582 |
system to print out the @code{Attributes} of the channel just like we did for |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
583 |
the net device: |
3332 | 584 |
|
585 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
586 |
./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointChannel" |
3332 | 587 |
@end verbatim |
588 |
||
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
589 |
We discover the @code{Delay} @code{Attribute} of the channel is set in the following |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
590 |
way: |
3332 | 591 |
|
592 |
@verbatim |
|
593 |
--ns3::PointToPointChannel::Delay=[0ns]: |
|
594 |
Transmission delay through the channel |
|
595 |
@end verbatim |
|
596 |
||
597 |
We can then set both of these default values through the command line system, |
|
598 |
||
599 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
600 |
./waf --run "scratch/myfirst |
3332 | 601 |
--ns3::PointToPointNetDevice::DataRate=5Mbps |
602 |
--ns3::PointToPointChannel::Delay=2ms" |
|
603 |
@end verbatim |
|
604 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
605 |
in which case we recover the timing we had when we explicitly set the |
3332 | 606 |
@code{DataRate} and @code{Delay} in the script: |
607 |
||
608 |
@verbatim |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
609 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/bu |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
610 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/bui |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
611 |
'build' finished successfully (0.417s) |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
612 |
0s UdpEchoServerApplication:UdpEchoServer() |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
613 |
1s UdpEchoServerApplication:StartApplication() |
3332 | 614 |
Sent 1024 bytes to 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
615 |
2.00369s Received 1024 bytes from 10.1.1.1 |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
616 |
2.00369s Echoing packet |
3332 | 617 |
Received 1024 bytes from 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
618 |
10s UdpEchoServerApplication:StopApplication() |
3332 | 619 |
UdpEchoServerApplication:DoDispose() |
620 |
UdpEchoServerApplication:~UdpEchoServer() |
|
621 |
@end verbatim |
|
622 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
623 |
Note that the packet is again received by the server at 2.00369 seconds. We |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
624 |
could actually set any of the @code{Attributes} used in the script in this way. |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
625 |
In particular we could set the @code{UdpEchoClient Attribute MaxPackets} |
3332 | 626 |
to some other value than one. |
627 |
||
628 |
How would you go about that? Give it a try. Remember you have to comment |
|
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
629 |
out the place we override the default @code{Attribute} and explicitly set |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
630 |
@code{MaxPackets} in the script. Then you have to rebuild the script. You |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
631 |
will also have to find the syntax for actually setting the new default atribute |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
632 |
value using the command line help facility. Once you have this figured out |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
633 |
you should be able to control the number of packets echoed from the command |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
634 |
line. Since we're nice folks, we'll tell you that your command line should |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
635 |
end up looking something like, |
3332 | 636 |
|
637 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
638 |
./waf --run "scratch/myfirst |
3332 | 639 |
--ns3::PointToPointNetDevice::DataRate=5Mbps |
640 |
--ns3::PointToPointChannel::Delay=2ms |
|
641 |
--ns3::UdpEchoClient::MaxPackets=2" |
|
642 |
@end verbatim |
|
643 |
||
644 |
@subsection Hooking Your Own Values |
|
645 |
You can also add your own hooks to the command line system. This is done |
|
646 |
quite simply by using the @code{AddValue} method to the command line parser. |
|
647 |
||
648 |
Let's use this facility to specify the number of packets to echo in a |
|
649 |
completely different way. Let's add a local variable called @code{nPackets} |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
650 |
to the @code{main} function. We'll initialize it to one to match our previous |
3332 | 651 |
default behavior. To allow the command line parser to change this value, we |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
652 |
need to hook the value into the parser. We do this by adding a call to |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
653 |
@code{AddValue}. Go ahead and change the @code{scratch/myfirst.cc} script to |
3332 | 654 |
start with the following code, |
655 |
||
656 |
@verbatim |
|
3771
21f40ccb03b3
tutorial typos fixed (bug 379)
Tom Henderson <tomh@tomh.org>
parents:
3382
diff
changeset
|
657 |
int |
3332 | 658 |
main (int argc, char *argv[]) |
659 |
{ |
|
660 |
uint32_t nPackets = 1; |
|
661 |
||
662 |
CommandLine cmd; |
|
663 |
cmd.AddValue("nPackets", "Number of packets to echo", nPackets); |
|
664 |
cmd.Parse (argc, argv); |
|
665 |
||
666 |
... |
|
667 |
@end verbatim |
|
668 |
||
669 |
Scroll down to the point in the script where we set the @code{MaxPackets} |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
670 |
@code{Attribute} and change it so that it is set to the variable @code{nPackets} |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
671 |
instead of the constant @code{1} as is shown below. |
3332 | 672 |
|
673 |
@verbatim |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
674 |
echoClient.SetAttribute ("MaxPackets", UintegerValue (nPackets)); |
3332 | 675 |
@end verbatim |
676 |
||
677 |
Now if you run the script and provide the @code{--PrintHelp} argument, you |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
678 |
should see your new @code{User Argument} listed in the help display. |
3332 | 679 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
680 |
Try, |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
681 |
|
3332 | 682 |
@verbatim |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
683 |
./waf --run "scratch/myfirst --PrintHelp" |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
684 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
685 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
686 |
@verbatim |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
687 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
688 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
689 |
'build' finished successfully (0.403s) |
3332 | 690 |
--PrintHelp: Print this help message. |
691 |
--PrintGroups: Print the list of groups. |
|
692 |
--PrintTypeIds: Print all TypeIds. |
|
693 |
--PrintGroup=[group]: Print all TypeIds of group. |
|
694 |
--PrintAttributes=[typeid]: Print all attributes of typeid. |
|
695 |
--PrintGlobals: Print the list of globals. |
|
696 |
User Arguments: |
|
697 |
--nPackets: Number of packets to echo |
|
698 |
@end verbatim |
|
699 |
||
700 |
If you want to specify the number of packets to echo, you can now do so by |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
701 |
setting the @code{--nPackets} argument in the command line, |
3332 | 702 |
|
703 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
704 |
./waf --run "scratch/myfirst --nPackets=2" |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
705 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
706 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
707 |
You should now see |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
708 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
709 |
@verbatim |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
710 |
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
711 |
Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-3.5-tutorial/ns-3-dev/build' |
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
712 |
'build' finished successfully (0.404s) |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
713 |
0s UdpEchoServerApplication:UdpEchoServer() |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
714 |
1s UdpEchoServerApplication:StartApplication() |
3332 | 715 |
Sent 1024 bytes to 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
716 |
2.25732s Received 1024 bytes from 10.1.1.1 |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
717 |
2.25732s Echoing packet |
3332 | 718 |
Received 1024 bytes from 10.1.1.2 |
719 |
Sent 1024 bytes to 10.1.1.2 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
720 |
3.25732s Received 1024 bytes from 10.1.1.1 |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
721 |
3.25732s Echoing packet |
3332 | 722 |
Received 1024 bytes from 10.1.1.2 |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
723 |
10s UdpEchoServerApplication:StopApplication() |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
724 |
UdpEchoServerApplication:DoDispose() |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
725 |
UdpEchoServerApplication:~UdpEchoServer() |
3332 | 726 |
@end verbatim |
727 |
||
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
728 |
You have now echoed two packets. Pretty easy, isn't it? |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
729 |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
730 |
You can see that if you are an @command{ns-3} user, you can use the command |
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
731 |
line argument system to control global values and @code{Attributes}. If you are |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
732 |
a model author, you can add new @code{Attributes} to your @code{Objects} and |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
733 |
they will automatically be available for setting by your users through the |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
734 |
command line system. If you are a script author, you can add new variables to |
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
735 |
your scripts and hook them into the command line system quite painlessly. |
3332 | 736 |
|
737 |
@c ======================================================================== |
|
738 |
@c Using the Tracing System |
|
739 |
@c ======================================================================== |
|
740 |
@node Using the Tracing System |
|
741 |
@section Using the Tracing System |
|
742 |
||
743 |
The whole point of simulation is to generate output for further study, and |
|
744 |
the @command{ns-3} tracing system is a primary mechanism for this. Since |
|
745 |
@command{ns-3} is a C++ program, standard facilities for generating output |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
746 |
from C++ programs could be used: |
3332 | 747 |
|
748 |
@verbatim |
|
749 |
#include <iostream> |
|
750 |
... |
|
751 |
int main () |
|
752 |
{ |
|
753 |
... |
|
754 |
std::cout << "The value of x is " << x << std::endl; |
|
755 |
... |
|
756 |
} |
|
757 |
@end verbatim |
|
758 |
||
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
759 |
You could even use the logging module to add a little structure to your |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
760 |
solution. There are many well-known problems generated by such approaches |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
761 |
and so we have provided a generic event tracing subsystem to address the |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
762 |
issues we thought were important. |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
763 |
|
3332 | 764 |
The basic goals of the @command{ns-3} tracing system are: |
765 |
||
766 |
@itemize @bullet |
|
767 |
@item For basic tasks, the tracing system should allow the user to generate |
|
768 |
standard tracing for popular tracing sources, and to customize which objects |
|
769 |
generate the tracing; |
|
770 |
@item Intermediate users must be able to extend the tracing system to modify |
|
771 |
the output format generated, or to insert new tracing sources, without |
|
772 |
modifying the core of the simulator; |
|
773 |
@item Advanced users can modify the simulator core to add new tracing sources |
|
774 |
and sinks. |
|
775 |
@end itemize |
|
776 |
||
777 |
The @command{ns-3} tracing system is built on the concepts of independent |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
778 |
tracing sources and tracing sinks, and a uniform mechanism for connecting |
3332 | 779 |
sources to sinks. Trace sources are entities that can signal events that |
780 |
happen in a simulation and provide access to interesting underlying data. |
|
781 |
For example, a trace source could indicate when a packet is received by a net |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
782 |
device and provide access to the packet contents for interested trace sinks. |
3332 | 783 |
|
784 |
Trace sources are not useful by themselves, they must be ``connected'' to |
|
785 |
other pieces of code that actually do something useful with the information |
|
786 |
provided by the sink. Trace sinks are consumers of the events and data |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
787 |
provided by the trace sources. For example, one could create a trace sink |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
788 |
that would (when connected to the trace source of the previous example) print |
3332 | 789 |
out interesting parts of the received packet. |
790 |
||
791 |
The rationale for this explicit division is to allow users to attach new |
|
792 |
types of sinks to existing tracing sources, without requiring editing and |
|
4032
2b675a0b3b94
Fix misprints in tutorial (bug 453)
Tom Henderson <tomh@tomh.org>
parents:
3771
diff
changeset
|
793 |
recompilation of the core of the simulator. Thus, in the example above, |
3332 | 794 |
a user could define a new tracing sink in her script and attach it to an |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
795 |
existing tracing source defined in the simulation core by editing only the |
3332 | 796 |
user script. |
797 |
||
798 |
In this tutorial, we will walk through some pre-defined sources and sinks and |
|
799 |
show how they may be customized with little user effort. See the ns-3 manual |
|
800 |
or how-to sections for information on advanced tracing configuration including |
|
801 |
extending the tracing namespace and creating new tracing sources. |
|
802 |
||
803 |
@cindex tracing |
|
3339
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
804 |
@cindex ASCII tracing |
3332 | 805 |
@subsection ASCII Tracing |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
806 |
@command{Ns-3} provides helper functionality that wraps the low-level tracing |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
807 |
system to help you with the details involved in configuring some easily |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
808 |
understood packet traces. If you enable this functionality, you will see |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
809 |
output in a ASCII files --- thus the name. For those familiar with |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
810 |
@command{ns-2} output, this type of trace is analogous to the @command{out.tr} |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
811 |
generated by many scripts. |
3332 | 812 |
|
3339
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
813 |
@cindex tracing packets |
3332 | 814 |
Let's just jump right in and add some ASCII tracing output to our |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
815 |
@code{scratch/myfirst.cc} script. |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
816 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
817 |
The first thing you need to do is to add the following include to the top of |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
818 |
the script just after the GNU GPL comment: |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
819 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
820 |
@verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
821 |
#include <fstream> |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
822 |
@end verbatim |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
823 |
|
4533 | 824 |
Then, right before the call to @code{Simulator::Run ()}, add the |
825 |
following lines of code: |
|
3332 | 826 |
|
827 |
@verbatim |
|
828 |
std::ofstream ascii; |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
829 |
ascii.open ("myfirst.tr"); |
3332 | 830 |
PointToPointHelper::EnableAsciiAll (ascii); |
831 |
@end verbatim |
|
832 |
||
833 |
The first two lines are just vanilla C++ code to open a stream that will be |
|
4533 | 834 |
written to a file named ``myfirst.tr''. See your favorite C++ tutorial if you |
3332 | 835 |
are unfamiliar with this code. The last line of code in the snippet above |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
836 |
tells @command{ns-3} that you want to enable ASCII tracing on all |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
837 |
point-to-point devices in your simulation; and you want the (provided) trace |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
838 |
sinks to write out information about packet movement in ASCII format to the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
839 |
stream provided. For those familiar with @command{ns-2}, the traced events are |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
840 |
equivalent to the popular trace points that log "+", "-", "d", and "r" events. |
3332 | 841 |
|
842 |
You can now build the script and run it from the command line: |
|
843 |
||
844 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
845 |
./waf --run scratch/myfirst |
3332 | 846 |
@end verbatim |
847 |
||
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
848 |
@cindex myfirst.tr |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
849 |
Just as you have seen many times before, you will see some messages from Waf and then |
4634
46687cc0acb6
update tutorial for ns-3.5
Craig Dowell <craigdo@ee.washington.edu>
parents:
4533
diff
changeset
|
850 |
``'build' finished successfully'' with some number of messages from |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
851 |
the running program. |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
852 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
853 |
When it ran, the program will have created a file named @code{myfirst.tr}. |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
854 |
Because of the way that Waf works, the file is not created in the local |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
855 |
directory, it is created at the top-level directory of the repository by |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
856 |
default. If you want to control where the traces are saved you can use the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
857 |
@code{--cwd} option of Waf to specify this. We have not done so, thus we |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
858 |
need to change into the top level directory of our repo and take a look at |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
859 |
the ASCII trace file @code{myfirst.tr} in your favorite editor. |
3332 | 860 |
|
861 |
@subsubsection Parsing Ascii Traces |
|
862 |
@cindex parsing ascii traces |
|
863 |
There's a lot of information there in a pretty dense form, but the first thing |
|
864 |
to notice is that there are a number of distinct lines in this file. It may |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
865 |
be difficult to see this clearly unless you widen your window considerably. |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
866 |
|
3332 | 867 |
Each line in the file corresponds to a @emph{trace event}. In this case |
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
868 |
we are tracing events on the @emph{transmit queue} present in every |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
869 |
point-to-point net device in the simulation. The transmit queue is a queue |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
870 |
through which every packet destined for a point-to-point channel must pass. |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
871 |
Note that each line in the trace file begins with a lone character (has a |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
872 |
space after it). This character will have the following meaning: |
3332 | 873 |
|
3339
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
874 |
@cindex ascii trace enqueue operation |
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
875 |
@cindex ascii trace dequeue operation |
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
876 |
@cindex ascii trace drop operation |
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
877 |
@cindex ascii trace receive operation |
3332 | 878 |
@itemize @bullet |
879 |
@item @code{+}: An enqueue operation occurred on the device queue; |
|
880 |
@item @code{-}: A dequeue operation occurred on the device queue; |
|
881 |
@item @code{d}: A packet was dropped, typically because the queue was full; |
|
882 |
@item @code{r}: A packet was received by the net device. |
|
883 |
@end itemize |
|
884 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
885 |
Let's take a more detailed view of the first line in the trace file. I'll |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
886 |
break it down into sections (indented for clarity) with a two digit reference |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
887 |
number on the left side: |
3332 | 888 |
|
889 |
@verbatim |
|
890 |
00 + |
|
891 |
01 2 |
|
892 |
02 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue |
|
893 |
03 ns3::PppHeader ( |
|
894 |
04 Point-to-Point Protocol: IP (0x0021)) |
|
895 |
05 ns3::Ipv4Header ( |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
896 |
06 tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] |
3332 | 897 |
07 length: 1052 10.1.1.1 > 10.1.1.2) |
898 |
08 ns3::UdpHeader ( |
|
899 |
09 length: 1032 49153 > 9) |
|
900 |
10 Payload (size=1024) |
|
901 |
@end verbatim |
|
902 |
||
903 |
@cindex trace event |
|
904 |
@cindex simulation time |
|
905 |
The first line of this expanded trace event (reference number 00) is the |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
906 |
operation. We have a @code{+} character, so this corresponds to an |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
907 |
@emph{enqueue} operation on the transmit queue. The second line (reference 01) |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
908 |
is the simulation time expressed in seconds. You may recall that we asked the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
909 |
@code{UdpEchoClientApplication} to start sending packets at two seconds. Here |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
910 |
we see confirmation that this is, indeed, happening. |
3332 | 911 |
|
912 |
@cindex node number |
|
913 |
@cindex net device number |
|
914 |
@cindex smart pointer |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
915 |
The next line of the example trace (reference 02) tell us which trace source |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
916 |
originated this event (expressed in the tracing namespace). You can think |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
917 |
of the tracing namespace somewhat like you would a filesystem namespace. The |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
918 |
root of the namespace is the @code{NodeList}. This corresponds to a container |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
919 |
managed in the @command{ns-3} core code that contains all of the nodes that are |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
920 |
created in a script. Just as a filesystem may have directories under the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
921 |
root, we may have node numbers in the @code{NodeList}. The string |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
922 |
@code{/NodeList/0} therefore refers to the zeroth node in the @code{NodeList} |
4533 | 923 |
which we typically think of as ``node 0''. In each node there is a list of |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
924 |
devices that have been installed. This list appears next in the namespace. |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
925 |
You can see that this trace event comes from @code{DeviceList/0} which is the |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
926 |
zeroth device installed in the node. |
3332 | 927 |
|
928 |
The next string, @code{$ns3::PointToPointNetDevice} tells you what kind of |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
929 |
device is in the zeroth position of the device list for node zero. |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
930 |
Recall that the operation @code{+} found at reference 00 meant that an enqueue |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
931 |
operation happened on the transmit queue of the device. This is reflected in |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
932 |
the final segments of the ``trace path'' which are @code{TxQueue/Enqueue}. |
3332 | 933 |
|
934 |
The remaining lines in the trace should be fairly intuitive. References 03-04 |
|
4032
2b675a0b3b94
Fix misprints in tutorial (bug 453)
Tom Henderson <tomh@tomh.org>
parents:
3771
diff
changeset
|
935 |
indicate that the packet is encapsulated in the point-to-point protocol. |
3332 | 936 |
References 05-07 show that the packet has an IP version four header and has |
937 |
originated from IP address 10.1.1.1 and is destined for 10.1.1.2. References |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
938 |
08-09 show that this packet has a UDP header and, finally, reference 10 shows |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
939 |
that the payload is the expected 1024 bytes. |
3332 | 940 |
|
941 |
The next line in the trace file shows the same packet being dequeued from the |
|
942 |
transmit queue on the same node. |
|
943 |
||
944 |
The Third line in the trace file shows the packet being received by the net |
|
945 |
device on the node with the echo server. I have reproduced that event below. |
|
946 |
||
947 |
@verbatim |
|
948 |
00 r |
|
949 |
01 2.25732 |
|
4295
6f7c05fd0f9b
fix some tutorial nits
Craig Dowell <craigdo@ee.washington.edu>
parents:
4294
diff
changeset
|
950 |
02 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx |
4533 | 951 |
03 ns3::Ipv4Header ( |
952 |
04 tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] |
|
953 |
05 length: 1052 10.1.1.1 > 10.1.1.2) |
|
954 |
06 ns3::UdpHeader ( |
|
955 |
07 length: 1032 49153 > 9) |
|
956 |
08 Payload (size=1024) |
|
3332 | 957 |
@end verbatim |
958 |
||
959 |
Notice that the trace operation is now @code{r} and the simulation time has |
|
960 |
increased to 2.25732 seconds. If you have been following the tutorial steps |
|
961 |
closely this means that you have left the @code{DataRate} of the net devices |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
962 |
and the channel @code{Delay} set to their default values. This time should |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
963 |
be familiar as you have seen it before in a previous section. |
3332 | 964 |
|
965 |
The trace source namespace entry (reference 02) has changed to reflect that |
|
966 |
this event is coming from node 1 (@code{/NodeList/1}) and the packet reception |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
967 |
trace source (@code{/MacRx}). It should be quite easy for you to follow the |
3332 | 968 |
progress of the packet through the topology by looking at the rest of the |
969 |
traces in the file. |
|
970 |
||
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
971 |
@subsection PCAP Tracing |
3332 | 972 |
@cindex pcap |
973 |
@cindex Wireshark |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
974 |
The @command{ns-3} device helpers can also be used to create trace files in the |
3332 | 975 |
@code{.pcap} format. The acronym pcap (usually written in lower case) stands |
976 |
for @emph{p}acket @emph{cap}ture, and is actually an API that includes the |
|
977 |
definition of a @code{.pcap} file format. The most popular program that can |
|
978 |
read and display this format is Wireshark (formerly called Ethereal). |
|
979 |
However, there are many traffic trace analyzers that use this packet format. |
|
980 |
We encourage users to exploit the many tools available for analyzing pcap |
|
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
981 |
traces. In this tutorial, we concentrate on viewing pcap traces with tcpdump. |
3332 | 982 |
|
3339
ff29f4ba75ed
finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents:
3332
diff
changeset
|
983 |
@cindex pcap tracing |
3332 | 984 |
The code used to enable pcap tracing is a one-liner. |
985 |
||
986 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
987 |
PointToPointHelper::EnablePcapAll ("myfirst"); |
3332 | 988 |
@end verbatim |
989 |
||
990 |
Go ahead and insert this line of code after the ASCII tracing code we just |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
991 |
added to @code{scratch/myfirst.cc}. Notice that we only passed the string |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
992 |
``myfirst,'' and not ``myfirst.pcap'' or something similar. This is because the |
3348
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
993 |
parameter is a prefix, not a complete file name. The helper will actually |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
994 |
create a trace file for every point-to-point device in the simulation. The |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
995 |
file names will be built using the prefix, the node number, the device number |
fe47da29d783
cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3343
diff
changeset
|
996 |
and a ``.pcap'' suffix. |
3332 | 997 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
998 |
In our example script, we will eventually see files named ``myfirst-0-0.pcap'' |
4533 | 999 |
and ``myfirst-1-0.pcap'' which are the pcap traces for node 0-device 0 and |
4032
2b675a0b3b94
Fix misprints in tutorial (bug 453)
Tom Henderson <tomh@tomh.org>
parents:
3771
diff
changeset
|
1000 |
node 1-device 0, respectively. |
3332 | 1001 |
|
3355
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
1002 |
Once you have added the line of code to enable pcap tracing, you can run the |
ea06eff669b3
some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
3354
diff
changeset
|
1003 |
script in the usual way: |
3332 | 1004 |
|
1005 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1006 |
./waf --run scratch/myfirst |
3332 | 1007 |
@end verbatim |
1008 |
||
1009 |
If you look at the top level directory of your distribution, you should now |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1010 |
see three log files: @code{myfirst.tr} is the ASCII trace file we have |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1011 |
previously examined. @code{myfirst-0-0.pcap} and @code{myfirst-1-0.pcap} |
3332 | 1012 |
are the new pcap files we just generated. |
1013 |
||
1014 |
@subsubsection Reading output with tcpdump |
|
1015 |
@cindex tcpdump |
|
1016 |
The easiest thing to do at this point will be to use @code{tcpdump} to look |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1017 |
at the @code{pcap} files. |
3332 | 1018 |
|
1019 |
@verbatim |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1020 |
tcpdump -nn -tt -r myfirst-0-0.pcap |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1021 |
reading from file myfirst-0-0.pcap, link-type PPP (PPP) |
3332 | 1022 |
2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 |
1023 |
2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024 |
|
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1024 |
|
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1025 |
tcpdump -nn -tt -r myfirst-1-0.pcap |
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1026 |
reading from file myfirst-1-0.pcap, link-type PPP (PPP) |
3332 | 1027 |
2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 |
1028 |
2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024 |
|
1029 |
@end verbatim |
|
1030 |
||
4533 | 1031 |
You can see in the dump of @code{myfirst-0-0.pcap} (the client device) that the |
3332 | 1032 |
echo packet is sent at 2 seconds into the simulation. If you look at the |
4533 | 1033 |
second dump (@code{myfirst-1-0.pcap}) you can see that packet being received |
4293
11a2cda6a096
clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents:
4207
diff
changeset
|
1034 |
at 2.257324 seconds. You see the packet being echoed back at 2.257324 seconds |
3332 | 1035 |
in the second dump, and finally, you see the packet being received back at |
1036 |
the client in the first dump at 2.514648 seconds. |
|
1037 |
||
1038 |
@subsubsection Reading output with Wireshark |
|
1039 |
@cindex Wireshark |
|
1040 |
If you are unfamilar with Wireshark, there is a web site available from which |
|
1041 |
you can download programs and documentation: @uref{http://www.wireshark.org/}. |
|
1042 |
||
1043 |
Wireshark is a graphical user interface which can be used for displaying these |
|
1044 |
trace files. If you have Wireshark available, you can open each of the trace |
|
1045 |
files and display the contents as if you had captured the packets using a |
|
1046 |
@emph{packet sniffer}. |