DEV Community

Harsh Mishra
Harsh Mishra

Posted on

Transport Layer: Computer Networks

Process-to-Process Delivery: Explained

In networking, data delivery isn't just about moving information from one node to another (node-to-node delivery) or even between two hosts (host-to-host delivery). True communication happens between processes, i.e., applications running on these hosts. This is where process-to-process delivery becomes vital.


Understanding Process-to-Process Delivery

Layers of Delivery

  1. Node-to-Node Delivery: Managed by the data link layer, responsible for delivering frames between two physically connected nodes.
  2. Host-to-Host Delivery: Handled by the network layer, ensuring data is delivered to the correct host across networks.
  3. Process-to-Process Delivery: Managed by the transport layer, ensuring the correct application (or process) on the destination host receives the data.

Each layer adds an address to the packet:

  • Data Link Layer: MAC addresses for node identification.
  • Network Layer: IP addresses for host identification.
  • Transport Layer: Port numbers for process identification.

Client/Server Paradigm

The most common model for process-to-process communication is the client/server paradigm:

  • Client Process: Initiates the communication, often running temporarily.
  • Server Process: Listens for incoming requests and serves data, often running continuously.

For example:

  • A Daytime Client requests the current time from a Daytime Server.
  • The server uses a well-known port number (e.g., 13), while the client uses an ephemeral (temporary) port number.

Port Numbers

The transport layer uses port numbers (16-bit integers ranging from 0 to 65,535) to identify processes.

IANA Port Number Ranges:

  1. Well-Known Ports (0–1023): Reserved for standard services (e.g., HTTP: 80, HTTPS: 443).
  2. Registered Ports (1024–49,151): For user-registered applications.
  3. Dynamic Ports (49,152–65,535): Assigned dynamically to client processes.

Socket Address

A socket address combines an IP address and a port number to uniquely identify a process on a host. For communication:

  • Client Socket Address: Includes the client’s IP and port.
  • Server Socket Address: Includes the server’s IP and port.

How the Process Works

  1. The client sends a request using its ephemeral port to the server’s well-known port.
  2. The server replies, identifying the client using its socket address.
  3. Communication continues until the process terminates.

Why Process-to-Process Delivery Matters

  • Enables multiple applications to run and communicate simultaneously on the same host.
  • Facilitates efficient client-server interactions over the internet.
  • Forms the backbone of modern-day internet services, from web browsing to database queries.

By understanding this layered approach and the critical role of port numbers and socket addresses, developers can build more efficient and reliable networking applications.


Connectionless Versus Connection-Oriented Service

Connectionless Service

  • In a connectionless service, communication occurs without establishing or terminating a connection.
  • Packets are transmitted independently, without numbering or sequencing.
  • There is no guarantee of delivery, and packets may:
    • Be delayed.
    • Arrive out of order.
    • Get lost entirely.
  • No acknowledgments are exchanged between the sender and receiver.
  • Example: UDP (User Datagram Protocol) is a connectionless protocol used in the Internet model.

Connection-Oriented Service

  • A connection-oriented service requires:
    1. Establishing a connection between sender and receiver.
    2. Transferring data over the established connection.
    3. Releasing the connection after communication ends.
  • Ensures reliable delivery with ordered packets.
  • Example: TCP (Transmission Control Protocol) and SCTP (Stream Control Transmission Protocol) are connection-oriented protocols.

Reliable Versus Unreliable Service

Reliable Service

  • Provides guarantees for data delivery using:
    • Flow control: Manages data transmission to prevent overwhelming the receiver.
    • Error control: Detects and corrects errors during data transmission.
  • Slower but ensures correctness and order of data.
  • Example: TCP and SCTP implement reliability for applications that need guaranteed data delivery.

Unreliable Service

  • Faster and simpler, as it does not involve flow or error control.
  • Suitable for applications where:
    • Speed is prioritized over reliability.
    • The application implements its own reliability mechanisms.
    • Reliability is unnecessary, such as for real-time applications.
  • Example: UDP is unreliable and suitable for scenarios like video streaming and DNS.

Error Control at Transport Layer

  • Why Needed?
    • The data link layer ensures reliability between two directly connected nodes.
    • The transport layer ensures end-to-end reliability over an unreliable network layer.
  • Example:
    • Error detection in the transport layer ensures data integrity even if errors occur at intermediate network nodes.

Transport Layer Protocols

  1. UDP (User Datagram Protocol):

    • Connectionless and unreliable.
    • Best suited for applications requiring fast, lightweight communication.
  2. TCP (Transmission Control Protocol):

    • Connection-oriented and reliable.
    • Implements error and flow control using mechanisms like sliding windows.
  3. SCTP (Stream Control Transmission Protocol):

    • Connection-oriented and reliable.
    • Designed for multi-streaming and multi-homing to enhance performance and fault tolerance.

User Datagram Protocol (UDP) Overview

The User Datagram Protocol (UDP) is a lightweight transport layer protocol in the TCP/IP suite. It is connectionless and unreliable, making it simple but fast. UDP is used in scenarios where low latency and minimal overhead are prioritized over reliability.


Key Characteristics of UDP

  1. Connectionless:

    • No need to establish a connection between sender and receiver.
    • Packets (datagrams) are sent independently, without guarantees of delivery or order.
  2. Unreliable:

    • Does not ensure packet delivery, order, or integrity beyond basic error checking.
    • Lacks retransmission mechanisms.
  3. Process-to-Process Communication:

    • Provides communication between specific processes running on source and destination hosts.
    • Uses port numbers to distinguish processes.
  4. Minimal Overhead:

    • Simple protocol with an 8-byte fixed header.
    • Ideal for applications where simplicity and speed are critical.
  5. Error Checking:

    • Limited to basic checksum functionality for detecting errors in the datagram.

Advantages of UDP

  • Efficiency: Minimal overhead allows for faster transmission.
  • Simplicity: Easy to implement and use in scenarios where reliability is not crucial.
  • Lower Latency: Lack of connection setup and maintenance makes it suitable for real-time applications.
  • Broadcast and Multicast Support: Used for scenarios like streaming media and online gaming.

Disadvantages of UDP

  • No delivery guarantees (packets may be lost).
  • No sequence control (packets may arrive out of order).
  • No flow or congestion control (can overwhelm the receiver or network).

UDP Datagram Format

A UDP packet, called a user datagram, consists of an 8-byte header and data. The structure of the datagram is as follows:

Field Size Description
Source Port Number 16 bits Identifies the sending process. Typically ephemeral for clients.
Destination Port 16 bits Identifies the receiving process. Often a well-known port for servers.
Length 16 bits Total size of the datagram (header + data). Maximum value: 65,535 bytes.
Checksum 16 bits Detects errors in the header and data. Optional in IPv4, mandatory in IPv6.

Field Details

  1. Source Port Number:

    • Identifies the process running on the source host.
    • Clients usually use an ephemeral (temporary) port number.
    • Servers may use a well-known port number.
  2. Destination Port Number:

    • Identifies the process on the destination host.
    • For server communication, this is typically a well-known port (e.g., 53 for DNS).
    • For client responses, it matches the ephemeral port used by the client.
  3. Length:

    • Specifies the total size of the datagram, including header and payload.
    • Maximum size is 65,535 bytes, though it is usually smaller to fit within an IP packet.
  4. Checksum:

    • Provides error detection for the datagram.
    • Covers the header and data but does not include error correction.
    • In IPv4, this field is optional; in IPv6, it is mandatory.

Checksum Calculation

The UDP checksum ensures the integrity of the datagram. It is calculated as follows:

  1. Add the UDP header, data, and a pseudo-header from the IP layer.
  2. Compute the one's complement sum of all 16-bit words.
  3. Take the one's complement of the result.
  4. If the result is 0, it is replaced with all ones (as 0 is reserved for "no checksum").

The pseudo-header includes:

  • Source IP address
  • Destination IP address
  • Protocol type (17 for UDP)
  • Length of UDP datagram

UDP Use Cases

  1. Domain Name System (DNS):

    • Quick and lightweight queries for name resolution.
    • Uses port 53.
  2. Streaming Media:

    • Video and audio streaming prioritize speed and low latency over reliability.
  3. Online Gaming:

    • Real-time interactions where occasional packet loss is acceptable.
  4. Voice over IP (VoIP):

    • Low latency communication for voice calls.
  5. Simple Network Management Protocol (SNMP):

    • Used for managing devices on IP networks.
  6. Trivial File Transfer Protocol (TFTP):

    • Lightweight file transfer protocol using UDP.

Comparison of UDP with TCP

Feature UDP TCP
Connection Connectionless Connection-oriented
Reliability Unreliable Reliable
Overhead Low High
Data Flow Control None Provides flow control
Congestion Control None Manages congestion
Error Handling Basic checksum for error detection Retransmission and acknowledgment
Applications Real-time apps, streaming, gaming File transfer, email, web browsing

Summary

UDP is a simple and efficient protocol that trades reliability for speed and low latency. Its lightweight nature makes it ideal for specific applications where minimal overhead is necessary, and occasional data loss is acceptable. While it lacks the reliability and flow control features of TCP, its design makes it indispensable for real-time and resource-sensitive communication tasks.


Transmission Control Protocol (TCP) Overview

The Transmission Control Protocol (TCP) is a connection-oriented, reliable transport layer protocol in the TCP/IP suite. It ensures data delivery, order, and integrity, making it suitable for applications requiring robust communication.


TCP Services

  1. Process-to-Process Communication:

    • TCP facilitates communication between specific processes on source and destination hosts using port numbers.
    • Each application is identified by its port number.
  2. Full-Duplex Communication:

    • TCP allows simultaneous data exchange in both directions.
    • Each end maintains a sending and receiving buffer.
  3. Connection-Oriented Service:

    • TCP requires a connection to be established before data exchange.
    • A connection involves three phases:
      1. Connection Establishment: A three-way handshake process.
      2. Data Transfer: Reliable exchange of data.
      3. Connection Termination: Graceful closing of the connection.
  4. Reliable Communication:

    • TCP uses acknowledgment, sequencing, and retransmission to ensure data delivery.
    • Packets are delivered in order and without duplication.
  5. Flow Control:

    • TCP prevents the sender from overwhelming the receiver using a sliding window mechanism.
    • The receiver dictates the amount of data the sender can send.
  6. Error Control:

    • TCP detects errors in segments using checksums and retransmits lost or corrupted packets.
  7. Congestion Control:

    • TCP manages network congestion by adjusting the data transmission rate based on network conditions.

Important Port Numbers

  • 20, 21: FTP (File Transfer Protocol)
  • 22: SSH (Secure Shell)
  • 23: Telnet
  • 25: SMTP (Simple Mail Transfer Protocol)
  • 53: DNS (Domain Name System)
  • 80: HTTP (Hypertext Transfer Protocol)
  • 443: HTTPS (Secure HTTP)
  • 110: POP3 (Post Office Protocol)
  • 143: IMAP (Internet Message Access Protocol)
  • 3306: MySQL Database
  • 8080: Alternative HTTP port

TCP Features

Numbering System

  • TCP assigns numbers to each byte of data for tracking and order.
  • Sequence Number:
    • Represents the byte number of the first byte in a segment.
    • Used to ensure correct sequencing of data.
  • Acknowledgment Number:
    • Represents the next byte expected by the receiver.
    • Acknowledges successful receipt of all previous bytes.

Flow Control

  • TCP uses the sliding window mechanism to manage data flow.
  • The receiver advertises a window size indicating how much data it can handle.

Error Control

  • TCP detects segment errors using checksums and retransmits damaged or lost segments.
  • Uses cumulative acknowledgment for confirming receipt of data.

Congestion Control

  • Adjusts the sender's rate based on network conditions to avoid congestion.
  • Employs algorithms like Slow Start, Congestion Avoidance, and Fast Recovery.

TCP Segment Format

A TCP packet, known as a segment, consists of a header and data. The header size ranges from 20 to 60 bytes.

Field Size Description
Source Port 16 bits Identifies the sending application.
Destination Port 16 bits Identifies the receiving application.
Sequence Number 32 bits Indicates the byte number of the first byte in the segment.
Acknowledgment Number 32 bits Specifies the next byte expected by the receiver.
Header Length (HLEN) 4 bits Specifies the size of the header in 4-byte words.
Control Flags 6 bits Indicates control functions (e.g., SYN, ACK, FIN).
Window Size 16 bits Specifies the size of the receiving window.
Checksum 16 bits Ensures the integrity of the header and data.
Urgent Pointer 16 bits Points to urgent data if the URG flag is set.
Options and Padding 0–40 bytes Optional fields for advanced configurations.

TCP Control Flags

Flag Description
URG Urgent pointer is valid.
ACK Acknowledgment field is valid.
PSH Push data to the receiving application immediately.
RST Reset the connection.
SYN Synchronize sequence numbers (used in connection establishment).
FIN Terminate the connection.

Three-Way Handshake (Connection Establishment)

  1. SYN:
    • The client sends a SYN (synchronize) segment with an initial sequence number.
  2. SYN-ACK:
    • The server responds with a SYN-ACK segment, acknowledging the client's SYN.
  3. ACK:
    • The client sends an ACK segment, acknowledging the server's SYN-ACK.
    • Connection is now established.

Connection Termination

  1. FIN:
    • One party sends a FIN segment to initiate termination.
  2. ACK:
    • The other party acknowledges the FIN and may still send remaining data.
  3. FIN-ACK:
    • Both parties exchange FIN-ACK segments to terminate the connection gracefully.

Summary

TCP is a robust, reliable transport protocol designed for applications requiring guaranteed data delivery. Its features like flow control, error control, and congestion control make it suitable for critical applications like web browsing, email, and file transfer. By numbering and sequencing data, TCP ensures that communication between processes is accurate and ordered.

Stream Control Transmission Protocol (SCTP)

The Stream Control Transmission Protocol (SCTP) is a transport layer protocol designed to combine features of both TCP and UDP. It provides reliable, connection-oriented communication like TCP while supporting message-oriented communication like UDP. SCTP is particularly useful for applications that require reliable transmission of message-based data.


Key Features of SCTP

  1. Message-Oriented Communication:

    • SCTP works with messages rather than byte streams, making it ideal for applications needing structured data transmission.
  2. Multi-Streaming:

    • SCTP supports multiple independent streams within a single connection.
    • If one stream encounters issues (e.g., loss or retransmission), others remain unaffected.
  3. Multi-Homing:

    • SCTP supports multi-homing, where endpoints can have multiple IP addresses.
    • If one path fails, SCTP can switch to an alternate path without disrupting the connection.
  4. Reliable Communication:

    • SCTP ensures that messages are delivered without duplication or loss.
    • Uses sequence numbers for each message for reliable delivery.
  5. Connection-Oriented:

    • SCTP requires an association (connection) to be established before communication begins.
  6. Congestion Control:

    • Like TCP, SCTP adjusts its transmission rate based on network conditions to prevent congestion.
  7. Flow Control:

    • The protocol ensures that the sender does not overwhelm the receiver with data.
  8. Error Control:

    • SCTP uses checksums for error detection and retransmits lost or corrupted packets.
  9. Graceful Termination:

    • SCTP terminates connections gracefully using a four-way handshake.

SCTP Services

  1. Process-to-Process Communication:

    • Uses port numbers to identify applications on the source and destination systems.
  2. Multi-Streaming:

    • Supports independent streams, reducing the impact of message loss or delay in one stream on others.
  3. Multi-Homing:

    • Ensures fault tolerance by supporting multiple network paths.
  4. Reliable Data Transfer:

    • Guarantees delivery, order, and integrity of messages.

SCTP Packet (Chunk) Format

SCTP packets are called chunks, and each packet may contain multiple chunks. The general structure of an SCTP packet is as follows:

SCTP Common Header

Field Size Description
Source Port 16 bits Identifies the source application.
Destination Port 16 bits Identifies the destination application.
Verification Tag 32 bits Ensures that the packet belongs to the correct association.
Checksum 32 bits Detects errors in the entire packet.

Chunks in SCTP

Each SCTP packet can contain multiple chunks. Chunks have the following format:

Field Size Description
Type 8 bits Specifies the chunk type (e.g., INIT, DATA).
Flags 8 bits Defines flags specific to the chunk type.
Length 16 bits Length of the chunk, including the header.
Value Variable Contains the data or control information.

Types of Chunks

  1. Control Chunks:

    • Used for managing the connection.
    • Examples: INIT (connection setup), INIT-ACK, SACK (Selective Acknowledgment), HEARTBEAT, SHUTDOWN.
  2. Data Chunks:

    • Used for transmitting user data.
    • Includes sequence numbers for reliability and reassembly.

Connection Establishment (Four-Way Handshake)

SCTP uses a four-way handshake to establish a connection, known as an association:

  1. INIT:

    • The initiator sends an INIT chunk to start the association, specifying the streams and a verification tag.
  2. INIT-ACK:

    • The receiver responds with an INIT-ACK chunk, echoing the verification tag and specifying its own.
  3. COOKIE-ECHO:

    • The initiator sends a COOKIE-ECHO chunk containing information to validate the association.
  4. COOKIE-ACK:

    • The receiver sends a COOKIE-ACK chunk to confirm the association is established.

Multi-Streaming

  • Each stream is independently numbered, allowing messages in different streams to arrive out of order without affecting others.
  • Useful in multimedia applications where different types of data (e.g., video, audio) need separate handling.

Multi-Homing

  • Each SCTP endpoint can be associated with multiple IP addresses.
  • In case of a network failure, SCTP automatically switches to an alternate path.
  • This feature enhances fault tolerance and reliability.

Reliable Data Transfer

  1. Sequencing:

    • Each message is assigned a sequence number within its stream.
    • Ensures messages are delivered in order within a stream.
  2. Acknowledgment:

    • SCTP uses selective acknowledgment (SACK) to confirm receipt of data.
  3. Retransmission:

    • Lost or corrupted chunks are retransmitted based on acknowledgments.

Graceful Termination

SCTP terminates an association using a four-way handshake:

  1. SHUTDOWN:

    • One endpoint sends a SHUTDOWN chunk to initiate termination.
  2. SHUTDOWN-ACK:

    • The other endpoint responds with a SHUTDOWN-ACK chunk.
  3. SHUTDOWN-COMPLETE:

    • The initiator acknowledges with a SHUTDOWN-COMPLETE chunk.

Differences Between TCP and SCTP

Feature TCP SCTP
Communication Byte-oriented Message-oriented
Streams Single stream Multiple independent streams
Homing Single-homed Multi-homed
Connection Three-way handshake Four-way handshake
Reliability Guaranteed order and delivery Guaranteed order per stream
Usage General-purpose applications Applications needing fault tolerance and structured data

Applications of SCTP

  • Telecommunication: Used in signaling protocols like SS7 over IP.
  • Real-Time Communication: VoIP, video conferencing.
  • Message-Oriented Services: Financial transactions, chat applications.

Summary

SCTP combines the best of TCP and UDP, offering reliable, connection-oriented, and message-based communication. Its unique features like multi-streaming and multi-homing make it a robust choice for specialized applications requiring high reliability and flexibility.

Top comments (0)