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 ...
script after making their own changes. Finally, after adding the scripts to ~ns/tcl/lib/ns-lib.tcl, and every time thereafter thatthey change their script, the user must recompile ns for their changes to take effect. Of course, in most cases 4 , the user cansource their script to override the embedded code.The rest of this subsection illustrate how to integrate individual scripts directly into ns. The first step is convert the script intoan EmbeddedTcl object. The lines below expand ns-lib.tcl and create the EmbeddedTcl object instance called et_ns_lib:tclsh bin/tcl-expand.tcl tcl/lib/ns-lib.tcl | \../Tcl/tcl2c++ et_ns_lib > gen/ns_tcl.ccThe script, ~ns/bin/tcl-expand.tcl expands ns-lib.tcl by replacing all source lines with the corresponding source files.The program, ~tclcl/tcl2cc.c, converts the OTcl code into an equivalent EmbeddedTcl object, et_ns_lib.During initialization, invoking the method EmbeddedTcl::load explicitly evaluates the array.— ~tclcl/tcl-object.tcl is evaluated by the method Tcl::init(void); Tcl_AppInit() invokes Tcl::Init(). Theexact command syntax for the load is:et_tclobject.load();— Similarly, ~ns/tcl/lib/ns-lib.tcl is evaluated directly by Tcl_AppInit in ~ns/ns_tclsh.cc.et_ns_lib.load();3.8 Class InstVarThis section describes the internals of the class InstVar. This class defines the methods and mechanisms to bind a C++member variable in the compiled shadow object to a specified OTcl instance variable in the equivalent interpreted object. Thebinding is set up such that the value of the variable can be set or accessed either from within the interpreter, or from withinthe compiled code at all times.There are five instance variable classes: class InstVarReal, class InstVarTime, class InstVarBandwidth,class InstVarInt, and class InstVarBool, corresponding to bindings for real, time, bandwidth, integer, andboolean valued variables respectively.We now describe the mechanism by which instance variables are set up. We use the class InstVarReal to illustrate theconcept. However, this mechanism is applicable to all five types of instance variables.When setting up an interpreted variable to access a member variable, the member functions of the class InstVar assume thatthey are executing in the appropriate method execution context; therefore, they do not query the interpreter to determine thecontext in which this variable must exist.In order to guarantee the correct method execution context, a variable must only be bound if its class is already establishedwithin the interpreter, and the interpreter is currently operating on an object in that class. Note that the former requires thatwhen a method in a given class is going to make its variables accessible via the interpreter, there must be an associated4 The few places where this might not work are when certain variables might have to be defined or undefined, or otherwise the script contains code otherthan procedure and variable definitions and executes actions directly that might not be reversible.35
class TclClass (Section 3.5) defined that identifies the appropriate class hierarchy to the interpreter. The appropriate methodexecution context can therefore be created in one of two ways.An implicit solution occurs whenever a new TclObject is created within the interpreter. This sets up the method executioncontext within the interpreter. When the compiled shadow object of the interpreted TclObject is created, the constructor forthat compiled object can bind its member variables of that object to interpreted instance variables in the context of the newlycreated interpreted object.An explicit solution is to define a bind-variables operation within a command function, that can then be invokedvia the cmd method. The correct method execution context is established in order to execute the cmd method. Likewise,the compiled code is now operating on the appropriate shadow object, and can therefore safely bind the required membervariables.An instance variable is created by specifying the name of the interpreted variable, and the address of the member variable inthe compiled object. The constructor for the base class InstVar creates an instance of the variable in the interpreter, and thensets up a trap routine to catch all accesses to the variable through the interpreter.Whenever the variable is read through the interpreter, the trap routine is invoked just prior to the occurrence of the read. Theroutine invokes the appropriate get function that returns the current value of the variable. This value is then used to set thevalue of the interpreted variable that is then read by the interpreter.Likewise, whenever the variable is set through the interpreter, the trap routine is invoked just after to the write is completed.The routine gets the current value set by the interpreter, and invokes the appropriate set function that sets the value of thecompiled member to the current value set within the interpreter.36
- 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 and 26: By convention in ns, the class Agen
- Page 27 and 28: $object set bwvar 1500kb$object set
- 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: The actual arguments passed by the
- 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
- Page 77 and 78: maxidle_ is the maximum amount of t
- Page 79 and 80: dst_ The destination address of pac
- Page 81 and 82: 7.5.2 ConfigurationRunning a JoBS s
- Page 83 and 84: mean_pkt_size_ Used to set the expe
- Page 85 and 86: Demarker objects$q trace-file This
class TclClass (Section 3.5) defined th<strong>at</strong> identifies the appropri<strong>at</strong>e class hierarchy to the interpreter. <strong>The</strong> appropri<strong>at</strong>e methodexecution context can therefore be cre<strong>at</strong>ed in one of two ways.An implicit solution occurs whenever a new TclObject is cre<strong>at</strong>ed within the interpreter. This sets up the method executioncontext within the interpreter. When the compiled shadow object of the interpreted TclObject is cre<strong>at</strong>ed, the co<strong>ns</strong>tructor forth<strong>at</strong> compiled object can bind its member variables of th<strong>at</strong> object to interpreted i<strong>ns</strong>tance variables in the context of the newlycre<strong>at</strong>ed interpreted object.An explicit solution is to define a bind-variables oper<strong>at</strong>ion within a comm<strong>and</strong> function, th<strong>at</strong> can then be invokedvia the cmd method. <strong>The</strong> correct method execution context is established in order to execute the cmd method. Likewise,the compiled code is now oper<strong>at</strong>ing on the appropri<strong>at</strong>e shadow object, <strong>and</strong> can therefore safely bind the required membervariables.An i<strong>ns</strong>tance variable is cre<strong>at</strong>ed by specifying the name of the interpreted variable, <strong>and</strong> the address of the member variable inthe compiled object. <strong>The</strong> co<strong>ns</strong>tructor for the base class I<strong>ns</strong>tVar cre<strong>at</strong>es an i<strong>ns</strong>tance of the variable in the interpreter, <strong>and</strong> the<strong>ns</strong>ets up a trap routine to c<strong>at</strong>ch all accesses to the variable through the interpreter.Whenever the variable is read through the interpreter, the trap routine is invoked just prior to the occurrence of the read. <strong>The</strong>routine invokes the appropri<strong>at</strong>e get function th<strong>at</strong> retur<strong>ns</strong> the current value of the variable. This value is then used to set thevalue of the interpreted variable th<strong>at</strong> is then read by the interpreter.Likewise, whenever the variable is set through the interpreter, the trap routine is invoked just after to the write is completed.<strong>The</strong> routine gets the current value set by the interpreter, <strong>and</strong> invokes the appropri<strong>at</strong>e set function th<strong>at</strong> sets the value of thecompiled member to the current value set within the interpreter.36