Network Layer4 Transport
Network Layer4 Transport
Layer 4 - Transport
4.1 Introduction
4.2 Transmission Control Protocol (TCP)
4.2.1 TCP ports
4.2.2 TCP segment header
4.2.3 Checksum computation
4.2.4 TCP 3-Way Handshake
4.2.5 Sliding window protocol
4.3 User Datagram Protocol (UDP)
4.3.1 UDP ports
4.3.2 UDP datagram header
4.3.3 Checksum computation
4.4 Comparison of UDP and TCP
4.5 References
4.1 Introduction
Layer 4 is the Transport layer. The transport layer creates virtual Transfer Control Protocol (TCP) or User Datagram Protocol (UDP)
connections between network hosts. This layer sends and receives data to and from the applications running on its host. The Transport
layer assigns port numbers to the processes running in applications on the host and adds a TCP or UDP header to the messages received
from the applications detailing the source and destination port numbers.
Sequence 32 bits If the SYN flag is set (1), then this is the initial sequence number. The sequence number of the actual
number first data byte is this sequence number plus 1.
If the SYN flag is unset (0), then this is the accumulated sequence number of the first data byte of this
segment for the current session.
Acknowledgment 32 bits If the ACK flag is set then this field value is the next sequence number that the sender of the ACK is
number expecting.
Data offset 4 bits Specifies the size of the TCP header in 32-bit words. The minimum size header is 5 words and the
maximum is 15 words thus giving the minimum size of 20 bytes and maximum of 60 bytes, allowing for up
to 40 bytes of options in the header.
CWR (1 bit): Congestion window reduced (CWR) flag is set by the sending host to indicate that it
received a TCP segment with the ECE flag set and had responded in congestion control mechanism.
ECE (1 bit): ECN-Echo has a dual role, depending on the value of the SYN flag. It indicates:
If the SYN flag is set (1), the TCP peer is ECN capable.
If the SYN flag is unset (0), a packet with the Congestion Experienced flag set (ECN=11) in its IP
header was received during normal transmission. This serves as an indication of network
congestion (or impending congestion) to the TCP sender.
URG (1 bit): Indicates that the Urgent pointer field is significant.
ACK (1 bit): Indicates that the Acknowledgment field is significant. All packets after the initial SYN
packet sent by the client should have this flag set.
PSH (1 bit): Push function. Asks to push the buffered data to the receiving application.
RST (1 bit): Reset the connection.
SYN (1 bit): Synchronize sequence numbers. Only the first packet sent from each end should have this
flag set. Some other flags and fields change meaning based on this flag, and some are only valid when
it is set, and others when it is clear.
FIN (1 bit): Last packet from sender
Checksum 16 bits The 16-bit checksum field is used for error-checking of the TCP header, the payload and an IP pseudo-
header. The pseudo-header consists of the source IP address, the destination IP address, the protocol
number for the TCP protocol (6) and the length of the TCP headers and payload (in bytes)
Urgent pointer 16 bits If the URG flag is set, then this 16-bit field is an offset from the sequence number indicating the last urgent
data byte.
Options Variable 0– The length of this field is determined by the data offset field.
320 bits, in
units of 32
bits
Padding The TCP header padding is used to ensure that the TCP header ends, and data begins, on a 32-bit
boundary. The padding is composed of zeros.
TCP prepends the pseudo header to TCP datagram, and computes the checksum for pseudo header, TCP header and data. Then the
checksum value is inserted to the Checksum field of TCP header. Pseudo header is used only for calculating the checksum value. It is not a
part of actual TCP packet and it is never sent over network.
The pseudo header is not the real IP header and used to send an IP packet. It is used only for the checksum calculation.
Protocol/ Next Header The protocol value for TCP 6 (0x06) with TCP
TCP Length The length of the TCP header and data Measured in octets (byte)
SYN: The active open is performed by the client sending a SYN to the server. The client sets the segment's sequence number to a
random value A.
SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received
sequence number i.e. A+1, and the sequence number that the server chooses for the packet is another random number, B.
ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgment value i.e.
A+1, and the acknowledgment number is set to one more than the received sequence number i.e., B+1.
In the sliding window protocol, some of the most important features that are applied in a network model are as mentioned:
This protocol allows sharing multiple data frames from the sender before receiving any acknowledgment from the receiver side.
The data frames shared in the channel are defined by the window size mentioned in the network model, which defines the
maximum number of frames that can be transmitted at a time from the sender to the receiver side before expecting any
acknowledgment.
Each of the frames in the network model is assigned a sequence number to increase the transmission efficiency.
The data frames shared from the sender to the receiver side are enclosed within a virtual sliding window, which represents that
these are awaiting acknowledgment from the receiver side.
The working of the sliding window protocol can be divided into two steps sender steps, and the receiver steps.
The sender side will share data frames with the receiver side per the window size assigned to the model.
The sliding window will appear on the frames transmitted over to the receiver side.
Then the sender will wait for an acknowledgment from the receiver side for the shared frames.
When the receiver transmits the acknowledgment of the first transmitted frame, the sliding window will shift from the
acknowledged frame.
On receiving the data frames from the sender side, the receiver will use the frames in the network model.
After the receiver uses the frame, it will transmit the acknowledgement to the sender side for that data frame.
Then, the receiver side will receive the next data frame from the sender side.
This process continues until all the frames are transmitted from the sender side to the receiver side, and the receiver side transmits the
acknowledgment of all the received frames.
Advantages:
In this protocol, a sender can share multiple frames and then wait for the acknowledgment.
This protocol has much better efficiency in comparison, with low time delay.
This protocol requires sorting for increased efficiency and applies full-duplex transmission.
Disadvantages:
In case the sender does not receive acknowledgement from the receiver side, the network model becomes inefficient.
Loss and wastage of bandwidth due to sharing multiple frames simultaneously.
Length The length in bytes of the UDP header and UDP data 8 - 65535 bytes
Header and Data Checksum (Chapter 4.3.3) Use for error-checking of the header and data Optional in IPv4
UDP prepends the pseudo header to UDP datagram, and computes the checksum for pseudo header, UDP header and data. Then the
checksum value is inserted to the Checksum field of UDP header. Pseudo header is used only for calculating the checksum value. It is not a
part of actual UDP packet and it is never sent over network.
The pseudo header is not the real IP header and used to send an IP packet. It is used only for the checksum calculation.
Protocol/ Next Header The protocol value for UDP 17 (0x11) with UDP
UDP Length The length of the UDP header and data measured in octets (byte)
Connection Requires an established connection to transmit data Connectionless protocol with no requirements
status (connection should be closed once transmission is for opening, maintaining, or terminating a
completed). connection.
Reliability Can guarantee delivery of data to the destination Cannot guarantee delivery of data to the
router. destination.
Error checking Extensive error checking and acknowledgment of data Basic error checking mechanism using
checksums.
Method of Data is read as a byte stream; messages are UDP packets with defined boundaries; sent
transfer transmitted to segment boundaries. individually and checked for integrity on arrival.
Optimal use Used by HTTPS, HTTP, SMTP, POP, FTP, etc. Video conferencing, streaming, DNS, VoIP, etc.
4.5 References
Sliding Window Protocol: Complete Step-by-Step Guide | Simplilearn