TCP - Transmission Control Protocol ===================================== .. panels:: :container: container-fluid p-4 bg-light :column: col-lg-12 .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is TCP?** TCP stands for Transmission Control Protocol. It's one of the core protocols of Internet Protocol(IP) suite. TCP ensures reliable, ordered, and error-checked delivery of data between applications running on devices connected to a network. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why is TCP useful?** Without TCP, data sent over the internet could arrive out of order, get lost, or be duplicated. So TCP solves this by * Breaking data into Packets. * Ensuring all packets arrive correctly and in order. * Retransmitting lost packets. * This makes it ideal for applications where accuracy and reliability are critical like web browsing, email. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How it works?** * Connection setup (3-way handshake) – The client and server exchange messages to establish a connection. * Data transfer – Data is broken into packets, sent, acknowledged, and reassembled in the correct order. * Error checking – TCP checks for errors and requests retransmission if needed. * Connection termination – Once data transfer is complete, the connection is closed gracefully. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Where is TCP used?** * Web browsing – HTTP and HTTPS use TCP to load websites reliably. * Email – Protocols like SMTP, IMAP, and POP3 rely on TCP. * File transfers – FTP and other file-sharing tools use TCP for accurate data delivery. * Remote access – SSH and Telnet use TCP to ensure secure and reliable sessions. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **Why OSI Layer: Transport Layer (Layer 4)?** * It manages end-to-end communication between devices. * It handles segmentation, flow control, error correction, and retransmission. * It provides a reliable communication channel for applications running at the Application Layer (Layer 7). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are the key features?** * Connection-oriented. * Reliable data transfer. * Error detection and recovery. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a three-way handshake in TCP?** A process used to establish a TCP connection: * SYN – Client sends a synchronize request. * SYN-ACK – Server acknowledges and synchronizes. * ACK – Client acknowledges server's response. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is a TCP segment?** A TCP segment is the unit of data sent over a TCP connection. It consists of: * TCP header (including sequence number, acknowledgment number, flags, etc.). * Data payload. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **How is retransmission handled in TCP?** If an ACK is not received within the timeout interval, TCP retransmits the segment. Modern TCP uses: * Timeout-based retransmission. * Fast retransmit (based on duplicate ACKs). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What are some applications that use TCP?** * HTTP/HTTPS (Web). * FTP (File Transfer). * SMTP (Email). * Telnet / SSH (Remote Access). .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the working flow of TCP?** * Connection Establishment (3-Way Handshake): * Client sends SYN → Says I want to start a connection. * Server replies with SYN-ACK → Says Okay, I got it. Let's sync. * Client sends ACK → Says Confirmed. Let's communicate. * Data Transfer: * Data is broken into segments with sequence numbers. * Each segment is sent from sender to receiver. * Receiver sends ACKs back to confirm receipt. * TCP uses a sliding window to send multiple packets before waiting. * If data is lost or corrupted, TCP retransmits it. * Flow control makes sure the sender doesn’t overload the receiver. * Congestion control adjusts speed based on network traffic. * Connection Termination (4-Way Handshake): * Sender sends FIN → Says I’m done sending data. * Receiver sends ACK → Says Okay, I got it. * Receiver sends FIN → Says I’m done too. * Sender sends ACK → Says Goodbye. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow **What is the difference between a port and an IP address?** * IP address identifies a host in the network. * Port number identifies a specific process/service on that host. Together (IP + Port) = Socket. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Learnings in this section ` * :ref:`Terminology ` * :ref:`Version Info ` * :ref:`TCP Version&RFC Details ` * :ref:`TCP Basic Setup on Ubuntu using IPv4 ` * :ref:`TCP Basic Setup on Ubuntu using IPv6 ` * :ref:`TCP Protocol Packet Details ` * :ref:`TCP Usecases ` * :ref:`TCP Basic Features ` * :ref:`TCP Feature : Connection Oriented ` * :ref:`TCP Feature : Reliable Data Transfer ` * :ref:`TCP Feature : Error Detection ` * :ref:`TCP Feature : Flow Control ` * :ref:`TCP Feature : Port Addressing ` * :ref:`TCP Feature : Graceful Connection Termination ` * :ref:`TCP Feature : Congestion Control ` * :ref:`TCP Feature : Stream Oriented ` * :ref:`TCP Feature : Ordered Delivery ` * :ref:`TCP Header ` * :ref:`TCP Header Options ` * :ref:`TCP Core Protocols ` * :ref:`TCP Common Level Options ` * :ref:`TCP Socket Level Options ` * :ref:`TCP Linux Settings ` * :ref:`Reference links ` .. _TCP_step1: .. tab-set:: .. tab-item:: Learnings in this section * In this section, you are going to learn .. _TCP_step2: .. tab-set:: .. tab-item:: Terminology * Terminology .. _TCP_step3: .. tab-set:: .. tab-item:: Version Info * Version Info .. _TCP_step5: .. tab-set:: .. tab-item:: TCP Version&RFC Details .. csv-table:: :file: ./TCP/TCP_RFCdetails.csv :widths: 10,10,10,30 :header-rows: 1 .. _TCP_step25: .. tab-set:: .. tab-item:: TCP Basic Setup on Ubuntu using IPv4 * setup .. _TCP_step26: .. tab-set:: .. tab-item:: TCP Basic Setup on Ubuntu using IPv6 * setup .. _TCP_step6: .. tab-set:: .. tab-item:: TCP Protocol Packet Details **TCP SYN Packet** .. csv-table:: :file: ./TCP/TCP_SYN_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP SYN-ACK Packet** .. csv-table:: :file: ./TCP/TCP_SYN_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP ACK Packet** .. csv-table:: :file: ./TCP/TCP_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP SUBSCRIBE Packet** **TCP PSH-ACK Packet** .. csv-table:: :file: ./TCP/TCP_PSH_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP FIN Packet** .. csv-table:: :file: ./TCP/TCP_FIN_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP FIN-ACK Packet** .. csv-table:: :file: ./TCP/TCP_FIN_ACK_Packet.csv :widths: 10,20,30,10 :header-rows: 1 **TCP RST Packet** .. csv-table:: :file: ./TCP/TCP_RST_PACKET.csv :widths: 10,20,30,10 :header-rows: 1 .. _TCP_step7: .. tab-set:: .. tab-item:: TCP Usecases .. csv-table:: :file: ./TCP/TCP_Use_Cases.csv :widths: 10,20,30 :header-rows: 1 .. _TCP_step8: .. tab-set:: .. tab-item:: TCP Basic Features .. csv-table:: :file: ./TCP/TCP_Features.csv :widths: 10,10,30 :header-rows: 1 .. _TCP_step9: .. tab-set:: .. tab-item:: TCP Feature : Connetion Oriented **Connection Oriented - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature1_Connection_oriented_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step10: .. tab-set:: .. tab-item:: TCP Feature : Reliable Data Transfer **Reliable Data Transfer - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature2_Reliable_Data_Transfer_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step11: .. tab-set:: .. tab-item:: TCP Feature : Error Detection **Error Detection - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature3_Error_detection_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step12: .. tab-set:: .. tab-item:: TCP Feature : Flow Control **Flow Control - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature4_Flow_control_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step13: .. tab-set:: .. tab-item:: TCP Feature : Port Addressing **Port Addressing - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature5_Port_addressing_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step14: .. tab-set:: .. tab-item:: TCP Feature : Graceful Connection Termination **Graceful Connection Termination - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature6_Graceful_connection_Termination_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step15: .. tab-set:: .. tab-item:: TCP Feature : Congestion Control **Congestion Control - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature7_congestion_control_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step16: .. tab-set:: .. tab-item:: TCP Feature : Stream Oriented **Stream Oriented - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature8_Stream_oriented_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step17: .. tab-set:: .. tab-item:: TCP Feature : Ordered Delivery **Ordered Delivery - Testcases** .. csv-table:: :file: ./TCP/TCP_Feature9_Ordered_delivery_feature_Test_Cases.csv :widths: 10,10,30,20 :header-rows: 1 .. _TCP_step18: .. tab-set:: .. tab-item:: TCP Header .. csv-table:: :file: ./TCP/TCP_Header.csv :widths: 10,10,10,30,40 :header-rows: 1 .. _TCP_step19: .. tab-set:: .. tab-item:: TCP Header Options .. csv-table:: :file: ./TCP/TCP_Header_Options.csv :widths: 10,10,10,30 :header-rows: 1 .. _TCP_step20: .. tab-set:: .. tab-item:: TCP Core Protocols .. csv-table:: :file: ./TCP/TCP_Core_Protocols.csv :widths: 10,10,10 :header-rows: 1 .. _TCP_step21: .. tab-set:: .. tab-item:: TCP Common Level Options .. csv-table:: :file: ./TCP/TCP_Common_Level_Options.csv :widths: 10,10,10,30 :header-rows: 1 .. _TCP_step22: .. tab-set:: .. tab-item:: TCP Socket Level Options .. csv-table:: :file: ./TCP/TCP_Socket_Level_Options.csv :widths: 10,10,10,30 :header-rows: 1 .. _TCP_step23: .. tab-set:: .. tab-item:: TCP Linux Settings .. csv-table:: :file: ./TCP/TCP_Linux_Settings.csv :widths: 10,10,10,30,40 :header-rows: 1 .. _TCP_step24: .. tab-set:: .. tab-item:: Reference links * Reference links