Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

tcp-simple.cc

Go to the documentation of this file.
00001 // Copyright (c) Xerox Corporation 1998. All rights reserved.
00002 //
00003 // License is granted to copy, to use, and to make and to use derivative
00004 // works for research and evaluation purposes, provided that Xerox is
00005 // acknowledged in all documentation pertaining to any such copy or
00006 // derivative work. Xerox grants no other licenses expressed or
00007 // implied. The Xerox trade name should not be used in any advertising
00008 // without its written permission. 
00009 //
00010 // XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00011 // MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00012 // FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00013 // express or implied warranty of any kind.
00014 //
00015 // These notices must be retained in any copies of any part of this
00016 // software. 
00017 //
00018 // SimpleTcp: Only share the same interface as FullTcp.
00019 // It's inherited from FullTcp solely for interface reason... :(
00020 //
00021 // If we have interface declaration independent from class type definition,
00022 // we'll be better off.
00023 //
00024 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/tcp-simple.cc,v 1.9 2000/09/01 03:04:12 haoboy Exp $
00025 
00026 #include <stdlib.h>
00027 #include "tclcl.h"
00028 #include "packet.h"
00029 #include "ip.h"
00030 #include "app.h"
00031 #include "tcp-simple.h"
00032 
00033 static class SimpleTcpClass : public TclClass {
00034 public:
00035         SimpleTcpClass() : TclClass("Agent/TCP/SimpleTcp") {}
00036         TclObject* create(int, const char*const*) {
00037                 return (new SimpleTcpAgent());
00038         }
00039 } class_simple_tcp_agent;
00040 
00041 SimpleTcpAgent::SimpleTcpAgent() : TcpAgent(), seqno_(0)
00042 {
00043 }
00044 
00045 // XXX Do *NOT* support infinite send of TCP (bytes == -1).
00046 void SimpleTcpAgent::sendmsg(int bytes, const char* /*flags*/)
00047 {
00048         if (bytes == -1) {
00049                 fprintf(stderr, 
00050 "SimpleTcp doesn't support infinite send. Do not use FTP::start(), etc.\n");
00051                 return;
00052         }
00053         // Simply sending out bytes out to target_
00054         curseq_ += bytes;
00055         seqno_ ++;
00056 
00057         Packet *p = allocpkt();
00058         hdr_tcp *tcph = HDR_TCP(p);
00059         tcph->seqno() = seqno_;
00060         tcph->ts() = Scheduler::instance().clock();
00061         tcph->ts_echo() = ts_peer_;
00062         hdr_cmn *th = HDR_CMN(p);
00063         th->size() = bytes + tcpip_base_hdr_size_;
00064         send(p, 0);
00065 }
00066 
00067 void SimpleTcpAgent::recv(Packet *pkt, Handler *)
00068 {
00069         hdr_cmn *th = HDR_CMN(pkt);
00070         int datalen = th->size() - tcpip_base_hdr_size_;
00071         if (app_)
00072                 app_->recv(datalen);
00073         // No lastbyte_ callback, because no packet fragmentation.
00074         Packet::free(pkt);
00075 }
00076 
00077 int SimpleTcpAgent::command(int argc, const char*const* argv)
00078 {
00079         // Copy FullTcp's tcl interface
00080 
00081         if (argc == 2) {
00082                 if (strcmp(argv[1], "listen") == 0) {
00083                         // Do nothing
00084                         return (TCL_OK);
00085                 }
00086                 if (strcmp(argv[1], "close") == 0) {
00087                         // Call done{} to match tcp-full's syntax
00088                         Tcl::instance().evalf("%s done", name());
00089                         return (TCL_OK);
00090                 }
00091         }
00092         return (TcpAgent::command(argc, argv));
00093 }

Generated on Tue Apr 20 12:14:35 2004 for NS2.26SourcesOriginal by doxygen 1.3.3