• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/webcache/tcpapp.h

00001 /*
00002  * Copyright (c) Xerox Corporation 1998. All rights reserved.
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by the
00006  * Free Software Foundation; either version 2 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with this program; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  * Linking this file statically or dynamically with other modules is making
00019  * a combined work based on this file.  Thus, the terms and conditions of
00020  * the GNU General Public License cover the whole combination.
00021  *
00022  * In addition, as a special exception, the copyright holders of this file
00023  * give you permission to combine this file with free software programs or
00024  * libraries that are released under the GNU LGPL and with code included in
00025  * the standard release of ns-2 under the Apache 2.0 license or under
00026  * otherwise-compatible licenses with advertising requirements (or modified
00027  * versions of such code, with unchanged license).  You may copy and
00028  * distribute such a system following the terms of the GNU GPL for this
00029  * file and the licenses of the other code concerned, provided that you
00030  * include the source code of that other code when and as the GNU GPL
00031  * requires distribution of source code.
00032  *
00033  * Note that people who make modified versions of this file are not
00034  * obligated to grant this special exception for their modified versions;
00035  * it is their choice whether to do so.  The GNU General Public License
00036  * gives permission to release a modified version without this exception;
00037  * this exception also makes it possible to release a modified version
00038  * which carries forward this exception.
00039  *
00040  * $Header: /cvsroot/nsnam/ns-2/webcache/tcpapp.h,v 1.15 2005/08/26 05:05:32 tomh Exp $
00041  */
00042 
00043 //
00044 // TcpApp - Transmitting real application data via TCP
00045 //
00046 // XXX Model a TCP connection as a FIFO byte stream. It shouldn't be used 
00047 // if this assumption is violated.
00048 
00049 #ifndef ns_tcpapp_h
00050 #define ns_tcpapp_h
00051 
00052 #include "ns-process.h"
00053 #include "app.h"
00054 
00055 class CBuf { 
00056 public:
00057         CBuf(AppData *c, int nbytes);
00058         ~CBuf() {
00059                 if (data_ != NULL)
00060                         delete data_;
00061         }
00062         AppData* data() { return data_; }
00063         int size() { return size_; }
00064         int bytes() { return nbytes_; }
00065 
00066 #ifdef TCPAPP_DEBUG     
00067         // debug only
00068         double& time() { return time_; }
00069 #endif
00070 
00071 protected:
00072         friend class CBufList;
00073         AppData *data_;
00074         int size_;
00075         int nbytes_;    // Total length of this transmission
00076         CBuf *next_;
00077 
00078 #ifdef TCPAPP_DEBUG
00079         // for debug only 
00080         double time_; 
00081 #endif
00082 };
00083 
00084 // A FIFO queue
00085 class CBufList {
00086 public: 
00087 #ifdef TCPAPP_DEBUG 
00088         CBufList() : head_(NULL), tail_(NULL), num_(0) {}
00089 #else
00090         CBufList() : head_(NULL), tail_(NULL) {}
00091 #endif
00092         ~CBufList();
00093 
00094         void insert(CBuf *cbuf);
00095         CBuf* detach();
00096 
00097 protected:
00098         CBuf *head_;
00099         CBuf *tail_;
00100 #ifdef TCPAPP_DEBUG
00101         int num_;
00102 #endif
00103 };
00104 
00105 
00106 class TcpApp : public Application {
00107 public:
00108         TcpApp(Agent *tcp);
00109         ~TcpApp();
00110 
00111         virtual void recv(int nbytes);
00112         virtual void send(int nbytes, AppData *data);
00113 
00114         void connect(TcpApp *dst) { dst_ = dst; }
00115 
00116         virtual void process_data(int size, AppData* data);
00117         virtual AppData* get_data(int&, AppData*) {
00118                 // Not supported
00119                 abort();
00120                 return NULL;
00121         }
00122 
00123         // Do nothing when a connection is terminated
00124         virtual void resume();
00125 
00126 protected:
00127         virtual int command(int argc, const char*const* argv);
00128         CBuf* rcvr_retrieve_data() { return cbuf_.detach(); }
00129 
00130         // We don't have start/stop
00131         virtual void start() { abort(); } 
00132         virtual void stop() { abort(); }
00133 
00134         TcpApp *dst_;
00135         CBufList cbuf_;
00136         CBuf *curdata_;
00137         int curbytes_;
00138 };
00139 
00140 #endif // ns_tcpapp_h

Generated on Tue Aug 10 2010 16:16:09 for ns-2.33 by  doxygen 1.7.1