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

inval-agent.cc

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 // Agents used to send and receive invalidation records
00019 // 
00020 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/inval-agent.cc,v 1.13 2000/09/01 03:04:12 haoboy Exp $
00021 
00022 #include "inval-agent.h"
00023 #include "ip.h"
00024 #include "http.h"
00025 
00026 // Implementation 1: Invalidation via multicast heartbeat
00027 int hdr_inval::offset_;
00028 static class HttpInvalHeaderClass : public PacketHeaderClass {
00029 public:
00030         HttpInvalHeaderClass() : PacketHeaderClass("PacketHeader/HttpInval",
00031                                                    sizeof(hdr_inval)) {
00032                 bind_offset(&hdr_inval::offset_);
00033         }
00034 } class_httpinvalhdr;
00035 
00036 static class HttpInvalClass : public TclClass {
00037 public:
00038         HttpInvalClass() : TclClass("Agent/HttpInval") {}
00039         TclObject* create(int, const char*const*) {
00040                 return (new HttpInvalAgent());
00041         }
00042 } class_httpinval_agent;
00043 
00044 HttpInvalAgent::HttpInvalAgent() : Agent(PT_INVAL)
00045 {
00046         // It should be initialized to the same as tcpip_base_hdr_size_
00047         bind("inval_hdr_size_", &inval_hdr_size_);
00048 }
00049 
00050 void HttpInvalAgent::recv(Packet *pkt, Handler*)
00051 {
00052         hdr_ip *ip = hdr_ip::access(pkt);
00053         if ((ip->saddr() == addr()) && (ip->sport() == port()))
00054                 // XXX Why do we need this?
00055                 return;
00056         if (app_ == 0) 
00057                 return;
00058         hdr_inval *ih = hdr_inval::access(pkt);
00059         ((HttpApp*)app_)->process_data(ih->size(), pkt->userdata());
00060         Packet::free(pkt);
00061 }
00062 
00063 // Send a list of invalidation records in user data area
00064 // realsize: the claimed size
00065 // datasize: the actual size of user data, used to allocate packet
00066 void HttpInvalAgent::send(int realsize, AppData* data)
00067 {
00068         Packet *pkt = allocpkt(data->size());
00069         hdr_inval *ih = hdr_inval::access(pkt);
00070         ih->size() = data->size();
00071         pkt->setdata(data);
00072 
00073         // Set packet size proportional to the number of invalidations
00074         hdr_cmn *ch = hdr_cmn::access(pkt);
00075         ch->size() = inval_hdr_size_ + realsize;
00076         Agent::send(pkt, 0);
00077 }
00078 
00079 
00080 // Implementation 2: Invalidation via TCP. 
00081 static class HttpUInvalClass : public TclClass {
00082 public:
00083         HttpUInvalClass() : TclClass("Application/TcpApp/HttpInval") {}
00084         TclObject* create(int argc, const char*const* argv) {
00085                 if (argc != 5)
00086                         return NULL;
00087                 Agent *a = (Agent *)TclObject::lookup(argv[4]);
00088                 a->set_pkttype(PT_INVAL); // It's TCP but used for invalidation
00089                 if (a == NULL)
00090                         return NULL;
00091                 return (new HttpUInvalAgent(a));
00092         }
00093 } class_httpuinval_agent;
00094 
00095 void HttpUInvalAgent::process_data(int size, AppData* data) 
00096 {
00097         target_->process_data(size, data);
00098 }
00099 
00100 int HttpUInvalAgent::command(int argc, const char*const* argv)
00101 {
00102         if (strcmp(argv[1], "set-app") == 0) {
00103                 // Compatibility interface
00104                 HttpApp* c = 
00105                         (HttpApp*)TclObject::lookup(argv[2]);
00106                 target_ = (Process *)c;
00107                 return TCL_OK;
00108         }
00109         return TcpApp::command(argc, argv);
00110 }

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