26.3 The C++ Trace Class

Underlying C++ objects are created in support of the interface specified in Section 26.3 and are linked into the network topology as network elements. The single C++ Trace class is used to implement the OTcl classes Trace/Hop, Trace/Enque, Trace/Deque, and Trace/Drop. The type
field is used to differentiate among the various types of traces any particular Trace object might implement. Currently, this field may contain one of the following symbolic characters: + for enque, - for deque, h for hop, and d for drop. The overall class is defined as follows in ~ns/trace.cc:

        class Trace : public Connector {
                int type_;
                nsaddr_t src_;
                nsaddr_t dst_;
                Tcl_Channel channel_;
                int callback_;
                char wrk_[256];
                void format(int tt, int s, int d, Packet* p);
                void annotate(const char* s);
                int show_tcphdr_;  // bool flags; backward compat
                Trace(int type);
                int command(int argc, const char*const* argv);
                void recv(Packet* p, Handler*);
                void dump();
                inline char* buffer() { return (wrk_); }
The src
, and dst
internal state is used to label trace output and is independent of the corresponding field names in packet headers. The main []recv method is defined as follows:
        void Trace::recv(Packet* p, Handler* h)
                format(type_, src_, dst_, p);
                /* hack: if trace object not attached to anything free packet */
                if (target_ == 0)
                        send(p, h); /* \fcn[]{Connector::send} */
The function merely formats a trace entry using the source, destination, and particular trace type character. The dump function writes the formatted entry out to the I/O handle associated with channel
. The format function, in effect, dictates the trace file format.

Tom Henderson 2011-11-05