http-aux.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Xerox Corporation 1998. All rights reserved.
00003  *
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  */
00041 
00042 //
00043 // Auxiliary classes for Http multicast invalidation proxy cache
00044 //
00045 
00046 #include "http-aux.h"
00047 #include "http.h"
00048 
00049 void PushTimer::expire(Event *) 
00050 {
00051     a_->timeout(HTTP_UPDATE);
00052 }
00053 
00054 void HBTimer::expire(Event *) 
00055 {
00056     a_->timeout(HTTP_INVALIDATION);
00057 }
00058 
00059 void LivenessTimer::expire(Event *)
00060 {
00061     a_->handle_node_failure(nbr_);
00062 }
00063 
00064 void HttpHbData::extract(InvalidationRec*& head)
00065 {
00066     // XXX head must be passed in from outside, because the 
00067     // InvalidationRec list will obtain the address of head
00068     head = NULL;
00069     InvalidationRec *q = NULL;
00070     // reconstruct a list of invalidation records.
00071     // We keep the updating record 
00072     for (int i = 0; i < num_inv(); i++) {
00073         // Used only to mark that this page will be send in 
00074         // the next multicast update. The updating field in 
00075         // this agent will only be set after it gets the real 
00076         // update. Here we set this field temporarily so that
00077         // recv_inv can find out the 
00078         q = inv_rec()[i].copyto();
00079         q->insert(&head);
00080     }
00081 }
00082 
00083 NeighborCache::~NeighborCache()
00084 {
00085     timer_->cancel();
00086     delete timer_;
00087     ServerEntry *s = sl_.gethead(), *p;
00088     while (s != NULL) {
00089         p = s;
00090         s = s->next();
00091         delete p;
00092     }
00093 }
00094 
00095 int NeighborCache::is_server_down(int sid)
00096 {
00097     ServerEntry *s = sl_.gethead();
00098     while (s != NULL) {
00099         if (s->server() == sid)
00100             return s->is_down();
00101         s = s->next();
00102     }
00103     return 0;
00104 }
00105 
00106 void NeighborCache::server_down(int sid)
00107 {
00108     ServerEntry *s = sl_.gethead();
00109     while (s != NULL) {
00110         if (s->server() == sid)
00111             s->down();
00112         s = s->next();
00113     }
00114 }
00115 
00116 void NeighborCache::server_up(int sid)
00117 {
00118     ServerEntry *s = sl_.gethead();
00119     while (s != NULL) {
00120         if (s->server() == sid)
00121             s->up();
00122         s = s->next();
00123     }
00124 }
00125 
00126 void NeighborCache::invalidate(HttpMInvalCache *c)
00127 {
00128     ServerEntry *s = sl_.gethead();
00129     while (s != NULL) {
00130         c->invalidate_server(s->server());
00131         s = s->next();
00132     }
00133 }
00134 
00135 void NeighborCache::pack_leave(HttpLeaveData& data)
00136 {
00137     int i;
00138     ServerEntry *s;
00139     for (i = 0, s = sl_.gethead(); s != NULL; s = s->next(), i++)
00140         data.add(i, s->server());
00141 }
00142 
00143 void NeighborCache::add_server(int sid)
00144 {
00145     ServerEntry *s = new ServerEntry(sid);
00146     sl_.insert(s);
00147 }

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