Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

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 // Copyright (c) 1999 by the University of Southern California
00004 // All rights reserved.
00005 //
00006 // Permission to use, copy, modify, and distribute this software and its
00007 // documentation in source and binary forms for non-commercial purposes
00008 // and without fee is hereby granted, provided that the above copyright
00009 // notice appear in all copies and that both the copyright notice and
00010 // this permission notice appear in supporting documentation. and that
00011 // any documentation, advertising materials, and other materials related
00012 // to such distribution and use acknowledge that the software was
00013 // developed by the University of Southern California, Information
00014 // Sciences Institute.  The name of the University may not be used to
00015 // endorse or promote products derived from this software without
00016 // specific prior written permission.
00017 //
00018 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00019 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00020 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00021 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00022 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00023 //
00024 // Other copyrights might apply to parts of this software and are so
00025 // noted when applicable.
00026 //
00027 // Incorporating Polly's web traffic module into the PagePool framework
00028 //
00029 // XXX This has nothing to do with the HttpApp classes. Because we are 
00030 // only interested in traffic pattern here, we do not want to be bothered 
00031 // with the burden of transmitting HTTP headers, etc. 
00032 //
00033 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/webtraf.h,v 1.16 2003/01/05 18:54:43 xuanc Exp $
00034 
00035 #ifndef ns_webtraf_h
00036 #define ns_webtraf_h
00037 
00038 #include "ranvar.h"
00039 #include "random.h"
00040 #include "timer-handler.h"
00041 
00042 #include "lib/bsd-list.h"
00043 #include "node.h"
00044 #include "tcp.h"
00045 #include "tcp-sink.h"
00046 #include "pagepool.h"
00047 #include "webserver.h"
00048 
00049 const int WEBTRAF_DEFAULT_OBJ_PER_PAGE = 1;
00050 
00051 class WebTrafPool;
00052 
00053 class WebTrafSession : public TimerHandler {
00054 public: 
00055         WebTrafSession(WebTrafPool *mgr, Node *src, int np, int id, int ftcp_, int recycle_p);
00056         virtual ~WebTrafSession();
00057 
00058         // Queried by individual pages/objects
00059         inline RandomVariable*& interPage() { return rvInterPage_; }
00060         inline RandomVariable*& pageSize() { return rvPageSize_; }
00061         inline RandomVariable*& interObj() { return rvInterObj_; }
00062         inline RandomVariable*& objSize() { return rvObjSize_; }
00063 
00064         void donePage(void* ClntData);
00065         void launchReq(void* ClntData, int obj, int size);
00066         inline int id() const { return id_; }
00067         inline WebTrafPool* mgr() { return mgr_; }
00068         inline void set_interPageOption(int option) { interPageOption_ = option; }
00069 
00070         static int LASTPAGE_;
00071 
00072 private:
00073         virtual void expire(Event *e = 0);
00074         virtual void handle(Event *e);
00075 
00076         RandomVariable *rvInterPage_, *rvPageSize_, *rvInterObj_, *rvObjSize_;
00077         WebTrafPool* mgr_;
00078         Node* src_;             // One Web client (source of request) per session
00079         int nPage_, curPage_, donePage_;
00080         int id_, interPageOption_;
00081         
00082         // fulltcp support
00083         int fulltcp_;
00084         // Reuse of page level attributes support
00085         int recycle_page_;
00086 };
00087 
00088 class WebServer;
00089 class WebTrafPool : public PagePool {
00090 public: 
00091         WebTrafPool(); 
00092         virtual ~WebTrafPool(); 
00093 
00094         Node* picksrc();
00095         Node* pickdst();
00096         inline void doneSession(int idx) { 
00097                 assert((idx>=0) && (idx<nSession_) && (session_[idx]!=NULL));
00098                 if (isdebug())
00099                         printf("deleted session %d\n", idx);
00100                 delete session_[idx];
00101                 session_[idx] = NULL; 
00102         }
00103 
00104         void launchReq(Node*, void*, int, int);
00105         void launchResp(int, Node*, Node*, Agent*, Agent*, int, void*);
00106         inline int nTcp() { return nTcp_; }
00107         inline int nSink() { return nSink_; }
00108         inline int isdebug() { return debug_; }
00109 
00110         virtual void delay_bind_init_all();
00111         virtual int delay_bind_dispatch(const char*, const char*, TclObject*);
00112 
00113         // pick end points for a new TCP connection
00114         void pick_ep(TcpAgent**, Agent**);
00115         TcpAgent* picktcp();
00116         TcpSink* picksink();
00117         // Given sever's node id, find server
00118         int find_server(int);
00119 
00120 protected:
00121         virtual int command(int argc, const char*const* argv);
00122 
00123         
00124 
00125         // Session management: fixed number of sessions, fixed number
00126         // of pages per session
00127         int nSession_;
00128         WebTrafSession** session_; 
00129 
00130         // Web servers
00131         int nServer_;
00132         //Node** server_;
00133         // keep the finish time of the last job (M/G/1)
00134         WebServer *server_;
00135 
00136         // Browsers
00137         int nClient_;
00138         Node** client_;
00139 
00140         // Debo added this
00141         int asimflag_;
00142 
00143         // TCP agent pool management
00144         struct AgentListElem {
00145                 AgentListElem(Agent* a) : agt_(a) {
00146                         link.le_next = NULL;
00147                         link.le_prev = NULL;
00148                 }
00149                 Agent* agt_;
00150                 LIST_ENTRY(AgentListElem) link;
00151         };
00152         LIST_HEAD(AgentList, AgentListElem);
00153         inline void insertAgent(AgentList* l, Agent *a) {
00154                 AgentListElem *e = new AgentListElem(a);
00155                 LIST_INSERT_HEAD(l, e, link);
00156         }
00157         inline Agent* detachHead(AgentList* l) {
00158                 AgentListElem *e = l->lh_first;
00159                 if (e == NULL)
00160                         return NULL;
00161                 Agent *a = e->agt_;
00162                 LIST_REMOVE(e, link);
00163                 delete e;
00164                 return a;
00165         }
00166         int nTcp_, nSink_;
00167         int dbTcp_a, dbTcp_r, dbTcp_cr;
00168         AgentList tcpPool_;     /* TCP agent pool */
00169         AgentList sinkPool_;    /* TCP sink pool */
00170 
00171         // Helper methods
00172         inline int lookup_rv(RandomVariable*& rv, const char* name) {
00173                 if (rv != NULL)
00174                         Tcl::instance().evalf("delete %s", rv->name());
00175                 rv = (RandomVariable*)lookup_obj(name);
00176                 return rv ? (TCL_OK) : (TCL_ERROR);
00177         }
00178         int debug_;
00179         // fulltcp support
00180         int fulltcp_;
00181         // Reuse of page level attributes support
00182         int recycle_page_;
00183 };
00184 
00185 #endif // ns_webtraf_h
00186 
00187 

Generated on Tue Apr 20 12:14:38 2004 for NS2.26SourcesOriginal by doxygen 1.3.3