ICP v2: Internet Cache Protocol (ICP), version 2
A lightweight message format that lets web caches ask their neighbors whether they already hold a URL.
Wessels, D. and K. Claffy, "Internet Cache Protocol (ICP), version 2", RFC 2186, DOI 10.17487/RFC2186, September 1997, <https://www.rfc-editor.org/info/rfc2186>.
@misc{rfc2186,
series = {Request for Comments},
number = 2186,
howpublished = {RFC 2186},
publisher = {RFC Editor},
doi = {10.17487/RFC2186},
url = {https://www.rfc-editor.org/info/rfc2186},
author = {D. Wessels and K. Claffy},
title = {{Internet Cache Protocol (ICP), version 2}},
pagetotal = 9,
year = 1997,
month = sep,
} RFC text
Contents
Network Working Group D. Wessels
Request for Comments: 2186 K. Claffy
Category: Informational National Laboratory for Applied
Network Research/UCSD
September 1997
Internet Cache Protocol (ICP), version 2
Status of this Memo
This memo provides information for the Internet community. This memo
does not specify an Internet standard of any kind. Distribution of
this memo is unlimited.
Abstract
This document describes version 2 of the Internet Cache Protocol
(ICPv2) as currently implemented in two World-Wide Web proxy cache
packages[3,5]. ICP is a lightweight message format used for
communicating among Web caches. ICP is used to exchange hints about
the existence of URLs in neighbor caches. Caches exchange ICP
queries and replies to gather information to use in selecting the
most appropriate location from which to retrieve an object.
This document describes only the format and fields of ICP messages.
A companion document (RFC2187) describes the application of ICP to
Web caches. Several independent caching implementations now use ICP,
and we consider it important to codify the existing practical uses of
ICP for those trying to implement, deploy, and extend its use for
their own purposes.
1. Introduction
ICP is a message format used for communicating between Web caches.
Although Web caches use HTTP[1] for the transfer of object data,
caches benefit from a simpler, lighter communication protocol. ICP
is primarily used in a cache mesh to locate specific Web objects in
neighboring caches. One cache sends an ICP query to its neighbors.
The neighbors send back ICP replies indicating a "HIT" or a "MISS."
In current practice, ICP is implemented on top of UDP, but there is
no requirement that it be limited to UDP. We feel that ICP over UDP
offers features important to Web caching applications. An ICP
query/reply exchange needs to occur quickly, typically within a
second or two. A cache cannot wait longer than that before beginning
to retrieve an object. Failure to receive a reply message most
likely means the network path is either congested or broken. In
either case we would not want to select that neighbor. As an
indication of immediate network conditions between neighbor caches,
ICP over a lightweight protocol such as UDP is better than one with
the overhead of TCP.
In addition to its use as an object location protocol, ICP messages
can be used for cache selection. Failure to receive a reply from a
cache may indicate a network or system failure. The ICP reply may
include information that could assist selection of the most
appropriate source from which to retrieve an object.
ICP was initially developed by Peter Danzig, et. al. at the
University of Southern California as a central part of hierarchical
caching in the Harvest research project[3].
ICP Message Format
The ICP message format consists of a 20-octet fixed header plus a
variable sized payload (see Figure 1).
NOTE: All fields must be represented in network byte order.
Opcode
One of the opcodes defined below.
Version
The ICP protocol version number. At the time of this writing,
both versions two and three are in use. This document describes
only version two. The version number field allows for future
development of this protocol.
Message Length
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Opcode | Version | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Request Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Option Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sender Host Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Payload |
/ /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
FIGURE 1: ICP message format.
The total length (octets) of the ICP message. ICP messages MUST
not exceed 16,384 octets in length.
Request Number
An opaque identifier. When responding to a query, this value must
be copied into the reply message.
Options
A 32-bit field of option flags that allows extension of this
version of the protocol in certain, limited ways. See "ICP Option
Flags" below.
Option Data
A four-octet field to support optional features. The following
ICP features make use of this field:
The ICP_FLAG_SRC_RTT option uses the low 16-bits of Option Data to
return RTT measurements. The ICP_FLAG_SRC_RTT option is further
described below.
Sender Host Address
The IPv4 address of the host sending the ICP message. This field
should probably not be trusted over what is provided by getpeer-
name(), accept(), and recvfrom(). There is some ambiguity over
the original purpose of this field. In practice it is not used.
Payload
The contents of the Payload field vary depending on the Opcode,
but most often it contains a null-terminated URL string.
2. ICP Opcodes
The following table shows currently defined ICP opcodes:
Value Name
----- -----------------
0 ICP_OP_INVALID
1 ICP_OP_QUERY
2 ICP_OP_HIT
3 ICP_OP_MISS
4 ICP_OP_ERR
5-9 UNUSED
10 ICP_OP_SECHO
11 ICP_OP_DECHO
12-20 UNUSED
21 ICP_OP_MISS_NOFETCH
22 ICP_OP_DENIED
23 ICP_OP_HIT_OBJ
ICP_OP_INVALID
A place holder to detect zero-filled or malformed messages. A
cache must never intentionally send an ICP_OP_INVALID message.
ICP_OP_ERR should be used instead.
ICP_OP_QUERY
A query message. NOTE this opcode has a different payload format
than most of the others. First is the requester's IPv4 address,
followed by a URL. The Requester Host Address is not that of the
cache generating the ICP message, but rather the address of the
caches's client that originated the request. The Requester Host
Address is often zero filled. An ICP message with an all-zero
Requester Host Address address should be taken as one where the
requester address is not specified; it does not indicate a valid
IPv4 address.
ICP_OP_QUERY payload format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Requester Host Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Null-Terminated URL /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
In response to an ICP_OP_QUERY, the recipient must return one of:
ICP_OP_HIT, ICP_OP_MISS, ICP_OP_ERR, ICP_OP_MISS_NOFETCH,
ICP_OP_DENIED, or ICP_OP_HIT_OBJ.
ICP_OP_SECHO
Similar to ICP_OP_QUERY, but for use in simulating a query to an
origin server. When ICP is used to select the closest neighbor,
the origin server can be included in the algorithm by bouncing an
ICP_OP_SECHO message off it's echo port. The payload is simply
the null-terminated URL.
NOTE: the echo server will not interpret the data (i.e. we could
send it anything). This opcode is used to tell the difference
between a legitimate query or response, random garbage, and an
echo response.
ICP_OP_DECHO
Similar to ICP_OP_QUERY, but for use in simulating a query to a
cache which does not use ICP. When ICP is used to choose the
closest neighbor, a non-ICP cache can be included in the algorithm
by bouncing an ICP_OP_DECHO message off it's echo port. The
payload is simply the null-terminated URL.
NOTE: one problem with this approach is that while a system's echo
port may be functioning perfectly, the cache software may not be
running at all.
One of the following six ICP opcodes are sent in response to an
ICP_OP_QUERY message. Unless otherwise noted, the payload must be
the null-terminated URL string. Both the URL string and the Request
Number field must be exactly the same as from the ICP_OP_QUERY
message.
ICP_OP_HIT
An ICP_OP_HIT response indicates that the requested URL exists in
this cache and that the requester is allowed to retrieve it.
ICP_OP_MISS
An ICP_OP_MISS response indicates that the requested URL does not
exist in this cache. The querying cache may still choose to fetch
the URL from the replying cache.
ICP_OP_ERR
An ICP_OP_ERR response indicates some kind of error in parsing or
handling the query message (e.g. invalid URL).
ICP_OP_MISS_NOFETCH
An ICP_OP_MISS_NOFETCH response indicates that this cache is up,
but is in a state where it does not want to handle cache misses.
An example of such a state is during a startup phase where a cache
might be rebuilding its object store. A cache in such a mode may
wish to return ICP_OP_HIT for cache hits, but not ICP_OP_MISS for
misses. ICP_OP_MISS_NOFETCH essentially means "I am up and
running, but please don't fetch this URL from me now."
Note, ICP_OP_MISS_NOFETCH has a different meaning than
ICP_OP_MISS. The ICP_OP_MISS reply is an invitation to fetch the
URL from the replying cache (if their relationship allows it), but
ICP_OP_MISS_NOFETCH is a request to NOT fetch the URL from the
replying cache.
ICP_OP_DENIED
An ICP_OP_DENIED response indicates that the querying site is not
allowed to retrieve the named object from this cache. Caches and
proxies may implement complex access controls. This reply must be
be interpreted to mean "you are not allowed to request this
particular URL from me at this particular time."
Caches receiving a high percentage of ICP_OP_DENIED replies are
probably misconfigured. Caches should track percentage of all
replies which are ICP_OP_DENIED and disable a neighbor which
exceeds a certain threshold (e.g. 95% of 100 or more queries).
Similarly, a cache should track the percent of ICP_OP_DENIED
messages that are sent to a given address. If the percent of
denied messages exceeds a certain threshold (e.g. 95% of 100 or
more), the cache may choose to ignore all subsequent ICP_OP_QUERY
messages from that address until some sort of administrative
intervention occurs.
ICP_OP_HIT_OBJ
Just like an ICP_OP_HIT response, but the actual object data has
been included in this reply message. Many requested objects are
small enough that it is possible to include them in the query
response and avoid the need to make a subsequent HTTP request for
the object.
CAVEAT: ICP_OP_HIT_OBJ has some negative side effects which make
its use undesirable. It transfers object data without HTTP and
therefore bypasses the standard HTTP processing, including
authorization and age validation. Another negative side effect is
that ICP_OP_HIT_OBJ messages will often be much larger than the
path MTU, thereby causing fragmentation to occur on the UDP
packet. For these reasons, use of ICP_OP_HIT_OBJ is NOT
recommended.
A cache must not send an ICP_OP_HIT_OBJ unless the
ICP_FLAG_HIT_OBJ flag is set in the query message Options field.
ICP_OP_HIT_OBJ payload format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Null-Terminated URL /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Object Size | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| |
/ Object Data /
/ /
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The receiving application must check to make sure it actually
receives Object Size octets of data. If it does not, then it
should treat the ICP_OP_HIT_OBJ reply as though it were a normal
ICP_OP_HIT.
NOTE: the Object Size field does not necessarily begin on a 32-bit
boundary as shown in the diagram above. It begins immediately
following the NULL byte of the URL string.
UNRECOGNIZED OPCODES
ICP messages with unrecognized or unused opcodes should be
ignored, i.e. no reply generated. The application may choose to
note the anomalous behaviour in a log file.
3. ICP Option Flags
0x80000000 ICP_FLAG_HIT_OBJ
This flag is set in an ICP_OP_QUERY message indicating that it is
okay to respond with an ICP_OP_HIT_OBJ message if the object data
will fit in the reply.
0x40000000 ICP_FLAG_SRC_RTT
This flag is set in an ICP_OP_QUERY message indicating that the
requester would like the ICP reply to include the responder's
measured RTT to the origin server.
Upon receipt of an ICP_OP_QUERY with ICP_FLAG_SRC_RTT bit set, a
cache should check an internal database of RTT measurements. If
available, the RTT value MUST be expressed as a 16-bit integer, in
units of milliseconds. If unavailable, the responder may either
set the RTT value to zero, or clear the ICP_FLAG_SRC_RTT bit in
the ICP reply. The ICP reply MUST not be delayed while waiting
for the RTT measurement to occur.
This flag is set in an ICP reply message (ICP_OP_HIT, ICP_OP_MISS,
ICP_OP_MISS_NOFETCH, or ICP_OP_HIT_OBJ) to indicate that the low
16-bits of the Option Data field contain the measured RTT to the
host given in the requested URL. If ICP_FLAG_SRC_RTT is clear in
the query then it MUST also be clear in the reply. If
ICP_FLAG_SRC_RTT is set in the query, then it may or may not be
set in the reply.
4. Security Considerations
The security issues relating to ICP are discussed in the companion
document, RFC2187.
5. References
[1] Fielding, R., et. al, "Hypertext Transfer Protocol -- HTTP/1.1",
RFC 2068, UC Irvine, January 1997.
[2] Berners-Lee, T., Masinter, L., and M. McCahill, "Uniform Resource
Locators (URL)", RFC 1738, CERN, Xerox PARC, University of Minnesota,
December 1994.
[3] Bowman M., Danzig P., Hardy D., Manber U., Schwartz M., and
Wessels D., "The Harvest Information Discovery and Access System",
Internet Research Task Force - Resource Discovery,
http://harvest.transarc.com/.
[4] Wessels D., Claffy K., "ICP and the Squid Web Cache", National
Laboratory for Applied Network Research,
http://www.nlanr.net/~wessels/Papers/icp-squid.ps.gz
[5] Wessels D., "The Squid Internet Object Cache", National
Laboratory for Applied Network Research,
http://squid.nlanr.net/Squid/
6. Acknowledgments
The authors wish to thank Paul A Vixie <paul@vix.com> for providing
excellent feedback on this document.
7. Authors' Addresses
Duane Wessels
National Laboratory for Applied Network Research
10100 Hopkins Drive
La Jolla, CA 92093
EMail: wessels@nlanr.net
K. Claffy
National Laboratory for Applied Network Research
10100 Hopkins Drive
La Jolla, CA 92093
EMail: kc@nlanr.net
AI ELI5
On this page
§1Why Caches Need a Lighter Protocol
The Internet Cache Protocol (ICP) is a message format that web caches use to talk to each other. Caches still move the actual object data with HTTP, but they benefit from something simpler and lighter for finding it. In a cache mesh, one cache sends an ICP query to its neighbors, and the neighbors reply with a HIT or a MISS.
In current practice ICP runs on top of UDP, although the RFC says nothing requires that. The reasoning is about timing. A query and reply need to happen within a second or two, because a cache cannot wait longer before it starts fetching the object. A missing reply most likely means the network path is congested or broken, and the cache would not want to pick that neighbor anyway. UDP's lack of overhead makes it a good probe of immediate network conditions.
ICP started with Peter Danzig and colleagues at the University of Southern California, as a central part of hierarchical caching in the Harvest research project. The memo covers only the format and fields of the messages. Version two was in use in two web proxy cache packages, and the authors wanted to codify existing practice.
Before fetching a web page the slow way, a cache quickly asks its friends if they already have it. A short note works better than a long conversation, and if a friend does not answer in a second or two, the cache just skips them.
§2The ICP Message Format
Every ICP message has a fixed header of 20 octets followed by a variable-size payload. All fields are in network byte order, and a message must not exceed 16,384 octets.
- Opcode and Version: the message type, and the protocol version. Versions two and three were both in use when the memo was written; this document describes only version two.
- Message Length: the total length of the message in octets.
- Request Number: an opaque identifier that must be copied into the reply to a query.
- Options: 32 bits of flags that allow limited extension of the protocol.
- Option Data: a four-octet field for optional features. The round-trip-time option uses its low 16 bits.
- Sender Host Address: the IPv4 address of the sender. The RFC warns it should probably not be trusted over what the socket calls report, and says that in practice it is not used.
The payload depends on the opcode. Most often it is a null-terminated URL string.
Every ICP note starts with the same short label that says what kind of note it is, how long it is, and which question it answers. The rest of the note, usually a web address, comes after the label.
| Field | Name | Size | Value | Description |
|---|---|---|---|---|
OPCODE | Opcode | 1 byte | The kind of message. | |
VERSION | Version | 1 byte | ICP version number; this document describes version two. | |
LENGTH | Message Length | 2 bytes | Total length of the message in octets, at most 16,384. | |
REQUEST-NUMBER | Request Number | 4 bytes | Opaque identifier copied into the reply. | |
OPTIONS | Options | 4 bytes | Option flags. | |
OPTION-DATA | Option Data | 4 bytes | Four octets for optional features, such as the RTT value. | |
SENDER | Sender Host Address | 4 bytes | IPv4 address of the sender; in practice not used. |
§3Queries and Replies
A cache sends ICP_OP_QUERY with the URL it wants. The payload starts with a Requester Host Address, which is the address of the cache's client rather than the cache itself and is often zero filled, meaning not specified. The recipient must answer with one of six replies, copying the URL and the Request Number exactly.
ICP_OP_HIT: the URL is in this cache and the requester is allowed to retrieve it.ICP_OP_MISS: the URL is not in this cache. The querying cache may still choose to fetch it from the replying cache.ICP_OP_ERR: an error in parsing or handling the query, such as an invalid URL.ICP_OP_MISS_NOFETCH: the cache is up but does not want to handle misses right now, for example while rebuilding its object store. It is a request to not fetch the URL from it.ICP_OP_DENIED: the querying site is not allowed to retrieve the object. A cache getting a high share of these is probably misconfigured; the RFC gives 95% of 100 or more queries as an example threshold for disabling a neighbor.ICP_OP_HIT_OBJ: a hit with the object data included in the reply.
ICP_OP_HIT_OBJ is NOT recommended. It bypasses normal HTTP processing, including authorization and age validation, and its messages are often much larger than the path MTU, causing UDP fragmentation. A cache must not send it unless the query set the ICP_FLAG_HIT_OBJ flag.
Two further opcodes let a cache include servers that do not speak ICP in its closest-neighbor selection. ICP_OP_SECHO bounces a message off an origin server's echo port, and ICP_OP_DECHO does the same to a cache that does not use ICP. Messages with unrecognized or unused opcodes should be ignored with no reply, though they may be logged.
You ask a neighbor, do you have this one? They can say yes, no, there was a mix-up, I am busy so please do not ask me to fetch it, or you are not allowed to have it. They can even hand you the page right away, but that is not a great idea.
- 0ICP_OP_INVALID — Placeholder to detect zero-filled or malformed messages; never sent on purpose.
- 1ICP_OP_QUERY — Asks whether a URL is held.
- 2ICP_OP_HIT — The URL is in this cache and may be retrieved.
- 3ICP_OP_MISS — The URL is not in this cache.
- 4ICP_OP_ERR — Error parsing or handling the query.
- 10ICP_OP_SECHO — Simulated query to an origin server's echo port.
- 11ICP_OP_DECHO — Simulated query to a cache that does not use ICP.
- 21ICP_OP_MISS_NOFETCH — Up, but please do not fetch this URL from me now.
- 22ICP_OP_DENIED — The querying site may not retrieve this object.
- 23ICP_OP_HIT_OBJ — A hit with the object data included; not recommended.
§4Option Flags
Two option flags are defined in the Options field. ICP_FLAG_HIT_OBJ (0x80000000) is set in a query to say it is okay to answer with ICP_OP_HIT_OBJ if the object fits in the reply.
ICP_FLAG_SRC_RTT (0x40000000) asks the responder to include its measured round-trip time to the origin server named in the URL. When the value is available, it MUST be a 16-bit integer in milliseconds, carried in the low 16 bits of Option Data. If it is not available, the responder may set the value to zero or clear the flag in the reply. The reply MUST NOT be delayed while waiting for a measurement. If the flag is clear in the query it MUST be clear in the reply; if it is set in the query, it may or may not be set in the reply.
A question can come with extra requests. One says it is fine to send the whole page back, and the other asks how long it takes you to reach the original web site. You can answer quickly without the extra if you do not know.
§5Security Considerations
This memo does not discuss security itself. It says the security issues relating to ICP are covered in the companion document, RFC 2187. Within this document, the only security-relevant advice is narrow: do not trust the Sender Host Address field over what the operating system reports about the packet, and be cautious with ICP_OP_HIT_OBJ, which skips HTTP authorization checks.
The note about security is in a different document. This one only warns that you should not believe the return address written on the note, and that handing over a page directly skips the usual checks.