Tags:conceptosimodeltransportlayer Status:🟩


OSI Model - Transport Layer

Summary

The Transport Layer ensures reliable or fast communication between applications on different hosts. It manages data segmentation, flow control, and error handling. Through process addressing with port numbers, it allows multiple applications to communicate over the same network. The main protocols are Transmission Control Protocol (TCP), which provides reliable, connection-oriented communication with error recovery, and User Datagram Protocol (UDP), which is connectionless and faster but lacks delivery guarantees. Sockets are used by applications to interface with transport protocols.

Transport layer

The Transport Layer is a critical component of the networking stack that facilitates communication between processes on hosts. It manages the transmission of data between applications, ensuring that information is delivered reliably and in the correct sequence.

  • Process Addressing: In the Transport Layer, processes on a host are identified using ports, which act as communication endpoints.
  • Port Binding: Each process is bound to a specific port, allowing multiple processes to run simultaneously and communicate over the same IP address.
  • Number of Ports: There are 65,535 available ports per IP address (from 0 to 65,535, excluding port 0), which provides room for various applications to operate simultaneously.
  • Common Transport Layer Protocols: The most widely used protocols in this layer are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP), each serving different needs for data transmission.
  • Sockets as Abstraction: Transport layer protocols are accessed through a programming abstraction known as a socket, which provides a standardized interface for applications to send and receive data over the network.

User Diagram Protocol (UDP)

User Datagram Protocol (UDP) is a connectionless transport layer protocol that allows applications to send messages, known as datagrams, to one or more destinations without establishing a connection first. While UDP offers certain advantages, it operates with fewer guarantees compared to its counterpart, TCP.

  • Single Datagram Transmission: UDP sends a single datagram to a specified destination, making it suitable for applications that require simple, fast communication.

  • Multicast Capability: UDP can transmit messages to multiple destinations simultaneously, supporting multicast communication for efficient data distribution.

  • Unreliable Delivery: Messages sent via UDP may be lost during transmission, making it an unreliable option for applications that require guaranteed delivery.

  • Strengths:

    • Simplicity: UDP’s design is straightforward, lacking the complexities of connection-oriented protocols.
    • Speed: The protocol’s lightweight nature allows for faster transmission of data.
    • Low Overhead: UDP has minimal protocol overhead, leading to efficient use of network resources.
    • Statelessness: Being connectionless, UDP does not maintain any session state, allowing for more efficient resource usage.
  • Common Use Cases:

    • Voice over IP (VoIP): UDP is often used in VoIP applications for real-time communication where speed is prioritized over reliability.
    • Applications Handling Retransmission: Protocols like QUIC/HTTP3, TFTP, and DNS can manage their own retransmissions, making them suitable candidates for UDP.
    • Invisible Applications: VPN services like WireGuard use UDP to maintain a low profile in network traffic.
    • Avoiding TCP Overhead: UDP is preferred in situations where the 3-way handshake of TCP is considered too costly in terms of time or resources.

Transmission Control Protocol (TCP)

Transmission Control Protocol (TCP) is a connection-oriented transport layer protocol that provides reliable data transmission between applications. TCP ensures that data is sent and received accurately, making it suitable for applications where reliability is essential.

  • Connection-Oriented: TCP establishes a connection between the sender and receiver before data transmission, ensuring that both parties are ready to communicate.
  • Reliable Streaming: TCP guarantees the delivery of data by implementing error-checking mechanisms, making it a reliable choice for applications requiring data integrity.
  • Maximum Segment Size (MSS): TCP defines the maximum size of data segments that can be sent in a single transmission, helping to optimize network performance.
  • 3-Way Handshake: TCP uses a 3-way handshake process to establish a connection, which involves SYN, SYN-ACK, and ACK messages to synchronize communication between the sender and receiver.
  • Flow Control: TCP manages the rate of data transmission between sender and receiver, preventing the sender from overwhelming the receiver’s buffer.
  • Duplex Communication: TCP supports full-duplex communication, allowing data to be sent and received simultaneously.
  • Sequence Numbers: Each TCP segment is assigned a sequence number, which helps in reordering segments upon arrival and ensuring the correct sequence of data.
  • Retransmission on Packet Loss: If a packet is lost during transmission, TCP automatically retransmits it, ensuring reliable delivery of all data.
  • Sliding Window: TCP uses a sliding window mechanism to manage the flow of data and optimize the use of network bandwidth by allowing multiple segments to be sent before requiring an acknowledgment.

3-way Handshake

The TCP 3-way handshake is a crucial process used to establish a reliable connection between a client and a server in a TCP/IP network. This ensures that both parties are ready to communicate and agree on initial sequence numbers for the data transmission.

Steps:

  • Step 1: SYN (Synchronize)
    The process begins when the client sends a SYN message to the server, indicating a request to establish a connection. This message includes the client’s initial sequence number.
  • Step 2: SYN-ACK (Synchronize-Acknowledge)
    In response, the server acknowledges the receipt of the SYN message by sending a SYN-ACK message back to the client. This message includes the server’s own initial sequence number and acknowledges the client’s sequence number by indicating the next expected sequence number.
  • Step 3: ACK (Acknowledge)
    Upon receiving the SYN-ACK message, the client sends an ACK message back to the server, confirming the receipt of the server’s sequence number. At this point, the TCP connection is fully established, and both parties are ready to begin data transfer.

Connection Identification:
Each TCP connection is uniquely identified by the combination of the client’s IP address and port number, along with the server’s IP address and port number.

Multiple Connections on a Single Port:
TCP allows multiple connections to be established on the same port by differentiating them through their unique IP addresses.

RST (Reset):
If either party receives a packet for an unknown connection, they may respond with an RST message, indicating that the connection does not exist or has been closed.

Sliding Window

The TCP sliding window is a flow control mechanism that allows for efficient data transmission between a sender and receiver. It enables multiple segments of data to be sent before requiring an acknowledgment, optimizing the use of available bandwidth and adapting to changing network conditions.

  • Window Size: The sliding window has a defined size, which indicates the maximum amount of unacknowledged data that can be sent at any given time. This size can vary based on network conditions and the receiver’s buffer capacity.
  • Networking Conditions: The sliding window mechanism adjusts dynamically according to the current network conditions, such as congestion and latency. This adaptability helps to maintain optimal performance during data transmission.
  • Buffer Size: The receiver’s buffer size plays a crucial role in determining the window size. If the buffer is full, the sender must wait for acknowledgments before sending more data, which helps prevent data loss and ensures efficient use of resources.
  • More Efficient: The sliding window allows for more efficient data transfer by enabling continuous flow without waiting for individual acknowledgments for each segment. This reduces latency and increases throughput, making TCP communication more effective, especially in high-latency environments.

Lost Segment

In TCP communication, a lost segment refers to a situation where a data packet fails to reach its destination due to network issues. This can lead to delays and reduced efficiency in data transmission. To address this problem, TCP employs several mechanisms to ensure reliable delivery.

  • Lost Segment: When a segment is lost, TCP recognizes this through missing acknowledgments. The sender will retransmit the lost segment after a timeout period or upon receiving duplicate acknowledgments for subsequent segments.
  • Improvement: Selective Acknowledgments (SACK): To enhance the efficiency of segment retransmission, TCP can use Selective Acknowledgments. With SACK, the receiver can inform the sender about all segments that have been received successfully, including those that may not have arrived in order. This allows the sender to retransmit only the lost segments rather than all segments following the lost one, improving overall performance and reducing unnecessary data transmission.

Timeout

TCP Timeout refers to the period the sender waits for an acknowledgment from the receiver before assuming that a segment has been lost. This mechanism is critical for maintaining reliable communication in TCP, ensuring that lost segments are retransmitted appropriately.

  • Timeout: If the sender does not receive an acknowledgment for a sent segment within the defined timeout period, it assumes that the segment has been lost. Consequently, the sender will retransmit the segment to ensure that the data reaches the receiver.
  • Lost Acknowledgment: Sometimes, the acknowledgment itself may be lost in transit, rather than the original data segment. In this case, the sender will also wait for a timeout period before retransmitting the segment, as it cannot distinguish between a lost segment and a lost acknowledgment. This mechanism helps maintain data integrity but can lead to unnecessary retransmissions if not managed correctly.