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.

39.1.4 Tra<strong>ns</strong>mitting user d<strong>at</strong>a over TCPTra<strong>ns</strong>mitting user d<strong>at</strong>a using TCP is trickier than doing th<strong>at</strong> over UDP, mainly because of TCP’s reassembly queue is onlyavailable for FullTcp. We deal with this problem by abstracting a TCP connection as a FIFO pipe.As indic<strong>at</strong>ed in section 38.2.4, tra<strong>ns</strong>mission of applic<strong>at</strong>ion d<strong>at</strong>a can be implemented via agent upcalls. Assuming we are usingTCP agents, all d<strong>at</strong>a are delivered in sequence, which mea<strong>ns</strong> we can view the TCP connection as a FIFO pipe. We emul<strong>at</strong>euser d<strong>at</strong>a tra<strong>ns</strong>mission over TCP as follows. We first provide buffer for applic<strong>at</strong>ion d<strong>at</strong>a <strong>at</strong> the sender. <strong>The</strong>n we count the bytesreceived <strong>at</strong> the receiver. When the receiver has got all bytes of the current d<strong>at</strong>a tra<strong>ns</strong>mission, it then gets the d<strong>at</strong>a directly fromthe sender. Class Applic<strong>at</strong>ion/TcpApp is used to implement this functionality.A TcpApp object contai<strong>ns</strong> a pointer to a tra<strong>ns</strong>port agent, presumably either a FullTcp or a SimpleTcp. 1 (Currently TcpAppdoesn’t support asymmetric TCP agents, i.e., sender is separ<strong>at</strong>ed from receiver). It provides the following OTcl interfaces:• connect: Connecting another TcpApp to this one. This connection is bi-directional, i.e., only one call to connectis needed, <strong>and</strong> d<strong>at</strong>a can be sent in either direction.• send: It takes two arguments: (nbytes, str). nbytes is the “nominal” size of applic<strong>at</strong>ion d<strong>at</strong>a. str is applic<strong>at</strong>iond<strong>at</strong>a in string form.In order to send applic<strong>at</strong>ion d<strong>at</strong>a in binary form, TcpApp provides a virtual C++ method send(int nbytes, intdsize, co<strong>ns</strong>t char *d<strong>at</strong>a). In fact, this is the method used to implement the OTcl method send. Because it’sdifficult to deal with binary d<strong>at</strong>a in Tcl, no OTcl interface is provided to h<strong>and</strong>le binary d<strong>at</strong>a. nbytes is the number of bytesto be tra<strong>ns</strong>mitted, dsize is the actual size of the array d<strong>at</strong>a.TcpApp provides a C++ virtual method process_d<strong>at</strong>a(int size, char*d<strong>at</strong>a) to h<strong>and</strong>le the received d<strong>at</strong>a. <strong>The</strong>default h<strong>and</strong>ling is to tre<strong>at</strong> the d<strong>at</strong>a as a tcl script <strong>and</strong> evalu<strong>at</strong>e the script. But it’s easy to derive a class to provide other typesof h<strong>and</strong>ling.Here is an example of using Applic<strong>at</strong>ion/TcpApp. A similar example is Test/TcpApp-2node in <strong>ns</strong>/tcl/test/test-suitewebcache.tcl.First, we cre<strong>at</strong>e FullTcp agents <strong>and</strong> connect them:set tcp1 [new Agent/TCP/FullTcp]set tcp2 [new Agent/TCP/FullTcp]# Set TCP parameters here, e.g., window_, iss_, . . .$<strong>ns</strong> <strong>at</strong>tach-agent $n1 $tcp1$<strong>ns</strong> <strong>at</strong>tach-agent $n2 $tcp2$<strong>ns</strong> connect $tcp1 $tcp2$tcp2 listen<strong>The</strong>n we cre<strong>at</strong>e TcpApps <strong>and</strong> connect them:set app1 [new Applic<strong>at</strong>ion/TcpApp $tcp1]set app2 [new Applic<strong>at</strong>ion/TcpApp $tcp2]$app1 connect $app21 A SimpleTcp agent is used solely for web caching simul<strong>at</strong>io<strong>ns</strong>. It is actually an UDP agent. It has neither error recovery nor flow/congestion control.It doesn’t do packet segment<strong>at</strong>ion. Assuming a loss-free network <strong>and</strong> in-order packet delivery, SimpleTcp agent simplifies the trace files <strong>and</strong> hence aids thedebugging of applic<strong>at</strong>ion protocols, which, in our case, is the web cache co<strong>ns</strong>istency protocol.344

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

Saved successfully!

Ooh no, something went wrong!