00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
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_;
00079 int nPage_, curPage_, donePage_;
00080 int id_, interPageOption_;
00081
00082
00083 int fulltcp_;
00084
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
00114 void pick_ep(TcpAgent**, Agent**);
00115 TcpAgent* picktcp();
00116 TcpSink* picksink();
00117
00118 int find_server(int);
00119
00120 protected:
00121 virtual int command(int argc, const char*const* argv);
00122
00123
00124
00125
00126
00127 int nSession_;
00128 WebTrafSession** session_;
00129
00130
00131 int nServer_;
00132
00133
00134 WebServer *server_;
00135
00136
00137 int nClient_;
00138 Node** client_;
00139
00140
00141 int asimflag_;
00142
00143
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_;
00169 AgentList sinkPool_;
00170
00171
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
00180 int fulltcp_;
00181
00182 int recycle_page_;
00183 };
00184
00185 #endif // ns_webtraf_h
00186
00187