1. Layer TCP/IP networks

TCP/IP Protocol model (Transmission Control Protocol/Internet Protocol), which contains a series of network protocols that constitute the foundation of the Internet, is the core Protocol of the Internet. After more than 20 years of development, it has become increasingly mature. And is widely used in local area network and wide area network, has become a de facto international standard. The TCP/IP protocol cluster is a combination of multiple protocols at different levels and is generally considered a four-tier protocol system, corresponding to the OSI seven-tier model.

The layers of protocol are from top to bottom

  • Ethernet II: Ethernet frame header at the network interface layer
  • Internet Protocol Version 4: Indicates the IP packet header of the Internet layer
  • Transmission Control Protocol: Indicates the header of a data segment at the transport layer. In this case, TCP
  • Hypertext Transfer Protocol: Indicates HTTP information at the application layer

1.1 Application Layer

The application layer is responsible for handling specific application details.

The essence of the application layer is that it defines how applications transmit packets to each other. Many application layer protocols are defined by RFC documents

  • Domain name resolution protocol DNS
  • SMTP and POP3 protocol for sending and receiving mails
  • Clock synchronization protocol NTP
  • Network file sharing protocol NFS

In HTTP, for example

  • The type of the packet, whether it is a request packet or a response packet
  • Syntax of a packet: A packet is divided into several segments. What are the meanings of each segment and how are they separated? What is the meaning of each field in each part
  • In what time sequence should the process send and process the response messages

1.2 Transport Layer

The transport layer primarily provides end-to-end communication for applications on two hosts.

The transport layer provides end-to-end logical communication between “application processes” of two hosts, separated by thousands of kilometers, as if they were communicating directly. In the TCP/IP protocol family, there are two distinct transport protocols: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).

1.3 Internet Layer

Handles group activities in the network, such as group routing.

The network interconnection layer provides host-to-host communication, encapsulates the packets generated by the transport layer into packets and sends them to the target host, and provides the capability of routing.

Network interconnection layer protocols include IP (Internet Protocol), ICMP (Internet Control Message Protocol), and IGMP (In Ternet Group Management Protocol).

IP is the main protocol at the network layer. Both TCP and UDP use IP as the network layer protocol. The main function of this layer is to add the source address and destination address to the packet and send the packet to the destination address.

IP is connectionless and does not have a retransmission mechanism, which is one of the reasons why TCP is complicated because it is based on such an unreliable protocol.

1.4 Network Access Layer

It usually includes the device driver in the operating system and the corresponding network interface card in the computer. Together they deal with the details of the physical interface with the cable (or any other transmission medium).

The network access layer is also known as the network interface layer. Ethernet, Wifi, and Bluetooth work at this layer. The network access layer provides the hardware and related protocols required by the host to connect to the physical network.

2. Overview of TCP

TCP is a reliable, connection-oriented, byte-stream – based, full-duplex protocol.

2.1 Connection-oriented

Connection-oriented means that two applications using TCP (typically a client and a server) must establish a TCP connection before exchanging data with each other. The process is very similar to making a phone call. You dial and ring, wait for the other person to pick up and say “Hello”, and then explain who it is.

The process of establishing a connection is done through a “three-way handshake”, which, as the name implies, establishes a connection through three data exchanges. The starting serial number, window scaling and other information of subsequent communication between the two parties are negotiated through the three-way handshake.

2.2 Reliable

IP is a connectionless, unreliable protocol: it does its best to transmit datagrams from the sender to the receiver, but there is no guarantee that packets will arrive in the same order as they were transmitted, that packets will be duplicated, or even that they will reach the receiver.

TCP reliability depends on:

  • Application data is divided into data blocks that TCP considers best for sending. Unlike UDP, the application-generated datagrams remain the same length. The unit of information transmitted to IP by TCPTCP is called packet segment or segment.
  • When TCP sends a segment, it starts a timer and waits for the destination to acknowledge receipt of the segment. If an acknowledgement cannot be received in time, the packet segment is resend.
  • When TCP receives data from the other end of the TCP connection, it sends an acknowledgement. This confirmation is not sent immediately and is usually delayed by a fraction of a second
  • TCP will keep its head and data checksum. This is an end-to-end checksum to detect any changes in the data during transmission. If a segment is checked and an error occurs, TCP discards the segment and does not acknowledge receipt of the segment (expecting the originator to time out and retransmit).
  • TCP packet segments are transmitted as IP datagrams, and the arrival of IP datagrams may be out of order, so the arrival of TCP packet segments may also be out of order. If necessary, TCP resorts the received data to the application layer in the correct order.
  • Since DUPLICATE IP datagrams can occur, TCP receivers must discard duplicate data.
  • TCP also provides traffic control. Each side of a TCP connection has a fixed amount of buffer space. The receiving end of TCP allows the other end to send only as much data as the receiving end buffer can accept. This prevents faster hosts from overrunning the buffer for slower hosts.

2.3 Byte-stream Based

TCP is a byte-stream protocol. A stream has no fixed packet boundary. The number of bytes sent in each TCP packet is not fixed and depends on the maximum transmission unit (MTU) of the path, the size of the sending window, and the size of the congestion window.

The two applications exchange a byte stream consisting of 8 bit bytes over a T C P connection. T C P Does not insert record identifiers in the byte stream. We call this a Byte stream service. If one side’s application sends 10 bytes, then 20 bytes, then 50 bytes, the other side of the connection has no way of knowing how many bytes the sender sent each time. The receiver can receive the 80 bytes four times, each time receiving 20 bytes. One end places the byte stream on the T C P connection, and the same byte stream will appear on the other end of the T C P connection.

2.4 Full-duplex

In TCP, the sender and receiver can be client/server or server/client. Both sides of communication can receive or send data at any time. Data flow in each direction independently manages serial number, sliding window size, MSS and other information.

The resources

Understanding TCP in Depth: From Principle to Action