1. 程式人生 > >17-TCP Transmission Control Protocol

17-TCP Transmission Control Protocol

  • The combination of an IP address and a port number is called a socket. The socket pair(the 4-tuple consisting of the client IP address, client port number, server IP address, and server port number) specifies the two end points that uniquely identifies each TCP connection in an internet.
  • The sequence number identifies the byte in the stream of data from the sending TCP to the receiving TCP that the first byte of data in this segment represents. If we consider the stream of bytes flowing in one direction between two applications, TCP numbers each byte with a sequence number. This sequence number is a 32-bit unsigned number that wraps back around to 0 after reaching 232 - 1.
  • When a new connection is being established, the SYN flag is turned on. The sequence number field contains the initial sequence number(ISN) chosen by this host for this connection. The sequence number of the first byte of data sent by this host will be the ISN + 1 because the SYN flag consumes a sequence number.
  • The acknowledgment number contains the next sequence number that the sender of the acknowledgment expects to receive. This is the sequence number plus 1 of the last successfully received byte of data. This field is valid only if the ACK flag is on.
  • TCP provides a full-duplex service to the application layer that data can be flowing in each direction, independent of the other direction. Therefore, each end of a connection must maintain a sequence number of the data flowing in each direction.
  • TCP can be described as a sliding-window protocol without selective or negative acknowledgments.
    1. TCP lacks selective acknowledgments because the acknowledgment number in the TCP header means that the sender has successfully received up through but not including that byte. There is no way to acknowledge selected pieces of the data stream. For example, if bytes 1-1024 are received OK, and the next segment contains bytes 2049-3072, the receiver cannot acknowledge this new segment. All it can send is an ACK with 1025 as the acknowledgment number.
    2. There is no means for negatively acknowledging a segment. For example, if the segment with bytes 1025-2048 did arrive, but had a checksum error, all the receiving TCP can send is an ACK with 1025 as the acknowledgment number.
  • The header length gives the length of the header in 32-bit words. This is required because the length of the options field is variable. With a 4-bit field, TCP is limited to a 60-byte header. Without options, the normal size is 20 bytes.
  • There are six flag bits in the TCP header. One or more of them can be turned on at the same time.
    URG The urgent pointer is valid(Section 20.8).
    ACK The acknowledgment number is valid.
    PSH The receiver should pass this data to the application as soon as possible
    (Section 20.5).
    RST Reset the connection(Section 18.7).
    SYN Synchronize sequence numbers to initiate a connection. This flag and the
    next are described in Chapter 18.
    FIN The sender is finished sending data.
  • TCP’s flow control is provided by each end advertising a window size. This is the number of bytes, starting with the one specified by the acknowledgment number field, that the receiver is willing to accept. This is a 16-bit field, limiting the window to 65535 bytes.
  • The checksum covers the TCP segment(TCP header and TCP data). This is a mandatory field that must be calculated and stored by the sender and then verified by the receiver. The TCP checksum is calculated using a pseudo-header as described in Section 11.3.
  • The urgent pointer is valid only if the URG flag is set. This pointer is a positive offset that must be added to the sequence number field of the segment to yield the sequence number of the last byte of urgent data. TCP’s urgent mode is a way for the sender to transmit emergency data to the other end. Section 20.8.
  • The most common option field is the maximum segment size option, called the MSS. Each end of a connection specifies this option on the first segment exchanged(the one with the SYN flag set to establish the connection). It specifies the maximum sized segment that the sender wants to receive. Section 18.4.
  • The data portion of the TCP segment is optional. When a connection is established and when a connection is terminated, segments are exchanged that contain only the TCP header with possible options. A header without any data is also used to acknowledge received data, if there is no data to be transmitted in that direction.