View | Details | Raw Unified | Return to bug 1997
Collapse All | Expand All

(-)a/doc/tutorial/source/data-collection.rst (-25 / +25 lines)
 Lines 103-121    Link Here 
103
103
104
::
104
::
105
105
106
  +  std::string probeName;
106
  +  std::string probeType;
107
  +  std::string probeTrace;
107
  +  std::string tracePath;
108
  +  if (useV6 == false)
108
  +  if (useV6 == false)
109
  +    {
109
  +    {
110
     ...
110
     ...
111
  +      probeName = "ns3::Ipv4PacketProbe";
111
  +      probeType = "ns3::Ipv4PacketProbe";
112
  +      probeTrace = "/NodeList/*/$ns3::Ipv4L3Protocol/Tx";
112
  +      tracePath = "/NodeList/*/$ns3::Ipv4L3Protocol/Tx";
113
  +    }
113
  +    }
114
  +  else
114
  +  else
115
  +    {
115
  +    {
116
     ...
116
     ...
117
  +      probeName = "ns3::Ipv6PacketProbe";
117
  +      probeType = "ns3::Ipv6PacketProbe";
118
  +      probeTrace = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
118
  +      tracePath = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
119
  +    }
119
  +    }
120
   ...
120
   ...
121
  +   // Use GnuplotHelper to plot the packet byte count over time
121
  +   // Use GnuplotHelper to plot the packet byte count over time
 Lines 129-140    Link Here 
129
  +                             "Time (Seconds)",
129
  +                             "Time (Seconds)",
130
  +                             "Packet Byte Count");
130
  +                             "Packet Byte Count");
131
  + 
131
  + 
132
  +   // Specify the probe type, probe path (in configuration namespace), and
132
  +   // Specify the probe type, trace source path (in configuration namespace), and
133
  +   // probe output trace source ("OutputBytes") to plot.  The fourth argument
133
  +   // probe output trace source ("OutputBytes") to plot.  The fourth argument
134
  +   // specifies the name of the data series label on the plot.  The last
134
  +   // specifies the name of the data series label on the plot.  The last
135
  +   // argument formats the plot by specifying where the key should be placed.
135
  +   // argument formats the plot by specifying where the key should be placed.
136
  +   plotHelper.PlotProbe (probeName,
136
  +   plotHelper.PlotProbe (probeType,
137
  +                         probeTrace,
137
  +                         tracePath,
138
  +                         "OutputBytes",
138
  +                         "OutputBytes",
139
  +                         "Packet Byte Count",
139
  +                         "Packet Byte Count",
140
  +                         GnuplotAggregator::KEY_BELOW);
140
  +                         GnuplotAggregator::KEY_BELOW);
 Lines 151-158    Link Here 
151
  + 
151
  + 
152
  +   // Specify the probe type, probe path (in configuration namespace), and
152
  +   // Specify the probe type, probe path (in configuration namespace), and
153
  +   // probe output trace source ("OutputBytes") to write.
153
  +   // probe output trace source ("OutputBytes") to write.
154
  +   fileHelper.WriteProbe (probeName,
154
  +   fileHelper.WriteProbe (probeType,
155
  +                          probeTrace,
155
  +                          tracePath,
156
  +                          "OutputBytes");
156
  +                          "OutputBytes");
157
  + 
157
  + 
158
      Simulator::Stop (Seconds (20));
158
      Simulator::Stop (Seconds (20));
 Lines 161-167    Link Here 
161
  
161
  
162
162
163
The careful reader will have noticed, when testing the IPv6 command
163
The careful reader will have noticed, when testing the IPv6 command
164
line attribute, that ``seventh.cc`` had created a number of new output files:
164
line attribute above, that ``seventh.cc`` had created a number of new output files:
165
165
166
::
166
::
167
167
 Lines 257-282    Link Here 
257
257
258
::
258
::
259
259
260
  +  std::string probeName;
260
  +  std::string probeType;
261
  +  std::string probeTrace;
261
  +  std::string tracePath;
262
  +  probeName = "ns3::Ipv6PacketProbe";
262
  +  probeType = "ns3::Ipv6PacketProbe";
263
  +  probeTrace = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
263
  +  tracePath = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
264
264
265
We use them here:
265
We use them here:
266
266
267
::
267
::
268
   
268
   
269
  +  // Specify the probe type, probe path (in configuration namespace), and
269
  +  // Specify the probe type, trace source path (in configuration namespace), and
270
  +  // probe output trace source ("OutputBytes") to plot.  The fourth argument
270
  +  // probe output trace source ("OutputBytes") to plot.  The fourth argument
271
  +  // specifies the name of the data series label on the plot.  The last
271
  +  // specifies the name of the data series label on the plot.  The last
272
  +  // argument formats the plot by specifying where the key should be placed.
272
  +  // argument formats the plot by specifying where the key should be placed.
273
  +  plotHelper.PlotProbe (probeName,
273
  +  plotHelper.PlotProbe (probeType,
274
  +                        probeTrace,
274
  +                        tracePath,
275
  +                        "OutputBytes",
275
  +                        "OutputBytes",
276
  +                        "Packet Byte Count",
276
  +                        "Packet Byte Count",
277
  +                        GnuplotAggregator::KEY_BELOW);
277
  +                        GnuplotAggregator::KEY_BELOW);
278
278
279
The first two arguments are the name of the probe type and the probe trace.
279
The first two arguments are the name of the probe type and the trace source path.
280
These two are probably the hardest to determine when you try to use
280
These two are probably the hardest to determine when you try to use
281
this framework to plot other traces.  The probe trace here is the ``Tx``
281
this framework to plot other traces.  The probe trace here is the ``Tx``
282
trace source of class ``Ipv6L3Protocol``.  When we examine this class
282
trace source of class ``Ipv6L3Protocol``.  When we examine this class
 Lines 417-433    Link Here 
417
  +   // Set the labels for this formatted output file.
417
  +   // Set the labels for this formatted output file.
418
  +   fileHelper.Set2dFormat ("Time (Seconds) = %.3e\tPacket Byte Count = %.0f");
418
  +   fileHelper.Set2dFormat ("Time (Seconds) = %.3e\tPacket Byte Count = %.0f");
419
419
420
Finally, the probe of interest must be hooked.  Again, the probeName and
420
Finally, the trace source of interest must be hooked.  Again, the probeType and
421
probeTrace variables in this example are used, and the probe's output
421
tracePath variables in this example are used, and the probe's output
422
trace source "OutputBytes" is hooked:
422
trace source "OutputBytes" is hooked:
423
423
424
::
424
::
425
425
426
  + 
426
  + 
427
  +   // Specify the probe type, probe path (in configuration namespace), and
427
  +   // Specify the probe type, trace source path (in configuration namespace), and
428
  +   // probe output trace source ("OutputBytes") to write.
428
  +   // probe output trace source ("OutputBytes") to write.
429
  +   fileHelper.WriteProbe (probeName,
429
  +   fileHelper.WriteProbe (probeType,
430
  +                          probeTrace,
430
  +                          tracePath,
431
  +                          "OutputBytes");
431
  +                          "OutputBytes");
432
  + 
432
  + 
433
433
(-)a/examples/tutorial/seventh.cc (-12 / +12 lines)
 Lines 210-217    Link Here 
210
  uint16_t sinkPort = 8080;
210
  uint16_t sinkPort = 8080;
211
  Address sinkAddress;
211
  Address sinkAddress;
212
  Address anyAddress;
212
  Address anyAddress;
213
  std::string probeName;
213
  std::string probeType;
214
  std::string probeTrace;
214
  std::string tracePath;
215
  if (useV6 == false)
215
  if (useV6 == false)
216
    {
216
    {
217
      Ipv4AddressHelper address;
217
      Ipv4AddressHelper address;
 Lines 219-226    Link Here 
219
      Ipv4InterfaceContainer interfaces = address.Assign (devices);
219
      Ipv4InterfaceContainer interfaces = address.Assign (devices);
220
      sinkAddress = InetSocketAddress (interfaces.GetAddress (1), sinkPort);
220
      sinkAddress = InetSocketAddress (interfaces.GetAddress (1), sinkPort);
221
      anyAddress = InetSocketAddress (Ipv4Address::GetAny (), sinkPort);
221
      anyAddress = InetSocketAddress (Ipv4Address::GetAny (), sinkPort);
222
      probeName = "ns3::Ipv4PacketProbe";
222
      probeType = "ns3::Ipv4PacketProbe";
223
      probeTrace = "/NodeList/*/$ns3::Ipv4L3Protocol/Tx";
223
      tracePath = "/NodeList/*/$ns3::Ipv4L3Protocol/Tx";
224
    }
224
    }
225
  else
225
  else
226
    {
226
    {
 Lines 229-236    Link Here 
229
      Ipv6InterfaceContainer interfaces = address.Assign (devices);
229
      Ipv6InterfaceContainer interfaces = address.Assign (devices);
230
      sinkAddress = Inet6SocketAddress (interfaces.GetAddress (1,1), sinkPort);
230
      sinkAddress = Inet6SocketAddress (interfaces.GetAddress (1,1), sinkPort);
231
      anyAddress = Inet6SocketAddress (Ipv6Address::GetAny (), sinkPort);
231
      anyAddress = Inet6SocketAddress (Ipv6Address::GetAny (), sinkPort);
232
      probeName = "ns3::Ipv6PacketProbe";
232
      probeType = "ns3::Ipv6PacketProbe";
233
      probeTrace = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
233
      tracePath = "/NodeList/*/$ns3::Ipv6L3Protocol/Tx";
234
    }
234
    }
235
235
236
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", anyAddress);
236
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", anyAddress);
 Lines 265-276    Link Here 
265
                            "Time (Seconds)",
265
                            "Time (Seconds)",
266
                            "Packet Byte Count");
266
                            "Packet Byte Count");
267
267
268
  // Specify the probe type, probe path (in configuration namespace), and
268
  // Specify the probe type, trace source path (in configuration namespace), and
269
  // probe output trace source ("OutputBytes") to plot.  The fourth argument
269
  // probe output trace source ("OutputBytes") to plot.  The fourth argument
270
  // specifies the name of the data series label on the plot.  The last
270
  // specifies the name of the data series label on the plot.  The last
271
  // argument formats the plot by specifying where the key should be placed.
271
  // argument formats the plot by specifying where the key should be placed.
272
  plotHelper.PlotProbe (probeName,
272
  plotHelper.PlotProbe (probeType,
273
                        probeTrace,
273
                        tracePath,
274
                        "OutputBytes",
274
                        "OutputBytes",
275
                        "Packet Byte Count",
275
                        "Packet Byte Count",
276
                        GnuplotAggregator::KEY_BELOW);
276
                        GnuplotAggregator::KEY_BELOW);
 Lines 285-294    Link Here 
285
  // Set the labels for this formatted output file.
285
  // Set the labels for this formatted output file.
286
  fileHelper.Set2dFormat ("Time (Seconds) = %.3e\tPacket Byte Count = %.0f");
286
  fileHelper.Set2dFormat ("Time (Seconds) = %.3e\tPacket Byte Count = %.0f");
287
287
288
  // Specify the probe type, probe path (in configuration namespace), and
288
  // Specify the probe type, trace source path (in configuration namespace), and
289
  // probe output trace source ("OutputBytes") to write.
289
  // probe output trace source ("OutputBytes") to write.
290
  fileHelper.WriteProbe (probeName,
290
  fileHelper.WriteProbe (probeType,
291
                         probeTrace,
291
                         tracePath,
292
                         "OutputBytes");
292
                         "OutputBytes");
293
293
294
  Simulator::Stop (Seconds (20));
294
  Simulator::Stop (Seconds (20));
(-)a/src/stats/doc/data-collection-helpers.rst (-72 / +58 lines)
 Lines 75-81    Link Here 
75
                       const std::string &yLegend,
75
                       const std::string &yLegend,
76
                       const std::string &terminalType = ".png");
76
                       const std::string &terminalType = ".png");
77
77
78
The second statement hooks the ``Probe`` of interest:
78
The second statement hooks the trace source of interest:
79
79
80
::
80
::
81
81
 Lines 87-95    Link Here 
87
The arguments are as follows:
87
The arguments are as follows:
88
88
89
* typeId:  The |ns3| TypeId of the Probe
89
* typeId:  The |ns3| TypeId of the Probe
90
* path:  The path in the |ns3| configuration namespace to one or more probes
90
* path:  The path in the |ns3| configuration namespace to one or more trace sources 
91
* probeTraceSource:  Which output of the probe should be connected to
91
* probeTraceSource:  Which output of the probe (itself a trace source) should be plotted
92
* title:  The title to associate with the dataset (in the gnuplot legend)
92
* title:  The title to associate with the dataset(s) (in the gnuplot legend)
93
93
94
A variant on the PlotProbe above is to specify a fifth optional argument
94
A variant on the PlotProbe above is to specify a fifth optional argument
95
that controls where in the plot the key (legend) is placed.
95
that controls where in the plot the key (legend) is placed.
 Lines 102-121    Link Here 
102
   GnuplotHelper plotHelper;
102
   GnuplotHelper plotHelper;
103
 
103
 
104
   // Configure the plot.
104
   // Configure the plot.
105
   // Configure the plot.  The first argument is the file name prefix
106
   // for the output files generated.  The second, third, and fourth
107
   // arguments are, respectively, the plot title, x-axis, and y-axis labels
105
   plotHelper.ConfigurePlot ("seventh-packet-byte-count",
108
   plotHelper.ConfigurePlot ("seventh-packet-byte-count",
106
                             "Packet Byte Count vs. Time",
109
                             "Packet Byte Count vs. Time",
107
                             "Time (Seconds)",
110
                             "Time (Seconds)",
108
                             "Packet Byte Count",
111
                             "Packet Byte Count",
109
                             "png");
112
                             "png");
110
113
111
   // Plot the values generated by the probe.
114
   // Specify the probe type, trace source path (in configuration namespace), and
112
   plotHelper.PlotProbe ("ns3::Ipv4PacketProbe",
115
   // probe output trace source ("OutputBytes") to plot.  The fourth argument
113
                         "/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
116
   // specifies the name of the data series label on the plot.  The last
117
   // argument formats the plot by specifying where the key should be placed.
118
   plotHelper.PlotProbe (probeType,
119
                         tracePath,
114
                         "OutputBytes",
120
                         "OutputBytes",
115
                         "Packet Byte Count",
121
                         "Packet Byte Count",
116
                         GnuplotAggregator::KEY_BELOW);
122
                         GnuplotAggregator::KEY_BELOW);
117
123
118
Note that the path specified may contain wildcards.  In this case, multiple
124
In this example, the ``probeType`` and ``tracePath`` are as follows (for IPv4):
125
126
::
127
128
   probeType = "ns3::Ipv4PacketProbe";
129
   tracePath = "/NodeList/*/$ns3::Ipv4L3Protocol/Tx";
130
131
The probeType is a key parameter for this helper to work.  This TypeId
132
must be registered in the system, and the signature on the Probe's trace
133
sink must match that of the trace source it is being hooked to.  Probe
134
types are pre-defined for a number of data types corresponding to |ns3|
135
traced values, and for a few other trace source signatures such as the 
136
'Tx' trace source of ``ns3::Ipv4L3Protocol`` class.
137
138
Note that the trace source path specified may contain wildcards.  
139
In this case, multiple
119
datasets are plotted on one plot; one for each matched path.
140
datasets are plotted on one plot; one for each matched path.
120
141
121
The main output produced will be three files:
142
The main output produced will be three files:
 Lines 224-233    Link Here 
224
  | Argument         | Description                  |
245
  | Argument         | Description                  |
225
  +==================+==============================+
246
  +==================+==============================+
226
  | typeId           | The type ID for the probe    |
247
  | typeId           | The type ID for the probe    |
227
  |                  | used when it is created.     |
248
  |                  | created by this helper.      |
228
  +------------------+------------------------------+
249
  +------------------+------------------------------+
229
  | path             | Config path to access the    |
250
  | path             | Config path to access the    |
230
  |                  | probe.                       |
251
  |                  | trace source.                |
231
  +------------------+------------------------------+
252
  +------------------+------------------------------+
232
  | probeTraceSource | The probe trace source to    |
253
  | probeTraceSource | The probe trace source to    |
233
  |                  | access.                      |
254
  |                  | access.                      |
 Lines 242-248    Link Here 
242
  
263
  
243
The GnuplotHelper's ``PlotProbe()`` function 
264
The GnuplotHelper's ``PlotProbe()`` function 
244
plots a dataset generated by hooking the |ns3| trace source with a
265
plots a dataset generated by hooking the |ns3| trace source with a
245
probe, and then plotting the values from the probeTraceSource. 
266
probe created by the helper, and then plotting the values from the 
267
probeTraceSource. 
246
The dataset will have the provided title, and will consist of 
268
The dataset will have the provided title, and will consist of 
247
the 'newValue' at each timestamp.
269
the 'newValue' at each timestamp.
248
270
 Lines 256-262    Link Here 
256
possible as labels for the datasets that are plotted.
278
possible as labels for the datasets that are plotted.
257
279
258
An example of how to use this function can be seen in the 
280
An example of how to use this function can be seen in the 
259
``seventh.cc`` code described above where it was used as follows:
281
``seventh.cc`` code described above where it was used (with
282
variable substitution) as follows:
260
283
261
::
284
::
262
285
 Lines 273-283    Link Here 
273
~~~~~~~~~~~~~~~~~~~~~~
296
~~~~~~~~~~~~~~~~~~~~~~
274
297
275
A slightly simpler example than the ``seventh.cc`` example can be 
298
A slightly simpler example than the ``seventh.cc`` example can be 
276
found in ``src/stats/examples/gnuplot-helper-example.cc``.  It
299
found in ``src/stats/examples/gnuplot-helper-example.cc``.  The 
277
is more of a toy example than ``seventh.cc`` because it has 
300
following 2-D gnuplot was created using the example.
278
a made-up trace source created for demonstration purposes.
279
280
The following 2-D gnuplot was created using the example.
281
301
282
.. _gnuplot-helper-example:
302
.. _gnuplot-helper-example:
283
303
 Lines 286-292    Link Here 
286
  2-D Gnuplot Created by gnuplot-helper-example.cc Example.
306
  2-D Gnuplot Created by gnuplot-helper-example.cc Example.
287
307
288
In this example, there is an Emitter object that increments 
308
In this example, there is an Emitter object that increments 
289
its counter at various random times and then emits the counter's 
309
its counter according to a Poisson process and then emits the counter's 
290
value as a trace source.
310
value as a trace source.
291
311
292
::
312
::
 Lines 294-318    Link Here 
294
  Ptr<Emitter> emitter = CreateObject<Emitter> ();
314
  Ptr<Emitter> emitter = CreateObject<Emitter> ();
295
  Names::Add ("/Names/Emitter", emitter);
315
  Names::Add ("/Names/Emitter", emitter);
296
316
297
The following code is probing the Counter exported by the
298
emitter object.  This DoubleProbe is using a path in the
299
configuration namespace to make the connection.  Note that 
300
the emitter registered itself in the configuration namespace 
301
after it was created; otherwise, the ConnectByPath would not work.
302
303
::
304
305
  Ptr<DoubleProbe> probe = CreateObject<DoubleProbe> ();
306
  probe->SetName ("PathProbe");
307
  Names::Add ("/Names/Probe", probe);
308
309
  // Note, no return value is checked here.
310
  probe->ConnectByPath ("/Names/Emitter/Counter");
311
312
Note that because there are no wildcards in the path 
317
Note that because there are no wildcards in the path 
313
used below, only 1 datastream was drawn in the plot.  
318
used below, only 1 datastream was drawn in the plot.  
314
This single datastream in the plot is simply labeled 
319
This single datastream in the plot is simply labeled 
315
"Emitter Count", with no extra suffixes like you would 
320
"Emitter Count", with no extra suffixes like one would 
316
see if there were wildcards in the path.
321
see if there were wildcards in the path.
317
322
318
::
323
::
 Lines 329-336    Link Here 
329
334
330
  // Plot the values generated by the probe.  The path that we provide
335
  // Plot the values generated by the probe.  The path that we provide
331
  // helps to disambiguate the source of the trace.
336
  // helps to disambiguate the source of the trace.
332
  plotHelper.PlotProbe ("ns3::DoubleProbe",
337
  plotHelper.PlotProbe ("ns3::Uinteger32Probe",
333
                        "/Names/Probe/Output",
338
                        "/Names/Emitter/Counter",
334
                        "Output",
339
                        "Output",
335
                        "Emitter Count",
340
                        "Emitter Count",
336
                        GnuplotAggregator::KEY_INSIDE);
341
                        GnuplotAggregator::KEY_INSIDE);
 Lines 492-501    Link Here 
492
  | Argument         | Description                  |
497
  | Argument         | Description                  |
493
  +==================+==============================+
498
  +==================+==============================+
494
  | typeId           | The type ID for the probe    |
499
  | typeId           | The type ID for the probe    |
495
  |                  | used when it is created.     |
500
  |                  | to be created.               |
496
  +------------------+------------------------------+
501
  +------------------+------------------------------+
497
  | path             | Config path to access the    |
502
  | path             | Config path to access the    |
498
  |                  | probe.                       |
503
  |                  | trace source.                |
499
  +------------------+------------------------------+
504
  +------------------+------------------------------+
500
  | probeTraceSource | The probe trace source to    |
505
  | probeTraceSource | The probe trace source to    |
501
  |                  | access.                      |
506
  |                  | access.                      |
 Lines 503-509    Link Here 
503
  
508
  
504
The FileHelper's ``WriteProbe()`` function
509
The FileHelper's ``WriteProbe()`` function
505
creates output text files generated by hooking the ns-3 trace source
510
creates output text files generated by hooking the ns-3 trace source
506
with a probe, and then writing the values from the
511
with a probe created by the helper, and then writing the values from the
507
probeTraceSource. The output file names will have the text stored
512
probeTraceSource. The output file names will have the text stored
508
in the member variable  m_outputFileNameWithoutExtension plus ".txt", 
513
in the member variable  m_outputFileNameWithoutExtension plus ".txt", 
509
and will consist of the 'newValue' at each timestamp.
514
and will consist of the 'newValue' at each timestamp.
 Lines 537-545    Link Here 
537
542
538
A slightly simpler example than the ``seventh.cc`` example can be 
543
A slightly simpler example than the ``seventh.cc`` example can be 
539
found in ``src/stats/examples/file-helper-example.cc``.  
544
found in ``src/stats/examples/file-helper-example.cc``.  
540
This example only uses the FileHelper, not the FileHelper.  It 
545
This example only uses the FileHelper.
541
is also more of a toy example than ``seventh.cc`` because it has 
542
a made-up trace source created for demonstration purposes.
543
546
544
The following text file with 2 columns of formatted values named 
547
The following text file with 2 columns of formatted values named 
545
``file-helper-example.txt`` was created using the example.  
548
``file-helper-example.txt`` was created using the example.  
 Lines 547-567    Link Here 
547
550
548
.. sourcecode:: text
551
.. sourcecode:: text
549
552
550
  Time (Seconds) = 4.995e-01	Count = 1
553
  Time (Seconds) = 0.203  Count = 1
551
  Time (Seconds) = 1.463e+00	Count = 2
554
  Time (Seconds) = 0.702  Count = 2
552
  Time (Seconds) = 1.678e+00	Count = 3
555
  Time (Seconds) = 1.404  Count = 3
553
  Time (Seconds) = 3.972e+00	Count = 4
556
  Time (Seconds) = 2.368  Count = 4
554
  Time (Seconds) = 4.150e+00	Count = 5
557
  Time (Seconds) = 3.364  Count = 5
555
  Time (Seconds) = 8.066e+00	Count = 6
558
  Time (Seconds) = 3.579  Count = 6
556
  Time (Seconds) = 8.731e+00	Count = 7
559
  Time (Seconds) = 5.873  Count = 7
557
  Time (Seconds) = 9.807e+00	Count = 8
560
  Time (Seconds) = 6.410  Count = 8
558
  Time (Seconds) = 1.078e+01	Count = 9
561
  Time (Seconds) = 6.472  Count = 9
559
  Time (Seconds) = 1.083e+01	Count = 10
560
  
561
  ...
562
  ...
562
563
563
In this example, there is an Emitter object that increments 
564
In this example, there is an Emitter object that increments 
564
its counter at various random times and then emits the counter's 
565
its counter according to a Poisson process and then emits the counter's 
565
value as a trace source.
566
value as a trace source.
566
567
567
::
568
::
 Lines 569-589    Link Here 
569
  Ptr<Emitter> emitter = CreateObject<Emitter> ();
570
  Ptr<Emitter> emitter = CreateObject<Emitter> ();
570
  Names::Add ("/Names/Emitter", emitter);
571
  Names::Add ("/Names/Emitter", emitter);
571
572
572
The following code is probing the Counter exported by the
573
emitter object.  This DoubleProbe is using a path in the
574
configuration namespace to make the connection.  Note that 
575
the emitter registered itself in the configuration namespace 
576
after it was created; otherwise, the ConnectByPath would not work.
577
578
::
579
580
  Ptr<DoubleProbe> probe = CreateObject<DoubleProbe> ();
581
  probe->SetName ("PathProbe");
582
  Names::Add ("/Names/Probe", probe);
583
584
  // Note, no return value is checked here.
585
  probe->ConnectByPath ("/Names/Emitter/Counter");
586
587
Note that because there are no wildcards in the path 
573
Note that because there are no wildcards in the path 
588
used below, only 1 text file was created.  
574
used below, only 1 text file was created.  
589
This single text file is simply named 
575
This single text file is simply named 
 Lines 604-611    Link Here 
604
590
605
  // Write the values generated by the probe.  The path that we
591
  // Write the values generated by the probe.  The path that we
606
  // provide helps to disambiguate the source of the trace.
592
  // provide helps to disambiguate the source of the trace.
607
  fileHelper.WriteProbe ("ns3::DoubleProbe",
593
  fileHelper.WriteProbe ("ns3::Uinteger32Probe",
608
                         "/Names/Probe/Output",
594
                         "/Names/Emitter/Counter",
609
                         "Output");
595
                         "Output");
610
596
611
Scope and Limitations
597
Scope and Limitations
 Lines 623-629    Link Here 
623
- ApplicationPacketProbe
609
- ApplicationPacketProbe
624
- Ipv4PacketProbe
610
- Ipv4PacketProbe
625
611
626
These Probes, therefore, are the only ones available to be used 
612
These Probes, therefore, are the only TypeIds available to be used 
627
in ``PlotProbe()`` and ``WriteProbe()``.
613
in ``PlotProbe()`` and ``WriteProbe()``.
628
614
629
In the next few sections, we cover each of the fundamental object
615
In the next few sections, we cover each of the fundamental object
(-)a/src/stats/examples/file-helper-example.cc (-30 / +9 lines)
 Lines 34-43    Link Here 
34
34
35
NS_LOG_COMPONENT_DEFINE ("FileHelperExample");
35
NS_LOG_COMPONENT_DEFINE ("FileHelperExample");
36
36
37
/*
37
//
38
 * This is our test object, an object that increments counters at
38
// This is our test object, an object that increments a counter according
39
 * various times and emits one of them as a trace source.
39
// to a Poisson process, and exports the (integer-valued) count as a
40
 */
40
// trace source.
41
//
41
class Emitter : public Object
42
class Emitter : public Object
42
{
43
{
43
public:
44
public:
 Lines 45-54    Link Here 
45
  Emitter ();
46
  Emitter ();
46
private:
47
private:
47
  void DoInitialize (void);
48
  void DoInitialize (void);
48
  void Emit (void);
49
  void Count (void);
49
  void Count (void);
50
50
51
  TracedValue<double> m_counter;  // normally this would be integer type
51
  TracedValue<uint32_t> m_counter;
52
  Ptr<ExponentialRandomVariable> m_var;
52
  Ptr<ExponentialRandomVariable> m_var;
53
53
54
};
54
};
 Lines 79-97    Link Here 
79
Emitter::DoInitialize (void)
79
Emitter::DoInitialize (void)
80
{
80
{
81
  NS_LOG_FUNCTION (this);
81
  NS_LOG_FUNCTION (this);
82
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
83
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Count, this);
82
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Count, this);
84
}
83
}
85
84
86
void
85
void
87
Emitter::Emit (void)
88
{
89
  NS_LOG_FUNCTION (this);
90
  NS_LOG_DEBUG ("Emitting at " << Simulator::Now ().GetSeconds ());
91
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
92
}
93
94
void
95
Emitter::Count (void)
86
Emitter::Count (void)
96
{
87
{
97
  NS_LOG_FUNCTION (this);
88
  NS_LOG_FUNCTION (this);
 Lines 114-131    Link Here 
114
  Names::Add ("/Names/Emitter", emitter);
105
  Names::Add ("/Names/Emitter", emitter);
115
106
116
  //
107
  //
117
  // This Probe will be hooked to the Emitter's trace source object by
118
  // accessing it by path name in the Config database.
119
  //
120
121
  Ptr<DoubleProbe> probe = CreateObject<DoubleProbe> ();
122
  probe->SetName ("PathProbe");
123
  Names::Add ("/Names/Probe", probe);
124
125
  // Note, no return value is checked here.
126
  probe->ConnectByPath ("/Names/Emitter/Counter");
127
128
  //
129
  // This file helper will be used to put data values into a file.
108
  // This file helper will be used to put data values into a file.
130
  //
109
  //
131
110
 Lines 137-148    Link Here 
137
                            FileAggregator::FORMATTED);
116
                            FileAggregator::FORMATTED);
138
117
139
  // Set the labels for this formatted output file.
118
  // Set the labels for this formatted output file.
140
  fileHelper.Set2dFormat ("Time (Seconds) = %.3e\tCount = %.0f");
119
  fileHelper.Set2dFormat ("Time (Seconds) = %.3f\tCount = %.0f");
141
120
142
  // Write the values generated by the probe.  The path that we
121
  // Write the values generated by the probe.  The path that we
143
  // provide helps to disambiguate the source of the trace.
122
  // provide helps to disambiguate the source of the trace.
144
  fileHelper.WriteProbe ("ns3::DoubleProbe",
123
  fileHelper.WriteProbe ("ns3::Uinteger32Probe",
145
                         "/Names/Probe/Output",
124
                         "/Names/Emitter/Counter",
146
                         "Output");
125
                         "Output");
147
126
148
  // The Emitter object is not associated with an ns-3 node, so
127
  // The Emitter object is not associated with an ns-3 node, so
(-)a/src/stats/examples/gnuplot-helper-example.cc (-34 / +14 lines)
 Lines 34-43    Link Here 
34
34
35
NS_LOG_COMPONENT_DEFINE ("GnuplotHelperExample");
35
NS_LOG_COMPONENT_DEFINE ("GnuplotHelperExample");
36
36
37
/*
37
//
38
 * This is our test object, an object that increments counters at
38
// This is our test object, an object that increments a counter according
39
 * various times and emits one of them as a trace source.
39
// to a Poisson process, and exports the (integer-valued) count as a
40
 */
40
// trace source.
41
//
41
class Emitter : public Object
42
class Emitter : public Object
42
{
43
{
43
public:
44
public:
 Lines 45-56    Link Here 
45
  Emitter ();
46
  Emitter ();
46
private:
47
private:
47
  void DoInitialize (void);
48
  void DoInitialize (void);
48
  void Emit (void);
49
  void Count (void);
49
  void Count (void);
50
50
51
  TracedValue<double> m_counter;  // normally this would be integer type
51
  TracedValue<uint32_t> m_counter;
52
  Ptr<ExponentialRandomVariable> m_var;
52
  Ptr<ExponentialRandomVariable> m_var;
53
54
};
53
};
55
54
56
NS_OBJECT_ENSURE_REGISTERED (Emitter);
55
NS_OBJECT_ENSURE_REGISTERED (Emitter);
 Lines 79-97    Link Here 
79
Emitter::DoInitialize (void)
78
Emitter::DoInitialize (void)
80
{
79
{
81
  NS_LOG_FUNCTION (this);
80
  NS_LOG_FUNCTION (this);
82
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
83
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Count, this);
81
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Count, this);
84
}
82
}
85
83
86
void
84
void
87
Emitter::Emit (void)
88
{
89
  NS_LOG_FUNCTION (this);
90
  NS_LOG_DEBUG ("Emitting at " << Simulator::Now ().GetSeconds ());
91
  Simulator::Schedule (Seconds (m_var->GetValue ()), &Emitter::Emit, this);
92
}
93
94
void
95
Emitter::Count (void)
85
Emitter::Count (void)
96
{
86
{
97
  NS_LOG_FUNCTION (this);
87
  NS_LOG_FUNCTION (this);
 Lines 114-131    Link Here 
114
  Names::Add ("/Names/Emitter", emitter);
104
  Names::Add ("/Names/Emitter", emitter);
115
105
116
  //
106
  //
117
  // This Probe will be hooked to the Emitter's trace source object by
118
  // accessing it by path name in the Config database.
119
  //
120
121
  Ptr<DoubleProbe> probe = CreateObject<DoubleProbe> ();
122
  probe->SetName ("PathProbe");
123
  Names::Add ("/Names/Probe", probe);
124
125
  // Note, no return value is checked here.
126
  probe->ConnectByPath ("/Names/Emitter/Counter");
127
128
  //
129
  // This gnuplot helper will be used to produce output used to make
107
  // This gnuplot helper will be used to produce output used to make
130
  // gnuplot plots.
108
  // gnuplot plots.
131
  //
109
  //
 Lines 133-149    Link Here 
133
  // Create the gnuplot helper.
111
  // Create the gnuplot helper.
134
  GnuplotHelper plotHelper;
112
  GnuplotHelper plotHelper;
135
113
136
  // Configure the plot.
114
  // Configure the plot.  Arguments include file prefix, plot title,
115
  // x-label, y-label, and output file type
137
  plotHelper.ConfigurePlot ("gnuplot-helper-example",
116
  plotHelper.ConfigurePlot ("gnuplot-helper-example",
138
                            "Emitter Counts vs. Time",
117
                            "Emitter Count vs. Time",
139
                            "Time (Seconds)",
118
                            "Time (Seconds)",
140
                            "Emitter Count",
119
                            "Emitter Count",
141
                            "png");
120
                            "png");
142
121
143
  // Plot the values generated by the probe.  The path that we provide
122
  // Create a probe.  Because the trace source we are interested in is 
144
  // helps to disambiguate the source of the trace.
123
  // of type uint32_t, we specify the type of probe to use by the first
145
  plotHelper.PlotProbe ("ns3::DoubleProbe",
124
  // argument specifying its ns3 TypeId.
146
                        "/Names/Probe/Output",
125
  plotHelper.PlotProbe ("ns3::Uinteger32Probe",
126
                        "/Names/Emitter/Counter",
147
                        "Output",
127
                        "Output",
148
                        "Emitter Count",
128
                        "Emitter Count",
149
                        GnuplotAggregator::KEY_INSIDE);
129
                        GnuplotAggregator::KEY_INSIDE);
(-)a/src/stats/helper/file-helper.h (-12 / +17 lines)
 Lines 75-81    Link Here 
75
75
76
  /**
76
  /**
77
   * \param typeId the type ID for the probe used when it is created.
77
   * \param typeId the type ID for the probe used when it is created.
78
   * \param path Config path to access the probe.
78
   * \param path Config path for underlying trace source to be probed
79
   * \param probeTraceSource the probe trace source to access.
79
   * \param probeTraceSource the probe trace source to access.
80
   *
80
   *
81
   * Creates output files generated by hooking the ns-3 trace source
81
   * Creates output files generated by hooking the ns-3 trace source
 Lines 84-89    Link Here 
84
   * in m_outputFileNameWithoutExtension plus ".txt", and will consist
84
   * in m_outputFileNameWithoutExtension plus ".txt", and will consist
85
   * of the 'newValue' at each timestamp.
85
   * of the 'newValue' at each timestamp.
86
   *
86
   *
87
   * This method will create one or more probes according to the TypeId 
88
   * provided, connect the probe(s) to the trace source specified by
89
   * the config path, and hook the probeTraceSource(s) to the downstream 
90
   * aggregator.
91
   *
87
   * If the config path has more than one match in the system
92
   * If the config path has more than one match in the system
88
   * (e.g. there is a wildcard), then one output file for each match
93
   * (e.g. there is a wildcard), then one output file for each match
89
   * will be created.  The output file names will contain the text in
94
   * will be created.  The output file names will contain the text in
 Lines 103-119    Link Here 
103
                   const std::string &probeTraceSource);
108
                   const std::string &probeTraceSource);
104
109
105
  /**
110
  /**
106
   * \param typeId the type ID for the probe used when it is created.
107
   * \param probeName the probe's name.
108
   * \param path Config path to access the probe
109
   *
110
   * \brief Adds a probe to be used to write values to files.
111
   */
112
  void AddProbe (const std::string &typeId,
113
                 const std::string &probeName,
114
                 const std::string &path);
115
116
  /**
117
   * \param adaptorName the timeSeriesAdaptor's name.
111
   * \param adaptorName the timeSeriesAdaptor's name.
118
   *
112
   *
119
   * \brief Adds a time series adaptor to be used to write the file.
113
   * \brief Adds a time series adaptor to be used to write the file.
 Lines 254-259    Link Here 
254
private:
248
private:
255
  /**
249
  /**
256
   * \param typeId the type ID for the probe used when it is created.
250
   * \param typeId the type ID for the probe used when it is created.
251
   * \param probeName the probe's name.
252
   * \param path Config path to access the probe
253
   *
254
   * \brief Adds a probe to be used to write values to files.
255
   */
256
  void AddProbe (const std::string &typeId,
257
                 const std::string &probeName,
258
                 const std::string &path);
259
260
  /**
261
   * \param typeId the type ID for the probe used when it is created.
257
   * \param matchIdentifier this string is used to make the probe's
262
   * \param matchIdentifier this string is used to make the probe's
258
   * context be unique.
263
   * context be unique.
259
   * \param path Config path to access the probe.
264
   * \param path Config path to access the probe.
(-)a/src/stats/helper/gnuplot-helper.cc (-4 / +7 lines)
 Lines 113-120    Link Here 
113
  // Get a pointer to the aggregator.
113
  // Get a pointer to the aggregator.
114
  Ptr<GnuplotAggregator> aggregator = GetAggregator ();
114
  Ptr<GnuplotAggregator> aggregator = GetAggregator ();
115
115
116
  // Add a subtitle to the title to show the probe's path.
116
  // Add a subtitle to the title to show the trace source's path.
117
  aggregator->SetTitle ( m_title + " \\n\\nProbe Path: " + path);
117
  aggregator->SetTitle ( m_title + " \\n\\nTrace Source Path: " + path);
118
118
119
  // Set the default dataset plotting style for the values.
119
  // Set the default dataset plotting style for the values.
120
  aggregator->Set2dDatasetDefaultStyle (Gnuplot2dDataset::LINES_POINTS);
120
  aggregator->Set2dDatasetDefaultStyle (Gnuplot2dDataset::LINES_POINTS);
 Lines 128-134    Link Here 
128
  // See if the path has any wildcards.
128
  // See if the path has any wildcards.
129
  bool pathHasNoWildcards = path.find ("*") == std::string::npos;
129
  bool pathHasNoWildcards = path.find ("*") == std::string::npos;
130
130
131
  // Remove the last token from the path.
131
  // Remove the last token from the path; this should correspond to the 
132
  // trace source attribute.
132
  size_t lastSlash = path.find_last_of ("/");
133
  size_t lastSlash = path.find_last_of ("/");
133
  if (lastSlash == std::string::npos)
134
  if (lastSlash == std::string::npos)
134
    {
135
    {
 Lines 145-153    Link Here 
145
    }
146
    }
146
147
147
  // See if there are any matches for the probe's path with the last
148
  // See if there are any matches for the probe's path with the last
148
  // token removed.
149
  // token removed; this corresponds to the traced object itself.
150
  NS_LOG_DEBUG ("Searching config database for trace source " << path);
149
  Config::MatchContainer matches = Config::LookupMatches (pathWithoutLastToken);
151
  Config::MatchContainer matches = Config::LookupMatches (pathWithoutLastToken);
150
  uint32_t matchCount = matches.GetN ();
152
  uint32_t matchCount = matches.GetN ();
153
  NS_LOG_DEBUG ("Found " << matchCount << " matches for trace source " << path);
151
154
152
  // This is used to make the probe's context be unique.
155
  // This is used to make the probe's context be unique.
153
  std::string matchIdentifier;
156
  std::string matchIdentifier;
(-)a/src/stats/helper/gnuplot-helper.h (-12 / +18 lines)
 Lines 95-101    Link Here 
95
95
96
  /**
96
  /**
97
   * \param typeId the type ID for the probe used when it is created.
97
   * \param typeId the type ID for the probe used when it is created.
98
   * \param path Config path to access the probe.
98
   * \param path Config path for underlying trace source to be probed
99
   * \param probeTraceSource the probe trace source to access.
99
   * \param probeTraceSource the probe trace source to access.
100
   * \param title the title to be associated to this dataset
100
   * \param title the title to be associated to this dataset
101
   * \param keyLocation the location of the key in the plot.
101
   * \param keyLocation the location of the key in the plot.
 Lines 105-110    Link Here 
105
   * will have the provided title, and will consist of the 'newValue'
105
   * will have the provided title, and will consist of the 'newValue'
106
   * at each timestamp.
106
   * at each timestamp.
107
   *
107
   *
108
   * This method will create one or more probes according to the TypeId 
109
   * provided, connect the probe(s) to the trace source specified by
110
   * the config path, and hook the probeTraceSource(s) to the downstream 
111
   * aggregator.
112
   *
108
   * If the config path has more than one match in the system
113
   * If the config path has more than one match in the system
109
   * (e.g. there is a wildcard), then one dataset for each match will
114
   * (e.g. there is a wildcard), then one dataset for each match will
110
   * be plotted.  The dataset titles will be suffixed with the matched
115
   * be plotted.  The dataset titles will be suffixed with the matched
 Lines 121-137    Link Here 
121
                  enum GnuplotAggregator::KeyLocation keyLocation = GnuplotAggregator::KEY_INSIDE);
126
                  enum GnuplotAggregator::KeyLocation keyLocation = GnuplotAggregator::KEY_INSIDE);
122
127
123
  /**
128
  /**
124
   * \param typeId the type ID for the probe used when it is created.
125
   * \param probeName the probe's name.
126
   * \param path Config path to access the probe.
127
   *
128
   * \brief Adds a probe to be used to make the plot.
129
   */
130
  void AddProbe (const std::string &typeId,
131
                 const std::string &probeName,
132
                 const std::string &path);
133
134
  /**
135
   * \param adaptorName the timeSeriesAdaptor's name.
129
   * \param adaptorName the timeSeriesAdaptor's name.
136
   *
130
   *
137
   * \brief Adds a time series adaptor to be used to make the plot.
131
   * \brief Adds a time series adaptor to be used to make the plot.
 Lines 155-160    Link Here 
155
  Ptr<GnuplotAggregator> GetAggregator ();
149
  Ptr<GnuplotAggregator> GetAggregator ();
156
150
157
private:
151
private:
152
153
  /**
154
   * \param typeId the type ID for the probe used when it is created.
155
   * \param probeName the probe's name.
156
   * \param path Config path to access the probe.
157
   *
158
   * \brief Adds a probe to be used to make the plot.
159
   */
160
  void AddProbe (const std::string &typeId,
161
                 const std::string &probeName,
162
                 const std::string &path);
163
158
  /**
164
  /**
159
   * \brief Constructs the aggregator.
165
   * \brief Constructs the aggregator.
160
   */
166
   */
(-)a/src/stats/model/double-probe.cc (-2 / +2 lines)
 Lines 84-90    Link Here 
84
DoubleProbe::ConnectByObject (std::string traceSource, Ptr<Object> obj)
84
DoubleProbe::ConnectByObject (std::string traceSource, Ptr<Object> obj)
85
{
85
{
86
  NS_LOG_FUNCTION (this << traceSource << obj);
86
  NS_LOG_FUNCTION (this << traceSource << obj);
87
  NS_LOG_DEBUG ("Name of probe (if any) in names database: " << Names::FindPath (obj));
87
  NS_LOG_DEBUG ("Name of trace source (if any) in names database: " << Names::FindPath (obj));
88
  bool connected = obj->TraceConnectWithoutContext (traceSource, MakeCallback (&ns3::DoubleProbe::TraceSink, this));
88
  bool connected = obj->TraceConnectWithoutContext (traceSource, MakeCallback (&ns3::DoubleProbe::TraceSink, this));
89
  return connected;
89
  return connected;
90
}
90
}
 Lines 93-99    Link Here 
93
DoubleProbe::ConnectByPath (std::string path)
93
DoubleProbe::ConnectByPath (std::string path)
94
{
94
{
95
  NS_LOG_FUNCTION (this << path);
95
  NS_LOG_FUNCTION (this << path);
96
  NS_LOG_DEBUG ("Name of probe to search for in config database: " << path);
96
  NS_LOG_DEBUG ("Name of trace source to search for in config database: " << path);
97
  Config::ConnectWithoutContext (path, MakeCallback (&ns3::DoubleProbe::TraceSink, this));
97
  Config::ConnectWithoutContext (path, MakeCallback (&ns3::DoubleProbe::TraceSink, this));
98
}
98
}
99
99

Return to bug 1997