• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/empweb/empftp.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * empftp.h
00005  * Copyright (C) 2001 by the University of Southern California
00006  * $Id: empftp.h,v 1.5 2005/08/25 18:58:05 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 
00048 //
00049 // Empirical FTP traffic model that simulates FTP traffic based on a set of
00050 // CDF (Cumulative Distribution Function) data derived from live tcpdump trace
00051 // The structure of this file is largely borrowed from empweb.h
00052 //
00053 
00054 #ifndef ns_empftp_h
00055 #define ns_empftp_h
00056 
00057 #include "ranvar.h"
00058 #include "random.h"
00059 #include "timer-handler.h"
00060 
00061 #include "lib/bsd-list.h"
00062 #include "node.h"
00063 #include "tcp.h"
00064 #include "tcp-sink.h"
00065 #include "persconn.h"
00066 
00067 
00068 class EmpFtpTrafPool;
00069 
00070 class EmpFtpTrafSession : public TimerHandler {
00071 public: 
00072         EmpFtpTrafSession(EmpFtpTrafPool *mgr, int np, int id) : 
00073                 rvInterFile_(NULL), rvFileSize_(NULL),
00074                 rvServerSel_(NULL), 
00075                 rvServerWin_(NULL), rvClientWin_(NULL),
00076                 mgr_(mgr), nFile_(np), curFile_(0), 
00077                 id_(id) {}
00078         virtual ~EmpFtpTrafSession();
00079 
00080         // Queried by individual pages/objects
00081         inline EmpiricalRandomVariable*& interFile() { return rvInterFile_; }
00082         inline EmpiricalRandomVariable*& fileSize() { return rvFileSize_; }
00083         inline EmpiricalRandomVariable*& serverSel() { return rvServerSel_; }
00084 
00085         inline EmpiricalRandomVariable*& serverWin() { return rvServerWin_; }
00086         inline EmpiricalRandomVariable*& clientWin() { return rvClientWin_; }
00087 
00088         inline void setServer(Node* s) { src_ = s; }
00089         inline void setClient(Node* c) { dst_ = c; }
00090 
00091         void sendFile(int obj, int size);
00092         inline int id() const { return id_; }
00093         inline EmpFtpTrafPool* mgr() { return mgr_; }
00094 
00095         static int LASTFILE_;
00096 
00097 private:
00098         virtual void expire(Event *e = 0);
00099         virtual void handle(Event *e);
00100 
00101         EmpiricalRandomVariable *rvInterFile_, *rvFileSize_, *rvServerSel_;
00102         EmpiricalRandomVariable *rvServerWin_, *rvClientWin_;
00103 
00104         EmpFtpTrafPool* mgr_;
00105         Node* src_;             
00106         Node* dst_;             
00107         int nFile_, curFile_ ;
00108         int id_;
00109 
00110 
00111 };
00112 
00113 class EmpFtpTrafPool : public PagePool {
00114 public: 
00115         EmpFtpTrafPool(); 
00116         virtual ~EmpFtpTrafPool(); 
00117 
00118         inline void doneSession(int idx) { 
00119 
00120                 assert((idx>=0) && (idx<nSession_) && (session_[idx]!=NULL));
00121                 if (isdebug()) {
00122                         printf("deleted session %d \n", idx );
00123                 }
00124                 delete session_[idx];
00125                 session_[idx] = NULL; 
00126         }
00127         TcpAgent* picktcp(int size);
00128         TcpSink* picksink();
00129         inline int nTcp() { return nTcp_; }
00130         inline int nSink() { return nSink_; }
00131         inline int isdebug() { return debug_; }
00132 
00133         virtual void delay_bind_init_all();
00134         virtual int delay_bind_dispatch(const char*, const char*, TclObject*);
00135 
00136         int nSrcL_;
00137         int nClientL_;
00138 
00139         int color_;
00140 
00141         int nSrc_;
00142         Node** server_;         /* FTP servers */
00143 
00144 protected:
00145         virtual int command(int argc, const char*const* argv);
00146 
00147         // Session management: fixed number of sessions, fixed number
00148         // of pages per session
00149         int nSession_;
00150         EmpFtpTrafSession** session_; 
00151 
00152         int nClient_;
00153         Node** client_;         /* FTP clients */
00154 
00155         // TCP agent pool management
00156         struct AgentListElem {
00157                 AgentListElem(Agent* a) : agt_(a) {
00158                         link.le_next = NULL;
00159                         link.le_prev = NULL;
00160                 }
00161                 Agent* agt_;
00162                 LIST_ENTRY(AgentListElem) link;
00163         };
00164         LIST_HEAD(AgentList, AgentListElem);
00165         inline void insertAgent(AgentList* l, Agent *a) {
00166                 AgentListElem *e = new AgentListElem(a);
00167                 LIST_INSERT_HEAD(l, e, link);
00168         }
00169         inline Agent* detachHead(AgentList* l) {
00170                 AgentListElem *e = l->lh_first;
00171                 if (e == NULL)
00172                         return NULL;
00173                 Agent *a = e->agt_;
00174                 LIST_REMOVE(e, link);
00175                 delete e;
00176                 return a;
00177         }
00178         int nTcp_, nSink_;
00179         AgentList tcpPool_;     /* TCP agent pool */
00180         AgentList sinkPool_;    /* TCP sink pool */
00181 
00182         // Helper methods
00183         inline int lookup_rv(EmpiricalRandomVariable*& rv, const char* name) {
00184                 if (rv != NULL)
00185                         Tcl::instance().evalf("delete %s", rv->name());
00186                 rv = (EmpiricalRandomVariable*)lookup_obj(name);
00187                 return rv ? (TCL_OK) : (TCL_ERROR);
00188         }
00189 
00190         int debug_;
00191 };
00192 
00193 
00194 #endif // ns_empftp_h

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