00001 /* 00002 * Copyright (c) 1997 The 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 Network Research 00016 * Group at Lawrence Berkeley National 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 * This agent is paired with one or more ftp clients. 00036 * It expects to be the target of a FullTcpAgent. 00037 */ 00038 static const char rcsid[] = 00039 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/baytcp/ftps.cc,v 1.6 2001/09/06 22:09:41 haldar Exp $ ()"; 00040 00041 #include "tcp-full-bay.h" 00042 #include "tclcl.h" 00043 #include "random.h" 00044 #include "trace.h" 00045 #include "tcp.h" 00046 00047 class FtpSrvrAgent : public BayTcpAppAgent { 00048 public: 00049 FtpSrvrAgent(); 00050 int command(int argc, const char*const* argv); 00051 void recv(Packet*, BayFullTcpAgent*, int code); 00052 //void recv(Packet*, BayFullTcpAgent*); 00053 protected: 00054 double now() { return Scheduler::instance().clock(); } 00055 int min_response_; //number of bytes in min response file 00056 int max_response_; //number of bytes in max response file 00057 int filesize_; //file size in Bytes 00058 }; 00059 00060 00061 static class FtpSrvrClass : public TclClass { 00062 public: 00063 FtpSrvrClass() : TclClass("Agent/BayTcpApp/FtpServer") {} 00064 TclObject* create(int, const char*const*) { 00065 return (new FtpSrvrAgent()); 00066 } 00067 } class_ftps; 00068 00069 FtpSrvrAgent::FtpSrvrAgent() : BayTcpAppAgent(PT_NTYPE) 00070 { 00071 // bind("min_byte_response", &min_response_); 00072 // bind("max_byte_response", &max_response_); 00073 // bind_time("service_time", &service_time_); 00074 filesize_ = 0x10000000; 00075 } 00076 00077 //should only be called when a get is received from a client 00078 //need to make sure it goes to the right tcp connection 00079 00080 void FtpSrvrAgent::recv(Packet*, BayFullTcpAgent* tcp, int code) 00081 { 00082 if(code == DATA_PUSH) { 00083 int length = filesize_; 00084 //tells tcp-full with my mods to send FIN when empty 00085 tcp->advance(length, 1); 00086 } 00087 } 00088 00089 /* 00090 * set length 00091 */ 00092 int FtpSrvrAgent::command(int argc, const char*const* argv) 00093 { 00094 if (argc == 3) { 00095 if (strcmp(argv[1], "file_size") == 0) { 00096 filesize_ = atoi(argv[2]); 00097 return (TCL_OK); 00098 } 00099 } 00100 return (Agent::command(argc, argv)); 00101 } 00102
1.4.6