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 #ifndef ns_packmime_h
00045 #define ns_packmime_h
00046
00047 #include "timer-handler.h"
00048 #include "app.h"
00049 #include "node.h"
00050 #include "packmime_ranvar.h"
00051 #include <string>
00052 #include <stack>
00053 #include <queue>
00054 #include <map>
00055
00056 #define MAX_NODES 10
00057
00058 class FullTcpAgent;
00059 class PackMimeHTTP;
00060 class PackMimeHTTPTimer;
00061 class PackMimeHTTPServerApp;
00062 class PackMimeHTTPClientApp;
00063
00064
00065
00066
00067 class PackMimeHTTPServerAppTimer : public TimerHandler {
00068 public:
00069 PackMimeHTTPServerAppTimer(PackMimeHTTPServerApp* t) : TimerHandler(),
00070 t_(t) {}
00071 virtual void handle(Event*);
00072 virtual void expire(Event*);
00073 protected:
00074 PackMimeHTTPServerApp* t_;
00075 };
00076
00077
00078 class PackMimeHTTPClientAppTimer : public TimerHandler {
00079 public:
00080 PackMimeHTTPClientAppTimer(PackMimeHTTPClientApp* t) : TimerHandler(),
00081 t_(t) {}
00082 virtual void handle(Event*);
00083 virtual void expire(Event*);
00084 protected:
00085 PackMimeHTTPClientApp* t_;
00086 };
00087
00088 class PackMimeHTTPTimer : public TimerHandler {
00089 public:
00090 PackMimeHTTPTimer(PackMimeHTTP* mgr) : TimerHandler(), mgr_(mgr) {}
00091 inline PackMimeHTTP* mgr() {return mgr_;}
00092 protected:
00093 virtual void handle(Event* e);
00094 virtual void expire(Event* e);
00095 PackMimeHTTP* mgr_;
00096 };
00097
00098
00099
00100 class PackMimeHTTPClientApp : public Application {
00101 public:
00102 PackMimeHTTPClientApp() : Application(), id_(0), running_(0),
00103 persistent_(false),
00104 totalbytes_(0), reqsize_(0), rspsize_(0),
00105 reqs_(0), reqsize_array_(NULL),
00106 rspsize_array_(NULL), reqgap_array_(NULL),
00107 array_ind_ (0), time_of_req_(0.0),
00108 timer_(this), server_(NULL), mgr_(NULL) {};
00109 ~PackMimeHTTPClientApp();
00110 void timeout();
00111 void start();
00112 void stop();
00113 void recycle();
00114
00115 inline void set_server(PackMimeHTTPServerApp* server) {server_ = server;}
00116 inline const char* get_agent_name() {return agent_->name();}
00117 inline PackMimeHTTPServerApp* get_server() {return server_;}
00118 inline void set_agent(Agent* tcp) {agent_ = tcp;}
00119 inline void set_mgr(PackMimeHTTP* mgr) {mgr_ = mgr;}
00120 inline void set_id (int id) {id_ = id;}
00121 inline int get_id () {return id_;}
00122 protected:
00123 void recv(int bytes);
00124
00125 int id_;
00126 int running_;
00127 bool persistent_;
00128 int totalbytes_;
00129 int reqsize_;
00130 int rspsize_;
00131 int reqs_;
00132 int* reqsize_array_;
00133 int* rspsize_array_;
00134 double* reqgap_array_;
00135 int array_ind_;
00136 double time_of_req_;
00137 PackMimeHTTPClientAppTimer timer_;
00138 PackMimeHTTPServerApp* server_;
00139 PackMimeHTTP* mgr_;
00140 };
00141
00142
00143 class PackMimeHTTPServerApp : public Application {
00144 public:
00145 PackMimeHTTPServerApp() : Application(), id_(0), running_(0),
00146 reqsize_(0), rspsize_(0), reqs_(0),
00147 lastreq_(false), totalbytes_(0),
00148 timer_(this), mgr_(NULL) {};
00149 ~PackMimeHTTPServerApp();
00150 void timeout();
00151 void stop();
00152 inline const char* get_agent_name() {return agent_->name();}
00153 inline void start() {running_ = 1;}
00154 inline void set_agent(Agent* tcp) {agent_ = tcp;}
00155 inline void set_mgr(PackMimeHTTP* mgr) {mgr_ = mgr;}
00156 inline void set_id (int id) {id_ = id;}
00157 inline int get_id () {return id_;}
00158 inline void set_reqsize(int size) {reqsize_ = size;}
00159 inline void set_rspsize(int size) {rspsize_ = size;}
00160 inline void set_reqs(int reqs) {reqs_ = reqs;}
00161 inline void set_last_req() {lastreq_ = true;}
00162 void recycle();
00163
00164 protected:
00165 void recv(int bytes);
00166
00167 int id_;
00168 int running_;
00169 int reqsize_;
00170 int rspsize_;
00171 int reqs_;
00172 bool lastreq_;
00173 int totalbytes_;
00174
00175 PackMimeHTTPServerAppTimer timer_;
00176 PackMimeHTTP* mgr_;
00177 };
00178
00179
00180
00181
00182
00183 class PackMimeHTTP : public TclObject {
00184 public:
00185 PackMimeHTTP();
00186 ~PackMimeHTTP();
00187 void recycle (PackMimeHTTPClientApp*);
00188 void recycle (PackMimeHTTPServerApp*);
00189 void setup_connection ();
00190 void incr_pairs();
00191
00192 inline double now() {return Scheduler::instance().clock();}
00193 inline int get_active() {return active_connections_;}
00194 inline int get_total() {return total_connections_;}
00195 inline int running() {return running_;}
00196 inline int debug() {return debug_;}
00197 inline int get_ID() {return ID_;}
00198 inline int get_warmup() {return warmup_;}
00199 inline double get_rate() {return rate_;}
00200 inline bool using_http_1_1() {return http_1_1_;}
00201 inline bool use_pm_persist_rspsz() {return use_pm_persist_rspsz_;}
00202 inline bool use_pm_persist_reqsz() {return use_pm_persist_reqsz_;}
00203
00204
00205 double connection_interval();
00206 int get_reqsize();
00207 int get_rspsize();
00208 double get_server_delay();
00209
00210
00211 bool is_persistent();
00212 int get_num_pages();
00213 int get_num_objs(int pages);
00214 double get_reqgap (int page, int obj);
00215 int adjust_persist_rspsz();
00216 void reset_persist_rspsz();
00217
00218 inline FILE* get_outfp() {return outfp_;}
00219 inline FILE* get_fileszfp() {return fileszfp_;}
00220 inline FILE* get_samplesfp() {return samplesfp_;}
00221
00222 protected:
00223 virtual int command (int argc, const char*const* argv);
00224 void start();
00225 void stop();
00226 void cleanup();
00227 void recycle (FullTcpAgent*);
00228
00229 FullTcpAgent* picktcp();
00230 PackMimeHTTPServerApp* pickServerApp();
00231 PackMimeHTTPClientApp* pickClientApp();
00232
00233 PackMimeHTTPTimer timer_;
00234 double connection_interval_;
00235
00236
00237 int next_client_ind_;
00238 int next_server_ind_;
00239 int total_nodes_;
00240 int current_node_;
00241
00242
00243 Node* server_[MAX_NODES];
00244 Node* client_[MAX_NODES];
00245 char tcptype_[20];
00246 FILE* outfp_;
00247 FILE* fileszfp_;
00248 FILE* samplesfp_;
00249 double rate_;
00250 int segsize_;
00251 int segsperack_;
00252 double interval_;
00253 int ID_;
00254 int run_;
00255 int debug_;
00256 int goal_pairs_;
00257 int cur_pairs_;
00258 int warmup_;
00259 bool http_1_1_;
00260 bool use_pm_persist_rspsz_;
00261 bool use_pm_persist_reqsz_;
00262
00263 int active_connections_;
00264 int total_connections_;
00265 int running_;
00266
00267
00268 RandomVariable* flowarrive_rv_;
00269 RandomVariable* reqsize_rv_;
00270 RandomVariable* rspsize_rv_;
00271 PackMimeHTTPPersistRspSizeRandomVariable* persist_rspsize_rv_;
00272 RandomVariable* persistent_rv_;
00273 RandomVariable* num_pages_rv_;
00274 RandomVariable* single_obj_rv_;
00275 RandomVariable* objs_per_page_rv_;
00276 RandomVariable* time_btwn_pages_rv_;
00277 RandomVariable* time_btwn_objs_rv_;
00278 RandomVariable* server_delay_rv_;
00279
00280 RNG* flowarrive_rng_;
00281 RNG* reqsize_rng_;
00282 RNG* rspsize_rng_;
00283 RNG* persist_rspsize_rng_;
00284 RNG* persistent_rng_;
00285 RNG* num_pages_rng_;
00286 RNG* single_obj_rng_;
00287 RNG* objs_per_page_rng_;
00288 RNG* time_btwn_pages_rng_;
00289 RNG* time_btwn_objs_rng_;
00290 RNG* server_delay_rng_;
00291
00292
00293 TclObject* lookup_obj(const char* name) {
00294 TclObject* obj = Tcl::instance().lookup(name);
00295 if (obj == NULL)
00296 fprintf(stderr, "Bad object name %s\n", name);
00297 return obj;
00298 }
00299
00300 inline int lookup_rv (RandomVariable*& rv, const char* name) {
00301 if (rv != NULL)
00302 Tcl::instance().evalf ("delete %s", rv->name());
00303 rv = (RandomVariable*) lookup_obj (name);
00304 return rv ? (TCL_OK) : (TCL_ERROR);
00305 }
00306
00307
00308 std::queue<FullTcpAgent*> tcpPool_;
00309 std::queue<PackMimeHTTPClientApp*> clientAppPool_;
00310 std::queue<PackMimeHTTPServerApp*> serverAppPool_;
00311
00312
00313 map<string, PackMimeHTTPClientApp*> clientAppActive_;
00314 map<string, PackMimeHTTPServerApp*> serverAppActive_;
00315 };
00316
00317 #endif
00318