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 ...
3.6 Class TclCommandThis class (class TclCommand) provides just the mechanism for ns to export simple commands to the interpreter, that canthen be executed within a global context by the interpreter. There are two functions defined in ~ns/misc.cc: ns-random andns-version. These two functions are initialized by the function init_misc(void), defined in ~ns/misc.cc; init_miscis invoked by Tcl_AppInit(void) during startup.• class VersionCommand defines the command ns-version. It takes no argument, and returns the current nsversion string.% ns-version ;# get the current version2.0a12• class RandomCommand defines the command ns-random. With no argument, ns-random returns an integer,uniformly distributed in the interval [0, 2 31 − 1].When specified an argument, it takes that argument as the seed. If this seed value is 0, the command uses a heuristicseed value; otherwise, it sets the seed for the random number generator to the specified value.% ns-random ;# return a random number2078917053% ns-random 0 ;#set the seed heuristically858190129% ns-random 23786 ;#set seed to specified value23786Note that, it is generally not advisable to construct top-level commands that are available to the user. We now describe howto define a new command using the example class say_hello. The example defines the command hi, to print the string“hello world”, followed by any command line arguments specified by the user. For example,% hi this is ns [ns-version]hello world, this is ns 2.0a121. The command must be defined within a class derived from the class TclCommand. The class definition is:class say_hello : public TclCommand {public:say_hello();int command(int argc, const char*const* argv);};2. The constructor for the class must invoke the TclCommand constructor with the command as argument; i.e.,say_hello() : TclCommand("hi") {}The TclCommand constructor sets up "hi" as a global procedure that invokes TclCommand::dispatch_cmd().3. The method command() must perform the desired action.The method is passed two arguments. The first argument, argc, contains the number of actual arguments passed bythe user.33
The actual arguments passed by the user are passed as an argument vector (argv) and contains the following:— argv[0] contains the name of the command (hi).— argv[1...(argc - 1)] contains additional arguments specified on the command line by the user.command() is invoked by dispatch_cmd().#include /* because we are using stream I/O */int say_hello::command(int argc, const char*const* argv) {cout
- 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: class Packet {......static int hdrl
- 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
- 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
3.6 Class TclComm<strong>and</strong>This class (class TclComm<strong>and</strong>) provides just the mechanism for <strong>ns</strong> to export simple comm<strong>and</strong>s to the interpreter, th<strong>at</strong> canthen be executed within a global context by the interpreter. <strong>The</strong>re are two functio<strong>ns</strong> defined in ~<strong>ns</strong>/misc.cc: <strong>ns</strong>-r<strong>and</strong>om <strong>and</strong><strong>ns</strong>-version. <strong>The</strong>se two functio<strong>ns</strong> are initialized by the function init_misc(void), defined in ~<strong>ns</strong>/misc.cc; init_miscis invoked by Tcl_AppInit(void) during startup.• class VersionComm<strong>and</strong> defines the comm<strong>and</strong> <strong>ns</strong>-version. It takes no argument, <strong>and</strong> retur<strong>ns</strong> the current <strong>ns</strong>version string.% <strong>ns</strong>-version ;# get the current version2.0a12• class R<strong>and</strong>omComm<strong>and</strong> defines the comm<strong>and</strong> <strong>ns</strong>-r<strong>and</strong>om. With no argument, <strong>ns</strong>-r<strong>and</strong>om retur<strong>ns</strong> an integer,uniformly distributed in the interval [0, 2 31 − 1].When specified an argument, it takes th<strong>at</strong> argument as the seed. If this seed value is 0, the comm<strong>and</strong> uses a heuristicseed value; otherwise, it sets the seed for the r<strong>and</strong>om number gener<strong>at</strong>or to the specified value.% <strong>ns</strong>-r<strong>and</strong>om ;# return a r<strong>and</strong>om number2078917053% <strong>ns</strong>-r<strong>and</strong>om 0 ;#set the seed heuristically858190129% <strong>ns</strong>-r<strong>and</strong>om 23786 ;#set seed to specified value23786Note th<strong>at</strong>, it is generally not advisable to co<strong>ns</strong>truct top-level comm<strong>and</strong>s th<strong>at</strong> are available to the user. We now describe howto define a new comm<strong>and</strong> using the example class say_hello. <strong>The</strong> example defines the comm<strong>and</strong> hi, to print the string“hello world”, followed by any comm<strong>and</strong> line arguments specified by the user. For example,% hi this is <strong>ns</strong> [<strong>ns</strong>-version]hello world, this is <strong>ns</strong> 2.0a121. <strong>The</strong> comm<strong>and</strong> must be defined within a class derived from the class TclComm<strong>and</strong>. <strong>The</strong> class definition is:class say_hello : public TclComm<strong>and</strong> {public:say_hello();int comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv);};2. <strong>The</strong> co<strong>ns</strong>tructor for the class must invoke the TclComm<strong>and</strong> co<strong>ns</strong>tructor with the comm<strong>and</strong> as argument; i.e.,say_hello() : TclComm<strong>and</strong>("hi") {}<strong>The</strong> TclComm<strong>and</strong> co<strong>ns</strong>tructor sets up "hi" as a global procedure th<strong>at</strong> invokes TclComm<strong>and</strong>::disp<strong>at</strong>ch_cmd().3. <strong>The</strong> method comm<strong>and</strong>() must perform the desired action.<strong>The</strong> method is passed two arguments. <strong>The</strong> first argument, argc, contai<strong>ns</strong> the number of actual arguments passed bythe user.33