/*
- * $Id: peer_select.cc,v 1.149 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id$
*
* DEBUG: section 44 Peer Selection Algorithm
* AUTHOR: Duane Wessels
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
#include "htcp.h"
#include "forward.h"
#include "SquidTime.h"
-
-const char *hier_strings[] =
- {
- "NONE",
- "DIRECT",
- "SIBLING_HIT",
- "PARENT_HIT",
- "DEFAULT_PARENT",
- "SINGLE_PARENT",
- "FIRST_UP_PARENT",
- "FIRST_PARENT_MISS",
- "CLOSEST_PARENT_MISS",
- "CLOSEST_PARENT",
- "CLOSEST_DIRECT",
- "NO_DIRECT_FAIL",
- "SOURCE_FASTEST",
- "ROUNDROBIN_PARENT",
+#include "icmp/net_db.h"
+
+const char *hier_strings[] = {
+ "NONE",
+ "DIRECT",
+ "SIBLING_HIT",
+ "PARENT_HIT",
+ "DEFAULT_PARENT",
+ "SINGLE_PARENT",
+ "FIRST_UP_PARENT",
+ "FIRST_PARENT_MISS",
+ "CLOSEST_PARENT_MISS",
+ "CLOSEST_PARENT",
+ "CLOSEST_DIRECT",
+ "NO_DIRECT_FAIL",
+ "SOURCE_FASTEST",
+ "ROUNDROBIN_PARENT",
#if USE_CACHE_DIGESTS
- "CD_PARENT_HIT",
- "CD_SIBLING_HIT",
+ "CD_PARENT_HIT",
+ "CD_SIBLING_HIT",
#endif
- "CARP",
- "ANY_PARENT",
- "USERHASH",
- "SOURCEHASH",
- "INVALID CODE"
- };
-
-static struct
-{
+ "CARP",
+ "ANY_PARENT",
+ "USERHASH",
+ "SOURCEHASH",
+ "INVALID CODE"
+};
+
+static struct {
int timeouts;
} PeerStats;
-static const char *DirectStr[] =
- {
- "DIRECT_UNKNOWN",
- "DIRECT_NO",
- "DIRECT_MAYBE",
- "DIRECT_YES"
- };
+static const char *DirectStr[] = {
+ "DIRECT_UNKNOWN",
+ "DIRECT_NO",
+ "DIRECT_MAYBE",
+ "DIRECT_YES"
+};
static void peerSelectFoo(ps_state *);
static void peerPingTimeout(void *data);
static int
peerCheckNetdbDirect(ps_state * psstate)
{
+#if USE_ICMP
peer *p;
int myrtt;
int myhops;
if (psstate->direct == DIRECT_NO)
return 0;
+ /* base lookup on RTT and Hops if ICMP NetDB is enabled. */
+
myrtt = netdbHostRtt(psstate->request->GetHost());
debugs(44, 3, "peerCheckNetdbDirect: MY RTT = " << myrtt << " msec");
debugs(44, 3, "peerCheckNetdbDirect: minimum_direct_rtt = " << Config.minDirectRtt << " msec");
-
if (myrtt && myrtt <= Config.minDirectRtt)
return 1;
debugs(44, 3, "peerCheckNetdbDirect: MY hops = " << myhops);
debugs(44, 3, "peerCheckNetdbDirect: minimum_direct_hops = " << Config.minDirectHops);
-
if (myhops && myhops <= Config.minDirectHops)
return 1;
if (myrtt && myrtt <= psstate->ping.p_rtt)
return 1;
+#endif /* USE_ICMP */
+
return 0;
}
if (!request->pinnedConnection())
return;
if (request->pinnedConnection()->validatePinnedConnection(request) != -1) {
- peer = request->pinnedConnection()->pinnedPeer();
+ peer = request->pinnedConnection()->pinnedPeer();
if (peer && peerAllowedToUse(peer, request)) {
peerAddFwdServer(&ps->servers, peer, PINNED);
if (ps->entry)
/*
* peerGetSomeNeighbor
- *
+ *
* Selects a neighbor (parent or sibling) based on one of the
* following methods:
* Cache Digests
* CARP
- * Netdb RTT estimates
+ * ICMP Netdb RTT estimates
* ICP/HTCP queries
*/
static void
if (ps->ping.n_sent == 0)
debugs(44, 0, "WARNING: neighborsUdpPing returned 0");
- debugs(44, 3, "peerSelect: " << ps->ping.n_replies_expected <<
- " ICP replies expected, RTT " << ps->ping.timeout <<
- " msec");
+ debugs(44, 3, "peerSelect: " << ps->ping.n_replies_expected <<
+ " ICP replies expected, RTT " << ps->ping.timeout <<
+ " msec");
if (ps->ping.n_replies_expected > 0) {
/*
* peerGetSomeNeighborReplies
- *
+ *
* Selects a neighbor (parent or sibling) based on ICP/HTCP replies.
*/
static void
if ((p = ps->hit)) {
code = ps->hit_type == PEER_PARENT ? PARENT_HIT : SIBLING_HIT;
- } else
- {
+ } else {
if (!ps->closest_parent_miss.IsAnyAddr()) {
p = whichPeer(ps->closest_parent_miss);
code = CLOSEST_PARENT_MISS;
/*
* peerGetSomeDirect
- *
+ *
* Simply adds a 'direct' entry to the FwdServers list if this
* request can be forwarded directly to the origin server
*/
/* WAIS is not implemented natively */
if (ps->request->protocol == PROTO_WAIS)
- return;
+ return;
peerAddFwdServer(&ps->servers, NULL, HIER_DIRECT);
}
peerIcpParentMiss(peer * p, icp_common_t * header, ps_state * ps)
{
int rtt;
- int hops;
+#if USE_ICMP
if (Config.onoff.query_icmp) {
if (header->flags & ICP_FLAG_SRC_RTT) {
rtt = header->pad & 0xFFFF;
- hops = (header->pad >> 16) & 0xFFFF;
+ int hops = (header->pad >> 16) & 0xFFFF;
if (rtt > 0 && rtt < 0xFFFF)
netdbUpdatePeer(ps->request, p, rtt, hops);
}
}
}
+#endif /* USE_ICMP */
/* if closest-only is set, then don't allow FIRST_PARENT_MISS */
if (p->options.closest_only)
peerHandleHtcpReply(peer * p, peer_t type, htcpReplyData * htcp, void *data)
{
ps_state *psstate = (ps_state *)data;
- debugs(44, 3, "peerHandleHtcpReply: " <<
- (htcp->hit ? "HIT" : "MISS") << " " <<
- psstate->entry->url() );
+ debugs(44, 3, "peerHandleHtcpReply: " <<
+ (htcp->hit ? "HIT" : "MISS") << " " <<
+ psstate->entry->url() );
psstate->ping.n_recv++;
if (htcp->hit) {
peerHtcpParentMiss(peer * p, htcpReplyData * htcp, ps_state * ps)
{
int rtt;
- int hops;
+#if USE_ICMP
if (Config.onoff.query_icmp) {
if (htcp->cto.rtt > 0) {
rtt = (int) htcp->cto.rtt * 1000;
- hops = (int) htcp->cto.hops * 1000;
+ int hops = (int) htcp->cto.hops * 1000;
netdbUpdatePeer(ps->request, p, rtt, hops);
if (rtt && (ps->ping.p_rtt == 0 || rtt < ps->ping.p_rtt)) {
}
}
}
+#endif /* USE_ICMP */
/* if closest-only is set, then don't allow FIRST_PARENT_MISS */
if (p->options.closest_only)
peerAddFwdServer(FwdServer ** FSVR, peer * p, hier_code code)
{
FwdServer *fs = (FwdServer *)memAllocate(MEM_FWD_SERVER);
- debugs(44, 5, "peerAddFwdServer: adding " <<
- (p ? p->host : "DIRECT") << " " <<
- hier_strings[code] );
+ debugs(44, 5, "peerAddFwdServer: adding " <<
+ (p ? p->host : "DIRECT") << " " <<
+ hier_strings[code] );
fs->_peer = cbdataReference(p);
fs->code = code;