doc/tracing.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 06 Nov 2007 15:05:56 +0100
changeset 2081 434742b27b1e
parent 1416 2daa908b1b33
child 1807 46f2df7d4eae
permissions -rw-r--r--
use the new style support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1398
607b6e86e143 reference the proper trace source list group
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1392
diff changeset
     1
/**
607b6e86e143 reference the proper trace source list group
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1392
diff changeset
     2
 * \defgroup TraceSourceList List of trace sources
607b6e86e143 reference the proper trace source list group
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1392
diff changeset
     3
 */
607b6e86e143 reference the proper trace source list group
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1392
diff changeset
     4
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
/**
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * \defgroup tracing Tracing
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 *
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * The flexibility of the ns-3 tracing system comes at the cost of quite
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * a bit of complexity so, before trying to use the low-level aspects
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * of the tracing API, it is important to focus on some basic definitions:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 *
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * - A trace source is an object instance which can report trace events
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *   to a set of listening trace sinks.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * - A trace sink is a user-provided callback (a function) which can
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 *   be connected to a set of trace sources to receive the events generated
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *   by each trace source.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * - A trace resolver is an object which allows users to establish 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 *   connections between a set of trace sources and a set of trace sinks.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    22
 * \section TraceSource Generating Trace Events
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    23
 *
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
 * So, what does it look like in practice ? First, let's look at trace
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
 * sources. We have two types of trace sources: numeric, and, normal 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
 * trace sources. Numeric trace sources behave as normal c++ integers 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
 * or c++ floating point numbers except that they report as trace events 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
 * each change of their value. For example:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
 * \code
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
 * class MyModel 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
 * public:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
 *   void DoSomething (void) 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
 *   {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
 *     // use the "int" trace source just 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
 *     // like any other "int" variable.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
 *     m_cwnd *= 2;
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
 *     m_cwnd += 4;
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
 *     if (m_cwnd > 100)
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
 *       {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
 *         // do something.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
 *       }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
 *   }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
 * private:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
 *   // declare an instance of a "int" trace source
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
 *   SVTraceSource<int> m_cwnd;
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
 * };
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
 * \endcode
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
 * Normal trace sources, on the other hand, allow you to trace the
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
 * call of arbitrary functions and methods, as shown below. They are
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
 * typically used to track "rx", "tx", or "drop" events but could
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
 * also be used to track route change events, or position change
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
 * events:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
 * \code
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
 * class MyModel 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
 * public:
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    58
 *   void DoSomething (Packet packet) 
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
 *   {
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    60
 *     // report this event on packet
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    61
 *     m_doSomething (packet);
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
 *     // do something
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
 *   }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
 * private:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
 *   // report every "something" function call.
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    66
 *   CallbackTraceSource<Packet> m_doSomething;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
 * };
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
 * \endcode
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
 * Every type of trace source derives from the ns3::TraceSource base class.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
 * As of today, the set of concrete subclasses is relatively short:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
 * ns3::CallbackTraceSource, ns3::SvTraceSource, ns3::UvTraceSource, and,
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
 * ns3::FvTraceSource.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    74
 * \section TraceSink Receiving Trace Events
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    75
 *
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
 * To receive these trace events, a user should specify a set of trace sinks.
1392
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    77
 * For example, to receive the "int" and the "something" events shown in the
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    78
 * examples above, a user would declare the following functions:
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
 * \code
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
 * // oldValue and newValue contain the previous and new values of 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
 * // the connected SVTraceSource<int> trace source.
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
 * void 
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
 * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue)
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
 *   // for example, print the new value:
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
 *   std::cout << "cwnd=" << newValue << std::endl;
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
 * }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
 * void 
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    89
 * DoSomethingTraceSink (const TraceContext &context, Packet packet)
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
 *   // for example, print the arguments
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
    92
 *   std::cout << "packet " << packet << std::endl;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
 * }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
 * \endcode
1392
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    95
 * Each of these sink function takes, as a first argument, a reference to a 
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    96
 * const TraceContext object. This context object contains information which
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    97
 * describes the instance of the connected trace source: that information is
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    98
 * setup during the connection process and does not change afterwards
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
    99
 * The type and the number of the other arguments to each trace sink depends
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
   100
 * on the type of the connected trace source: it conveys per-event information
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
   101
 * from the trace source to the trace sink. For example, UVTraceSource and 
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
   102
 * SVTraceSource trace sources require two extra arguments. The former requires
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
   103
 * two unsigned 64 bit integers while the latter requires two signed 64 bit 
1398
607b6e86e143 reference the proper trace source list group
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1392
diff changeset
   104
 * integers. More generally, users can consult the \ref TraceSourceList
1392
c73109c96c85 add some text on trace sink signatures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1391
diff changeset
   105
 * to figure out the arguments which a trace sink is required to receive
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   106
 * for each trace source: a signature of the user trace sink must match 
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   107
 * _exactly_ the signature documented in the \ref TraceSourceList.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   108
 *
1415
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   109
 *
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   110
 * \section TraceSourceSimpleExport A simple way to connect Trace Sources with Trace Sinks
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
 *
1415
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   112
 * The crux of the complexity of the ns-3 tracing system comes from its 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   113
 * flexible system used to connect trace sources to trace sinks but what is really
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   114
 * nice about it is that it is not necessary to use it to setup simple traces.
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   115
 * 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   116
 * The simplest way to export a set of trace sources to a user, for example, 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   117
 * during the early prototyping phases of a system, is to add a set of public methods
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   118
 * to give to your users access to the trace source object instances you use to generate
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   119
 * trace events:
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   120
 * \code
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   121
 * class MyModel 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   122
 * {
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   123
 * public:
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   124
 *   void DoSomething (Packet packet) 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   125
 *   {
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   126
 *     // report this event on packet
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   127
 *     m_doSomething (packet);
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   128
 *     // do something
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   129
 *   }
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   130
 *   CallbackTraceSource<Packet> *PeekSomethingTraceSource (void) const 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   131
 *   {
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   132
 *     return &m_doSomething
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   133
 *   }
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   134
 * private:
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   135
 *   // report every "something" function call.
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   136
 *   CallbackTraceSource<Packet> m_doSomething;
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   137
 * };
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   138
 * \endcode
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   139
 * If your users hold a pointer to an instance of MyModel, and if they want to connect
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   140
 * a MySomethingSink, they can simply do the following which invokes the 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   141
 * TraceSource::AddCallback method and creates a Callback object from the user's
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   142
 * sink with the MakeCallback function.
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   143
 * \code
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   144
 * void 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   145
 * MySomethingSink (const TraceContext &context, Packet packet)
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   146
 * {
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   147
 *   // do whatever you want.
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   148
 * }
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   149
 * MyModel *model = ...;
1416
2daa908b1b33 fix a small typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1415
diff changeset
   150
 * CallbackTraceSource<Packet> *source = model->PeekSomethingTraceSource ();
2daa908b1b33 fix a small typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1415
diff changeset
   151
 * source->AddCallback (MakeCallback (&MySomethingSink));
1415
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   152
 * \endcode
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   153
 *
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   154
 * The full power of the tracing system comes however from its ns3::NodeList::Connect
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   155
 * method which is described in the following sections.
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   156
 *
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   157
 * \section TraceConnection Connecting Trace Sources to Trace Sinks
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   158
 * 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   159
 * If a trace source is integrated in the ns-3 trace connection facility, a user 
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   160
 * should call the ns3::NodeList::Connect method to establish a connection between
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   161
 * a trace sink and a set of matching trace sources. The second argument to that
ac1df67308e6 add missing section on simple trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1413
diff changeset
   162
 * method is a callback to the user's trace sink.
1407
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   163
 * That callback is easy to construct: call ns3::MakeCallback and you are done. The
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   164
 * first argument is a string whose format is similar to a unix path and which is 
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   165
 * used to uniquely identify the set of trace sources you want to connect to.
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   166
 * The set of acceptable path strings is also documented in the \ref TraceSourceList.
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   167
 *
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   168
 * So, what does this look like from the perspective of a user ? If we wanted to 
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   169
 * connect to a trace source defined somewhere deep into the a set of NetDevice objects
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   170
 * located in some nodes of the system, we could write the following:
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   171
 * \code
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   172
 * void 
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   173
 * DoSomethingTraceSink (const TraceContext &context, Packet packet)
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   174
 * {
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   175
 *   // for example, print the arguments
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   176
 *   std::cout << "packet: " << packet << std::endl;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   177
 * }
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   178
 * // connect the above sink to a matching trace source
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   179
 * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback &DoSomethingTraceSink);
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   180
 * \endcode
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   181
 *
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   182
 * The connection path string "/nodes/* /devices/* /rx" matches the "rx" trace source
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   183
 * located in every netdevice located in every node. The syntax of that path string
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   184
 * is loosely based on regular expressions so, a user could conceivably connect
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   185
 * to the trace sources present in only one node identified by node index:
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   186
 * "/nodex/3/devices/* /rx".
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   187
 *
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   188
 * The matching algorithm used here is very useful since it allows you to connect
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   189
 * at once a large set of trace sources to a single sink but it introduces another 
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   190
 * problem: it becomes impossible when you receive an event in your trace sink to
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   191
 * know from _which_ trace source the event is coming from. In our example, the
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   192
 * trace source might be coming from the NetDevice number 2 of Node 10 or Netdevice
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   193
 * number 0 of Node 5. In both cases, you might need to know which of these NetDevice
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   194
 * is generating this event, if only to generate some ascii trace dump. Another 
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   195
 * similar use-case is that you might have connected the same trace sink to
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   196
 * multiple types of events which have the same signature: it is quite common
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   197
 * to receive all tx, rx, and drop events in the same trace sink and that would be
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   198
 * quite trivial to achieve with a string such as: "/nodes/* /devices/* /*"
1407
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   199
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   200
 * The source of a trace event can be retrieved from a trace sink using 
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   201
 * different means: the simplest
1407
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   202
 * way to get this information is to use the builtin printing facility of
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   203
 * the TraceContext object:
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   204
 * \code
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   205
 * void 
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   206
 * DoSomethingTraceSink (const TraceContext &context, Packet packet)
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   207
 * {
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   208
 *   // for example, print the arguments
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   209
 *   std::cout << "context=\"" << context << "\" packet: " << packet << std::endl;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   210
 * }
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   211
 * \endcode
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   212
 * The above code is going to generate output which looks like the following:
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   213
 * \code
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   214
 * context="nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ...
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   215
 * context="nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ...
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   216
 * ...
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   217
 * \endcode
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   218
 *
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   219
 * Another more advanced way to get information out of a TraceContext is to call its
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   220
 * ns3::TraceContext::GetElement method. This method takes as its first and only
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   221
 * argument an instance of the object we want to read and the list of available
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   222
 * object instances we can read from a TraceContext is documented, once again,
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   223
 * in the \ref TraceSourceList. For example, we could write the following to
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   224
 * generate adhoc trace output:
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   225
 * \code
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   226
 * void DeviceRxSink (const TraceContext &context, const Packet &packet)
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   227
 * {
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   228
 *   NodeListIndex nodeIndex;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   229
 *   NodeNetDeviceIndex deviceIndex;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   230
 *   context.GetElement (nodeIndex);
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   231
 *   context.GetElement (deviceIndex);
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   232
 *   std::cout << "node-index=" << nodeIndex.Get ();
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   233
 *   std::cout << ", device-index=" << deviceIndex.Get ();
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   234
 *   std::cout << ", packet: " << packet;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   235
 *   std::cout << std::endl;
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   236
 * }
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   237
 * \endcode
853d1696aece add section on TraceContexts in tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1398
diff changeset
   238
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   239
 * \section ExportingTraceSources Exporting new Trace Sources
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   240
 *
1408
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   241
 * Using existing trace sources to connect them to a set of adhoc trace sinks
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   242
 * is not really complicated but, setting up new trace sources which can hook
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   243
 * in this automatic connection system is a bit more complicated.
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   244
 *
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   245
 * So far, we know that a model author can generate trace events really easily:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   246
 * \code
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   247
 * class MyModel 
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   248
 * {
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   249
 * public:
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   250
 *   void DoSomething (Packet packet) 
1408
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   251
 *   {
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   252
 *     // report this event on packet with value
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   253
 *     m_doSomething (packet);
1408
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   254
 *     // do something
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   255
 *   }
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   256
 * private:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   257
 *   // report every "something" function call.
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   258
 *   CallbackTraceSource<Packet> m_doSomething;
1408
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   259
 * };
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   260
 * \endcode
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   261
 *
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   262
 * To make these new trace sources available to the rest of the connection system,
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   263
 * the first step is to make sure that your model object derives from the ns3::Object
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   264
 * base class either directly (as shown below) or indirectly through another base class:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   265
 * \code
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   266
 * class MyModel : public Object {...};
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   267
 * // or:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   268
 * class SomeOtherObject : public Object {...};
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   269
 * class MyModel : public SomeOtherObject {...};
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   270
 * \endcode
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   271
 *
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   272
 * This is pretty trivial and lays the ground for the second step: overriding the
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   273
 * ns3::Object::GetTraceResolver method:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   274
 * \code
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   275
 * class MyModel : public MyParent
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   276
 * {
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   277
 * public:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   278
 *   // declare overriden method
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   279
 *   virtual Ptr<TraceResolver> GetTraceResolver (void) const;
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   280
 * private:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   281
 *   // the new trace source to export.
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   282
 *   CallbackTraceSource<Packet> m_rxSource;
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   283
 * };
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   284
 * \endcode
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   285
 *
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   286
 * To implement this method, you could attempt to implement a new subclass of
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   287
 * the ns3::TraceResolver base class and return an instance from this method but
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   288
 * this would be very hard. Instead, you should use the helper class
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   289
 * ns3::CompositeTraceResolver to register your trace sources and chain up to
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   290
 * your parent:
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   291
 * \code
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   292
 * Ptr<TraceResolver>
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   293
 * MyModel::GetTraceResolver (void) const
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   294
 * {
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   295
 *   // create an empty trace resolver
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   296
 *   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   297
 *   // register m_rxSource
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   298
 *   resolver->AddSource ("rx", // the name of the trace source in the path string
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   299
 *                        TraceDoc ("some help text to explain the purpose of this trace source",
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   300
 *                                  "Packet", // the type of the first argument to the trace source
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   301
 *                                  "the purpose of the first argument",
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   302
 *                                  "type-of-second-argument", "purpose-of-second-argument"),
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   303
 *                        m_rxSource // the trace source itself is registered
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   304
 *                       );
1408
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   305
 *   // make sure we include the trace sources implemented in the parent.
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   306
 *   resolver->SetParentResolver (MyParent::GetTraceResolver ());
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   307
 *   return resolver;
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   308
 * }
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   309
 * \endcode
3ddff4d9b27c start section on registering new TraceSource objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1407
diff changeset
   310
 *
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   311
 * Once you have written that code, you must make sure that this new method GetTraceResolver
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   312
 * is going to be called at some point by the tracing system. If your model is located somewhere
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   313
 * deep in MAC or PHY layer, that is, it is part of a NetDevice implementation, all you
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   314
 * have to do is to make sure that your model is registered as a "composite" of your NetDevice
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   315
 * subclass:
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
 * \code
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   317
 * class MyNetDevice : public NetDevice
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
 * public:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   320
 *   Ptr<TraceResolver> GetTraceResolver (void) const;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   321
 * private:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   322
 *   Ptr<MyModel> m_model;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   323
 * };
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   324
 * 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   325
 * Ptr<TraceResolver>
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   326
 * MyNetDevice::GetTraceResolver (void) const
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   327
 * {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   328
 *   Ptr<CompositeTraceResolver> resolver = ...;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   329
 *   // register other trace source
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   330
 *   ...
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   331
 *   // register now your model as a "composite"
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   332
 *   resolver->AddComposite ("my-model", m_model);
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   333
 *   // chain up to parent.
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   334
 *   resolver->SetParentResolver (NetDevice::GetTraceResolver ());
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   335
 *   return resolver;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   336
 * }
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   337
 * \endcode
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   338
 * 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   339
 * The code above will make your "rx" trace source appear under the
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   340
 * /nodes/xx/devices/xx/my-model/rx namespace path.
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   341
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   342
 * If you have implemented a new layer 3 or 4 protocol object, the process to
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   343
 * export your trace sources is quite similar. You need to subclass from
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   344
 * ns3::Object, override the ns3::Object::GetTraceResolver method, make
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   345
 * sure you chain up to your parent's GetTraceResolver method, and, finally,
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   346
 * make sure that someone calls your new GetTraceResolver method. How to accomplish
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   347
 * the latter should be documented in the node's API documentation which describes
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   348
 * how to implement a new layer 3 or 4 protocol object.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   349
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   350
 * \section AdvancedTraceContext Creating new Trace Context Elements
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   351
 *
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   352
 * The last important feature which model developers need to understand
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   353
 * is how to provide extra context information to trace sinks. For example,
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   354
 * if your model exports both rx and tx trace sources which share the same 
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   355
 * signature, it is quite natural for a user to connect to a single trace sink
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   356
 * to both of them with a trace path string such as "/nodes/* /devices/* /(rx|tx)".
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   357
 * In this case, it becomes necessary to be able, from the trace sink function,
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   358
 * to tell which event triggered the call to the trace sink: a rx or a tx event.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   359
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   360
 * That example is detailed below with a TX, a RX, and a DROP source:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   361
 * \code
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   362
 * class MyModel
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   363
 * {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   364
 * private:
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   365
 *   CallbackTraceSource<Packet> m_rxSource;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   366
 *   CallbackTraceSource<Packet> m_txSource;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   367
 *   CallbackTraceSource<Packet> m_dropSource;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
 * };
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
 * \endcode
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   370
 * When a single sink is connected to all 3 sources here, one might want
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   371
 * to write code like the following:
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   372
 * \code
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
 * void DeviceRxSink (const TraceContext &context, const Packet &packet)
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
 * {
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   375
 *   switch (type) {
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   376
 *     case RX:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   377
 *       std::cout << "rx" << std::endl;
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   378
 *       break;
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   379
 *     case TX:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   380
 *       std::cout << "tx" << std::endl;
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   381
 *       break;
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   382
 *     case DROP:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   383
 *       std::cout << "drop" << std::endl;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   384
 *       break;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   385
 *   }
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
 * \endcode
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   387
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   388
 * \subsection AdvancedTraceContextSimpleSolution The simple solution
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   389
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   390
 * The simplest way to do achieve the result shown above is to include
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   391
 * in the trace source an extra explicit argument which describes the source event:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   392
 *   - define a small enum with 3 values
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   393
 *   - change the signature of m_rxSource, m_txSource, and m_dropSource to include
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   394
 *     the enum
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   395
 *   - pass the enum value in each event
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   396
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   397
 * The resulting code is shown below:
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   398
 * \code
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   399
 * class MyModel
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   400
 * {
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   401
 * public:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   402
 *   // define the trace type enum.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   403
 *   enum TraceType {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   404
 *     RX,
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   405
 *     TX,
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   406
 *     DROP
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   407
 *   };
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   408
 * private:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   409
 *   // generate events
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   410
 *   void NotifyRxPacket (Packet p) {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   411
 *     m_rxSource (p, MyModel::RX);
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   412
 *   }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   413
 *   void NotifyTxPacket (Packet p) {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   414
 *     m_rxSource (p, MyModel::TX);
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   415
 *   }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   416
 *   void NotifyDropPacket (Packet p) {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   417
 *     m_rxSource (p, MyModel::DROP);
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   418
 *   }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   419
 *   CallbackTraceSource<Packet,enum TraceType> m_rxSource;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   420
 *   CallbackTraceSource<Packet,enum TraceType> m_txSource;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   421
 *   CallbackTraceSource<Packet,enum TraceType> m_dropSource;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   422
 * };
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   423
 * \endcode
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   424
 * These 3 new sources can be connected easily to a new trace sink:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   425
 * \code
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   426
 * void ASimpleTraceSink (const TraceContext &context, const Packet &packet, enum MyModel::TraceType type)
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   427
 * {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   428
 *   // here, read the "type" argument
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   429
 * }
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   430
 * \endcode
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
 *
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   432
 * This solution works but it makes it impossible to connect a single trace sink to a set
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   433
 * of trace sources which represent "rx" events in different NetDevice objects since
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   434
 * each of them will define a different enum type with different values: since the
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   435
 * trace sink signature must match exactly the trace source signature, it is impossible
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   436
 * to connect at the same time to all "rx" events of different NetDevice.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   437
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   438
 * \subsection AdvancedTraceContextFancySolution The more complex and generic solution
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   439
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   440
 * There is, hopefully, a way to get the best of both worlds, that is, to allow a
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   441
 * user to connect to a lot of trace source events of the same kind but coming from different
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   442
 * implementations and to allow the user to differentiate between these different
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   443
 * implementations.
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   444
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   445
 * Rather than define an adhoc enum type with a list of trace sources, you can also
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   446
 * define a new ns3::TraceContextElement for your source sources. For example, if you
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   447
 * define a new MyModelTraceType class which contains the type of trace, your users can
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   448
 * then write trace sink code which looks like this:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   449
 * \code
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   450
 * void AFancyTraceSink (const TraceContext &context, const Packet &packet)
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   451
 * {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   452
 *   MyModelTraceType type;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   453
 *   if (context.GetElement (type))
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   454
 *     {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   455
 *       switch (type.Get ())
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   456
 *         {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   457
 *         case MyModelTraceType::RX:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   458
 *           std::cout << "rx" << std::endl;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   459
 *           break;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   460
 *         case MyModelTraceType::TX:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   461
 *           std::cout << "tx" << std::endl;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   462
 *           break;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   463
 *         case MyModelTraceType::DROP:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   464
 *           std::cout << "drop" << std::endl;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   465
 *           break;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   466
 *         }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   467
 *     }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   468
 * }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   469
 * \endcode
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   470
 *
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   471
 * Of course, since the type of trace is stored in the TraceContext, your users can
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   472
 * also take the shortcut which uses the printing functionality of the TraceContext:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   473
 * \code
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   474
 * void ALessFancyTraceSink (const TraceContext &context, const Packet &packet)
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   475
 * {
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   476
 *   std::cout << "context=\"" << context << "\" packet: " << packet << std::endl;
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   477
 * }
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   478
 * \endcode
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   479
 * which will generate something like the following when the trace source comes
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   480
 * from MyModel:
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   481
 * \code
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   482
 * context="my-model-rx" packet: ...
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   483
 * \endcode
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
 *
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   485
 * The first step to achieve this is to define and implement a new
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   486
 * subclass of the ns3::TraceContextElement base class. The exact list of
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   487
 * public methods which must be implemented is described in the API
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   488
 * documentation of the ns3::TraceContextElement class. 
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
 * \code
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   490
 * class MyModelTraceType : public TraceContextElement
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   491
 * {
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
 * public:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   493
 *   enum Type {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   494
 *     RX,
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   495
 *     TX,
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   496
 *     DROP
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   497
 *   };
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   498
 *   // called from MyModel::GetTraceResolver
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   499
 *   MyModelTraceType (enum Type type);
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   500
 *   // called from trace sink
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   501
 *   enum Type Get (void) const;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   502
 *   // needed by the tracing subsystem
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   503
 *   static uint16_t GetUid (void);
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   504
 *   // needed by the tracing subsystem to
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   505
 *   // print the content of a TraceContext
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   506
 *   void Print (std::ostream &os) const;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   507
 *   // needed by the tracing subsystem to
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   508
 *   // generate the doxygen documentation.
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   509
 *   std::string GetTypeName (void) const;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   510
 * private:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   511
 *   enum Type m_type;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   512
 * };
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   513
 * \endcode
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   514
 * The implementation does not require much thinking:
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   515
 * \code
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   516
 * MyModelTraceType::MyModelTraceType (enum Type type)
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   517
 *  : m_type (type)
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   518
 * {}
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   519
 * enum Type 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   520
 * MyModelTraceType::Get (void) const
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   521
 * {
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   522
 *   return m_type;
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   523
 * }
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   524
 * uint16_t 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   525
 * MyModelTraceType::GetUid (void)
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   526
 * {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   527
 *   // use protected TraceContextElement::AllocateUid method
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   528
 *   // the input string is used to uniquely identify this new subclass
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   529
 *   static uint16_t uid = AllocateUid<MyModelTraceType> ("ns3::MyModelTraceType");
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   530
 *   return uid;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   531
 * }
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   532
 * void 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   533
 * MyModelTraceType::Print (std::ostream &os) const
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   534
 * (
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   535
 *   // this method is invoked by the print function of a TraceContext
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   536
 *   // if it contains an instance of this TraceContextElement.
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   537
 *   switch (m_type) {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   538
 *     case RX: os << "rx"; break;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   539
 *     // ...
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   540
 *   }
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   541
 * )
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   542
 * std::string 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   543
 * MyModelTraceType::GetTypeName (void) const
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   544
 * {
1413
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   545
 *   // This method should return a fully-qualified c++ typename
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   546
 *   // This method is used only for documentation purposes to
a84b1ece69a2 re-organize the tutorial and use sections
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1411
diff changeset
   547
 *   // generate the content of the Trace Source List.
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   548
 *   return "ns3::MyModelTraceType";
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   549
 * }
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
 * \endcode
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   551
 *
1410
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   552
 * Once this subclass is implemented, the work is almost completed: you
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   553
 * just need to pass an instance of that class as the last argument of 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   554
 * the ns3::CompositeTraceResolver::AddSource method as shown below:
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   555
 * \code
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   556
 * Ptr<TraceResolver>
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   557
 * MyModel::GetTraceResolver (void) const
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   558
 * {
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   559
 *   // create an empty trace resolver
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   560
 *   Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   561
 *   // register m_rxSource
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   562
 *   resolver->AddSource ("rx", // the name of the trace source in the path string
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   563
 *                        TraceDoc ("some help text to explain the purpose of this trace source",
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   564
 *                                  "Packet", // the type of the first argument to the trace source
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   565
 *                                  "the purpose of the first argument",
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   566
 *                                  "type-of-second-argument", "purpose-of-second-argument"),
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   567
 *                        m_rxSource, // the trace source itself is registered
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   568
 *                        // the TraceContextElement associated to this trace source.
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   569
 *                        MyModelTraceType (MyModelTraceType::RX) 
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   570
 *                       );
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   571
 *   // make sure we include the trace sources implemented in the parent.
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   572
 *   resolver->SetParentResolver (MyParent::GetTraceResolver ());
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   573
 *   return resolver;
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   574
 * }
70cc59001a4d finish trace tutorial
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1408
diff changeset
   575
 * \endcode
1391
ce9ab2cbf936 add some tracing documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   576
 */