TCP and UDP Comments (attached interview FAQ)

table of Contents

UDP User Datagram Protocol

TCP Transmission Control Protocol

TCP header

TCP connection

How TCP to ensure reliable transmission

TCP reliable communications embodied

How to implement TCP flow control?

What is a zero window (how would receive window is zero)?

TCP congestion control is how to achieve?

The difference between TCP and UDP

When selecting TCP, when the election UDP?

HTTP can use UDP do?

The difference between connection oriented and connectionless

 


TCP and UDP are the most basic responsibility: the IP (network layer) of the delivery of services to expand the system to run between two processes on end delivery services (transport layer) between the two end systems.

UDP is relatively simple, let's talk about UDP

 

UDP User Datagram Protocol

Data Delivery (multiplexing and demultiplexing), error checking is minimal transport layer services, only two UDP services are also able to provide. So UDP only adds a few little features on the IP datagram.

UDP features:

. 1, the UDP is connectionless. (Without establishing a connection)

2, UDP best effort. (Does not guarantee reliable delivery)

3, UDP is a message-oriented. (It does not split merge message, plus a direct transmission on UDP header down, once delivered a complete packet.)

4, UDP no congestion control. (For multimedia communications)

5, UDP support one to one, one to many, and many-to-many interactive communication. (Since no connection)

6, UDP header overhead small, 8 bytes, while TCP requires 20 bytes of header. (Less service, the information stored less)

Pseudo-header: Not really UDP header, only purpose is to calculate the checksum. In calculating the checksum, temporarily add before the UDP datagram, not handed down does not pass, so called pseudo-header.

Source Port: dispatch, for the situation to return to prevent others.

[If the recipient found UDP packet received by the destination port number is incorrect, the packet is discarded by the Internet Control Message Protocol ICMP sends a "port unreachable" error message to send to put]

Destination Port: Receipt

Length: length of the UDP user datagram, min = 8 (only the first portion, without data)

And testing: detecting UDP User Datagram there is no error in the transmission process

 

 

Why UDP to provide error checking it? (Of course, UDP transport layer can be changed here clams, UDP is a representative transport layer)

Because UDP does not guarantee that all links between source and destination provide error checking, in line with the mentality of ownership, UDP to think: Well, I own on it.

In the case of both link reliability can not be guaranteed, it can not ensure that the memory in error checking, end to end data transmission to provide error checking. This is the " end to end principle ."

Like most of the exam calculate the answer not sure, check again weak chickens I -

 

 

TCP is much more complicated, they speak slowly ~

 

TCP Transmission Control Protocol

TCP features:

. 1, the TCP is connection-oriented. (Connection is a virtual connection (logical connection) instead of a real physical connection.)

2, TCP is a point to point, both one to one.

3, TCP provides reliable service. Connected via TCP data transfer, error-free, is not lost, will not be repeated, arrive in order

. 4, the TCP provides full-duplex channels. Any suitable communication parties can send data

. 5, the TCP byte stream oriented ( determined according to the degree of network congestion and other values of the current window of a given segment should contain the number of bytes, the data block is divided into shorter long re-transmission, can wait accumulate a sufficient number of bytes then constitute segments sent )

 

TCP header

Source and destination ports: the shipping and delivery, the half and two bytes

No.: TCP data stream transport connection in each byte compiled on a serial number. It refers to sequence number field value of the first byte of the sequence number of data segments transmitted newspaper. 
Confirmation Number: is the desired number of the first byte of data in the other of the next segment. (If the acknowledgment number is N, indicating that all the data including the number N-1 has been correctly received)
data offset: start of the TCP data segment at the beginning of how close the TCP segment. (I.e., the header length, because the "Options" and "fill" unknown length) "data offset" in units of 32-bit words (4 bytes as the unit) the maximum of 60 bytes, i.e. TCP header min = 20 bytes max = 60 bytes. 
Reserved field: a rainy day, reserved for future use, but should be set to 0.

 

URG: Emergency! When URG = 1, it indicates that the urgent pointer field is valid, the processing needs (high priority) as soon as possible. TCP urgent data will then be inserted into the data first.

ACK: acknowledgment. When ACK = 0, the acknowledgment number is invalid, ACK = 1 when the acknowledgment number field is valid.

PUSH: Push. Receiving a TCP segment received PSH = 1, then the delivery of the receiving application process as soon as possible, rather than wait until the entire cache are filled up after delivery.  

RST: reset. When RST = 1, show that serious errors occur TCP connection (eg due to a host crash or other reasons), the connection must be released and then re-establish the transport connection. 

SYN: synchronization. SYN = 1 and ACK = 0, indicates that this is a connection request. If you agreed to establish a connection, the need to set the response packet SYN = 1, ACK = 1.

FIN: termination. For releasing a connection. FIN = 1 indicates that the data transmitting side to this segment has been transmitted, and for the release of the transport connection. 

 

Window: refers to the sending party newspaper segment of the receive window (A: give you something, I told you: I can receive such a large amount of data), so that the other party (the receiving party B, he needs to send data in the past, ) set up in accordance with the send window. Clearly pointed out the window now allows the amount of data sent each other and dynamically changing.

And testing: testing and field testing range comprises two portions and header data. In calculating the checksum, to add the pseudo-header of 12 bytes in front of the TCP segment.

Urgent Pointer: Indicates total number of bytes in the newspaper article segment urgent data

 

 

 

TCP connection

TCP is connection-oriented, each TCP connection has two ends .

TCP socket connection endpoint is called (socket).
Splicing the port number to the IP address constitutes a socket: Socket = (IP address: port number)               

Each TCP connection uniquely be communication ends two end points (i.e., two sockets) are determined. That is:
the TCP connection :: = {socket1, socket2} = {(IP1: port1), (IP2: port2)}

 

TCP connections, IP address, port number

  • The same IP address can have multiple different TCP connection.
  • The same port number may be present in a plurality of different TCP connections.

 

 

How TCP to ensure reliable transmission

  1. Packet Checksum: object detecting any change in the data transmission process, if the check is wrong the packets, packets are discarded and do not give a response period, then the TCP sender timeout data terminal retransmits the data.
  2. For reordering out of sequence packets (TCP packets having sequence numbers): TCP segment is transmitted as IP datagrams, and reaches the IP datagram may be out of order, thus reaching the TCP segment may also be out of order. TCP will reorder out of sequence data before to the application layer;
  3. Discards the duplicate data: For repetitive data, it is possible to discard duplicate data;
  4. Response mechanism: the recipient after receiving the data, it sends an acknowledgment (typically a fraction of a delay);
  5. Retransmission timeout: After supplying the data sender starts a timer times out without receiving an acknowledgment of the recipient, the re-transmission data;
  6. Flow control: to ensure that the receiving end can receive the data sender without buffer overflow, the flow control protocol TCP is used in a variable size sliding window protocol.

 

TCP reliable communications embodied

Each end of a TCP connection must be provided with two windows - a send window and a receive window .
TCP reliable transport mechanism with the byte count control. All are based on TCP acknowledgment number and not on the segment.
TCP four windows across often in a dynamic change in.
Round-trip time RTT TCP connection is not fixed. We need to use a specific algorithm to estimate reasonable retransmission time .

 

How to implement TCP flow control?

Flow control: Let the transmission rate of the sender's not too fast, time to let the recipient receives.

Using a sliding window protocol to achieve flow control. Transmission rate is too fast to prevent the sender, the receiver buffer not cause an overflow.

Receiver maintains a receive window receiver window (the window size in bytes), the size of the receive window in accordance with their own resources is dynamically adjusted, when ACK is returned on the TCP window size to accept packets inform Window Field sender. Send window size can not exceed the size of the acceptance window, and only when the sender sends and receives confirmation before sending a window to the right.

The upper limit for the transmitting window and congestion window to accept the smaller window. Acceptance window indicates the reception capability of the receiving side, the congestion window indicates the transmission capability of the network.

 

What is a zero window (how would receive window is zero)?

If the receiver is not capable of receiving data, the receive window will be set to 0, then the sender must stop sending data, it starts a timer duration (persistence timer), after the expiry of a transmission of 1 byte detection data packet, the receiving window to view the status. If the recipient is able to receive data, the receive window size is updated in the return packets, the data transfer is resumed.

 

TCP congestion control is how to achieve?

Congestion: at a certain time, the demand for network resources over a portion of the available resources can provide, leading to deterioration of network performance.

Congestion control: to prevent excessive data injected into the network, routers in the network to prevent an overload or link.

Here is a method of TCP congestion control:

TCP congestion control algorithm consists of four main components: a slow start (Slow Start), congestion avoidance (Congestion voidance), fast retransmission (Fast Retransmit), fast recovery (Fast Recovery)

First, the principle of the sender control congestion window is: as long as the network is not congested, the window can then larger. And there are ways to determine that congestion does not occur if a timeout occurs.

1, Slow Start: small to large gradually increasing the transmission window. After the beginning of data transmission, first the congestion window (congestion window) is set to a maximum value of the MSS segment, each receive a new message acknowledgment, put the congestion window plus one MSS. Such a transfer after each round (or is each through a round-trip time RTT), will double the size of the congestion window

2, congestion avoidance: When the size of the congestion window reaches the slow start threshold (slow start threshold), begin congestion avoidance algorithm, the congestion window size is no longer an exponential increase, but increases linearly , i.e., each through a round only increases transmission 1MSS .

Whether or congestion avoidance phase in the slow start phase, as long as the sender to determine the network is congested half (which is based on acknowledgment is not received), it should slow start threshold ssthresh is set to appear congestion window value of the sender (but not less than 2). Then the congestion window cwnd is reset to 1, execute slow start algorithm. (This is not the use of fast retransmission)

 

      3, fast retransmit: let the sender know that loss of individual segments occurred as early as possible. Fast retransmission claim issued immediately after the receiver receives a packet out of sequence segments duplicate acknowledgments rather than wait for piggybacking data is transmitted himself. Fast retransmit algorithm provides the sender as long as three consecutive receive duplicate acknowledgments should immediately retransmit the other segments have not yet received , rather than continue to wait for the retransmission timer set time expires.

 

     4, Fast Recovery: When the sender receives three consecutive duplicate acknowledgment, put the slow start threshold is reduced by half, and then performs congestion avoidance algorithm.

          The reason does not perform slow start algorithm: if the network is congested because then you will not receive several duplicate acknowledgments, the sender may not think the network is congested.
 

 

The difference between TCP and UDP

  1. TCP is connection-oriented, UDP is connectionless;
  2. TCP is a reliable, UDP is not reliable;
  3. TCP only supports point to point communication, UDP support one to one, one to many, many-to-many;
  4. TCP is a byte-oriented stream, UDP is a message-oriented;
  5. TCP congestion control mechanism, UDP does not.
  6. TCP header overhead (20 bytes) is larger than the UDP header overhead (8 bytes)

 

When selecting TCP, when the election UDP?

Expand the real-time requirements for some relatively high, select UDP, such as games, media and communications, real-time video streaming (live), even if the transmission error can be tolerated; most other cases, HTTP is a TCP, as required reliable content delivery, loss does not occur.

 

HTTP can use UDP do?

HTTP not use UDP, HTTP-based need reliable transport protocol, while UDP is not reliable.

 

The difference between connection oriented and connectionless

No service network (datagram service) connection - connection-oriented network services (virtual circuit service)

VC service: first establish a connection, all data packets pass through the same path, to ensure a good quality of service;

When the network is congested; Each packet contains the destination address, data routing independent of each other (the path may vary); best effort delivery network data, but does not guarantee that loss, does not guarantee the order, does not guarantee delivery within the time frame: datagram service , some packets might be discarded;

 

 

 

 

 

Published 38 original articles · won praise 6 · views 1894

Guess you like

Origin blog.csdn.net/weixin_43827227/article/details/105023037