Review: Only the host has the transport layer, and the routers, switches and hubs in the network core only use the functions of the last three layers.
Reporter: Split-Complex Process Finding Error-Reliable
In a computer, different application processes are distinguished by a process identifier (process ID).
Under the network environment:
TCP/IP architecture network solution;
At the transport layer, the protocol port number, usually referred to as a port, is used to uniquely identify a communication endpoint through IP address+port number in the whole network.
The port number of the transport layer is an integer of 16, which can be numbered as 65536 (2 to the power of 16).
Universal port: a port with a port number less than 256.
Transport layer port number:
Port number used by 1. server: well-known port number and registered port number.
2. The port number used by the client is temporary. When the client process runs, the operating system will randomly select a unique unused port number:
Multiplexing: At the source host, the transport layer protocol collects data blocks sent by the application process from different sockets, encapsulates the header information of each data block (including information for decomposition) to form a message segment, and then transmits the message segment to the network layer.
Demultiplexing: On the destination host, the transport layer protocol reads the fields in the message segment, identifies the receiving socket, and then transmits the data in the transport layer message segment to the correct socket through this socket.
Multiplexing and demultiplexing (Multiplexing and demultiplexing): Support multiple application processes to use the same transport layer protocol, and accurately deliver the received data to different application processes.
User Datagram Protocol (UDP): A transport layer protocol that provides connectionless services on the Internet.
UDP socket binary:;
Transmission Control Protocol (TCP): The Internet provides a transport layer protocol for connection-oriented services.
TCP Socket Quad:;
Measures to Realize Reliable Data Transmission Based on Unreliable Channel
Error detection: bit error detection in datagram transmission is realized by coding.
Confirmation: the receiver feeds back the receiving status to the sender. ACK (positive confirmation); Negative confirmation
Retransmission: The sender retransmits the data that the receiver did not receive correctly.
Serial number: ensure that the data is submitted in order (number the data, even if it does not arrive in order, it can be submitted in order).
Timer: solving the problem of data loss
TCP provides reliable data transmission services.
UDP does not provide reliable data transmission service.
The simplest automatic retransmission request protocol is the stop-and-wait protocol.
Pipeline protocol: a pipeline protocol that allows the sender to send multiple packets continuously before receiving an acknowledgement.
The most typical pipeline protocol: sliding window protocol
1, increase the grouping sequence number.
2. The sender and the receiver can cache multiple data packets.
Sender's sending window: the maximum number of unacknowledged packets that the sender can send.
Receiving window of the receiver: the maximum number of correctly arrived packets that can be buffered by the receiver.
Send:
Receive:
Sliding window protocol: according to the size of the window, it can be divided into:
Back n-step protocol: GBN protocol
Select the retransmission protocol: SR protocol (selective repetition).
GBN protocol: send window >; = 1; Receiving window =1;
The sender has high buffering capacity and can send multiple packets before being acknowledged.
The buffer capacity of the receiver is very low, and it can only receive a packet that arrives in order, but can't buffer packets that don't arrive in order.
The GBN sender responded to three types of events:
SR protocol: send window >; 1 receiving window > 1
The sender has high buffering capacity.
The receiver has high buffering capacity.
SR sender response event:
User Datagram Protocol (UDP): Internet transport layer protocol that provides connectionless, unreliable and best-effort datagram transmission services.
0- 15-3 1: 32-bit binary
The UDP header has four fields: each field is 2 bytes long and 8 bytes long.
Source port number and destination port number: UDP realizes multiplexing and decomposition.
Length: indicates the number of bytes in the UDP data segment (sum of header and data).
Checksum: It is used by the receiver to detect whether there is any error in the datagram.
Application data field: application layer data occupation
UDP checksum: provides error detection function.
UDP checksum is used to detect whether the data in the UDP data segment has changed during the transmission from the source to the destination.
UDP checksum calculation rules
1, everything involved in the operation is summed according to 16 bit alignment.
The content of UDP checksum calculation includes three parts: UDP pseudo header and application data.
Transmission control protocol (TCP): Internet transport layer protocol.
Provide connection-oriented, reliable and orderly byte stream transmission services.
First, the application process first establishes a connection.
Second: each TCP connection has only two endpoints.
Third: reliable delivery: no mistakes, no loss, no duplication and orderly arrival.
Fourth: full duplex communication
Fifth: oriented to byte streams.
Stream: a sequence of bytes. The interaction between the application and TCP is data blocks, which TCP regards as unstructured byte streams.
1, source port number field, destination port number field: 16 bits, which multiplexes and decomposes the data applied by the upper layer.
2. Serial number field and confirmation serial number field: 32 digits.
Serial number field: TCP serial number is to number each byte of each application layer data.
Confirm Serial Number field: the byte serial number of the data expected to be received from the other party, that is, the byte corresponding to this serial number has not been received.
9. The length of the option field is variable, with a minimum of 0 bytes and a maximum of 40 bytes.
TCP Connection Management: Connection Establishment and Connection Demolition
Take an application process on the client as an example to establish a TCP connection with an application process on the server.
First, establish contact.
The first handshake:
Client sends connection request segment to server: (SYN= 1, seq=x)
SYN = 1; Connection establishment request control section
seq = x; The serial number of the 1 th data byte of the transmitted message segment is X, which represents the serial number of the whole message segment.
The client enters SYN_SEND.
The second handshake:
Confirmation messages sent back by the server: (syn = 1, ack = 1, seq = y, ack _ seq = x+ 1).
SYN= 1 Confirmation segment for agreeing to establish a new connection.
ack _ seq = x+ 1; It means that the message segment with serial number X has been received, and it is ready to accept the message segment with serial number x+ 1.
Seq=y: the server tells the customer that the serial number of the confirmation segment is Y.
The server enters SYN_RCVD (synchronous reception) from LISTEN.
Di three-way handshake
The client confirms the connection message segments agreed by the server: (ack = 1, seq = x+ 1, ack _ seq = y+ 1).
Seq=x+ 1: the sequence number of this message segment of the client is x+1;
Ack_seq = y+ 1: The client expects to receive the message segment with the server serial number of y+ 1.
When the client sends an ACK, the client enters the established state.
When the server receives the ACK, it also enters the establishment state.
Three-way handshake portable data
Second, remove the connection: four waves.
Wave for the first time
Client sends connection release message segment to server: (FIN= 1, seq=u)
FIN= 1。 The sender has finished sending data and requested to release the connection.
Seq=u the sequence number of the first data byte sent is u.
The client state changed from ESTABLISHED to FIN_WAIT_ 1 (wait 1 terminate).
Wave for the second time
The server sends a confirmation segment to the client: (ack = 1, seq = v, ack _ seq = u+ 1).
ACK = 1; Verify that the font size segment is valid.
Ack_seq=u+ 1: The serial number of customer data that the server expects to accept is u+ 1.
Seq=v: the serial number of the data sent by the server is v.
The server state changed from ESTABLISHED to CLOSE_WAIT.
After the client receives the ACK segment, it is sent by FIN_WAIT_! Input Fin _ Wait _2
Wave for the third time
The server sends a connection release message segment to the client: (fin = 1, ack = 1, seq = v+ 1, ack _ seq = u+ 1).
FIN = 1: Request to release the connection.
ACK = 1: Confirm that the font size segment is valid.
Ack_seq=u+ 1: The sequence number indicating that the server expects to accept customer data is 1.
Seq=v+ 1 indicates that the sequence number of the first data byte sent by itself is v+ 1.
The server state changes from CLOSE_WAIT to LAST_ACK (last confirmed state).
The fourth wave:
The client sends a confirmation segment to the server: (ack = 1, seq = u+ 1, ack _ seq = w+ 1).
ACK= 1: Confirm that the font size segment is valid.
Ack_seq=v+ 1+ 1: indicates that the customer expects to accept the server data serial number as v+ 1+ 1.
Seq=u+ 1 indicates that the serial number of the data sent by the customer is u+ 1.
The client state changes from FIN_WAIT_2 to TIME_WAIT for 2MSL, and then enters the closed state.
After the server receives the last ACK again, it enters CLOSED by LAST_ACK.
1. Reliability: Ensure that the byte stream read by the receiver application process from the buffer is exactly the same as the byte stream sent and sent.
Second, the working mechanism of TCP to realize reliable data transmission service
1. Application layer data is divided into data blocks that TCP thinks are most suitable for transmission.
2. Serial number: The sender numbers the sent data packets to ensure that the data are submitted to the receiver in order for cumulative confirmation.
3. Confirmation: the receiver feeds back the receiving status to the sender to confirm whether the data is received correctly.
4, error detection, using error coding to realize bit error detection (even error correction) in the process of data packet transmission.
5. Retransmission: The sender retransmits the data that the receiver did not receive correctly.
6. Timer is introduced at the sending end to solve the problem of data loss.
Maximum message segment length: 1500 bytes
Maximum length of application layer data encapsulated in a message segment: 1480 bytes = 1500- the shortest header length.
Strategy of generating ACK by TCP
Flow control: coordinate the sending and receiving speed of data between sender and receiver.
In the communication process, the receiver sets the receiving window field of the message segment to inform the sender of the window size.
1. Network congestion: Too many hosts send too much data to the network at too fast a speed, which exceeds the processing capacity of the network, resulting in a large number of packets crowded in the queue of intermediate devices waiting to be forwarded, and the network performance is obviously degraded.
2. Congestion control: Congestion can be avoided or eliminated by reasonably scheduling, standardizing and adjusting the number of hosts, sending rate and data volume that send data to the network.
Third, the concept of supplementary introduction.
4.TCP congestion control algorithm
Before threshold: slow start-up phase
After threshold: congestion avoidance stage
L For example, if the timer expires, the current congestion window is 24MSS, and the current threshold is 16MSS.
New threshold: half of the current congestion window, new threshold =24/2= 12MSS.
New congestion window: directly adjust to 1MSS. New congestion window = 1 ms.
After adjusting the new threshold and the new congestion window, slow start is used. Congestion avoidance algorithm increases the size of congestion window.
For example, when three duplicate acknowledgements are sent, the current congestion window is 24 milliseconds and the current threshold is 16 milliseconds.
New threshold: half of the current congestion window
New Congestion Window: Adjust to New Threshold
After adjusting the new threshold and the new congestion window, the congestion avoidance algorithm is used to increase the congestion window size.
Five, the basic strategy of window adjustment (addition increase, multiplication decrease, AIMD):
When the network is not congested: gradually "additionally" increase the window.
"Multiplication" Decreasing Window in Network Congestion
6. Congestion prevention strategy: traffic shaping technology: adjust the data flow sent by the host to the network.