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 ...
virtual void process_data(int size, char* data) = 0;virtual void send_data(int size, char* data = 0);protected:Process* target_;};Process enables Application to link together.39.1.3 Transmitting user data over UDPCurrently there is no support in class Agent to transmit user data. There are two ways to transmit a serialized ADU throughtransport agents. First, for UDP agent (and all agents derived from there), we can derive from class UDP and add a newmethod send(int nbytes, char *userdata) to pass user data from Application to Agent. To pass data from anAgent to an Application is somewhat trickier: each agent has a pointer to its attached application, we dynamically cast thispointer to an AppConnector and then call AppConnector::process_data().As an example, we illustrate how class HttpInvalAgent is implemented. It is based on UDP, and is intended to deliver webcache invalidation messages (ns/webcache/inval-agent.h). It is defined as:class HttpInvalAgent : public Agent {public:HttpInvalAgent();virtual void recv(Packet *, Handler *);virtual void send(int realsize, AppData* data);protected:int off_inv_;};Here recv(Packet*, Handler*) overridden to extract user data, and a new send(int, AppData*) is providedto include user data in packetes. An application (HttpApp) is attached to an HttpInvalAgent using Agent::attachApp()(a dynamic cast is needed). In send(), the following code is used to write user data from AppData to the user data area in apacket:Packet *pkt = allocpkt(data->size());hdr_inval *ih = (hdr_inval *)pkt->access(off_inv_);ih->size() = data->size();char *p = (char *)pkt->accessdata();data->pack(p);In recv(), the following code is used to read user data from packet and to deliver to the attached application:hdr_inval *ih = (hdr_inval *)pkt->access(off_inv_);((HttpApp*)app_)->process_data(ih->size(), (char *)pkt->accessdata());Packet::free(pkt);343
39.1.4 Transmitting user data over TCPTransmitting user data using TCP is trickier than doing that 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 indicated in section 38.2.4, transmission of application data can be implemented via agent upcalls. Assuming we are usingTCP agents, all data are delivered in sequence, which means we can view the TCP connection as a FIFO pipe. We emulateuser data transmission over TCP as follows. We first provide buffer for application data at the sender. Then we count the bytesreceived at the receiver. When the receiver has got all bytes of the current data transmission, it then gets the data directly fromthe sender. Class Application/TcpApp is used to implement this functionality.A TcpApp object contains a pointer to a transport agent, presumably either a FullTcp or a SimpleTcp. 1 (Currently TcpAppdoesn’t support asymmetric TCP agents, i.e., sender is separated 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, and data can be sent in either direction.• send: It takes two arguments: (nbytes, str). nbytes is the “nominal” size of application data. str is applicationdata in string form.In order to send application data in binary form, TcpApp provides a virtual C++ method send(int nbytes, intdsize, const char *data). In fact, this is the method used to implement the OTcl method send. Because it’sdifficult to deal with binary data in Tcl, no OTcl interface is provided to handle binary data. nbytes is the number of bytesto be transmitted, dsize is the actual size of the array data.TcpApp provides a C++ virtual method process_data(int size, char*data) to handle the received data. Thedefault handling is to treat the data as a tcl script and evaluate the script. But it’s easy to derive a class to provide other typesof handling.Here is an example of using Application/TcpApp. A similar example is Test/TcpApp-2node in ns/tcl/test/test-suitewebcache.tcl.First, we create FullTcp agents and connect them:set tcp1 [new Agent/TCP/FullTcp]set tcp2 [new Agent/TCP/FullTcp]# Set TCP parameters here, e.g., window_, iss_, . . .$ns attach-agent $n1 $tcp1$ns attach-agent $n2 $tcp2$ns connect $tcp1 $tcp2$tcp2 listenThen we create TcpApps and connect them:set app1 [new Application/TcpApp $tcp1]set app2 [new Application/TcpApp $tcp2]$app1 connect $app21 A SimpleTcp agent is used solely for web caching simulations. It is actually an UDP agent. It has neither error recovery nor flow/congestion control.It doesn’t do packet segmentation. Assuming a loss-free network and in-order packet delivery, SimpleTcp agent simplifies the trace files and hence aids thedebugging of application protocols, which, in our case, is the web cache consistency protocol.344
- Page 293 and 294: 34.2.1 The Base TCP SinkThe base TC
- Page 295 and 296: Agent/TCP/FullTcp set dupseg_fix_ t
- Page 297 and 298: 34.5 Tracing TCP DynamicsThe behavi
- Page 299 and 300: Chapter 35SCTP AgentsThis chapter d
- Page 301 and 302: Figure 35.1: Example of a Multihome
- Page 303 and 304: Note: the actual value of these tra
- Page 305 and 306: 1.526624 1 4 sctp 1500 -------D 0 1
- Page 307 and 308: $ns at 5.0 "finish"$ns run35.5.2 Mu
- Page 309 and 310: Chapter 36Agent/SRMThis chapter des
- Page 311 and 312: 36.1.2 Other Configuration Paramete
- Page 313 and 314: 3.6274 n 0 m r 1 type repair servi
- Page 315 and 316: 3.6029 n 3 m r 2 Q NTIMER at 3.730
- Page 317 and 318: 36.4 Loss Detection—The Class SRM
- Page 319 and 320: same packet. The repair objet does
- Page 321 and 322: }hdr_asrm* seh = (hdr_asrm*) p->acc
- Page 323 and 324: set grp [Node allocaddr]$srm set ds
- Page 325 and 326: #set up the multicast routingDM set
- Page 327 and 328: 37.3 Architecture of the PLM Protoc
- Page 329 and 330: We add in void PLMLossMonitor::recv
- Page 331 and 332: Part VIApplication330
- Page 333 and 334: Traffic generatorsApplication/Traff
- Page 335 and 336: • recv(int nbytes)—Announces th
- Page 337 and 338: 1. EXPOO_Traffic—generates traffi
- Page 339 and 340: set src [new Agent/UDP]set sink [ne
- Page 341 and 342: Application FTP FTP objects produce
- Page 343: send_data(ADU)Application(HttpApp,
- Page 347 and 348: and teardown of connections. Only O
- Page 349 and 350: TclObjectPagePoolPagePool/CompMathP
- Page 351 and 352: PagePool/ProxyTrace takes these two
- Page 353 and 354: }int id_; // object IDWebTrafSessio
- Page 355 and 356: An Http/Server object waits for inc
- Page 357 and 358: set tmp [new RandomVariable/Exponen
- Page 359 and 360: Object Type Event Type Explaination
- Page 361 and 362: Chapter 40Worm ModelIn this chapter
- Page 363 and 364: $w local-p 0.5Following are some co
- Page 365 and 366: (nsnode) clientcloudPackM ime(nsnod
- Page 367 and 368: HTTP responsesclients servers Delay
- Page 369 and 370: 41.5 Commands at a GlanceThe follow
- Page 371 and 372: • HTTP response size (bytes)• s
- Page 373 and 374: Chapter 42Session-level Packet Dist
- Page 375 and 376: 42.1.2 Inserting a Loss ModuleWhen
- Page 377 and 378: Delay and Loss Modules Each receive
- Page 379 and 380: Chapter 43Asim: approximate analyti
- Page 381 and 382: set n(1) [$ns node]set link(0:1) [$
- Page 383 and 384: Part VIIIEmulation382
- Page 385 and 386: When using the emulation mode, a sp
- Page 387 and 388: set intf [$pf1 open readonly]puts "
- Page 389 and 390: puts "install nets into taps..."$a0
- Page 391 and 392: Chapter 45Nam45.1 IntroductionNam i
- Page 393 and 394: • Button 6 (Chevron logo) - Close
virtual void process_d<strong>at</strong>a(int size, char* d<strong>at</strong>a) = 0;virtual void send_d<strong>at</strong>a(int size, char* d<strong>at</strong>a = 0);protected:Process* target_;};Process enables Applic<strong>at</strong>ion to link together.39.1.3 Tra<strong>ns</strong>mitting user d<strong>at</strong>a over UDPCurrently there is no support in class Agent to tra<strong>ns</strong>mit user d<strong>at</strong>a. <strong>The</strong>re are two ways to tra<strong>ns</strong>mit a serialized ADU throughtra<strong>ns</strong>port agents. First, for UDP agent (<strong>and</strong> all agents derived from there), we can derive from class UDP <strong>and</strong> add a newmethod send(int nbytes, char *userd<strong>at</strong>a) to pass user d<strong>at</strong>a from Applic<strong>at</strong>ion to Agent. To pass d<strong>at</strong>a from anAgent to an Applic<strong>at</strong>ion is somewh<strong>at</strong> trickier: each agent has a pointer to its <strong>at</strong>tached applic<strong>at</strong>ion, we dynamically cast thispointer to an AppConnector <strong>and</strong> then call AppConnector::process_d<strong>at</strong>a().As an example, we illustr<strong>at</strong>e how class HttpInvalAgent is implemented. It is based on UDP, <strong>and</strong> is intended to deliver webcache invalid<strong>at</strong>ion messages (<strong>ns</strong>/webcache/inval-agent.h). It is defined as:class HttpInvalAgent : public Agent {public:HttpInvalAgent();virtual void recv(Packet *, H<strong>and</strong>ler *);virtual void send(int realsize, AppD<strong>at</strong>a* d<strong>at</strong>a);protected:int off_inv_;};Here recv(Packet*, H<strong>and</strong>ler*) overridden to extract user d<strong>at</strong>a, <strong>and</strong> a new send(int, AppD<strong>at</strong>a*) is providedto include user d<strong>at</strong>a in packetes. An applic<strong>at</strong>ion (HttpApp) is <strong>at</strong>tached to an HttpInvalAgent using Agent::<strong>at</strong>tachApp()(a dynamic cast is needed). In send(), the following code is used to write user d<strong>at</strong>a from AppD<strong>at</strong>a to the user d<strong>at</strong>a area in apacket:Packet *pkt = allocpkt(d<strong>at</strong>a->size());hdr_inval *ih = (hdr_inval *)pkt->access(off_inv_);ih->size() = d<strong>at</strong>a->size();char *p = (char *)pkt->accessd<strong>at</strong>a();d<strong>at</strong>a->pack(p);In recv(), the following code is used to read user d<strong>at</strong>a from packet <strong>and</strong> to deliver to the <strong>at</strong>tached applic<strong>at</strong>ion:hdr_inval *ih = (hdr_inval *)pkt->access(off_inv_);((HttpApp*)app_)->process_d<strong>at</strong>a(ih->size(), (char *)pkt->accessd<strong>at</strong>a());Packet::free(pkt);343