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 ...
static class ECHOClass : public TclClass {public:ECHOClass() : TclClass("Agent/ECHO") {}TclObject* create(int argc, const char*const* argv) {return (new ECHO_Agent());}} class_echo;Here, a static object “class_echo” is created. It’s constructor (executed immediately when the simulator is executed) placesthe class name “Agent/ECHO” into the OTcl name space. The mixing of case is by convention; recall from Section 3.5 in theearlier chapters that the “/” character is a hierarchy delimiter for the interpreted hierarchy. The definition of the create()method specifies how a C++ shadow object should be created when the OTcl interpreter is instructed to create an objectof class “Agent/ECHO”. In this case, a dynamically-allocated object is returned. This is the normal way new C++ shadowobjects are created.Once we have the object creation set up, we will want to link C++ member variables with corresponding variables in the OTclnname space, so that accesses to OTcl variables are actually backed by member variables in C++. Assume we would likeOTcl to be able to adjust the sending interval and the packet size. This is accomplished in the class’s constructor:ECHO_Agent::ECHO_Agent() : Agent(PT_ECHO){bind_time("interval_", &interval_);bind("packetSize_", &size_);}Here, the C++ variables interval_ and size_ are linked to the OTcl instance variables interval_ and packetSize_,respectively. Any read or modify operation to the Otcl variables will result in a corresponding access to the underlying C++variables. The details of the bind() methods are described elsewhere (Section 3.4.2). The defined constant PT_ECHO ispassed to the Agent() constuctor so that the Agent::allocpkt() method may set the packet type field used by the tracesupport (Section 26.5). In this case, PT_ECHO represents a new packet type and must be defined in ~ns/trace.h (Section 26.4).Once object creation and variable binding is set up, we may want to create methods implemented in C++ but which can beinvoked from OTcl (Section 3.4.4). These are often control functions that initiate, terminate or modify behavior. In our presentexample, we may wish to be able to start the ping query agent from OTcl using a “start” directive. This may be implementedas follows:int ECHO_Agent::command(int argc, const char*const* argv){if (argc == 2) {if (strcmp(argv[1], "start") == 0) {timeout(0);return (TCL_OK);}}return (Agent::command(argc, argv));}Here, the start() method available to OTcl simply calls the C++ member function timeout() which initiates the firstpacket generation and schedules the next. Note this class is so simple it does not even include a way to be stopped.105
10.6.4 Using the agent through OTclThe agent we have created will have to be instantiated and attached to a node. Note that a node and simulator object isassumed to have already been created. The following OTcl code performs these functions:set echoagent [new Agent/ECHO]$simulator attach-agent $node $echoagentTo set the interval and packet size, and start packet generation, the following OTcl code is executed:$echoagent set dst_ $dest$echoagent set fid_ 0$echoagent set prio_ 0$echoagent set flags_ 0$echoagent set interval_ 1.5$echoagent set packetSize_ 1024$echoagent startThis will cause our agent to generate one 1024-byte packet destined for node $dest every 1.5 seconds.10.7 The Agent APISimulated applications may be implemented on top of protocol agents. Chapter 38 describes the API used by applications toaccess the services provided by the protocol agent.10.8 Different agent objectsClass Agent forms the base class from which different types of objects like Nullobject, TCP etc are derived. The methods forAgent class are described in the next section. Configuration parameters for:fid_ Flowid.prio_ Priority.agent_addr_ Address of this agent.agent_port_ Port adress of this agent.dst_addr_Destination address for the agent.dst_port_ Destination port address for the agent.flags_ttl_ TTL defaults to 32.There are no state variables specific to the generic agent class. Other objects derived from Agent are given below:106
- 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
- Page 87 and 88: The recv() method overrides the bas
- Page 89 and 90: 9.2 ImplementationThe procedures an
- Page 91 and 92: Average sending rateTSW window leng
- Page 93 and 94: The following command adds an entry
- Page 95 and 96: $qCE configQ 0 1 10 20 0.10Note tha
- Page 97 and 98: Chapter 10AgentsAgents represent en
- Page 99 and 100: CtrMcast/EncapCtrMcast/DecapMessage
- Page 101 and 102: }bind("windowOption_", &wnd_option_
- Page 103 and 104: hdr_flags* nf = (hdr_flags*)npkt->a
- Page 105: public:ECHO_Timer(ECHO_Agent *a) :
- Page 109 and 110: State Variables are:dupacks_ Number
- Page 111 and 112: $agent attach-tbf Attaches a token
- Page 113 and 114: (void)Scheduler::instance().schedul
- Page 115 and 116: * outstanding, cancel it.*/void Tcp
- Page 117 and 118: Chapter 12Packet Headers and Format
- Page 119 and 120: method is now obsolete; its usage i
- Page 121 and 122: Packethdrsize_next_bits()points to
- Page 123 and 124: the system’s memory allocator. In
- Page 125 and 126: }incr hdrlen_ $incrreturn $baseFrom
- Page 127 and 128: Chapter 13Error ModelThis chapter d
- Page 129 and 130: SimpleLink::errormodule argsSimulat
- Page 131 and 132: This is a simple example of how to
- Page 133 and 134: Higher LayersNode 1Node 2. . .Node
- Page 135 and 136: };void recv(Packet* p, Handler*);vi
- Page 137 and 138: and the frame type. It then passes
- Page 139 and 140: $ll_ set delay_ $delay$ll_ set band
- Page 141 and 142: 14.10 Commands at a glanceThe follo
- Page 143 and 144: 15.2.1 Default Hierarchical Setting
- Page 145 and 146: Chapter 16Mobile Networking in nsTh
- Page 147 and 148: entry_addrdemuxIP addressdefaulttar
- Page 149 and 150: 16.1.2 Creating Node movementsThe m
- Page 151 and 152: set netif $netif_($t)set mac $mac_(
- Page 153 and 154: the hardware address of a packet’
- Page 155 and 156: destined to itself to the port dmux
st<strong>at</strong>ic class ECHOClass : public TclClass {public:ECHOClass() : TclClass("Agent/ECHO") {}TclObject* cre<strong>at</strong>e(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv) {return (new ECHO_Agent());}} class_echo;Here, a st<strong>at</strong>ic object “class_echo” is cre<strong>at</strong>ed. It’s co<strong>ns</strong>tructor (executed immedi<strong>at</strong>ely when the simul<strong>at</strong>or is executed) placesthe class name “Agent/ECHO” into the OTcl name space. <strong>The</strong> mixing of case is by convention; recall from Section 3.5 in theearlier chapters th<strong>at</strong> the “/” character is a hierarchy delimiter for the interpreted hierarchy. <strong>The</strong> definition of the cre<strong>at</strong>e()method specifies how a C++ shadow object should be cre<strong>at</strong>ed when the OTcl interpreter is i<strong>ns</strong>tructed to cre<strong>at</strong>e an objectof class “Agent/ECHO”. In this case, a dynamically-alloc<strong>at</strong>ed object is returned. This is the normal way new C++ shadowobjects are cre<strong>at</strong>ed.Once we have the object cre<strong>at</strong>ion set up, we will want to link C++ member variables with corresponding variables in the OTclnname space, so th<strong>at</strong> accesses to OTcl variables are actually backed by member variables in C++. Assume we would likeOTcl to be able to adjust the sending interval <strong>and</strong> the packet size. This is accomplished in the class’s co<strong>ns</strong>tructor:ECHO_Agent::ECHO_Agent() : Agent(PT_ECHO){bind_time("interval_", &interval_);bind("packetSize_", &size_);}Here, the C++ variables interval_ <strong>and</strong> size_ are linked to the OTcl i<strong>ns</strong>tance variables interval_ <strong>and</strong> packetSize_,respectively. Any read or modify oper<strong>at</strong>ion to the Otcl variables will result in a corresponding access to the underlying C++variables. <strong>The</strong> details of the bind() methods are described elsewhere (Section 3.4.2). <strong>The</strong> defined co<strong>ns</strong>tant PT_ECHO ispassed to the Agent() co<strong>ns</strong>tuctor so th<strong>at</strong> the Agent::allocpkt() method may set the packet type field used by the tracesupport (Section 26.5). In this case, PT_ECHO represents a new packet type <strong>and</strong> must be defined in ~<strong>ns</strong>/trace.h (Section 26.4).Once object cre<strong>at</strong>ion <strong>and</strong> variable binding is set up, we may want to cre<strong>at</strong>e methods implemented in C++ but which can beinvoked from OTcl (Section 3.4.4). <strong>The</strong>se are often control functio<strong>ns</strong> th<strong>at</strong> initi<strong>at</strong>e, termin<strong>at</strong>e or modify behavior. In our presentexample, we may wish to be able to start the ping query agent from OTcl using a “start” directive. This may be implementedas follows:int ECHO_Agent::comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv){if (argc == 2) {if (strcmp(argv[1], "start") == 0) {timeout(0);return (TCL_OK);}}return (Agent::comm<strong>and</strong>(argc, argv));}Here, the start() method available to OTcl simply calls the C++ member function timeout() which initi<strong>at</strong>es the firstpacket gener<strong>at</strong>ion <strong>and</strong> schedules the next. Note this class is so simple it does not even include a way to be stopped.105