webtraf.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  * webtraf.h
00005  * Copyright (C) 1999 by the University of Southern California
00006  * $Id: webtraf.h,v 1.18 2005/08/25 18:58:13 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 // Incorporating Polly's web traffic module into the PagePool framework
00049 //
00050 // XXX This has nothing to do with the HttpApp classes. Because we are 
00051 // only interested in traffic pattern here, we do not want to be bothered 
00052 // with the burden of transmitting HTTP headers, etc. 
00053 //
00054 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/webtraf.h,v 1.18 2005/08/25 18:58:13 johnh Exp $
00055 
00056 #ifndef ns_webtraf_h
00057 #define ns_webtraf_h
00058 
00059 #include "ranvar.h"
00060 #include "random.h"
00061 #include "timer-handler.h"
00062 
00063 #include "lib/bsd-list.h"
00064 #include "node.h"
00065 #include "tcp.h"
00066 #include "tcp-sink.h"
00067 #include "pagepool.h"
00068 #include "webserver.h"
00069 
00070 const int WEBTRAF_DEFAULT_OBJ_PER_PAGE = 1;
00071 
00072 class WebTrafPool;
00073 
00074 class WebTrafSession : public TimerHandler {
00075 public: 
00076     WebTrafSession(WebTrafPool *mgr, Node *src, int np, int id, int ftcp_, int recycle_p);
00077     virtual ~WebTrafSession();
00078 
00079     // Queried by individual pages/objects
00080     inline RandomVariable*& interPage() { return rvInterPage_; }
00081     inline RandomVariable*& pageSize() { return rvPageSize_; }
00082     inline RandomVariable*& interObj() { return rvInterObj_; }
00083     inline RandomVariable*& objSize() { return rvObjSize_; }
00084 
00085     void donePage(void* ClntData);
00086     void launchReq(void* ClntData, int obj, int size);
00087     inline int id() const { return id_; }
00088     inline WebTrafPool* mgr() { return mgr_; }
00089     inline void set_interPageOption(int option) { interPageOption_ = option; }
00090 
00091     static int LASTPAGE_;
00092 
00093 private:
00094     virtual void expire(Event *e = 0);
00095     virtual void handle(Event *e);
00096 
00097     RandomVariable *rvInterPage_, *rvPageSize_, *rvInterObj_, *rvObjSize_;
00098     WebTrafPool* mgr_;
00099     Node* src_;     // One Web client (source of request) per session
00100     int nPage_, curPage_, donePage_;
00101     int id_, interPageOption_;
00102     
00103     // fulltcp support
00104     int fulltcp_;
00105     // Reuse of page level attributes support
00106     int recycle_page_;
00107 };
00108 
00109 class WebServer;
00110 class WebTrafPool : public PagePool {
00111 public: 
00112     WebTrafPool(); 
00113     virtual ~WebTrafPool(); 
00114 
00115     Node* picksrc();
00116     Node* pickdst();
00117     inline void doneSession(int idx) { 
00118         assert((idx>=0) && (idx<nSession_) && (session_[idx]!=NULL));
00119         if (isdebug())
00120             printf("deleted session %d\n", idx);
00121         delete session_[idx];
00122         session_[idx] = NULL; 
00123     }
00124 
00125     void launchReq(Node*, void*, int, int);
00126     void launchResp(int, Node*, Node*, Agent*, Agent*, int, void*);
00127     inline int nTcp() { return nTcp_; }
00128     inline int nSink() { return nSink_; }
00129     inline int isdebug() { return debug_; }
00130 
00131     virtual void delay_bind_init_all();
00132     virtual int delay_bind_dispatch(const char*, const char*, TclObject*);
00133 
00134     // pick end points for a new TCP connection
00135     void pick_ep(TcpAgent**, Agent**);
00136     TcpAgent* picktcp();
00137     TcpSink* picksink();
00138     // Given sever's node id, find server
00139     int find_server(int);
00140 
00141 protected:
00142     virtual int command(int argc, const char*const* argv);
00143 
00144     
00145 
00146     // Session management: fixed number of sessions, fixed number
00147     // of pages per session
00148     int nSession_;
00149     WebTrafSession** session_; 
00150 
00151     // Web servers
00152     int nServer_;
00153     //Node** server_;
00154     // keep the finish time of the last job (M/G/1)
00155     WebServer *server_;
00156 
00157     // Browsers
00158     int nClient_;
00159     Node** client_;
00160 
00161     // Debo added this
00162     int asimflag_;
00163 
00164     // TCP agent pool management
00165     struct AgentListElem {
00166         AgentListElem(Agent* a) : agt_(a) {
00167             link.le_next = NULL;
00168             link.le_prev = NULL;
00169         }
00170         Agent* agt_;
00171         LIST_ENTRY(AgentListElem) link;
00172     };
00173     LIST_HEAD(AgentList, AgentListElem);
00174     inline void insertAgent(AgentList* l, Agent *a) {
00175         AgentListElem *e = new AgentListElem(a);
00176         LIST_INSERT_HEAD(l, e, link);
00177     }
00178     inline Agent* detachHead(AgentList* l) {
00179         AgentListElem *e = l->lh_first;
00180         if (e == NULL)
00181             return NULL;
00182         Agent *a = e->agt_;
00183         LIST_REMOVE(e, link);
00184         delete e;
00185         return a;
00186     }
00187     int nTcp_, nSink_;
00188     int dbTcp_a, dbTcp_r, dbTcp_cr;
00189     AgentList tcpPool_; /* TCP agent pool */
00190     AgentList sinkPool_;    /* TCP sink pool */
00191 
00192     // Helper methods
00193     inline int lookup_rv(RandomVariable*& rv, const char* name) {
00194         if (rv != NULL)
00195             Tcl::instance().evalf("delete %s", rv->name());
00196         rv = (RandomVariable*)lookup_obj(name);
00197         return rv ? (TCL_OK) : (TCL_ERROR);
00198     }
00199     int debug_;
00200     // fulltcp support
00201     int fulltcp_;
00202     // Reuse of page level attributes support
00203     int recycle_page_;
00204 
00205     int dont_recycle_; // Do not recycle tcp agents
00206 };
00207 
00208 #endif // ns_webtraf_h
00209 
00210 

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