TCP 的实现(第 1 部分)
4.1 引言
从概念上讲,TCP 由若干个进程组成。其中一些处理 USER/TCP 命令,另一些处理从网络到达的分组。TCP 还有一个可以远程激活的内部测量设施。
任何特定的 TCP 都可以从多个角度来看待。它可以实现为一个独立的进程,为许多用户进程提供服务。它可以被视为一组可重入的库例程,共享与本地 PSN 的公共接口以及公共的缓冲区存储。它甚至可以被视为一组进程,其中一些处理用户,一些处理从网络输入的分组,还有一些处理向网络输出的分组。
4.2 TCP 数据结构
4.2.1 互联网络分组格式(INTERNETWORK PACKET FONMAT)
8 bits: Internet information
2 bits: Reserved for local PSN use
2 bits: Header format (11 in binary)
4 bits: Protocol version number
8 bits: Header length in octets (32 is the current value)
16 bits: Length of text in octets
32 bits: Packet sequence number
32 bits: Acknowledgment number (i.e. sequence number of next octet
expected).
16 bits: Window size (in octets)
16 bits: Control Information
Listed from high to low order:
SYN: Request to synchronize sending sequence numbers
ACK: There is a valid acknowledgment in the 32 bit ACK field
FIN: Sender will stop SENDing and RECEIVEing on this connection
DSN: The sender has stopped using sequence numbers and wants to
initiate a new sequence number for sending.
EOS: This packet is the end of a segment and therefore has a
checksum in the 16 bit checksum field. If this bit is not set, the
16 bit checksum field is to be ignored. The bit is usually set,
but if fragmentation at a GATEWAY occurs, the packets preceding
the last one will not have checksums, and the last packet will
have the checksum for the entire original fragment (segment) as it
was calculated by the sending TCP.
EOL: This packet contains the last fragment of a letter. The EOS
bit will always be set in this case.
INT: The sender wants to INTERRUPT on this connection.
XXX: six (6) unused control bits
OD: three (3) bits of control dispatch:
000: Null (the control octet contents should be ignored}
001: Event Code is present in the control octet. These were
defined in section 2.4.3.
010: Special Functions
011: Reject (codes as yet undefined)
1XX: Unused
8 bits: Control Data Octet
If CD is 000 then this octet is to be ignored.
If CD is 001, this octet contains event codes defined in section
2.4.3
If CD is 010, this octet contains a special function code as
defined below:
0: RESET all connections between Source and Destination TCPs
l: RESET the specific connection referenced in this packet
2: ECHO return packet to sender with the special function code
ECHOR (Echo Reply).
3: QUERY Query status of connection referenced in this packet
4: STATUS Reply to QUERY with requested status.
5: ECHOR Echo Reply
6: TRASH Discard packet without acknowledgment
>6: Unused
Note: Special function packets not pertaining to a particular
connection [RESET all, ECHO, ECHOR, and TRASH] are normally
sent using socket zero as described in section 3.2.
If CD is 01l, this octet contains an as yet undefined REJECT code.
If CD is 1XX, this octet is undefined.
4 bits: Length of destination network address in 4 bit units (current
value is 1)
4 bits: Destination network address
1010-1111 are addresses of ARPANET, UCL, CYCLADES, NPL, CADC, and
EPSS respectively.
16 bits: Destination TCP address
8 bits: Padding
4 bits: length of source network address in 4 bit units (current
value is 1)
4 bits: source network address (as for destination address)
16 bits: Source TCP address
24 bits: Destination port address
24 bits: Source port address
16 bits: Checksum (if EOS bit is set)