Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

http.h

Go to the documentation of this file.
00001 // Copyright (c) Xerox Corporation 1998. All rights reserved.
00002 //
00003 // License is granted to copy, to use, and to make and to use derivative
00004 // works for research and evaluation purposes, provided that Xerox is
00005 // acknowledged in all documentation pertaining to any such copy or
00006 // derivative work. Xerox grants no other licenses expressed or
00007 // implied. The Xerox trade name should not be used in any advertising
00008 // without its written permission. 
00009 //
00010 // XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
00011 // MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
00012 // FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
00013 // express or implied warranty of any kind.
00014 //
00015 // These notices must be retained in any copies of any part of this
00016 // software. 
00017 //
00018 // Definition of the HTTP agent
00019 // 
00020 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/http.h,v 1.13 1999/08/24 04:16:24 haoboy Exp $
00021 
00022 #ifndef ns_http_h
00023 #define ns_http_h
00024 
00025 #include <stdlib.h>
00026 #include <tcl.h>
00027 #include "config.h"
00028 #include "agent.h"
00029 #include "ns-process.h"
00030 #include "app.h"
00031 
00032 #include "pagepool.h"
00033 #include "inval-agent.h"
00034 #include "tcpapp.h"
00035 #include "http-aux.h"
00036 
00037 class HttpApp : public Process {
00038 public:
00039         HttpApp();
00040         virtual ~HttpApp();
00041 
00042         virtual int command(int argc, const char*const* argv);
00043         void log(const char *fmt, ...);
00044         int id() const { return id_; }
00045 
00046         virtual void process_data(int size, AppData* d);
00047         virtual AppData* get_data(int&, AppData*) {
00048                 // Do not support it
00049                 abort();
00050                 return NULL;
00051         }
00052 
00053 protected:
00054         int add_cnc(HttpApp *client, TcpApp *agt);
00055         void delete_cnc(HttpApp *client);
00056         TcpApp* lookup_cnc(HttpApp *client);
00057 
00058         void set_pagepool(ClientPagePool* pp) { pool_ = pp; }
00059 
00060         Tcl_HashTable *tpa_;    // TcpApp hash table
00061         int id_;                // Node id
00062         ClientPagePool *pool_;  // Page repository
00063         Tcl_Channel log_;       // Log file descriptor
00064 };
00065 
00066 
00067 //----------------------------------------------------------------------
00068 // Servers
00069 //----------------------------------------------------------------------
00070 class HttpServer : public HttpApp {
00071 public: 
00072         // All methods are in TCL
00073 };
00074 
00075 class HttpInvalServer : public HttpServer {
00076 public:
00077 };
00078 
00079 // Http server with periodic unicast heartbeat invalidations
00080 class HttpYucInvalServer : public HttpInvalServer {
00081 public:
00082         HttpYucInvalServer();
00083 
00084         virtual int command(int argc, const char*const* argv);
00085         void add_inv(const char *name, double mtime);
00086 
00087 protected:
00088         // heartbeat methods
00089         HttpUInvalAgent *inv_sender_; // Heartbeat/invalidation sender
00090         InvalidationRec *invlist_; 
00091         int num_inv_;
00092 
00093         void send_heartbeat();
00094         HttpHbData* pack_heartbeat();
00095         virtual void send_hb_helper(int size, AppData *data);
00096         InvalidationRec* get_invrec(const char *name);
00097 
00098         int Ca_, Cb_, push_thresh_, enable_upd_;
00099         int push_high_bound_, push_low_bound_;
00100         double hb_interval_;            // Heartbeat interval (second)
00101 };
00102 
00103 
00104 
00105 //----------------------------------------------------------------------
00106 // Clients
00107 //----------------------------------------------------------------------
00108 
00109 // Place holder: everything is in OTcl. We declare it as a split object
00110 // in case that its derived classes need some C++ handling.
00111 class HttpClient : public HttpApp {
00112 };
00113 
00114 
00115 
00116 //----------------------------------------------------------------------
00117 // Caches
00118 //----------------------------------------------------------------------
00119 
00120 class HttpCache : public HttpApp {
00121 };
00122 
00123 class HttpInvalCache : public HttpCache {
00124 };
00125 
00126 // Invalidations embedded in periodic heartbeats
00127 // Used by recv_inv() and recv_inv_filter() to filter invalidations.
00128 const int HTTP_INVALCACHE_FILTERED      = 0;
00129 const int HTTP_INVALCACHE_UNFILTERED    = 1;
00130 
00131 // Http cache with periodic multicast heartbeat invalidation
00132 class HttpMInvalCache : public HttpInvalCache {
00133 public:
00134         HttpMInvalCache();
00135         virtual ~HttpMInvalCache();
00136 
00137         virtual int command(int argc, const char*const* argv);
00138         virtual void process_data(int size, AppData* data);
00139         virtual void timeout(int reason);
00140 
00141         void handle_node_failure(int cid);
00142         void invalidate_server(int sid);
00143         void add_inv(const char *name, double mtime);
00144 
00145 protected:
00146         HBTimer hb_timer_;              // Heartbeat/Inval timer
00147         HttpInvalAgent **inv_sender_;   // Heartbeat/Inval sender agents
00148         int num_sender_;                // # of heartbeat sender agents
00149         int size_sender_;               // Maximum size of array inv_sender_
00150         InvalidationRec *invlist_;      // All invalidations to be sent
00151         int num_inv_;                   // # of invalidations in invlist_
00152 
00153         void send_heartbeat();
00154         HttpHbData* pack_heartbeat();
00155         virtual void send_hb_helper(int size, AppData *data);
00156 
00157         int recv_inv(HttpHbData *d);
00158         virtual void process_inv(int n, InvalidationRec *ivlist, int cache);
00159         virtual int recv_inv_filter(ClientPage* pg, InvalidationRec *p) {
00160                 return ((pg == NULL) || (pg->mtime() >= p->mtime()) ||
00161                         !pg->is_valid()) ? 
00162                         HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00163         }
00164         InvalidationRec* get_invrec(const char *name);
00165 
00166         // Maintaining SState(Server, NextCache)
00167         // Use the shadow names of server and cache as id
00168         struct SState {
00169                 SState(NeighborCache* c) : down_(0), cache_(c) {}
00170                 int is_down() { return down_; }
00171                 void down() { down_ = 1; }
00172                 void up() { down_ = 0; }
00173                 NeighborCache* cache() { return cache_; }
00174                 int down_;              // If the server is disconnected
00175                 NeighborCache *cache_;  // NextCache
00176         };
00177 
00178         Tcl_HashTable sstate_;
00179         void add_sstate(int sid, SState* sst);
00180         SState* lookup_sstate(int sid);
00181         // check & establish sstate
00182         void check_sstate(int sid, int cid); 
00183 
00184         // Maintaining liveness of neighbor caches
00185         Tcl_HashTable nbr_;
00186         void add_nbr(HttpMInvalCache* c);
00187         NeighborCache* lookup_nbr(int id);
00188 
00189         HttpUInvalAgent *inv_parent_;   // Heartbeat/Inval to parent cache
00190         
00191         void recv_heartbeat(int id);
00192         void recv_leave(HttpLeaveData *d);
00193         void send_leave(HttpLeaveData *d);
00194 
00195         double hb_interval_;            // Heartbeat interval (second)
00196         int enable_upd_;                // Whether enable push
00197         int Ca_, Cb_, push_thresh_;
00198         int push_high_bound_, push_low_bound_;
00199 
00200         HttpInvalAgent **upd_sender_;   // Agents to push updates to
00201         int num_updater_;               // # number of update agents
00202         int size_updater_;              // Size of array upd_sender_
00203 
00204         void add_update(const char *name, double mtime);
00205         void send_upd(ClientPage *pg);
00206         int recv_upd(HttpUpdateData *d);
00207         virtual void send_upd_helper(int pgsize, AppData* data);
00208         HttpUpdateData* pack_upd(ClientPage *pg);
00209 
00210         // Use a static mapping to convert cache id to cache pointers
00211         static HttpMInvalCache** CacheRepository_;
00212         static int NumCache_;
00213         static void add_cache(HttpMInvalCache* c);
00214         static HttpMInvalCache* map_cache(int id) {
00215                 return CacheRepository_[id];
00216         }
00217 };
00218 
00219 //----------------------------------------------------------------------
00220 // Multicast invalidation + two way liveness messages + 
00221 // invalidation filtering. 
00222 //----------------------------------------------------------------------
00223 class HttpPercInvalCache : virtual public HttpMInvalCache {
00224 public:
00225         HttpPercInvalCache();
00226         int command(int argc, const char*const* argv);
00227 
00228 protected: 
00229         virtual int recv_inv_filter(ClientPage *pg, InvalidationRec *ir) {
00230                 // If we already have an invalid page, don't forward the
00231                 // invalidation any more.
00232                 return ((pg == NULL) || (pg->mtime() >= ir->mtime()) ||
00233                         !pg->is_header_valid()) ? 
00234                         HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00235         }
00236 
00237         // Flag: if we allow direct request, and hence pro formas
00238         int direct_request_;
00239 };
00240 
00241 #endif // ns_http_h

Generated on Tue Apr 20 12:14:19 2004 for NS2.26SourcesOriginal by doxygen 1.3.3