• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/packmime/packmime_HTTP.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /* 
00004  * Copyright 2002, Statistics Research, Bell Labs, Lucent Technologies and
00005  * The University of North Carolina at Chapel Hill
00006  * 
00007  * Redistribution and use in source and binary forms, with or without 
00008  * modification, are permitted provided that the following conditions are met:
00009  * 
00010  *    1. Redistributions of source code must retain the above copyright 
00011  * notice, this list of conditions and the following disclaimer.
00012  *    2. Redistributions in binary form must reproduce the above copyright 
00013  * notice, this list of conditions and the following disclaimer in the 
00014  * documentation and/or other materials provided with the distribution.
00015  *    3. The name of the author may not be used to endorse or promote 
00016  * products derived from this software without specific prior written 
00017  * permission.
00018  * 
00019  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
00020  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00022  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
00023  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00025  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00026  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00027  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00028  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 /*
00033  * Reference
00034  *     Stochastic Models for Generating Synthetic HTTP Source Traffic 
00035  *     J. Cao, W.S. Cleveland, Y. Gao, K. Jeffay, F.D. Smith, and M.C. Weigle 
00036  *     IEEE INFOCOM 2004.
00037  *
00038  * Documentation available at http://dirt.cs.unc.edu/packmime/
00039  * 
00040  * Contacts: Michele Weigle (mcweigle@cs.unc.edu),
00041  *           Kevin Jeffay (jeffay@cs.unc.edu)
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 /*::::::::::::::::::::::::: TIMER HANDLER classes :::::::::::::::::::::::::::*/
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_;                         // pointer to PackMimeHTTP object
00096 };
00097 
00098 /*:::::::::::::::::::::::: PACKMIME APPLICATION Classes ::::::::::::::::::::*/
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_;                // persistent connection?
00128         int totalbytes_;
00129         int reqsize_;
00130         int rspsize_;
00131         int reqs_;                      // total requests in this connection
00132         int* reqsize_array_;            // array of request sizes
00133         int* rspsize_array_;            // array of response sizes
00134         double* reqgap_array_;          // array of request intervals
00135         int array_ind_;                 // index into the arrays
00136         double time_of_req_;
00137         PackMimeHTTPClientAppTimer timer_;
00138         PackMimeHTTPServerApp* server_;     // pointer to Server
00139         PackMimeHTTP* mgr_;                 // pointer to PackMimeHTTP object
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_;                    // total number of requests
00172         bool lastreq_;                // is this the last request?
00173         int totalbytes_;              // total bytes received so far
00174 
00175         PackMimeHTTPServerAppTimer timer_;
00176         PackMimeHTTP* mgr_;                 // pointer to PackMimeHTTP object
00177 };
00178 
00179 
00180 
00181 /*::::::::::::::::::::::::: class PACKMIME :::::::::::::::::::::::::::::::::*/
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         /* HTTP 1.0 random variable fns */
00205         double connection_interval();
00206         int get_reqsize();
00207         int get_rspsize();
00208         double get_server_delay();
00209 
00210         /* HTTP 1.1 random variable fns */
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_;  // set in setup_connection()
00235 
00236         // variables used to maintain array of server and client nodes
00237         int next_client_ind_;    
00238         int next_server_ind_;
00239         int total_nodes_;
00240         int current_node_;
00241 
00242         // TCL configurable variables
00243         Node* server_[MAX_NODES];
00244         Node* client_[MAX_NODES];
00245         char tcptype_[20];         // {Reno, Tahoe, NewReno, SACK}
00246         FILE* outfp_;              // output file for completed pairs
00247         FILE* fileszfp_;           // output file for requested pairs (@ server)
00248         FILE* samplesfp_;          // output file for requested pairs (@ client)
00249         double rate_;              // connections per second
00250         int segsize_;              // FullTCP max segment size
00251         int segsperack_;           // = 2 for delayed ACKS
00252         double interval_;          // delayed ACK interval
00253         int ID_;                   // PackMimeHTTP cloud ID
00254         int run_;                  // exp run number (for RNG stream selection)
00255         int debug_;
00256         int goal_pairs_;           // req/rsp pairs to allow
00257         int cur_pairs_;            // number of current req/rsp pairs
00258         int warmup_;               // warmup interval (s)
00259         bool http_1_1_;            // use HTTP 1.1?  (default: no)
00260         bool use_pm_persist_rspsz_; // use PM response sizes for persistent conns (def: yes)
00261         bool use_pm_persist_reqsz_; // use PM request size rule for persistent conns (def: yes)
00262 
00263         int active_connections_;   // number of active connections
00264         int total_connections_;    // number of total connections
00265         int running_;              // start new connections?
00266         
00267         // statistics objects
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         // helper methods
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         // Agent and App Pools  
00308         std::queue<FullTcpAgent*> tcpPool_;
00309         std::queue<PackMimeHTTPClientApp*> clientAppPool_;
00310         std::queue<PackMimeHTTPServerApp*> serverAppPool_;
00311 
00312         // string = tcpAgent's name
00313         map<string, PackMimeHTTPClientApp*> clientAppActive_;
00314         map<string, PackMimeHTTPServerApp*> serverAppActive_;
00315 };
00316 
00317 #endif
00318 

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1