src/core/trace-root.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 10 Aug 2007 15:53:43 +0200
changeset 1334 e8e07f44359f
parent 1333 src/common/trace-root.h@c0d66de933e9
child 1335 d0e45d84f9c6
permissions -rw-r--r--
move trace code to core module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * All rights reserved.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * GNU General Public License for more details.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#ifndef TRACE_ROOT_H
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#define TRACE_ROOT_H
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include <string>
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/callback.h"
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
/**
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    28
 * \defgroup lowleveltracing Low-level tracing
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    30
 * This low-level API is built around a few concepts:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
 *   - There can be any number of trace source objects. Each trace source
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
 *     object can generate any number of trace events. The current
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
 *     trace source objects are: ns3::CallbackTraceSourceSource, ns3::UVTraceSource,
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
 *     ns3::SVTraceSource, and, ns3::FVTraceSource.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
 *   - Each trace source can be connected to any number of trace sinks.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
 *     A trace sink is a ns3::Callback with a very special signature. Its
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
 *     first argument is always a ns3::TraceContext.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
 *   - Every trace source is uniquely identified by a ns3::TraceContext. Every
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
 *     trace sink can query a ns3::TraceContext for information. This allows
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
 *     a trace sink which is connected to multiple trace sources to identify
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
 *     from which source each event is coming from.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    43
 * To define new trace sources, a model author needs to instante one trace source
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    44
 * object for each kind of tracing event he wants to export. The trace source objects
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    45
 * currently defined are:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    46
 *  - ns3::CallbackTraceSourceSource: this trace source can be used to convey any kind of 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    47
 *    trace event to the user. It is a functor, that is, it is a variable
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    48
 *    which behaves like a function which will forward every event to every
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    49
 *    connected trace sink (i.e., ns3::Callback). This trace source takes
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    50
 *    up to four arguments and forwards these 4 arguments together with the
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    51
 *    ns3::TraceContext which identifies this trace source to the connected
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    52
 *    trace sinks.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    53
 *  - ns3::UVTraceSource: this trace source is used to convey key state variable
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    54
 *    changes to the user. It behaves like a normal integer unsigned variable:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    55
 *    you can apply every normal arithmetic operator to it. It will forward
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    56
 *    every change in the value of the variable back to every connected trace 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    57
 *    sink by providing a TraceContext, the old value and the new value.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    58
 *  - ns3::SVTraceSource: this is the signed integer equivalent of 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    59
 *    ns3::UVTraceSource.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    60
 *  - ns3::FVTraceSource: this is the floating point equivalent of 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    61
 *    ns3::UVTraceSource and ns3::SVTraceSource.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    62
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    63
 * For example, to define a trace source which notifies you of a new packet
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    64
 * being transmitted, you would have to:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    65
 * \code
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    66
 * class MyModel
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    67
 * {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    68
 *  public:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    69
 *   void Tx (Packet const &p);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    70
 *  private:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    71
 *   CallbackTraceSource<Packet const &> m_txTrace;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    72
 * };
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    73
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    74
 * void
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    75
 * MyModel::Tx (Packet const &p)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    76
 * {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    77
 *   // trace packet tx event.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    78
 *   m_txTrace (p);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    79
 *   // ... send the packet for real.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    80
 * }
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    81
 * \endcode
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    82
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    83
 * Once the model author has instantiated these objects and has wired them 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    84
 * in his simulation code (that is, he calls them wherever he wants to trigger 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    85
 * a trace event), he needs to make these trace sources available to users
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    86
 * to allow them to connect any number of trace sources to any number
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    87
 * of user trace sinks. While it would be possible to make each model
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    88
 * export directly each of his trace source instances and request users to
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    89
 * invoke a source->Connect (callback) method to perform the connection
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    90
 * explicitely, it was felt that this was a bit cumbersome to do.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    91
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    92
 * As such, the ``connection'' between a set of sources and a sink is 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    93
 * performed through a third-party class, the TraceResolver, which
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    94
 * can be used to automate the connection of multiple matching trace sources
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    95
 * to a single sink. This TraceResolver works by defining a hierarchical 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    96
 * tracing namespace: the root of this namespace is accessed through the 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    97
 * ns3::TraceRoot class. The namespace is represented as a string made of 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    98
 * multiple elements, each of which is separated from the other elements 
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
 * by the '/' character. A namespace string always starts with a '/'.
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   100
 * 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   101
 * By default, the current simulation models provide a '/nodes' tracing root. 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   102
 * This '/nodes' namespace is structured as follows:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
 * \code
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   104
 *  /nodes/n/arp
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
 *  /nodes/n/udp
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
 *  /nodes/n/ipv4
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
 *               /tx
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
 *               /rx
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
 *               /drop
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
 *               /interfaces/n/netdevice
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   111
 *                                      /queue/
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   112
 *                                            /enque
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   113
 *                                            /deque
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   114
 *                                            /drop
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
 * \endcode
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
 * The 'n' element which follows the /nodes and /interfaces namespace elements
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
 * identify a specific node and interface through their index within the 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
 * ns3::NodeList and ns3::Ipv4 objects respectively.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
 * To connect a trace sink to a trace source identified by a namespace string,
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
 * a user can call the ns3::TraceRoot::Connect method (the ns3::TraceRoot::Disconnect
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
 * method does the symmetric operation). This connection method can accept
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
 * fully-detailed namespace strings but it can also perform pattern matching
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
 * on the user-provided namespace strings to connect multiple trace sources
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
 * to a single trace sink in a single connection operation.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
 * The syntax of the pattern matching rules are loosely based on regular 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
 * expressions:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
 *   - the '*' character matches every element
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
 *   - the (a|b) construct matches element 'a' or 'b'
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
 *   - the [ss-ee] construct matches all numerical values which belong
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
 *     to the interval which includes ss and ee
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
 * For example, the user could use the following to connect a single sink
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
 * to the ipv4 tx, rx, and drop trace events:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
 * \code
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
 * void MyTraceSink (TraceContext const &context, Packet &packet);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
 * TraceRoot::Connect ("/nodes/ * /ipv4/ *", MakeCallback (&MyTraceSink));
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
 * \endcode
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
 * Of course, this code would work only if the signature of the trace sink
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
 * is exactly equal to the signature of all the trace sources which match
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
 * the namespace string (if one of the matching trace source does not match
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
 * exactly, a fatal error will be triggered at runtime during the connection
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
 * process). The ns3::TraceContext extra argument contains
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
 * information on where the trace source is located in the namespace tree.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
 * In that example, if there are multiple nodes in this scenario, each
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
 * call to the MyTraceSink function would receive a different TraceContext,
941
7a81f1ef8c74 Fixed a typo in the documentation. Had to change NodeList::Index to
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents: 393
diff changeset
   151
 * each of which would contain a different NodeList::NodeIndex object.
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
 * It is important to understand exactly what an ns3::TraceContext
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
 * is. It is a container for a number of type instances. Each instance of
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
 * a ns3::TraceContext contains one and only one instance of a given type.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
 * ns3::TraceContext::Add can be called to add a type instance into a 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
 * TraceContext instance and ns3::TraceContext::Get can be called to get
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
 * a copy of a type instance stored into the ns3::TraceContext. If ::Get
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
 * cannot retrieve the requested type, a fatal error is triggered at
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
 * runtime. The values stored into an ns3::TraceContext attached to a 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
 * trace source are automatically determined during the namespace
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
 * resolution process. To retrieve a value from a ns3::TraceContext, the
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
 * code can be as simple as this:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
 * \code
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
 * void MyTraceSink (TraceContext const &context, Packet &packet)
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
 * {
941
7a81f1ef8c74 Fixed a typo in the documentation. Had to change NodeList::Index to
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents: 393
diff changeset
   167
 *   NodeList::NodeIndex index;
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
 *   context.Get (index);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
 *   std::cout << "node id=" << NodeList::GetNode (index)->GetId () << std::endl;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
 * }
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
 * \endcode
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   173
 * The hierarchical global namespace described here is not implemented
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   174
 * in a single central location: it was felt that doing this would make
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   175
 * it too hard to introduce user-specific models which could hook
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   176
 * automatically into the overal tracing system. If the tracing
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   177
 * namespace was implemented in a single central location, every model
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   178
 * author would have had to modify this central component to make
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   179
 * his own model available to trace users.
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   181
 * Instead, the handling of the namespace is distributed across every relevant
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   182
 * model: every model implements only the part of the namespace it is
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   183
 * really responsible for. To do this, every model is expected
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   184
 * to provide an instance of a TraceResolver whose
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   185
 * responsability is to recursively provide access to the trace sources
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   186
 * defined in its model. Each TraceResolver instance should be a subclass
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   187
 * of the TraceResolver base class which implements either the DoLookup
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   188
 * or the DoConnect and DoDisconnect methods. Because implementing these
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   189
 * methods can be a bit tedious, our tracing framework provides a number 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   190
 * of helper template classes which should save the model author from 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   191
 * having to implement his own in most cases:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   192
 *    - ns3::CompositeTraceResolver: this subclass of ns3::TraceResolver can 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   193
 *      be used to aggregate together multiple trace sources and multiple other 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   194
 *      ns3::TraceResolver instances.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   195
 *    - ns3::ArrayTraceResolver: this subclass of ns3::TraceResolver can be 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   196
 *      used to match any number of elements within an array where every element 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   197
 *      is identified by its index.
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   199
 * Once you can instantiate your own ns3::TraceResolver object instance, you 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   200
 * have to hook it up into the global namespace. There are two ways to do this:
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
 *   - you can hook your ns3::TraceResolver creation method as a new trace 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
 *     root by using the ns3::TraceRoot::Register method
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   203
 *   - you can hook your new ns3::TraceResolver creation method into the 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   204
 *     container of your model. This step will obvsiouly depend on which model
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   205
 *     contains your own model but, if you wrote a new l3 protocol, all you
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   206
 *     would have to do to hook into your container L3Demux class is to implement 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   207
 *     the pure virtual method inherited from the L3Protocol class whose name is 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   208
 *     ns3::L3protocol::CreateTraceResolver.
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   209
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   210
 * So, in most cases, exporting a model's trace sources is a matter of 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   211
 * implementing a method CreateTraceResolver as shown below:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   212
 * \code
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   213
 * class MyModel
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   214
 * {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   215
 * public:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   216
 *   enum TraceType {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   217
 *    TX,
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   218
 *    RX,
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   219
 *    ...
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   220
 *   };
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   221
 *   TraceResolver *CreateTraceResolver (TraceContext const &context);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   222
 *   void Tx (Packet const &p);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   223
 * private:
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   224
 *   CallbackTraceSource<Packet const &> m_txTrace;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   225
 * };
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   226
 *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   227
 * TraceResolver *
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   228
 * MyModel::CreateTraceResolver (TraceContext const &context)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   229
 * {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   230
 *   CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   231
 *   resolver->Add ("tx", m_txTrace, MyModel::TX);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   232
 *   return resolver;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   233
 * }
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   234
 * void 
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   235
 * MyModel::Tx (Packet const &p)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   236
 * {
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   237
 *   m_txTrace (p);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   238
 * }
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   239
 * \endcode
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
 * If you really want to have fun and implement your own ns3::TraceResolver 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
 * subclass, you need to understand the basic Connection and Disconnection
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
 * algorithm. The code of that algorithm is wholy contained in the
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
 * ns3::TraceResolver::Connect and ns3::TraceResolver::Disconnect methods.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
 * The idea is that we recursively parse the input namespace string by removing
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
 * the first namespace element. This element is 'resolved' is calling
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
 * the ns3::TraceResolver::DoLookup method which returns a list of
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
 * TraceResolver instances. Each of the returned TraceResolver instance is
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
 * then given what is left of the namespace by calling ns3::TraceResolver::Connect
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
 * until the last namespace element is processed. At this point, we invoke
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
 * the ns3::TraceResolver::DoConnect or ns3::TraceResolver::DoDisconnect 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
 * methods to break the recursion. A good way to understand this algorithm
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
 * is to trace its behavior. Let's say that you want to connect to
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
 * '/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *'. It would generate
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
 * the following call traces:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
 *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
 * \code
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   258
 * TraceRoot::Connect ("/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   259
 * traceContext = TraceContext ();
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   260
 * rootResolver = CompositeTraceResolver (traceContext);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   261
 * rootResolver->Connect ("/nodes/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   262
 *   resolver = CompositeTraceResolver::DoLookup ("nodes");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   263
 *     return NodeList::CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   264
 *       return ArrayTraceResolver (context);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   265
 *   resolver->Connect ("/ * /ipv4/interfaces/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   266
 *     ArrayTraceResolver::DoLookup ("*");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   267
 *       for (i = 0; i < n_nodes; i++)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   268
 *         resolver = nodes[i]->CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   269
 *           return CompositeTraceResolver (context);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   270
 *         resolvers.add (resolver);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   271
 *       return resolvers;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   272
 *     for resolver in (resolvers)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   273
 *       resolver->Connect ("/ipv4/interfaces/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   274
 *         CompositeTraceResolver::DoLookup ("ipv4");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   275
 *           resolver = ipv4->CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   276
 *             return CompositeTraceResolver (context);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   277
 *           return resolver;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   278
 *         resolver->Connect ("/interfaces/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   279
 *           CompositeTraceResolver::DoLookup ("interfaces");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   280
 *             resolver = ArrayTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   281
 *           resolver->Connect ("/ * /netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   282
 *             ArrayTraceResolver::DoLookup ("*");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   283
 *               for (i = 0; i < n_interfaces; i++)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   284
 *                  resolver = interfaces[i]->CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   285
 *                    return CompositeTraceResolver ()
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   286
 *                  resolvers.add (resolver);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   287
 *               return resolvers;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   288
 *             resolver->Connect ("/netdevice/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   289
 *               CompositeTraceResolver::DoLookup ("netdevice");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   290
 *                 resolver = NetDevice::CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   291
 *                   return CompositeTraceResolver ();
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   292
 *                 return resolver;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   293
 *               resolver->Connect ("/queue/ *", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   294
 *                 CompositeTraceResolver::DoLookup ("queue");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   295
 *                   resolver = Queue::CreateTraceResolver (GetContext ());
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   296
 *                     return CompositeTraceResolver ();
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   297
 *                   return resolver
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   298
 *                 resolver->Connect ("*", callback);
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   299
 *                   CompositeTraceResolver::DoLookup ("*");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   300
 *                     for match in (matches)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   301
 *                       resolver = TerminalTraceResolver ("match");
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   302
 *                       resolvers.add (resolver)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   303
 *                     return resolvers;
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   304
 *                   for resolver in (resolvers)
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   305
 *                     TerminalTraceResolver->DoConnect (callback);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
 * \endcode
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
 */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
namespace ns3 {
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
class CompositeTraceResolver;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
class TraceResolver;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
class TraceContext;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
class CallbackBase;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
/**
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
 * \brief The main class used to access tracing functionality for
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
 * a user.
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
 *
393
18ed386bee75 rework the tracing architecture description
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   320
 * \ingroup lowleveltracing
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
 */
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
class TraceRoot
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
public:
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
  static void Connect (std::string path, CallbackBase const &cb);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
  static void Disconnect (std::string path, CallbackBase const &cb);
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
  static void Register (std::string name, 
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
   328
                        Callback<Ptr<TraceResolver> > createResolver);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
private:
1333
c0d66de933e9 convert TraceResolver * to Ptr<TraceResolver>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1325
diff changeset
   330
  static Ptr<CompositeTraceResolver> GetComposite (void);
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
};
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
}// namespace ns3
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
#endif /* TRACE_ROOT_H */