Volume Chapter XXI: TCP principle

TCP

(. 1) is defined in RFC793 TCP is a connection-oriented, reliable end to end transport protocol. The main features of TCP:
"1" three-way handshake to establish a connection: to ensure the reliability of the connection is established.
"2" Port Number: The port number identifies the upper layer protocols and services, implement multiplexing network channel.
"3" integrity check of: determining and loading protocol data checksum (Checksum), to ensure that the receiver can detect errors that may occur during transmission.
"4" acknowledgment mechanism: the data correctly received, the receiver can reply by explicitly notify the sender, after exceeding a certain time, the sender will retransmit the segment has not been confirmed, to ensure the reliability of transmission.
"5" SEQ ID NO: all the data transmitted has a unique serial number, so that not only uniquely identifies each segment, but also defines the location of each segment in the entire data stream, the receiver can use this information to achieve confirmed lost detecting, rearrangement function disorder.
"6" window mechanism: by an adjustable window, TCP receiver may advertise the desired transmission speed, to control the flow of data.


(2) TCP / UDP port numbers:
To distinguish between TCP and UDP protocol, IP protocol number 6 identified using TCP, so use UDP protocol identification number 17;

 

 


TCP / UDP port number is a 16-bit binary numbers, i.e. port number in the range 0-to-16 power of 2 equal to 65535, wherein the unified management by IANA 0-1023, assigned to the well-known service usage; greater than 1023 port number is not uniform the management, which could be by the application.

 

 




(. 3) Package TCP:
the application layer data received by TCP submitted to the segment and a TCP header before encapsulating each segment. The final IP packet, then add the IP header TCP header before the formation.

 

 


A TCP header is 20 bytes (120 bits) plus the fixed length portion of variable length options (Option-) fields.

 

 


"2" source, destination port: 16-bit application programming interface defines the source and destination host;
"3" SEQ SEQ ID NO: 32 bit field is used to identify the byte TCP source device transmits the stream to the destination device it indicates that the segment if the first data byte in the byte stream considered one-way flow between the two applications, the calculated TCP sequence number to each byte.
"4" confirmation number ACK: TCP acknowledgment number using a 32-bit field represents the next stage of the first byte expect to receive, and to declare all previous data has been received without error. Therefore, Ga acknowledgment number should be the last data byte serial number has been successfully received plus 1. When you receive a confirmation number of the source host will know a particular segment has been received. Acknowledgment number field indicates only when ACK is set valid.
"5" Offset Data Date Offset: This 4-bit field comprises a TCP header size, in units of 32-bit data structure.
"6" reserved: 0 6 position field. Define new uses for future reservations.
"7" control bits: 6 bits, each bit can open a designated control function. Are: URG (Urgent Pointer field identification), ACK (Acknowledgment field flag), PSH (Push Function), RST (Reset the connection), SYN (synchronization sequence number), FIN (data transfer complete)

 

   


"8" Window Window: destination host with 16bit window field source host to tell it the desired number of bytes of each received data.
"9" checksum (Checksum): TCP header includes a 16-bit checksum field for error checking. Source host part of the IP header, TCP header, and a data content based on the calculated checksum, destination host should perform the same calculation, if the content is received without error over two results should be exactly the same, thereby demonstrating data effectiveness.
"10" urgent pointer Urgent Pointer: the urgent pointer field is an optional 16-bit pointers, the last byte (6) in the segment position point, this field is effective only when the URG flag is set.
"11" option Option: at least 1 byte variable-length field, indicating which option is valid. If not, this byte is equal to 0, indicating the end of the options field. 1 byte equals no longer represents an operation; byte equals 2 represents a maximum length of 4 bytes including the original machine (Maximum Segment Size, MSS) MSS field is the maximum amount of data may be included in the source and destination machines To this consensus. When a TCP connection is established, both sides of the connection must announce their MSS, the maximum segment length of the transmission can negotiate the amount. Common MSS 1024 bytes, Ethernet up to 1460 bytes of
"12" is filled Padding: extra zero added to this field to ensure that the TCP header is an integer multiple of 32
"13" data Date: Technically, it does not part of the TCP header, but it should be appreciated that the size of the field is the largest MSS, MSS may be negotiated between the source and destination machines. Data segment may be smaller than the MSS, but it can not be larger than the MSS.

 

(4) TCP reliable transport mechanism
three-way handshake:
". 1" HostA sends a SYN bit is set (A = seq);
"2" seq HostB received and read after a, transmission seq = b, ACK = SYN a + 1 is package;
". 3" HostA received and read after seq B, transmission seq = a + 1, ACK = SYN packet is b + 1;
establishing good TCP connection, then data may be transmitted;

 

 


Four-way handshake:
". 1" is set HostA transmits FIN (SEQ = P);
"2" HostB back ACK (ack = p + 1) , the connection is closed;
". 3" HostB set FIN (seq = q), the notification connection closed;
". 3" HostA back ACK (ack = q + 1) , the connection is closed;

 

 


Transmitting an acknowledgment:
when transmitting 4096 bytes of data, the receiving terminal is not a reply ACK acknowledge all packets, but all the other sub-received packets back an ACK = + 1 to 4096 to confirm;

 

 


Timeout Retransmission:
suppose HostA sent to the second paragraph HostB lost, then the highest segment sequence number in sequence all HostB only error-free reception for confirmation.
Retransmission trigger receiver HostB not transmit the ACK seq non-completed, but in each successive packet destined HostA value of RTT (Round Trip Time, round-trip time) expires, the HostA considers a segment has been lost, and trigger retransmission;
Thus, RTT values become an important parameter too large TCP retransmission delay, reduce the transmission rate; too small frequent cause TCP retransmissions. In a practical implementation, TCP segments sent by their respective real-time tracking time interval between the acknowledgment to dynamically adjust the value of the RTT.

 

 



Sliding window:
for example HostA transmit 4096 bytes of data, divided into four packets. When HostB due to insufficient cache or limited processing power is limited, I think that sending too fast, look forward to the lower half of the window is 2048 bytes. When HostA receives, two consecutive data packets into a total of 2048 bytes per transmission.
If the recipient device requires the window size to zero, indicating that the receiver has received all the data, or the recipient application is not time to read the data required to suspend transmission.
Variable sliding window-end flow control to solve the problem, but can not intervene network. If the intermediate node, such as a router is blocked, then there is no mechanism to notify TCP. If a particular TCP implementation for the retransmission timeout resistant and will increase the level of extreme network congestion.

 

Guess you like

Origin www.cnblogs.com/key-network/p/12446557.html