Lecture 6
Lecture 6
Article 3.5
UDP packet Discussion:
UDP packet Discussion:
Connection-Oriented Transport: TCP
• TCP—the Internet’s transport-layer, connection-oriented, reliable transport protocol
• TCP is defined in RFC 793, RFC 1122, RFC 2018, RFC 5681, and RFC 7323.
The TCP Connection
1: TCP is said to be connection-oriented because before one application process can begin to send
data to another, the two processes must first “handshake” with each Other
• that is, they must send some preliminary segments to each other to establish the parameters of
the ensuing data transfer.
• As part of TCP connection establishment, both sides of the connection will initialize many TCP
state variables associated with the TCP connection.
2: The TCP “connection” is not an end-to-end TDM or FDM circuit as in a circuit switched network.
• Instead, the “connection” is a logical one, with common state residing only in the TCPs in the two
communicating end systems.
• The TCP protocol runs only in the end systems and not in the intermediate network elements
(routers and link-layer switches).
• The intermediate network elements do not maintain TCP connection state. In fact, the
intermediate routers are completely oblivious to TCP connections; they see datagrams, not
connections.
The TCP Connection
3: A TCP connection provides a full-duplex service:
4: A TCP connection is also always point-to-point, that is, between a single sender and a single
receiver.
So-called “multicasting” —the transfer of data from one sender to many receivers in a single
send operation—is not possible with TCP.
With TCP, two hosts are company and three are a crowd!
How a TCP connection is established?
• The connection-establishment procedure is often referred to as a three-way handshake.
• Client first sends a special TCP segment; the server responds with a second special TCP segment;
and finally the client responds again with a third special segment.
• The first two segments carry no payload, that is, no application-layer data; the third of these
segments may carry a payload and a total of three segments are sent between the two Hosts.
How a TCP connection is established?
• Once a TCP connection is established, the two application
processes can send data to each other.
• Let’s consider the sending of data from the client process
to the server process.
• The client process passes a stream of data through the
socket (the door of the process)
• Once the data passes through the door, the data is in the
hands of TCP running in the client.
• TCP directs this data to the connection’s send buffer, which
is one of the buffers that is set aside during the initial
three-way handshake.
• From time to time, TCP will grab chunks of data from the
send buffer and pass the data to the network layer.
How a TCP connection is established?
• TCP pairs each chunk of client data with a TCP header,
thereby forming TCP segments.
• The segments are passed down to the network layer, where
they are separately encapsulated within network-layer IP
datagrams.
• The IP datagrams are then sent into the network. When TCP
receives a segment at the other end, the segment’s data is
placed in the TCP connection’s receive buffer.
• The application reads the stream of data from this buffer.
Each side of the connection has its own send buffer and its
own receive buffer.
How a TCP connection is established?
• The maximum amount of data that can be grabbed and placed in a TCP segment is limited by the
maximum segment size (MSS).
• The MSS is the maximum amount of application-layer data in the segment, not the maximum size
of the TCP segment including headers.
• The MSS is typically set by first determining the length of the largest link-layer frame that can be
sent by the local sending host (the so-called maximum transmission unit, MTU),
• The MSS is done to ensure that a TCP segment (when encapsulated in an IP datagram) plus the
TCP/IP header length (typically 40 bytes) will fit into a single link-layer frame.
• Both Ethernet and PPP link-layer protocols have an MTU of 1,500 bytes. Thus, a typical value of
MSS is 1460 bytes.
• Approaches have also been proposed for discovering the path MTU—the largest link-layer frame
that can be sent on all links from source to destination [RFC 1191]—and setting the MSS based on
the path MTU value.
TCP Segment Structure
Let’s examine the TCP segment structure.
The TCP segment consists of header fields and a data field.
Data Field:
• The data field contains a chunk of application data.
• As mentioned above, the MSS limits the maximum size of a segment’s data
field.
• When TCP sends a large file, such as an image as part of a Web page, it
typically breaks the file into chunks of size MSS (except for the last chunk,
which will often be less than the MSS).
• Interactive applications, however, often transmit data chunks that are
smaller than the MSS;
• For example, with remote login applications such as Telnet and ssh, the data
field in the TCP segment is often only one byte.
• Because the TCP header is typically 20 bytes segments sent by Telnet and ssh
may be only 21 bytes in length.
TCP Segment Structure
TCP Segment Structure
TCP Header:
TCP header is typically 20 bytes. The header includes
• source and destination port numbers
• checksum field.
A TCP segment header also contains the following fields:
• The 32-bit sequence number field and the 32-bit acknowledgment number field are used by the
TCP sender and receiver in implementing a reliable data transfer service.
• The 16-bit receive window field is used for flow control.
• The 4-bit header length field specifies the length of the TCP header in 32-bit words. The TCP
header can be of variable length due to the TCP options field. (Typically, the options field is
empty, so that the length of the typical TCP header is 20 bytes.)
• The optional and variable-length options field is used when a sender and receiver negotiate the
maximum segment size (MSS) or as a window scaling factor for use in high-speed networks.
TCP Segment Structure
The flag field contains 6 bits.
• The ACK bit is used to indicate that the value carried in the acknowledgment field is valid; that is,
the segment contains an acknowledgment for a segment that has been successfully received.
• The RST, SYN, and FIN bits are used for connection setup and teardown,
• The CWR and ECE bits are used in explicit congestion notification,
• Setting the PSH bit indicates that the receiver should pass the data to the upper layer immediately.
• Finally, the URG bit is used to indicate that there is data in this segment that the sending-side
upper layer entity has marked as “urgent.”
• The location of the last byte of this urgent data is indicated by the 16-bit urgent data pointer field.
• TCP must inform the receiving-side upper-layer entity when urgent data exists and pass it a
pointer to the end of the urgent data.
• (In practice, the PSH, URG, and the urgent data pointer are not used. However, we mention these
fields for completeness.)
TCP Segment Structure
Sequence Numbers and Acknowledgment Numbers
• Two of the most important fields in the TCP segment header are the sequence number field and
the acknowledgment number field.
• These fields are a critical part of TCP’s reliable data transfer service. But before discussing how
these fields are used to provide reliable data transfer, let us first explain what exactly TCP puts in
these fields.
TCP Segment Structure
Sequence Numbers
• TCP views data as an unstructured, but ordered, stream of bytes.
• TCP’s use of sequence numbers reflects this view in that sequence numbers
• The sequence number for a segment is therefore the byte-stream number of the first byte in the
segment.
• Example:
• Suppose that a process in Host A wants to send a stream of data to a process in Host B over a TCP
connection. Suppose that the data stream consists of a file consisting of 500,000 bytes, that the
MSS is 1,000 bytes,
TCP Segment Structure
Sequence Numbers