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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public:ECHO_Timer(ECHO_Agent *a) : TimerH<strong>and</strong>ler() { a_ = a; }protected:virtual void expire(Event *e);ECHO_Agent *a_;};10.6.2 <strong>The</strong> recv() <strong>and</strong> timeout() Methods<strong>The</strong> recv() method is not defined here, as this agent represents a request function <strong>and</strong> will generally not be receiving eventsor packets 1 . By not defining the recv() method, the base class version of recv() (i.e., Connector::recv()) is used. <strong>The</strong>timeout() method is used to periodically send request packets. <strong>The</strong> following timeout() method is used, along with ahelper method, sendit():void ECHO_Agent::timeout(int){sendit();echo_timer_.resched(interval_);}void ECHO_Agent::sendit(){Packet* p = allocpkt();ECHOHeader *eh = ECHOHeader::access(p->bits());eh->timestamp() = Scheduler::i<strong>ns</strong>tance().clock();send(p, 0); // Connector::send()}void ECHO_Timer::expire(Event *e){a_->timeout(0);}<strong>The</strong> timeout() method simply arranges for sendit() to be executed every interval_ seconds. <strong>The</strong> sendit() methodcre<strong>at</strong>es a new packet with most of its header fields already set up by allocpkt(). <strong>The</strong> packet is only lacks the current timestamp. <strong>The</strong> call to access() provides for a structured interface to the packet header fields, <strong>and</strong> is used to set the timestampfield. Note th<strong>at</strong> this agent uses its own special header (“ECHOHeader”). <strong>The</strong> cre<strong>at</strong>ion <strong>and</strong> use of packet headers is describedin l<strong>at</strong>er chapter (Chapter 12); to send the packet to the next dow<strong>ns</strong>tream node, Connector::send() is invoked without ah<strong>and</strong>ler.10.6.3 Linking the “ping” Agent with OTclWe have the methods <strong>and</strong> mechanisms for establishing OTcl Linkage earlier (Chapter 3). This section is a brief review of theessential fe<strong>at</strong>ures of th<strong>at</strong> earlier chapter, <strong>and</strong> describes the minimum functionality required to cre<strong>at</strong>e the ping agent.<strong>The</strong>re are three items we must h<strong>and</strong>le to properly link our agent with Otcl. First we need to establish a mapping between theOTcl name for our class <strong>and</strong> the actual object cre<strong>at</strong>ed when an i<strong>ns</strong>tanti<strong>at</strong>ion of the class is requested in OTcl. This is done asfollows:1 This is perhaps unrealistically simple. An ICMP ECHO REQUEST agent would likely wish to process ECHO REPLY messages.104

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

Saved successfully!

Ooh no, something went wrong!