Transport Layer
Transport Layer
Part A: Introduction
• The transport layer is an end-to-end layer – this means that nodes within the subnet do not
participate in transport layer protocols – only the end hosts.
• As with other layers, transport layer protocols send data as a sequence of packets (segments).
• The transport layer is responsible for process-to process delivery—the delivery of a packet, part
of a message, from one process to another.
Introduction
Introduction
• The network layer provides communication between two hosts.
• The transport layer provides communication between two processes running on different
hosts.
• A process is an instance of a program that is running on a host.
• Example: There may be multiple processes communicating between two hosts – for example,
there could be a FTP session and a Telnet session between the same two hosts.
Transport Layer Services
• Process to Process delivery
• Multiplexing/Demultiplexing
• Connectionless/Connection-oriented service
• Reliability
Process to Process delivery: Port Addresses
• Encapsulation and Decapsulation: To send a message from one process to another, the UDP
protocol encapsulates and decapsulates messages in an IP datagram
• Queuing: In UDP, queues are associated with ports
Queuing in UDP
Use of UDP
UDP is suitable for
• a process that requires simple request-response communication with little concern for flow and
error control.
• a process with internal flow and error control mechanisms. For example, the Trivial File
Transfer Protocol (TFTP) process includes flow and error control.
• multicasting.
• management processes such as SNMP.
• route updating protocols such as Routing Information Protocol (RIP).
➢ Because the sending and the receiving processes may not write or read data at the same speed,
TCP needs buffers for storage.
➢ There are two buffers, the sending buffer and the receiving buffer, one for each direction.
➢ One way to implement a buffer is to use a circular array of 1-byte locations as shown in Fig.
TCP Services
TCP Services
• Segments: TCP groups a number of bytes together into a packet called a segment. TCP adds a
header to each segment (for control purposes) and delivers the segment to the IP layer for
transmission.
• Full-Duplex Communication: TCP offers full-duplex service, in which data can flow in both
directions at the same time.
• Connection-Oriented Service: TCP establishes a virtual connection between the two devices
that need to communicate with each other.
• Reliable Service: TCP is a reliable transport protocol. It uses an acknowledgment mechanism
to check the safe and sound arrival of data.
TCP Features
To provide the services discussed, TCP has several feature:
• Numbering System:
➢ Byte Number:
◦ TCP numbers all data bytes that are transmitted in a connection. Numbering is independent in
each direction.
◦ TCP generates a random number between 0 and 232 − 1 for the number of the first byte.
◦ For example, if the random number happens to be 1057 and the total data to be sent are 6000
bytes, the bytes are numbered from 1057 to 7056.
➢ Sequence Number:
◦ TCP assigns a sequence number to each segment that is being sent.
◦ The sequence number for each segment is the number of the first byte carried in that segment
TCP Features
Example: Suppose a TCP connection is transferring a file of 5000 bytes. The first byte is
numbered 1000l. What are the sequence numbers for each segment if data are sent in five
segments, each carrying 1000 bytes?
Sol:
TCP Features
➢ Acknowledgement Number:
◦ The value of the acknowledgment field in a segment defines the number of the next byte a party
expects to receive.
◦ The acknowledgment number is cumulative, which means that the party takes the number of the last
byte that it has received, safe and sound, adds 1 to it, and announces this sum as the acknowledgment
number.
◦ Example: A party announces 5643 as an acknowledgment number, it has received all bytes from the
beginning up to 5642
• Flow Control: In TCP, the receiver of the data controls the amount of data that are to be sent by
the sender. This is done to prevent the receiver from being overwhelmed with data.
• Error Control: To provide reliable service, TCP implements an error control mechanism.
• Congestion Control
TCP Segment Format
TCP Segment Format
The segment consists of a 20- to 60-byte header, followed by data from the application program.
The header is 20 bytes if there are no options and up to 60 bytes if it contains options.
• Source port address: This is a 16-bit field that defines the port number of the application
program in the host that is sending the segment.
• Destination port address: This is a 16-bit field that defines the port number of the application
program in the host that is receiving the segment.
• Sequence number: This 32-bit field defines the number assigned to the first byte of data
contained in this segment.
• Acknowledgment number: This 32-bit field defines the byte number that the receiver of the
segment is expecting to receive from the other party
TCP Segment Format
• Header length: This 4-bit field indicates the number of 4-byte words in the TCP header.
➢ The length of the header can be between 20 and 60 bytes.
➢ Therefore, the value of this field can be between 5 (5 x 4 =20) and 15 (15 x 4 =60).
• The server sends the second segment, a SYN + ACK segment, with 2 flag bits set: SYN and
ACK. This segment has a dual purpose. It is a SYN segment for communication in the other
direction and serves as the acknowledgment for the SYN segment.
Connection Establishment: Three-Way Handshaking
• The client sends the third segment. This is just an ACK segment. It acknowledges the receipt of
the second segment with the ACK flag and acknowledgment number field.
Data Transfer
• After connection is established, bidirectional data transfer can take place.
• The client and server can both send data and acknowledgments.
• Data traveling in the same direction as an acknowledgment are carried on the same segment.
The acknowledgment is piggybacked with the data.
Data Transfer
Data Transfer
• In this example, after connection is established, the client sends 2000 bytes of data in two
segments.
• The server then sends 2000 bytes in one segment.
• The client sends one more segment.
• The first three segments carry both data and acknowledgment, but the last segment carries only
an acknowledgment because there are no more data to be sent.
• The data segments sent by the client have the PSH (push) flag set so that the server TCP knows
to deliver data to the server process as soon as they are received.
Data Transfer
• Pushing Data:
➢ The application program at the sending site can request a push operation. This means that the sending
TCP must not wait for the window to be filled. It must create a segment and send it immediately.
➢ The sending TCP must set the push bit (PSH) to let the receiving TCP know that the segment includes
data that must be delivered to the receiving application program as soon as possible and not to wait for
more data to come.
• Urgent Data:
➢ TCP is a stream-oriented protocol. Each byte of data has a position in the stream. However, on occasion
an application program needs to send urgent bytes.
➢ The solution is to send a segment with the URG bit set. The sending application program tells the
sending TCP that the piece of data is urgent.
➢ The urgent pointer field in the header defines the end of the urgent data and the start of normal data.
Connection Termination
• Any of the two parties involved in exchanging data (client or server) can close the connection,
although it is usually initiated by the client.
• Most implementations today allow two options for connection termination:
➢ three-way handshaking and
➢ four-way handshaking with a half-close option.
Connection Termination: Three-Way Handshaking:
• In a normal situation, the client TCP, after receiving a close command from the client process,
sends the first segment, a FIN segment in which the FIN flag is set.
➢ The FIN segment consumes one sequence number if it does not carry data.
• The server TCP, after receiving the FIN segment, informs its process of the situation and sends
the second segment, a FIN + ACK segment, to confirm the receipt of the FIN segment from the
client and at the same time to announce the closing of the connection in the other direction.
➢ The FIN +ACK segment consumes one sequence number if it does not carry data.
• The client TCP sends the last segment, an ACK segment, to confirm the receipt of the FIN
segment from the TCP server.
➢ This segment cannot carry data and consumes no sequence numbers.
Connection Termination: Three-Way Handshaking
Connection Termination: Half-Close
• In TCP, one end can stop sending data while still receiving data. This is called a half-close.
Although either end can issue a half-close, it is normally initiated by the client.
• Figure shows an example of a half-close. The client half-closes the connection by sending a
FIN segment.
• The server accepts the half-close by sending the ACK segment.
• The data transfer from the client to the server stops. The server, however, can still send data.
• When the server has sent all the processed data, it sends a FIN segment, which is
acknowledged by an ACK from the client.
Connection Termination: Half-Close
TCP Sliding Window: Flow Control
• TCP uses a sliding window to handle flow control.
• The sliding window protocol used by TCP is something between the Go-Back-N and Selective
Repeat sliding window:
➢ The sliding window protocol in TCP looks like the Go-Back-N protocol because it does not use NACKs
➢ It looks like Selective Repeat because the receiver holds the out-of-order segments until the missing
ones arrive.
TCP Sliding Window: Flow Control
• Figure shows the sliding window in TCP.
• The window spans a portion of the buffer containing bytes received from the process.
• The bytes inside the window are the bytes that can be in transit; they can be sent without
worrying about acknowledgment.
• The imaginary window has two walls: one left and one right.
TCP Sliding Window: Flow Control
TCP Sliding Window: Flow Control
• The window is opened, closed, or shrunk. These three activities are in the control of the
receiver.
• Opening a window means moving the right wall to the right. This allows more new bytes in the
buffer that are eligible for sending.
• Closing the window means moving the left wall to the right. This means that some bytes have
been acknowledged, and the sender need not worry about them anymore.
• Shrinking the window means moving the right wall to the left.
TCP Sliding Window: Flow Control
• The size of the window at one end is determined by the lesser of two values: receiver window
(rwnd) or congestion window (cwnd).
• The receiver window is the number of bytes the other end can accept before its buffer
overflows and data are discarded.
• The congestion window is a value determined by the network to avoid congestion.
TCP Sliding Window: Flow Control
TCP Sliding Window: Flow Control
TCP Sliding Window: Flow Control
TCP Sliding Window: Flow Control
TCP: Error Control
• Error control includes mechanisms for detecting corrupted segments, lost segments, out-of-
order segments, and duplicated segments.
• Error control also includes a mechanism for correcting errors after they are detected.
• Error detection and correction in TCP is achieved through the use of three simple tools:
checksum, acknowledgment, and time-out
TCP: Error Control
• Checksum: Each segment includes a checksum field which is used to check for a corrupted
segment. If the segment is corrupted, it is discarded by the destination TCP and is considered as
lost.