Side_1_360

(Dana P.) #1
5.1 TCP Format

The unit of transfer between two TCP layers is
frequently called a segment. Segments are ex-
changed to establish connections, to transfer user
data, to send acknowledgements, to advertise
window size and to release connections. The for-
mat of a TCP segment is illustrated in Figure 9.

The TCP header starts with the Source portand
the Destination port, similar to the UDP header
format. The Sequence numberidentifies the
position in the sender’s byte stream of the data
in the segment. The Acknowledgement number
identifies the position of the highest byte that
the source has received. Note that the sequence
number refers to the flow in the same direction
as the segment, while the acknowledgement
number refers to the stream flowing in the oppo-
site direction as the segment. The Offsetfield
contains the integer specifying the offset of the
data portion in the segment. This is needed as
the length of the Options field varies. After the
Offset field, 4 bits are reserved for future use.

The Codefield gives the contents of the segment
by setting 6 flags (urgent pointer is valid – URG,
acknowledgement field is valid – ACK, a push is
requested – PSH, reset of the connection – RST,
synchronise sequence numbers – SYN, sender
reached end of its stream – FIN).

The TCP layer at the receiver uses the Window
field to advertise how much data it is willing to
accept. Having the Urgent pointerfield allows
TCP to specify that some data is urgent. The
value shows where the urgent data is located.

The Checksumis calculated in a similar manner
as for UDP by appending a pseudo header.

Note that acknowledgements, windows, etc.
refer to volume/byte and not to number of seg-
ments. The TCP acknowledgement scheme is
called cumulate as it reports how much of the
stream has been well received. A motivation for
this is that it is simple to implement. In addition,
a lost acknowledgement does not necessarily
lead to a retransmission. On the other hand, the
sender would not receive information on which
information that is successfully received and
may prepare for retransmitting all segments
starting with the one being lost.

5.2 TCP Connection Handling

In order to establish a TCP connection three
messages are commonly exchanged as illustrated
in Figure 10. In the two first messages the flag
called SYN in the Code field is set. In the two
last messages the ACK flag as part of the Code
field is set.

To close a TCP connection, the FIN flag (part
of the Code field) is set. The receiver acknowl-
edges the segment and the session is over.
A TCP connection is unidirectional although
acknowledgements are transferred in the oppo-
site direction.

The units of user data seen at the sender side and
the receiver side may differ. For instance, at the
sender side a TCP entity may receive two blocks
of 10 kbyte, while at the receiver side, the TCP
entity delivers 20 blocks of 1 kbyte. Further-
more, the TCP entity may collect user data
before sending it, unless a Push flagis used or
Urgent datais indicated. Then the information
is sent without awaiting further user data.

To accommodate interactive users, TCP pro-
vides a push operation that can be used to force
delivery of bytes (the PSH flag as part of the
Code field is set in the segment). An example of
this is when TCP is used to transfer keystrokes.

Similar to UDP, TCP has also some port num-
bers that are reserved, although most ports are
available for dynamic binding. Port numbers
below 256 are called well-known portsand are
reserved for “standard” services, like FTP and
Telnet. Having the sender and receiver aligned
a pair of sockets sets up a TCP service. Each of
the sockets has a socket address consisting of the
IP address (32 bit or 128 bit) and a port number
(16 bit). A TCP connection can then be identi-
fied by the socket addresses at both ends,
(receiver_socket number, sender_socket num-
ber). A socket can be used for a number of paral-
lel flows. All connections are full duplex and
point-to-point.

Figure 9 TCP segment format

Figure 10 Messages
exchanged for establishing
a TCP connection


Offset Reserved

Source port Destination port
Sequence number
Acknowledgement number
Window
Urgent pointer

Options

Data

Padding

04 8 16 24 31


Code
Checksum

SYN-flag, seq = x

SYN-flag, ACK-flag, seq = y
, ack = x + 1

ACK-flag, ack = y + 1

source destination

seq = sequence number
ack = acknowledgement number
Free download pdf