This is the 17th day of my participation in the August Challenge
Recently I reread TCP/IP protocol, sure enough, every time I read it, I have a different experience. TCP/IP is the foundation of the Internet and the backbone of the Internet protocol stack.
1. Protocol Stack
- The Internet uses a four-tier architecture based on TCP/IP, with TCP at the transport layer for establishing end-to-end connections and IP at the network layer for addressing and routing.
1. Connection level:
-
TCP is a connection between two ports. The TCP header contains only the port number. A port can be thought of as a separate channel for a computer, with each application using a different port to send data and listen on a designated port. The sender needs to know that the receiver is always listening on the specified port, otherwise there will be no response or an error.
-
An IP address is a connection established between two network addresses. An IP address is added to the packet.
-
Together, the two make a complete passage.
3. Data Format:
-
TCP divides application data into the size most suitable for sending, and adds TCP headers to the data. These data are called “segments” on the TCP layer.
-
IP adds its own header to these segments and sends them as packets.
-
At the interface layer below, the header is added and converted to a binary frame to send;
4. Connection-oriented and connectionless:
-
TCP is connection-oriented. What does that mean? Before data exchange between the two parties, a fixed and exclusive channel must be established using TCP. All DATA at the TCP layer are transmitted through a dedicated channel. Even if there is no data transmission, as long as the two parties do not dislink, this channel will always exist. It can be understood that both parties are “on the phone”;
-
IP is connectionless. What does that mean? That is, the two parties do not need to establish a fixed exclusive channel before communication, using the form of “short message”, data is sent, the use of shared public transmission, and each packet path is not necessarily the same;
5. Reliability and unreliability
-
TCP uses ACK and checksum to ensure that the received data is complete and correct. TCP combines the out-of-order data in the original order. If a timeout or packet loss occurs, TCP retransmission and congestion control are triggered.
-
IP protocol does not support congestion control, ACK confirmation mechanism, and error correction function, and each packet is independent, out of order, IP addressing and routing is BE business, the best effort is to ensure that the packet will BE correct and complete to the destination, which requires TCP to achieve;
6. Full-duplex? Half duplex? Simplex?
-
Full Duplex is a Duplex that allows data to be transmitted in two directions at the same time.
-
The so-called half duplex, that is, at the same time, only one party to send information, such as one party to send the end, the other party to send; Simplex means that only the sender is allowed to send messages to the receiver.
-
Obviously, a TCP connection allows both parties to send data to each other at the same time. TCP is full-duplex. Therefore, this is why it is necessary to shake hands 4 times to confirm that both parties have no data to send before disconnecting the chain.
7. Why do WE need to wait 2MSL after chain removal?
-
MSL: Maximum segment lifetime Indicates the maximum lifetime of TCP segments before they are discarded.
-
It ensures that the sent FIN ACK is not discarded (1 MSL) and that the re-FIN returned by the other party is received (1 MSL).
-
On the other hand, the interval between two TCP connections is sufficient to prevent the data of the old session from affecting the new session.
8. Key fields of TCP packets
-
Header length: 4 bits. The value ranges from 5 to 15. The default value is 5. The length of the corresponding header ranges from 5 x 32 bits (160 bits) to 15 x 32 bits (480 bits).
-
TCP refers to the number of bytes in the TCP segment. Each byte in the TCP segment is numbered. SEQ is the number of the first byte in this segment.
-
The first function of Seq is to restore the correct order of received data by serial number. The second is to check whether a packet is missing and which byte is missing.
-
The Seq number is available for each message. The ACK number is available only when the ACK flag is 1.
-
The ACK number of the sender is the SEQ number it expects to receive the next TCP packet.
-
The ACK number of the next received TCP packet is the byte length of its own SEQ+payload. ACK=374=next SEQ; SEQ+LEN=340+387=727=next ACK
9. Slide Windows
-
The purpose of sliding Windows is to improve data transmission efficiency as much as possible without exceeding the receiver’s cache capacity. The window size refers to the total number of packets that can continue to be sent without waiting for an acknowledgement packet;
-
The sender and receiver maintain a send window and a receive window respectively
-
The size of the receiving window is sent to the other party through the Window field in the TCP packet, in byte. This byte is only 16 bits, so the Window size Scaling factor is also used for capacity expansion. The actual Window size is the product of these two values. The Window size scaling factor is determined during the three-way handshake. When the value is -1, it indicates unknown and the Window size is not trusted.
-
Receive window (RWND): Receive window, which prevents the application from sending data beyond the buffer of the other party. The flow control used by the receiver. Congestion Control Window (CWND) : Congestion window, preventing applications from sending more data than the network can carry. The flow control used by the sender. Send window: refers to the smaller values of both.
-
Both the send and receive Windows slide through the system’s cache, decreasing to 0 if the cache is full.
-
A group of data is divided into different segments for transmission and assembled at the receiving end.
-
Retransmission mechanism: If the size of a segment exceeds the window size of the receiving end, the segment will fail to be ack and the segment and subsequent segments will be retransmitted. In case of packet loss, the receiving window does not move and does not acknowledge subsequent segments in case of segment loss, ensuring that the sender will retransmit this segment.
Thank you for reading, if there are inaccurate and wrong place please comment, I will immediately correct, thank you!
Summary is not easy, please do not reprint without permission, otherwise don’t blame old uncle you are welcome
Welcome technical friends to communicate with me, wechat 1296386616
References:
“The OSI and TCP/IP models” communicationstechnologyblog.wordpress.com/2nd-child-p…
Why TIME_WAIT state Need to be 2MSL long? Alex Wu stackoverflow.com/questions/2…
The Transmission Control Protocol “Wikipedia en.wikipedia.org/wiki/Transm…
How Does the Internet Work? Rus Shuler web.stanford.edu/class/msand…
TCP/IP Networking in a Nutshell Kevin Cleary ubnetdef.org/slides/fall…
The TCP IP – a: Sliding Window (Sliding Windows), CQ boy blog.csdn.net/wdscq1234/a…