Connected: An Internet Encyclopedia
3.2.3 Compressor processing
Up:
Connected: An Internet Encyclopedia
Up:
Requests For Comments
Up:
RFC 1144
Up:
3 The compression algorithm
Up:
3.2 The ugly details
Prev: 3.2.2 Compressed packet format
Next: 3.2.4 Decompressor processing
3.2.3 Compressor processing
3.2.3 Compressor processing
The compressor is called with the IP packet to be processed and the
compression state structure for the outgoing serial line. It returns a
packet ready for final framing and the link level `type' of that packet.
As the last section noted, the compressor converts every input packet
into either a TYPE_IP, UNCOMPRESSED_TCP or COMPRESSED_TCP packet. A
TYPE_IP packet is an unmodified copy/16/ of the input packet and
processing it doesn't change the compressor's state in any way.
An UNCOMPRESSED_TCP packet is identical to the input packet except the
IP protocol field (byte 9) is changed from `6' (protocol TCP) to a
connection number. In addition, the state slot associated with the
connection number is updated with a copy of the input packet's IP and
TCP headers and the connection number is recorded as the last connection
sent on this serial line (for the C compression described below).
A COMPRESSED_TCP packet contains the data, if any, from the original
packet but the IP and TCP headers are completely replaced with a new,
compressed header. The connection state slot and last connection sent
are updated by the input packet exactly as for an UNCOMPRESSED_TCP
packet.
The compressor's decision procedure is:
- If the packet is not protocol TCP, send it as TYPE_IP.
- If the packet is an IP fragment (i.e., either the fragment offset
field is non-zero or the more fragments bit is set), send it as
TYPE_IP./17/
- If any of the TCP control bits SYN, FIN or RST are set or if the ACK
bit is clear, consider the packet uncompressible and send it as
TYPE_IP./18/
If a packet makes it through the above checks, it will be sent as either
UNCOMPRESSED_TCP or COMPRESSED_TCP:
- If no connection state can be found that matches the packet's source
and destination IP addresses and TCP ports, some state is reclaimed
(which should probably be the least recently used) and an
UNCOMPRESSED_TCP packet is sent.
- If a connection state is found, the packet header it contains is
checked against the current packet to make sure there were no
unexpected changes. (E.g., that all the shaded fields in fig. 3 are
the same). The IP protocol, fragment offset, more fragments, SYN,
FIN and RST fields were checked above and the source and destination
address and ports were checked as part of locating the state. So
the remaining fields to check are protocol version, header length,
type of service, don't fragment, time-to-live, data offset, IP
options (if any) and TCP options (if any). If any of these fields
differ between the two headers, an UNCOMPRESSED_TCP packet is sent.
If all the `unchanging' fields match, an attempt is made to compress the
current packet:
- If the URG flag is set, the urgent data field is encoded (note that
it may be zero) and the U bit is set in the change mask.
Unfortunately, if URG is clear, the urgent data field must be
checked against the previous packet and, if it changes, an
UNCOMPRESSED_TCP packet is sent. (`Urgent data' shouldn't change
when URG is clear but [11] doesn't require this.)
- The difference between the current and previous packet's window
field is computed and, if non-zero, is encoded and the W bit is set
in the change mask.
- The difference between ack fields is computed. If the result is
less than zero or greater than 2^16 - 1, an UNCOMPRESSED_TCP packet
is sent./19/ Otherwise, if the result is non-zero, it is encoded
and the A bit is set in the change mask.
- The difference between sequence number fields is computed. If the
result is less than zero or greater than 2^16 - 1, an
UNCOMPRESSED_TCP packet is sent./20/ Otherwise, if the result is
non-zero, it is encoded and the S bit is set in the change mask.
Once the U, W, A and S changes have been determined, the special-case
encodings can be checked:
- If U, S and W are set, the changes match one of the special-case
encodings. Send an UNCOMPRESSED_TCP packet.
- If only S is set, check if the change equals the amount of user data
in the last packet. I.e., subtract the TCP and IP header lengths
from the last packet's total length field and compare the result to
the S change. If they're the same, set the change mask to SAWU (the
special case for `unidirectional data transfer') and discard the
encoded sequence number change (the decompressor can reconstruct it
since it knows the last packet's total length and header length).
- If only S and A are set, check if they both changed by the same
amount and that amount is the amount of user data in the last
packet. If so, set the change mask to SWU (the special case for
`echoed interactive' traffic) and discard the encoded changes.
- If nothing changed, check if this packet has no user data (in which
case it is probably a duplicate ack or window probe) or if the
previous packet contained user data (which means this packet is a
retransmission on a connection with no pipelining). In either of
these cases, send an UNCOMPRESSED_TCP packet.
Finally, the TCP/IP header on the outgoing packet is replaced with a
compressed header:
- The change in the packet ID is computed and, if not one,/21/ the
difference is encoded (note that it may be zero or negative) and the
I bit is set in the change mask.
- If the PUSH bit is set in the original datagram, the P bit is set in
the change mask.
- The TCP and IP headers of the packet are copied to the connection
state slot.
- The TCP and IP headers of the packet are discarded and a new header
is prepended consisting of (in reverse order):
- the accumulated, encoded changes.
- the TCP checksum (if the new header is being constructed `in
place', the checksum may have been overwritten and will have to
be taken from the header copy in the connection state or saved
in a temporary before the original header is discarded).
- the connection number (if different than the last one sent on
this serial line). This also means that the the line's last
connection sent must be set to the connection number and the C
bit set in the change mask.
- the change mask.
At this point, the compressed TCP packet is passed to the framer for
transmission.
Next: 3.2.4 Decompressor processing
Connected: An Internet Encyclopedia
3.2.3 Compressor processing