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.

38.2.2 Attaching applic<strong>at</strong>io<strong>ns</strong> to agentsAfter applic<strong>at</strong>io<strong>ns</strong> are i<strong>ns</strong>tanti<strong>at</strong>ed, they must be connected to a tra<strong>ns</strong>port agent. <strong>The</strong> <strong>at</strong>tach-agent method can be used to<strong>at</strong>tach an applic<strong>at</strong>ion to an agent, as follows:set ftp1 [new Applic<strong>at</strong>ion/FTP]$ftp1 <strong>at</strong>tach-agent $src<strong>The</strong> following shortcut accomplishes the same result:set ftp1 [$src <strong>at</strong>tach-app FTP]<strong>The</strong> <strong>at</strong>tach-agent method, which is also used by <strong>at</strong>tach-app, is implemented in C++. It sets the agent_ pointer in classApplic<strong>at</strong>ion to point to the tra<strong>ns</strong>port agent, <strong>and</strong> then it calls <strong>at</strong>tachApp() in agent.cc to set the app_ pointerto point back to the applic<strong>at</strong>ion. By maintaining this binding only in C++, OTcl-level i<strong>ns</strong>tvars pointers are avoided <strong>and</strong>co<strong>ns</strong>istency between OTcl <strong>and</strong> C++ is guaranteed. <strong>The</strong> OTcl-level comm<strong>and</strong> [$ftp1 agent] can be used by applic<strong>at</strong>io<strong>ns</strong>to obtain the h<strong>and</strong>ler for the tra<strong>ns</strong>port agent.38.2.3 Using tra<strong>ns</strong>port agents via system callsOnce tra<strong>ns</strong>port agents have been configured <strong>and</strong> applic<strong>at</strong>io<strong>ns</strong> <strong>at</strong>tached, applic<strong>at</strong>io<strong>ns</strong> can use tra<strong>ns</strong>port services via the followingsystem calls. <strong>The</strong>se calls can be invoked <strong>at</strong> either OTcl or C++ level, thereby allowing applic<strong>at</strong>io<strong>ns</strong> to be coded in either C++or OTcl. <strong>The</strong>se functio<strong>ns</strong> have been implemented as virtual functio<strong>ns</strong> in the base class Agent, <strong>and</strong> can be redefined asneeded by derived Agents.• send(int nbytes)—Send nbytes of d<strong>at</strong>a to peer. For TCP agents, if nbytes == -1, this corresponds to an“infinite” send; i.e., the TCP agent will act as if its send buffer is continually replenished by the applic<strong>at</strong>ion.• sendmsg(int nbytes, co<strong>ns</strong>t char* flags = 0)—Identical to send(int nbytes), except th<strong>at</strong> it passesan additional string flags. Currently one flag value, “MSG_EOF,” is defined; MSG_EOF specifies th<strong>at</strong> this is the lastb<strong>at</strong>ch of d<strong>at</strong>a th<strong>at</strong> the applic<strong>at</strong>ion will submit, <strong>and</strong> serves as an implied close (so th<strong>at</strong> TCP can send FIN with d<strong>at</strong>a).• close()—Requests the agent to close the connection (only applicable for TCP).• listen()—Requests the agent to listen for new connectio<strong>ns</strong> (only applicable for Full TCP).• set_pkttype(int pkttype)—This function sets the type_ variable in the agent to pkttype. Packet typesare defined in packet.h. This function is used to override the tra<strong>ns</strong>port layer packet type for tracing purposes.Note th<strong>at</strong> certain calls are not applicable for certain agents; e.g., a call to close() a UDP connection results in a no-op.Additional calls can be implemented in specialized agents, provided th<strong>at</strong> they are made public member functio<strong>ns</strong>.38.2.4 Agent upcalls to applic<strong>at</strong>io<strong>ns</strong>Since presently in <strong>ns</strong> there is no actual d<strong>at</strong>a being passed between applic<strong>at</strong>io<strong>ns</strong>, agents can i<strong>ns</strong>tead announce to applic<strong>at</strong>io<strong>ns</strong>the occurrence of certain events <strong>at</strong> the tra<strong>ns</strong>port layer through “upcalls.” For example, applic<strong>at</strong>io<strong>ns</strong> can be notified of thearrival of a number of bytes of d<strong>at</strong>a; this inform<strong>at</strong>ion may aid the applic<strong>at</strong>ion in modelling real-world applic<strong>at</strong>ion behaviormore closely. Two basic “upcalls” have been implemented in base class Applic<strong>at</strong>ion <strong>and</strong> in the tra<strong>ns</strong>port agents:333

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

Saved successfully!

Ooh no, something went wrong!