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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
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_;
00143
00144 protected:
00145 virtual int command(int argc, const char*const* argv);
00146
00147
00148
00149 int nSession_;
00150 EmpFtpTrafSession** session_;
00151
00152 int nClient_;
00153 Node** client_;
00154
00155
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_;
00180 AgentList sinkPool_;
00181
00182
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