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.

In the configur<strong>at</strong>ion script, the first five lines of code alloc<strong>at</strong>es two new FullTcp agents, <strong>at</strong>taches them to the correct nodes,<strong>and</strong> "connects" them together (assig<strong>ns</strong> the correct destin<strong>at</strong>ion addresses to each agent). <strong>The</strong> next two lines configure theTCP agents further, placing one of them in LISTEN mode. Next, ftp1 is defined as a new FTP Applic<strong>at</strong>ion, <strong>and</strong> the<strong>at</strong>tach-agent method is called in C++ (app.cc).<strong>The</strong> ftp1 applic<strong>at</strong>ion is started <strong>at</strong> time 0:Applic<strong>at</strong>ion/FTP i<strong>ns</strong>tproc start {} {[$self agent] send -1; # Send indefinitely}Altern<strong>at</strong>ively, the FTP applic<strong>at</strong>ion could have been implemented in C++ as follows:void FTP::start(){agent_->send(-1);}// Send indefinitelySince the FTP applic<strong>at</strong>ion does not make use of callbacks, these functio<strong>ns</strong> are null in C++ <strong>and</strong> no OTcl callbacks are made.38.3 <strong>The</strong> class TrafficGener<strong>at</strong>orTrafficGener<strong>at</strong>or is an abstract C++ class defined as follows:class TrafficGener<strong>at</strong>or : public Applic<strong>at</strong>ion {public:TrafficGener<strong>at</strong>or();virtual double next_interval(int &) = 0;virtual void init() {}virtual double interval() { return 0; }virtual int on() { return 0; }virtual void timeout();virtual void recv() {}virtual void resume() {}protected:virtual void start();virtual void stop();double nextPkttime_;int size_;int running_;TrafficTimer timer_;};<strong>The</strong> pure virtual function next_interval() retur<strong>ns</strong> the time until the next packet is cre<strong>at</strong>ed <strong>and</strong> also sets the size in bytesof the next packet. <strong>The</strong> function start() calls init(void) <strong>and</strong> starts the timer. <strong>The</strong> function timeout() sends a packet <strong>and</strong>reschedules the next timeout. <strong>The</strong> function stop() cancels any pending tra<strong>ns</strong>missio<strong>ns</strong>. Callbacks are typically not used fortraffic gener<strong>at</strong>ors, so these functio<strong>ns</strong> (recv, resume) are null.Currently, there are four C++ classes derived from the class TrafficGener<strong>at</strong>or:335

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

Saved successfully!

Ooh no, something went wrong!