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.

10.5.5 Implementing TimersAs described in the following chapter (Chapter 11), specific timer classes must be derived from an abstract base classTimerH<strong>and</strong>ler defined in ~<strong>ns</strong>/timer-h<strong>and</strong>ler.h. I<strong>ns</strong>tances of these subclasses can then be used as various agent timers. Anagent may wish to override the Agent::timeout() method (which does nothing). In the case of the Tahoe TCP agent,two timers are used: a delayed send timer delsnd_timer_ <strong>and</strong> a retra<strong>ns</strong>mission timer rtx_timer_. We describe theretra<strong>ns</strong>mission timer in TCP (Section 11.1.2) as an example of timer usage.10.6 Cre<strong>at</strong>ing a New AgentTo cre<strong>at</strong>e a new agent, one has to do the following:1. decide its inheritance structure (Section 10.6.1), <strong>and</strong> cre<strong>at</strong>e the appropri<strong>at</strong>e class definitio<strong>ns</strong>,2. define the recv() <strong>and</strong> timeout() methods (Section 10.6.2),3. define any necessary timer classes,4. define OTcl linkage functio<strong>ns</strong> (Section 10.6.3),5. write the necessary OTcl code to access the agent (Section 10.6.4).<strong>The</strong> action required to cre<strong>at</strong>e <strong>and</strong> agent can be illustr<strong>at</strong>ed by mea<strong>ns</strong> of a very simple example. Suppose we wish to co<strong>ns</strong>tructan agent which performs the ICMP ECHO REQUEST/REPLY (or “ping”) oper<strong>at</strong>io<strong>ns</strong>.10.6.1 Example: A “ping” requestor (Inheritance Structure)Deciding on the inheritance structure is a m<strong>at</strong>ter of personal choice, but is likely to be rel<strong>at</strong>ed to the layer <strong>at</strong> which the agentwill oper<strong>at</strong>e <strong>and</strong> its assumptio<strong>ns</strong> on lower layer functionality. <strong>The</strong> simplest type of Agent, connectionless d<strong>at</strong>agram-orientedtra<strong>ns</strong>port, is the Agent/UDP base class. Traffic gener<strong>at</strong>ors can easily be connected to UDP Agents. For protocols wishing touse a connection-oriented stream tra<strong>ns</strong>port (like TCP), the various TCP Agents could be used. Finally, if a new tra<strong>ns</strong>port or“sub-tra<strong>ns</strong>port” protocol is to be developed, using Agent as the base class would likely be the best choice. In our example,we’ll use Agent as the base class, given th<strong>at</strong> we are co<strong>ns</strong>tructing an agent logically belonging to the IP layer (or just above it).We may use the following class definitio<strong>ns</strong>:class ECHO_Timer;class ECHO_Agent : public Agent {public:ECHO_Agent();int comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv);protected:void timeout(int);void sendit();double interval_;ECHO_Timer echo_timer_;};class ECHO_Timer : public TimerH<strong>and</strong>ler {103

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

Saved successfully!

Ooh no, something went wrong!