Chapter III TCP / IP Protocol
· 3.1 OSI reference model, agreement and service
The physical layer is realized by 0, 1 bit transmission of communication channels;
The data link layer enhances the bit transmission function, and the 01 bit is organized into a data frame to realize reliable transmission;
The network layer mainly implements routing, determines the transmission path of the end-to-end;
Transport layer realizes the non-morble data transmission of point-to-point points;
The session layer mainly implements user session relationships and synchronization management;
The syntax and semantic difference of the layer elimination information;
Applying levels to different needs to different needs.
· Comparison of TCP and UDP
The TCP implements the connection-oriented, end-to-end reliable stream transmission. TCP is the most important task for its reliability: confirmation and timeout reissue, and flow control, etc. Suitable for applications with high reliability of data.
UDP is built on the IP protocol, providing an efficient service with an IP package. But it does not consider the correct and reliability of the packet, you need to apply yourself yourself. Suitable for applications where real-time, smaller amounts of data or network communication is reliable.
· 3.3 Transport layer port
The most important part of the transport layer and the network layer is to provide "process to process" communication capabilities, and the network layer can only find the IP package to the host. Realize inter-process communication, in addition to the host address also requires a process logo.
TCP, UDP proposes the concept of protocol ports, this port is different from the hardware port. The port operation is designed as a general file in the TCP / IP implementation. The ports of TCP and UDP are completely independent, even in the same process, if they use port numbers such as 9999 / TCP and 9999 / UDP, they will not be conflicted.
There are two types of port assignments: 1 global allocation, that is, centralized control mode, and the authority is allocated as needed; 2 local allocation, the process is dynamically applied to the system when the process needs to transmit the service, and the operating system returns to the current unique port according to the current system port use. number. Due to the uniqueness of the port, you can also mark a process.
TCP / IP divides ports into two parts: 1 small amount of reserved port 2 free port, before the process is communicated.
· 3.4 Domain Name System and Name Server
Domain name parsing is the corresponding relationship between IP addresses and hostnames. The forward parsing is mapped from the domain name to the IP address, and the reverse resolution is a domain name from the IP address. In TCP / IP, the name and address conversion is completed by a set of server software that independently and collaborate, ie named servers.
· 3.5 TCP protocol
1. Confirmation mechanism for TCP
TCP transmission data is a sequence of byte composed of data in byte flow, and the sequence structure is interpreted by an application. The basic transmission unit of TCP is a TCP data segment. When the receiving end receives the data, if the data correct TCP will send a confirmation information to the sender, the confirmation value is the sequence ACK of the next byte. The sequence prior to the sender's ACK has been received correctly.
2. TCP timeout retransmission mechanism
After the TCP is sent after sending a packet, the data information is retained in the buffer until they delete them until the receiving ends send a confirmation information. If you do not receive the receiving confirmation after a period of time, the sender will resecure the packet and wait for another confirmation. If the timeout reaches a certain number of times, the sender believes that the peer is not reachable, disconnect the TCP connection.
TCP uses an adaptive determination timing time long algorithm. Define RTT (Round Trip Time) to issue a length of time between packets to packet confirmation. TCP checks the performance of each connection and recalculates the RTT value according to the change:
Timeout = β × RTT
RTT = α × OLD_RTT (1-α) × New_RTT_SAMPLE
Where α determines the speed of the RTT to the time delay, if α is close to 1, the time change does not affect the RTT value, and if it is close to 0, the RTT will extend fast speed at any time.
TCP data segment data structure, slightly;
3. TCP sliding window protocol
The TCP implements congestion control through the sliding window protocol, that is, the transmit party can only send data of the control window size, and the transmitted data is confirmed by the data confirmed by the receiver. The size of the control window is determined by two factors: one is the congestion window control of the sender itself; but the control window size is the minimum value in the transmission and reception. 4. TCP's "slow start" strategy
When the TCP discovers that the data is lost, the network is crowded, and the congestion window size is halved. When TCP believes that congestion is over, use the "slow start" policy: Each received a packet congestion window plus 1 until the number of windows is half the window, this is the time to send all the packets to be sent. And the crowd window plus 1.
5. Small knot
TCP guarantees the reliability of packets by confirming and timeout retransmission; using sliding window protocols and "slow start" policies to perform traffic control. The UDP protocol does not have the above functions, so it is good, but the reliability is poor.
· 3.6 TCP status transfer process
A TCP connection is in its life cycle, will experience a series of status: Listen, Syn-Sent, Syn-Received, Established, Fin-Wait-1, Fin-Wait-2, Close-Wait, Closing, Last-Ack, Time-wait, closed.
TCP connection establishment process, transmit request by TCP at the A terminal, the TCP response of the counter-end B:
(1) a-> b syn my sequence number is x
(2) A <- b Ack Your Sequence Number IS X
(3) a-> b syn my sequence number is y
(4) a <- b Ack your sequence number is y
A and B send their own synchronous SYN information to the other party, including the initial data serial number of the host in SYN, and requires receiving the other party to confirm the ACK confirmation of the SYN from itself. This process is called "three handshakes", which has sent three packets to pass 4 information.
The TCP connection is set to the TIME-WAIT state before the TCP connection is closed, and the TCP will enter the Closed status after waiting for the 2msL (Maximum Segment Lifetime). Where MSL is the maximum survival time in the network. The peer TCP is closed when the FIN data is transmitted, since the IP protocol is unreliable transmission, the confirmation packet that may be sent by the active party has not reached the peer, and the peer starts timeout reissue. If this, the active end is turned off TCP Connection, the TCP protocol will consider a network connection error, which will send the RST old connection data segment. Therefore, the active end is waiting to wait for 2MSL time before the TCP will ensure that the data packets of the send and receiving end disappear in the network. Active initiative is initiated by A-terminal disconnect state diagram:
TCP a TCP B
Established Established
(Turn off)
FIN-WAIT-1 ->
FIN-WAIT-2 <-
Time-Wait <-
Time-Wait ->
(Waiting for 2MSL)
Closed
IP packet format, slightly
The control packet generated by the ICMP protocol is placed in the IP packet, and is sent to the formulation via the IP packet.