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 ...
(a) adds the new object to hash table of TclObjects described earlier (Section 3.3.5).(b) makes cmd{} an instance procedure of the newly created interpreted object. This instance procedure invokes thecommand() method of the compiled object. In a later subsection (Section 3.4.4), we describe how the commandmethod is defined, and invoked.Note that all of the above shadowing mechanisms only work when the user creates a new TclObject through the interpreter.It will not work if the programmer creates a compiled TclObject unilaterally. Therefore, the programmer is enjoined not touse the C++ new method to create compiled objects directly.Deletion of TclObjects The delete operation destroys the interpreted object, and the corresponding shadow object. Forexample, use-scheduler{〈scheduler〉} uses the delete procedure to remove the default list scheduler, and instantiatean alternate scheduler in its place.Simulator instproc use-scheduler type {$self instvar scheduler_}delete scheduler_set scheduler_ [new Scheduler/$type];# first delete the existing list schedulerAs with the constructor, the object destructor must call the destructor for the parent class explicitly as the very last statementof the destructor. The TclObject destructor will invoke the instance procedure delete-shadow, that in turn invokes theequivalent compiled method to destroy the shadow object. The interpreter itself will destroy the interpreted object.3.4.2 Variable BindingsIn most cases, access to compiled member variables is restricted to compiled code, and access to interpreted member variablesis likewise confined to access via interpreted code; however, it is possible to establish bi-directional bindings such that boththe interpreted member variable and the compiled member variable access the same data, and changing the value of eithervariable changes the value of the corresponding paired variable to same value.The binding is established by the compiled constructor when that object is instantiated; it is automatically accessible by theinterpreted object as an instance variable. ns supports five different data types: reals, bandwidth valued variables, time valuedvariables, integers, and booleans. The syntax of how these values can be specified in OTcl is different for each variable type.• Real and Integer valued variables are specified in the “normal” form. For example,$object set realvar 1.2e3$object set intvar 12• Bandwidth is specified as a real value, optionally suffixed by a ‘k’ or ‘K’ to mean kilo-quantities, or ‘m’ or ‘M’ to meanmega-quantities. A final optional suffix of ‘B’ indicates that the quantity expressed is in Bytes per second. The defaultis bandwidth expressed in bits per second. For example, all of the following are equivalent:$object set bwvar 1.5m$object set bwvar 1.5mb$object set bwvar 1500k25
$object set bwvar 1500kb$object set bwvar .1875MB$object set bwvar 187.5kB$object set bwvar 1.5e6• Time is specified as a real value, optionally suffixed by a ‘m’ to express time in milli-seconds, ‘n’ to express time innano-seconds, or ‘p’ to express time in pico-seconds. The default is time expressed in seconds. For example, all of thefollowing are equivalent:$object set timevar 1500m$object set timevar 1.5$object set timevar 1.5e9n$object set timevar 1500e9pNote that we can also safely add a s to reflect the time unit of seconds. ns will ignore anything other than a valid realnumber specification, or a trailing ‘m’, ‘n’, or ‘p’.• Booleans can be expressed either as an integer, or as ‘T’ or ‘t’ for true. Subsequent characters after the first letter areignored. If the value is neither an integer, nor a true value, then it is assumed to be false. For example,$object set boolvar t$object set boolvar true$object set boolvar 1$object set boolvar false$object set boolvar junk$object set boolvar 0;# set to true;# or any non-zero value;# set to falseThe following example shows the constructor for the ASRMAgent 3 .ASRMAgent::ASRMAgent() {bind("pdistance_", &pdistance_); /* real variable */bind("requestor_", &requestor_); /* integer variable */bind_time("lastSent_", &lastSessSent_); /* time variable */bind_bw("ctrlLimit_", &ctrlBWLimit_); /* bandwidth variable */bind_bool("running_", &running_); /* boolean variable */}Note that all of the functions above take two arguments, the name of an OTcl variable, and the address of the correspondingcompiled member variable that is linked. While it is often the case that these bindings are established by the constructor ofthe object, it need not always be done in this manner. We will discuss such alternate methods when we describe the classInstVar (Section 3.8) in detail later.Each of the variables that is bound is automatically initialised with default values when the object is created. The defaultvalues are specified as interpreted class variables. This initialisation is done by the routing init-instvar{}, invoked bymethods in the class Instvar, described later (Section 3.8). init-instvar{} checks the class of the interpreted object, andall of the parent class of that object, to find the first class in which the variable is defined. It uses the value of the variable inthat class to initialise the object. Most of the bind initialisation values are defined in ~ns/tcl/lib/ns-default.tcl.For example, if the following class variables are defined for the ASRMAgent:3 Note that this constructor is embellished to illustrate the features of the variable binding mechanism.26
- Page 6 and 7: 18 Radio Propagation Models 17718.1
- Page 8 and 9: 30 Multicast Routing 25130.1 Multic
- Page 10 and 11: 38.2.5 An example . . . . . . . . .
- Page 12 and 13: X Other 40347 Educational use of NS
- Page 14: # so, we lied. now, we define the t
- Page 17 and 18: Chapter 2Undocumented FacilitiesNs
- Page 19 and 20: Part IInterface to the Interpreter1
- Page 21 and 22: • if you can do what you want by
- Page 23 and 24: • tcl.result(const char* s)Pass t
- Page 25: By convention in ns, the class Agen
- Page 29 and 30: For a C++ variable to be traceable,
- Page 31 and 32: 3.5 Class TclClassThis compiled cla
- Page 33 and 34: class Packet {......static int hdrl
- Page 35 and 36: The actual arguments passed by the
- Page 37 and 38: class TclClass (Section 3.5) define
- Page 39 and 40: Chapter 4The Class SimulatorThe ove
- Page 41 and 42: 4.2.2 the heap schedulerThe heap sc
- Page 43 and 44: 4.4 Commands at a glanceSynopsis:ns
- Page 45 and 46: $ns_ dumpqCommand for dumping event
- Page 47 and 48: NODEPortClassifierAgentAgentAddrCla
- Page 49 and 50: The Node instance variable, entry_,
- Page 51 and 52: The default values for all the abov
- Page 53 and 54: The classify() method is pure virtu
- Page 55 and 56: };The class imposes no direct seman
- Page 57 and 58: flow-specific queuing disciplines a
- Page 59 and 60: 5.5 Routing Module and Classifier O
- Page 61 and 62: Module NameRtModule/BaseRtModule/Mc
- Page 63 and 64: $node neighborsThis returns the lis
- Page 65 and 66: Linkhead_enqT_queue_ deqT_ link_ tt
- Page 67 and 68: 6.2 ConnectorsConnectors, unlink cl
- Page 69 and 70: $ns_ link-lossmodel This function
- Page 71 and 72: Chapter 7Queue Management and Packe
- Page 73 and 74: }}}void Queue::resume(){Packet* p =
- Page 75 and 76: 7.3 Different types of Queue object
$object set bwvar 1500kb$object set bwvar .1875MB$object set bwvar 187.5kB$object set bwvar 1.5e6• Time is specified as a real value, optionally suffixed by a ‘m’ to express time in milli-seconds, ‘n’ to express time innano-seconds, or ‘p’ to express time in pico-seconds. <strong>The</strong> default is time expressed in seconds. For example, all of thefollowing are equivalent:$object set timevar 1500m$object set timevar 1.5$object set timevar 1.5e9n$object set timevar 1500e9pNote th<strong>at</strong> we can also safely add a s to reflect the time unit of seconds. <strong>ns</strong> will ignore anything other than a valid realnumber specific<strong>at</strong>ion, or a trailing ‘m’, ‘n’, or ‘p’.• Boolea<strong>ns</strong> can be expressed either as an integer, or as ‘T’ or ‘t’ for true. Subsequent characters after the first letter areignored. If the value is neither an integer, nor a true value, then it is assumed to be false. For example,$object set boolvar t$object set boolvar true$object set boolvar 1$object set boolvar false$object set boolvar junk$object set boolvar 0;# set to true;# or any non-zero value;# set to false<strong>The</strong> following example shows the co<strong>ns</strong>tructor for the ASRMAgent 3 .ASRMAgent::ASRMAgent() {bind("pdistance_", &pdistance_); /* real variable */bind("requestor_", &requestor_); /* integer variable */bind_time("lastSent_", &lastSessSent_); /* time variable */bind_bw("ctrlLimit_", &ctrlBWLimit_); /* b<strong>and</strong>width variable */bind_bool("running_", &running_); /* boolean variable */}Note th<strong>at</strong> all of the functio<strong>ns</strong> above take two arguments, the name of an OTcl variable, <strong>and</strong> the address of the correspondingcompiled member variable th<strong>at</strong> is linked. While it is often the case th<strong>at</strong> these bindings are established by the co<strong>ns</strong>tructor ofthe object, it need not always be done in this manner. We will discuss such altern<strong>at</strong>e methods when we describe the classI<strong>ns</strong>tVar (Section 3.8) in detail l<strong>at</strong>er.Each of the variables th<strong>at</strong> is bound is autom<strong>at</strong>ically initialised with default values when the object is cre<strong>at</strong>ed. <strong>The</strong> defaultvalues are specified as interpreted class variables. This initialis<strong>at</strong>ion is done by the routing init-i<strong>ns</strong>tvar{}, invoked bymethods in the class I<strong>ns</strong>tvar, described l<strong>at</strong>er (Section 3.8). init-i<strong>ns</strong>tvar{} checks the class of the interpreted object, <strong>and</strong>all of the parent class of th<strong>at</strong> object, to find the first class in which the variable is defined. It uses the value of the variable inth<strong>at</strong> class to initialise the object. Most of the bind initialis<strong>at</strong>ion values are defined in ~<strong>ns</strong>/tcl/lib/<strong>ns</strong>-default.tcl.For example, if the following class variables are defined for the ASRMAgent:3 Note th<strong>at</strong> this co<strong>ns</strong>tructor is embellished to illustr<strong>at</strong>e the fe<strong>at</strong>ures of the variable binding mechanism.26