empweb.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * empweb.h
00005  * Copyright (C) 2001 by the University of Southern California
00006  * $Id: empweb.h,v 1.19 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 Web traffic model that simulates Web 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 webtraf.h
00052 //
00053 // $Header: /nfs/jade/vint/CVSROOT/ns-2/empweb/empweb.h,v 1.19 2005/08/25 18:58:05 johnh Exp $
00054 
00055 #ifndef ns_empweb_h
00056 #define ns_empweb_h
00057 
00058 #include "ranvar.h"
00059 #include "random.h"
00060 #include "timer-handler.h"
00061 
00062 #include "lib/bsd-list.h"
00063 #include "node.h"
00064 #include "tcp.h"
00065 #include "tcp-sink.h"
00066 #include "persconn.h"
00067 
00068 const int WEBTRAF_DEFAULT_OBJ_PER_PAGE = 1;
00069 
00070 class EmpWebTrafPool;
00071 
00072 class EmpWebTrafSession : public TimerHandler {
00073 public: 
00074     EmpWebTrafSession(EmpWebTrafPool *mgr, Node *src, int np, int id, int connNum, int cl, int ftcp_) : 
00075         rvInterPage_(NULL), rvPageSize_(NULL),
00076         rvInterObj_(NULL), rvObjSize_(NULL), 
00077         rvReqSize_(NULL), rvPersistSel_(NULL), rvServerSel_(NULL),
00078         rvServerWin_(NULL), rvClientWin_(NULL),
00079         rvMtu_(NULL),
00080         mgr_(mgr), src_(src), nPage_(np), curPage_(0), donePage_(0),
00081         id_(id), clientIdx_(cl), fulltcp_(0), interPageOption_(1) {
00082             fulltcp_ = ftcp_;   
00083         }
00084     virtual ~EmpWebTrafSession();
00085 
00086     // Queried by individual pages/objects
00087     inline EmpiricalRandomVariable*& interPage() { return rvInterPage_; }
00088     inline EmpiricalRandomVariable*& pageSize() { return rvPageSize_; }
00089     inline EmpiricalRandomVariable*& interObj() { return rvInterObj_; }
00090     inline EmpiricalRandomVariable*& objSize() { return rvObjSize_; }
00091 
00092     inline EmpiricalRandomVariable*& reqSize() { return rvReqSize_; }
00093     inline EmpiricalRandomVariable*& persistSel() { return rvPersistSel_; }
00094     inline EmpiricalRandomVariable*& serverSel() { return rvServerSel_; }
00095 
00096     inline EmpiricalRandomVariable*& serverWin() { return rvServerWin_; }
00097     inline EmpiricalRandomVariable*& clientWin() { return rvClientWin_; }
00098 
00099     inline EmpiricalRandomVariable*& mtu() { return rvMtu_; }
00100 
00101     void donePage(void* ClntData);
00102     void launchReq(void* ClntData, int obj, int size, int reqSize, int sid, int p);
00103     inline int id() const { return id_; }
00104     inline EmpWebTrafPool* mgr() { return mgr_; }
00105 
00106         inline void set_interPageOption(int option) { interPageOption_ = option; }
00107      
00108     static int LASTPAGE_;
00109 
00110 private:
00111     virtual void expire(Event *e = 0);
00112     virtual void handle(Event *e);
00113 
00114     EmpiricalRandomVariable *rvInterPage_, *rvPageSize_, *rvInterObj_, *rvObjSize_;
00115     EmpiricalRandomVariable *rvReqSize_, *rvPersistSel_, *rvServerSel_;
00116     EmpiricalRandomVariable *rvServerWin_, *rvClientWin_;
00117     EmpiricalRandomVariable *rvMtu_;
00118     EmpWebTrafPool* mgr_;
00119     Node* src_;     // One Web client (source of request) per session
00120     int nPage_, curPage_, donePage_;
00121     int id_;
00122 
00123 
00124         int clientIdx_;
00125 
00126         int fulltcp_;
00127 
00128         int interPageOption_;
00129 
00130     TcpAgent* ctcp_;
00131         TcpAgent* stcp_;
00132     TcpSink* csnk_;
00133     TcpSink* ssnk_;
00134 
00135 };
00136 
00137 class EmpWebTrafPool : public PagePool {
00138 public: 
00139     EmpWebTrafPool(); 
00140     virtual ~EmpWebTrafPool(); 
00141 
00142     inline void startSession() {
00143             concurrentSess_++;
00144         if (isdebug()) 
00145             printf("concurrent number of sessions = %d \n", concurrentSess_ );
00146     }
00147     inline void doneSession(int idx) { 
00148 
00149         assert((idx>=0) && (idx<nSession_) && (session_[idx]!=NULL));
00150         if (concurrentSess_ > 0) concurrentSess_--;
00151         if (isdebug()) {
00152             printf("deleted session %d \n", idx );
00153             printf("concurrent number of sessions = %d \n", concurrentSess_ );
00154                 }
00155         delete session_[idx];
00156         session_[idx] = NULL; 
00157     }
00158     void recycleTcp(Agent* a);
00159     void recycleSink(Agent* a);
00160     TcpAgent* picktcp(int size, int mtu);
00161     TcpSink* picksink();
00162     inline int nTcp() { return nTcp_; }
00163     inline int nSink() { return nSink_; }
00164     inline int isdebug() { return debug_; }
00165 
00166     virtual void delay_bind_init_all();
00167     virtual int delay_bind_dispatch(const char*, const char*, TclObject*);
00168 
00169     int nSrcL_;
00170     int nClientL_;
00171 
00172     int concurrentSess_;
00173 
00174     int color_;
00175 
00176     static int LASTFLOW_;
00177     int nSrc_;
00178     Node** server_;     /* Web servers */
00179 
00180 protected:
00181     virtual int command(int argc, const char*const* argv);
00182 
00183     // Session management: fixed number of sessions, fixed number
00184     // of pages per session
00185     int nSession_;
00186     EmpWebTrafSession** session_; 
00187 
00188     int nClient_;
00189     Node** client_;     /* Browsers */
00190 
00191     // TCP agent pool management
00192     struct AgentListElem {
00193         AgentListElem(Agent* a) : agt_(a) {
00194             link.le_next = NULL;
00195             link.le_prev = NULL;
00196         }
00197         Agent* agt_;
00198         LIST_ENTRY(AgentListElem) link;
00199     };
00200     LIST_HEAD(AgentList, AgentListElem);
00201     inline void insertAgent(AgentList* l, Agent *a) {
00202         AgentListElem *e = new AgentListElem(a);
00203         LIST_INSERT_HEAD(l, e, link);
00204     }
00205     inline Agent* detachHead(AgentList* l) {
00206         AgentListElem *e = l->lh_first;
00207         if (e == NULL)
00208             return NULL;
00209         Agent *a = e->agt_;
00210         LIST_REMOVE(e, link);
00211         delete e;
00212         return a;
00213     }
00214     int nTcp_, nSink_;
00215     AgentList tcpPool_; /* TCP agent pool */
00216     AgentList sinkPool_;    /* TCP sink pool */
00217 
00218     // Helper methods
00219     inline int lookup_rv(EmpiricalRandomVariable*& rv, const char* name) {
00220         if (rv != NULL)
00221             Tcl::instance().evalf("delete %s", rv->name());
00222         rv = (EmpiricalRandomVariable*)lookup_obj(name);
00223         return rv ? (TCL_OK) : (TCL_ERROR);
00224     }
00225 
00226     int debug_;
00227 
00228     int fulltcp_;
00229 };
00230 
00231 
00232 #endif // ns_empweb_h

Generated on Tue Mar 6 16:47:44 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6