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

ftpc.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1994 Regents of the University of California.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the Computer Systems
00016  *      Engineering Group at Lawrence Berkeley Laboratory.
00017  * 4. Neither the name of the University nor of the Laboratory may be used
00018  *    to endorse or promote products derived from this software without
00019  *    specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  */
00033 
00034 /*
00035  * For use with "full tcp" model.
00036  */
00037 
00038 static const char rcsid[] =
00039     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/baytcp/ftpc.cc,v 1.5 2001/09/06 21:01:18 johnh Exp $ (LBL)";
00040 
00041 #include "tcp-full-bay.h"
00042 #include "tclcl.h"
00043 #include "trace.h"
00044 #include "random.h"
00045 #include "ftp.h"
00046 
00047 
00048 static class FtpClientClass : public TclClass {
00049 public:
00050         FtpClientClass() : TclClass("Agent/BayTcpApp/FtpClient") {}
00051         TclObject* create(int, const char*const*) {
00052                 return (new FtpClientAgent());
00053         }
00054 } class_ftpcli;
00055 
00056 FtpClientAgent::FtpClientAgent() : BayTcpAppAgent(PT_NTYPE), running_(0), newfile_timer_(this)
00057 {
00058 }
00059 
00060 void FtpClientAgent::start()
00061 {
00062         running_ = 1;
00063         newfile_timer_.resched(0.);
00064 }
00065 
00066 void FtpClientAgent::stop()
00067 {
00068         running_ = 0;
00069 }
00070 
00071 void FtpClientAgent::timeout(int event_type)
00072 {
00073         if (running_)
00074                 if(event_type == NEW_FILE)      {
00075                         if(sendget())   {
00076                                 state_ = REQ_SENT;
00077                                 start_trans_ = now();
00078                         }
00079                         else {
00080                                 printf("ftpclient:timeout erroneous tcp state\n");
00081                         }
00082                 }
00083 }
00084 
00085 //assumes 80 bytes
00086 int FtpClientAgent::sendget()
00087 {
00088         return tcp_->advance(80, 0);
00089 }
00090 
00091 //scheduled only when the tcp connection(s) are upcalling
00092 // ask for another file after a delay to allow connection to close
00093 // 6/8/00 shouldn't need the delay. Consider reducing or removing -kmn
00094 void FtpClientAgent::recv(Packet*, BayFullTcpAgent*, int code)
00095 {
00096   //at data complete time, schedule a "far out" event to ensure
00097   // simulator doesn't terminate
00098   if(running_ && code == DATA_PUSH) {
00099   state_ = DATA_RCVD;
00100   newfile_timer_.resched(5.0);
00101   }
00102   else if(running_ && code == CONNECTION_END) {
00103     state_ = END_RCVD;
00104     newfile_timer_.cancel();
00105     newfile_timer_.resched(.0);
00106   }
00107 }
00108 
00109 int FtpClientAgent::command(int argc, const char*const* argv)
00110 {
00111         Tcl& tcl = Tcl::instance();
00112         if (argc == 2) {
00113                 if (strcmp(argv[1], "start") == 0) {
00114                         start();
00115                         return(TCL_OK);
00116                 } else if (strcmp(argv[1], "stop") == 0) {
00117                         stop();
00118                         return(TCL_OK);
00119                 }
00120         } else if(argc == 3) {
00121                 if(strcmp(argv[1], "tcp") == 0) {
00122                         tcp_ = (BayFullTcpAgent*)TclObject::lookup(argv[2]);
00123                         if(tcp_ == 0) {
00124                                 tcl.resultf("no such agent %s", argv[2]);
00125                                 return(TCL_ERROR);
00126                         }
00127                         return(TCL_OK);
00128                 }
00129         }
00130         return (Agent::command(argc, argv));
00131 }
00132 
00133 
00134 void NewFileTimer::expire(Event *e) {
00135         a_->timeout(NEW_FILE);
00136 }

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