12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Agent/SRM/Adaptive set pdistance_ 15.0Agent/SRM set pdistance_ 10.0Agent/SRM set lastSent_ 8.345mAgent set ctrlLimit_ 1.44MAgent/SRM/Adaptive set running_ f<strong>The</strong>refore, every new Agent/SRM/Adaptive object will have pdistance_ set to 15.0; lastSent_ is set to 8.345m fromthe setting of the class variable of the parent class; ctrlLimit_ is set to 1.44M using the class variable of the parent classtwice removed; running is set to false; the i<strong>ns</strong>tance variable pdistance_ is not initialised, because no class variable existsin any of the class hierarchy of the interpreted object. In such i<strong>ns</strong>tance, init-i<strong>ns</strong>tvar{} will invoke warn-i<strong>ns</strong>tvar{},to print out a warning about such a variable. <strong>The</strong> user can selectively override this procedure in their simul<strong>at</strong>ion scripts, toelide this warning.Note th<strong>at</strong> the actual binding is done by i<strong>ns</strong>tanti<strong>at</strong>ing objects in the class I<strong>ns</strong>tVar. Each object in the class I<strong>ns</strong>tVar binds onecompiled member variable to one interpreted member variable. A TclObject stores a list of I<strong>ns</strong>tVar objects corresponding toeach of its member variable th<strong>at</strong> is bound in this fashion. <strong>The</strong> head of this list is stored in its member variable i<strong>ns</strong>tvar_ ofthe TclObject.One last point to co<strong>ns</strong>ider is th<strong>at</strong> <strong>ns</strong> will guarantee th<strong>at</strong> the actual values of the variable, both in the interpreted object <strong>and</strong> thecompiled object, will be identical <strong>at</strong> all times. However, if there are methods <strong>and</strong> other variables of the compiled object th<strong>at</strong>track the value of this variable, they must be explicitly invoked or changed whenever the value of this variable is changed.This usually requires additional primitives th<strong>at</strong> the user should invoke. One way of providing such primitives in <strong>ns</strong> is throughthe comm<strong>and</strong>() method described in the next section.3.4.3 Variable TracingIn addition to variable bindings, TclObject also supports tracing of both C++ <strong>and</strong> Tcl i<strong>ns</strong>tance variables. A traced variablecan be cre<strong>at</strong>ed <strong>and</strong> configured either in C++ or Tcl. To establish variable tracing <strong>at</strong> the Tcl level, the variable must be visiblein Tcl, which mea<strong>ns</strong> th<strong>at</strong> it must be a bounded C++/Tcl or a pure Tcl i<strong>ns</strong>tance variable. In addition, the object th<strong>at</strong> ow<strong>ns</strong>the traced variable is also required to establish tracing using the Tcl trace method of TclObject. <strong>The</strong> first argument to thetrace method must be the name of the variable. <strong>The</strong> optional second argument specifies the trace object th<strong>at</strong> is respo<strong>ns</strong>iblefor tracing th<strong>at</strong> variable. If the trace object is not specified, the object th<strong>at</strong> own the variable is respo<strong>ns</strong>ible for tracing it.For a TclObject to trace variables, it must extend the C++ trace method th<strong>at</strong> is virtually defined in TclObject. <strong>The</strong> Traceclass implements a simple trace method, thereby, it can act as a generic tracer for variables.class Trace : public Connector {...virtual void trace(TracedVar*);};Below is a simple example for setting up variable tracing in Tcl:# \$tcp tracing its own variable cwnd_\$tcp trace cwnd_# the variable ssthresh_ of \$tcp is traced by a generic \$tracerset tracer [new Trace/Var]\$tcp trace ssthresh_ \$tracer27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!