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.

3.5 Class TclClassThis compiled class (class TclClass) is a pure virtual class. Classes derived from this base class provide two functio<strong>ns</strong>:co<strong>ns</strong>truct the interpreted class hierarchy to mirror the compiled class hierarchy; <strong>and</strong> provide methods to i<strong>ns</strong>tanti<strong>at</strong>e newTclObjects. Each such derived class is associ<strong>at</strong>ed with a particular compiled class in the compiled class hierarchy, <strong>and</strong> cani<strong>ns</strong>tanti<strong>at</strong>e new objects in the associ<strong>at</strong>ed class.As an example, co<strong>ns</strong>ider a class such as the class RenoTcpClass. It is derived from class TclClass, <strong>and</strong> is associ<strong>at</strong>edwith the class RenoTcpAgent. It will i<strong>ns</strong>tanti<strong>at</strong>e new objects in the class RenoTcpAgent. <strong>The</strong> compiled class hierarchyfor RenoTcpAgent is th<strong>at</strong> it derives from TcpAgent, th<strong>at</strong> in turn derives from Agent, th<strong>at</strong> in turn derives (roughly) fromTclObject. RenoTcpClass is defined asst<strong>at</strong>ic class RenoTcpClass: public TclClass {public:RenoTcpClass() : TclClass("Agent/TCP/Reno") {}TclObject* cre<strong>at</strong>e(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv) {return (new RenoTcpAgent());}} class_reno;We can make the following observ<strong>at</strong>io<strong>ns</strong> from this definition:1. <strong>The</strong> class defines only the co<strong>ns</strong>tructor, <strong>and</strong> one additional method, to cre<strong>at</strong>e i<strong>ns</strong>tances of the associ<strong>at</strong>ed TclObject.2. <strong>ns</strong> will execute the RenoTcpClass co<strong>ns</strong>tructor for the st<strong>at</strong>ic variable class_reno, when it is first started. This setsup the appropri<strong>at</strong>e methods <strong>and</strong> the interpreted class hierarchy.3. <strong>The</strong> co<strong>ns</strong>tructor specifies the interpreted class explicitly as Agent/TCP/Reno. This also specifies the interpretedclass hierarchy implicitly.Recall th<strong>at</strong> the convention in <strong>ns</strong> is to use the character slash (’/’) is a separ<strong>at</strong>or. For any given class A/B/C/D, theclass A/B/C/D is a sub-class of A/B/C, th<strong>at</strong> is itself a sub-class of A/B, th<strong>at</strong>, in turn, is a sub-class of A. A itself is asub-class of TclObject.In our case above, the TclClass co<strong>ns</strong>tructor cre<strong>at</strong>es three classes, Agent/TCP/Reno sub-class of Agent/TCP subclassof Agent sub-class of TclObject.4. This class is associ<strong>at</strong>ed with the class RenoTcpAgent; it cre<strong>at</strong>s new objects in this associ<strong>at</strong>ed class.5. <strong>The</strong> RenoTcpClass::cre<strong>at</strong>e method retur<strong>ns</strong> TclObjects in the class RenoTcpAgent.6. When the user specifies new Agent/TCP/Reno, the routine RenoTcpClass::cre<strong>at</strong>e is invoked.7. <strong>The</strong> arguments vector (argv) co<strong>ns</strong>ists of— argv[0] contai<strong>ns</strong> the name of the object.— argv[1...3] contain $self, $class, <strong>and</strong> $proc.Since cre<strong>at</strong>e is called through the i<strong>ns</strong>tance procedurecre<strong>at</strong>e-shadow, argv[3] contai<strong>ns</strong> cre<strong>at</strong>e-shadow.— argv[4] contain any additional arguments (passed as a string) provided by the user.<strong>The</strong> class Trace illustr<strong>at</strong>es argument h<strong>and</strong>ling by TclClass methods.class TraceClass : public TclClass {public:30

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

Saved successfully!

Ooh no, something went wrong!