next up previous contents index
Next: 21.3 The C++ Trace Up: 21. Trace and Monitoring Previous: 21.1.1 OTcl Helper Functions

   
21.2 Library support and examples

The Simulator procedures described above require the trace and init-monitor methods associated with the OTcl Link class. Several subclasses of link are defined, the most common of which is called SimpleLink. Thus, the trace and init-monitor methods are actually part of the SimpleLink class rather than the Link base class. The trace function is defined as follows (in ns-link.tcl):

#
# Build trace objects for this link and
# update the object linkage
#
SimpleLink instproc trace { ns f } {
        $self instvar enqT_ deqT_ drpT_ queue_ link_ head_ fromNode_ toNode_
        $self instvar drophead_

        set enqT_ [$ns create-trace Enque $f $fromNode_ $toNode_]
        set deqT_ [$ns create-trace Deque $f $fromNode_ $toNode_]
        set drpT_ [$ns create-trace Drop $f $fromNode_ $toNode_]

        $drpT_ target [$drophead_ target]
        $drophead_ target $drpT_
        $queue_ drop-target $drpT_

        $deqT_ target [$queue_ target]
        $queue_ target $deqT_

        if { [$head_ info class] == "networkinterface" } {
            $enqT_ target [$head_ target]
            $head_ target $enqT_
            # puts "head is i/f"
        } else {
            $enqT_ target $head_
            set head_ $enqT_
            # puts "head is not i/f"
        }
}
This function establishes Enque, Deque, and Drop traces in the simulator $ns and directs their output to I/O handle $f. The function assumes a queue has been associated with the link. It operates by first creating three new trace objects and inserting the Enque object before the queue, the Deque object after the queue, and the Drop object between the queue and its previous drop target. Note that all trace output is directed to the same I/O handle.

This function performs one other additional tasks. It checks to see if a link contains a network interface, and if so, leaves it as the first object in the chain of objects in the link, but otherwise inserts the Enque object as the first one.

The following functions, init-monitor and attach-monitor, are used to create a set of objects used to monitor queue sizes of a queue associated with a link. They are defined as follows:

        SimpleLink instproc attach-monitors { insnoop outsnoop dropsnoop qmon } {
                $self instvar queue_ head_ snoopIn_ snoopOut_ snoopDrop_
                $self instvar drophead_ qMonitor_

                set snoopIn_ $insnoop
                set snoopOut_ $outsnoop
                set snoopDrop_ $dropsnoop

                $snoopIn_ target $head_
                set head_ $snoopIn_

                $snoopOut_ target [$queue_ target]
                $queue_ target $snoopOut_

                $snoopDrop_ target [$drophead_ target]
                $drophead_ target $snoopDrop_

                $snoopIn_ set-monitor $qmon
                $snoopOut_ set-monitor $qmon
                $snoopDrop_ set-monitor $qmon
                set qMonitor_ $qmon
        }

        #
        # Insert objects that allow us to monitor the queue size
        # of this link.  Return the name of the object that
        # can be queried to determine the average queue size.
        #
        SimpleLink instproc init-monitor { ns qtrace sampleInterval} {
                $self instvar qMonitor_ ns_ qtrace_ sampleInterval_

                set ns_ $ns
                set qtrace_ $qtrace
                set sampleInterval_ $sampleInterval
                set qMonitor_ [new QueueMonitor]

                $self attach-monitors [new SnoopQueue/In] \bs
                        [new SnoopQueue/Out] [new SnoopQueue/Drop] $qMonitor_

                set bytesInt_ [new Integrator]
                $qMonitor_ set-bytes-integrator $bytesInt_
                set pktsInt_ [new Integrator]
                $qMonitor_ set-pkts-integrator $pktsInt_
                return $qMonitor_
        }
These functions establish queue monitoring on the SimpleLink object in the simulator ns. Queue monitoring is implemented by constructing three SnoopQueue objects and one QueueMonitor object. The SnoopQueue objects are linked in around a Queue in a way similar to Trace objects. The SnoopQueue/In(Out) object monitors packet arrivals(departures) and reports them to an associated QueueMonitor agent. In addition, a SnoopQueue/Out object is also used to accumulate packet drop statistics to an associated QueueMonitor object. For init-monitor the same QueueMonitor object is used in all cases. The C++ definitions of the SnoopQueue and QueueMonitor classes are described below.


next up previous contents index
Next: 21.3 The C++ Trace Up: 21. Trace and Monitoring Previous: 21.1.1 OTcl Helper Functions

2000-08-24