http.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) Xerox Corporation 1998. All rights reserved.
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by the
00006  * Free Software Foundation; either version 2 of the License, or (at your
00007  * option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with this program; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  * Linking this file statically or dynamically with other modules is making
00019  * a combined work based on this file.  Thus, the terms and conditions of
00020  * the GNU General Public License cover the whole combination.
00021  *
00022  * In addition, as a special exception, the copyright holders of this file
00023  * give you permission to combine this file with free software programs or
00024  * libraries that are released under the GNU LGPL and with code included in
00025  * the standard release of ns-2 under the Apache 2.0 license or under
00026  * otherwise-compatible licenses with advertising requirements (or modified
00027  * versions of such code, with unchanged license).  You may copy and
00028  * distribute such a system following the terms of the GNU GPL for this
00029  * file and the licenses of the other code concerned, provided that you
00030  * include the source code of that other code when and as the GNU GPL
00031  * requires distribution of source code.
00032  *
00033  * Note that people who make modified versions of this file are not
00034  * obligated to grant this special exception for their modified versions;
00035  * it is their choice whether to do so.  The GNU General Public License
00036  * gives permission to release a modified version without this exception;
00037  * this exception also makes it possible to release a modified version
00038  * which carries forward this exception.
00039  *
00040  * $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/http.h,v 1.14 2005/08/26 05:05:31 tomh Exp $
00041  *
00042  */
00043 //
00044 // Definition of the HTTP agent
00045 // 
00046 
00047 #ifndef ns_http_h
00048 #define ns_http_h
00049 
00050 #include <stdlib.h>
00051 #include <tcl.h>
00052 #include "config.h"
00053 #include "agent.h"
00054 #include "ns-process.h"
00055 #include "app.h"
00056 
00057 #include "pagepool.h"
00058 #include "inval-agent.h"
00059 #include "tcpapp.h"
00060 #include "http-aux.h"
00061 
00062 class HttpApp : public Process {
00063 public:
00064     HttpApp();
00065     virtual ~HttpApp();
00066 
00067     virtual int command(int argc, const char*const* argv);
00068     void log(const char *fmt, ...);
00069     int id() const { return id_; }
00070 
00071     virtual void process_data(int size, AppData* d);
00072     virtual AppData* get_data(int&, AppData*) {
00073         // Do not support it
00074         abort();
00075         return NULL;
00076     }
00077 
00078 protected:
00079     int add_cnc(HttpApp *client, TcpApp *agt);
00080     void delete_cnc(HttpApp *client);
00081     TcpApp* lookup_cnc(HttpApp *client);
00082 
00083     void set_pagepool(ClientPagePool* pp) { pool_ = pp; }
00084 
00085     Tcl_HashTable *tpa_;    // TcpApp hash table
00086     int id_;        // Node id
00087     ClientPagePool *pool_;  // Page repository
00088     Tcl_Channel log_;   // Log file descriptor
00089 };
00090 
00091 
00092 //----------------------------------------------------------------------
00093 // Servers
00094 //----------------------------------------------------------------------
00095 class HttpServer : public HttpApp {
00096 public: 
00097     // All methods are in TCL
00098 };
00099 
00100 class HttpInvalServer : public HttpServer {
00101 public:
00102 };
00103 
00104 // Http server with periodic unicast heartbeat invalidations
00105 class HttpYucInvalServer : public HttpInvalServer {
00106 public:
00107     HttpYucInvalServer();
00108 
00109     virtual int command(int argc, const char*const* argv);
00110     void add_inv(const char *name, double mtime);
00111 
00112 protected:
00113     // heartbeat methods
00114     HttpUInvalAgent *inv_sender_; // Heartbeat/invalidation sender
00115     InvalidationRec *invlist_; 
00116     int num_inv_;
00117 
00118     void send_heartbeat();
00119     HttpHbData* pack_heartbeat();
00120     virtual void send_hb_helper(int size, AppData *data);
00121     InvalidationRec* get_invrec(const char *name);
00122 
00123     int Ca_, Cb_, push_thresh_, enable_upd_;
00124     int push_high_bound_, push_low_bound_;
00125     double hb_interval_;        // Heartbeat interval (second)
00126 };
00127 
00128 
00129 
00130 //----------------------------------------------------------------------
00131 // Clients
00132 //----------------------------------------------------------------------
00133 
00134 // Place holder: everything is in OTcl. We declare it as a split object
00135 // in case that its derived classes need some C++ handling.
00136 class HttpClient : public HttpApp {
00137 };
00138 
00139 
00140 
00141 //----------------------------------------------------------------------
00142 // Caches
00143 //----------------------------------------------------------------------
00144 
00145 class HttpCache : public HttpApp {
00146 };
00147 
00148 class HttpInvalCache : public HttpCache {
00149 };
00150 
00151 // Invalidations embedded in periodic heartbeats
00152 // Used by recv_inv() and recv_inv_filter() to filter invalidations.
00153 const int HTTP_INVALCACHE_FILTERED  = 0;
00154 const int HTTP_INVALCACHE_UNFILTERED    = 1;
00155 
00156 // Http cache with periodic multicast heartbeat invalidation
00157 class HttpMInvalCache : public HttpInvalCache {
00158 public:
00159     HttpMInvalCache();
00160     virtual ~HttpMInvalCache();
00161 
00162     virtual int command(int argc, const char*const* argv);
00163     virtual void process_data(int size, AppData* data);
00164     virtual void timeout(int reason);
00165 
00166     void handle_node_failure(int cid);
00167     void invalidate_server(int sid);
00168     void add_inv(const char *name, double mtime);
00169 
00170 protected:
00171     HBTimer hb_timer_;      // Heartbeat/Inval timer
00172     HttpInvalAgent **inv_sender_;   // Heartbeat/Inval sender agents
00173     int num_sender_;        // # of heartbeat sender agents
00174     int size_sender_;       // Maximum size of array inv_sender_
00175     InvalidationRec *invlist_;  // All invalidations to be sent
00176     int num_inv_;           // # of invalidations in invlist_
00177 
00178     void send_heartbeat();
00179     HttpHbData* pack_heartbeat();
00180     virtual void send_hb_helper(int size, AppData *data);
00181 
00182     int recv_inv(HttpHbData *d);
00183     virtual void process_inv(int n, InvalidationRec *ivlist, int cache);
00184     virtual int recv_inv_filter(ClientPage* pg, InvalidationRec *p) {
00185         return ((pg == NULL) || (pg->mtime() >= p->mtime()) ||
00186             !pg->is_valid()) ? 
00187             HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00188     }
00189     InvalidationRec* get_invrec(const char *name);
00190 
00191     // Maintaining SState(Server, NextCache)
00192     // Use the shadow names of server and cache as id
00193     struct SState {
00194         SState(NeighborCache* c) : down_(0), cache_(c) {}
00195         int is_down() { return down_; }
00196         void down() { down_ = 1; }
00197         void up() { down_ = 0; }
00198         NeighborCache* cache() { return cache_; }
00199         int down_;      // If the server is disconnected
00200         NeighborCache *cache_;  // NextCache
00201     };
00202 
00203     Tcl_HashTable sstate_;
00204     void add_sstate(int sid, SState* sst);
00205     SState* lookup_sstate(int sid);
00206     // check & establish sstate
00207     void check_sstate(int sid, int cid); 
00208 
00209     // Maintaining liveness of neighbor caches
00210     Tcl_HashTable nbr_;
00211     void add_nbr(HttpMInvalCache* c);
00212     NeighborCache* lookup_nbr(int id);
00213 
00214     HttpUInvalAgent *inv_parent_;   // Heartbeat/Inval to parent cache
00215     
00216     void recv_heartbeat(int id);
00217     void recv_leave(HttpLeaveData *d);
00218     void send_leave(HttpLeaveData *d);
00219 
00220     double hb_interval_;        // Heartbeat interval (second)
00221     int enable_upd_;        // Whether enable push
00222     int Ca_, Cb_, push_thresh_;
00223     int push_high_bound_, push_low_bound_;
00224 
00225     HttpInvalAgent **upd_sender_;   // Agents to push updates to
00226     int num_updater_;       // # number of update agents
00227     int size_updater_;      // Size of array upd_sender_
00228 
00229     void add_update(const char *name, double mtime);
00230     void send_upd(ClientPage *pg);
00231     int recv_upd(HttpUpdateData *d);
00232     virtual void send_upd_helper(int pgsize, AppData* data);
00233     HttpUpdateData* pack_upd(ClientPage *pg);
00234 
00235     // Use a static mapping to convert cache id to cache pointers
00236     static HttpMInvalCache** CacheRepository_;
00237     static int NumCache_;
00238     static void add_cache(HttpMInvalCache* c);
00239     static HttpMInvalCache* map_cache(int id) {
00240         return CacheRepository_[id];
00241     }
00242 };
00243 
00244 //----------------------------------------------------------------------
00245 // Multicast invalidation + two way liveness messages + 
00246 // invalidation filtering. 
00247 //----------------------------------------------------------------------
00248 class HttpPercInvalCache : virtual public HttpMInvalCache {
00249 public:
00250     HttpPercInvalCache();
00251     int command(int argc, const char*const* argv);
00252 
00253 protected: 
00254     virtual int recv_inv_filter(ClientPage *pg, InvalidationRec *ir) {
00255         // If we already have an invalid page, don't forward the
00256         // invalidation any more.
00257         return ((pg == NULL) || (pg->mtime() >= ir->mtime()) ||
00258             !pg->is_header_valid()) ? 
00259             HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00260     }
00261 
00262     // Flag: if we allow direct request, and hence pro formas
00263     int direct_request_;
00264 };
00265 
00266 #endif // ns_http_h

Generated on Tue Mar 6 16:47:46 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6