Computer Network Summary - Transport Layer

5.1 Overview of Transport Layer

The real entities that communicate in a computer network are the processes in the communicating hosts .

The task of the transport layer is to provide direct communication services between processes running on different hosts, and the transport layer protocol is also called an end-to-end protocol.

According to different application requirements, the transport layer provides two different transport protocols for the application layer, namely connection-oriented TCP and connectionless UDP .

image-20210614163920365

5.2 Concepts of Transport Layer Port Numbers, Multiplexing and Demultiplexing

1. Port number

Processes running on a computer are identified by the process identifier PID .

However, computers on the Internet do not use a unified operating system, and different operating systems (windows, linux, Mac OS) use different formats of process identifiers .

In order to enable communication between application processes of computers running different operating systems, a unified method must be used to identify the application processes in the TCP/IP system .

The transport layer of the TCP/IP system uses port numbers to distinguish different application processes.

  • The port number is represented by 16 bits , and the value range is 0-65535 , which is divided into the following three types:
    • Familiar port numbers : 0-1023, IANA assigns these port numbers to some of the most important application protocols in the TCP/IP system , such as: FTP uses ports 21 and 20, HTTP uses port 80, and DNS uses port 53.
    • Registered port numbers: 1024-49151, used by applications without well-known port numbers. The use of such port numbers must be registered with IANA in accordance with the prescribed procedures to prevent duplication. For example, the port number used by Microsoft Remote Desktop RDP is 3389.
    • Ephemeral port numbers: 49152-65535, reserved for temporary use by client processes . After the communication is over, this port number can be used by other client processes.
  • The port number has only local significance, that is, the port number is only used to identify the processes in the computer. Different computers may have the same port number, but there is no relationship.

2. Multiplexing of the sender and demultiplexing of the receiver

image-20210614170229220

3. Port numbers used by commonly used protocols in the application layer

The well-known port numbers of the transport layer used by the common protocols of the application layer of the TCP/IP system:

image-20210614170837722

4. Give an example to illustrate the role of the port number

Application scenario: The user queries the content of the web page by entering a URL.

image-20210614171858265

  1. When the user uses a browser to access the Web server, the DNS client process in the user's PC will send a DNS query request message , the content of which is "what is the IP address whose domain name is www.porttest.com".

  2. The DNS query request message is encapsulated into a UDP user datagram by the UDP protocol of the transport layer . The value of the source port field of the datagram header is selected from an unused ephemeral port number 49151-65535, and the value of the destination port field is set to 53 , which is a well-known port number used by the DNS server process.

  3. It is then encapsulated into an IP datagram and sent.

image-20210614172916004

  1. After the DNS server receives the IP datagram, it unblocks the UDP user datagram from it. The destination port number in the datagram is 53, indicating that the data payload part of the UDP user datagram (that is, the DNS query request message) should handed over to the DNS server process.
  2. The DNS server-side process parses the content of the DNS query request message, then searches for the corresponding IP address, and sends a DNS query response message, the content of which is *"the IP address of the domain name www.porttest.com" is 192.168.0.3"*.
  3. The DNS response message is encapsulated into a UDP user datagram, the source port number of the datagram header is 53, and the destination port number is 49152.
  4. It is then encapsulated into an IP datagram for transmission.

image-20210614173512359

  1. After the user PC receives the IP datagram, it decapsulates the UDP user datagram. The destination port number in the datagram is 49152, indicating that the data payload part of the UDP user datagram (that is, the DNS response message) should be handed over to the DNS client process.
  2. The DNS client process parses the content in the DNS response message to know the IP address corresponding to the previously requested domain name.
  3. Now the HTTP client process in the user's PC can send an HTTP request message to the Web server.

image-20210614173903846

  1. The content of the HTTP request message is *"What is the content of the home page?"*, and then it is encapsulated into a TCP message segment by the TCP protocol of the transport layer. The source port value of the header is an unused one among the ephemeral port numbers 49151-65535, and the destination port number is 80 , which is a well-known port number used by the HTTP server-side process.
  2. It is then encapsulated into an IP datagram for transmission.

The rest of the process is similar to the above, so I won't go into details here.

5.3 Comparison of UDP and TCP

UDP and TCP are two important protocols in the transport layer of the TCP/IP architecture .

The following is a comparison of the two from several aspects:

image-20210614181256997

  1. UDP can send data at any time, which is connectionless.
  2. TCP needs to establish a connection before sending data, which is connection-oriented .

image-20210614181443324

  1. In LAN, UDP can send unicast, multicast, broadcast data
  2. TCP, on the other hand, can only send unicast data.

image-20210614182245406

The processing methods for application packets are different:

  1. UDP directly adds a header to the application layer message of the application layer, and then sends it directly . After receiving the datagram, the receiver removes the header and hands it over to the upper application layer.
  2. TCP regards the data blocks delivered by the application layer only as a series of unstructured byte streams, and numbers them and stores them in its own sending buffer. TCP extracts a certain number of bytes from the sending buffer according to the sending strategy, and constructs them into TCP segments for sending. On the one hand, the receiver takes out the data load part from the received TCP segment and stores it in the receiving buffer; on the other hand, it delivers some bytes of the receiving buffer to the application process.

image-20210614182749154

  1. The UDP protocol provides a connectionless and unreliable transmission service to its upper layer , and the datagram is only discarded if there is a bit error, and no other measures will be taken.
  2. The TCP protocol provides connection-oriented and reliable services to its upper layer .

image-20210614224738245

  1. Since UDP does not provide reliable transmission services, the header is relatively simple .
  2. Since TCP needs to realize reliable transmission, flow control, congestion control and other services, its header is relatively complicated .

summary:

image-20210614224841012

5.4 TCP flow control

Flow control: let the sender not send too fast, let the receiver have time to accept.

The sliding window mechanism is used in the TCP protocol to implement flow control.

for example:

Assume that each TCP segment sent by host A can carry 100 bytes of data.

When host A and host B establish a TCP connection, B tells A: My receiving window is 400, so host A also sets its own sending window to 400.

image-20210616211449808

  1. Host A encapsulates the data from 1 to 100 in the sending window into a message segment and sends it out. At this time, there are still 300 bytes in the sending window to send.

  2. Then host A encapsulates the data from 101 to 200 in the sending window into a TCP segment and sends it out. At this time, there are still 200 bytes in the sending window that can be sent.

  3. Then host A encapsulates the data from 201 to 300 in the sending window into a TCP segment and sends it out, but the segment is lost during transmission, and there are still 100 bytes in the sending window to send.

  4. Host B confirms the data before 200, and adjusts the window value to 300 in the confirmation (B adjusted according to its own situation), and performs flow control on host A for the first time.

image-20210616213101080

  1. After receiving the acknowledgment, host A slides the sending window forward, so that the data that has been sent and received the acknowledgment is moved out of the sending window, and at the same time adjusts its own sending window to 300.
  2. Host A can now delete bytes 1 to 200 in the send buffer because it has received cumulative acknowledgments from host B for them.
  3. Host A encapsulates the bytes from 301 to 400 into a message segment and sends it out, and there are still 100 bytes in the sending window to send.
  4. Then host A encapsulates 400 to 500 bytes into a TCP segment and sends it out. At this time, there is no data to send in the sending window.
  5. The retransmission timer of 100 bytes from 201 to 300 in the sending window expires, and host A repackages and sends it.
  6. Host B confirms the byte data from 201 to 500, and changes the window field value to 100 in the cumulative confirmation. This is the second flow control performed by host B on host A.

The following process is similar, here only described by pictures, no more text. The detailed process can be seen in this video

image-20201021231945653

image-20201021232027721

image-20201021232600497

Note: There may be a deadlock here. The solution: start the continuous timer, and send a zero-window detection message after timeout.

TCP has a persistent timer for each connection. As long as one party receives the zero window notification from the other party, the persistent timer will be started. When the timer expires, a zero window detection message will be sent, carrying only one byte of data. The receiver will give its own window value after acceptance. If it is still zero, the persistent timer will be restarted.

image-20201021232645300

The zero-window detection message may also be lost. The solution: start a retransmission timer and retransmit after timeout.

Practice questions:

image-20210616215049070

5.5 TCP Congestion Control

1. Basic concepts

Congestion: The demand for a resource in the network exceeds what the resource can provide, and the network resource will go bad.

Network resources: link capacity (i.e. bandwidth), caches and processors in switching nodes, etc.

When congestion occurs and is not controlled, the throughput of the entire network will decrease as the input load increases.

The curves of ideal congestion control, actual congestion control, and no congestion control are shown in the following figure:

image-20210616215832586

2. Congestion control algorithm

TCP's four congestion control algorithms:

  1. slow start
  2. congestion avoidance
  3. fast retransmission
  4. fast recovery

To better describe these algorithms, the following conditions are assumed:

  1. Data is sent in one direction, the other direction only sends an acknowledgment
  2. The receiver always has enough buffer space, so the size of the sending window of the sender is determined by the congestion level of the network.
  3. The unit of discussion is the number of maximum message segments, not bytes.

Real send window value = Min (receiver window value, congestion window value)

(1) Congestion window and slow start threshold

The sender maintains a state variable called the congestion window cwnd , whose value depends on the degree of network congestion and changes dynamically.

  • The maintenance principle of the congestion window cwnd: if there is no congestion in the network, the congestion window will be larger, and if the network is congested, the congestion window will be reduced.
  • The basis for judging the occurrence of network congestion: the acknowledgment message that should have arrived was not received on time (that is, a timeout retransmission occurred)

Earlier we assumed that the conditional receiver has enough buffer to accept, so here the sender takes the congestion window as the sending window swnd, that is, swnd=cwnd.

The sender also maintains a state variable of the slow start threshold ssthresh:

  • When cwnd < ssthresh, the slow start algorithm is used.
  • When cwnd > ssthresh, stop using the slow start algorithm and use the congestion avoidance algorithm instead.
  • When cwnd = ssthresh, either the slow start algorithm or the congestion avoidance algorithm can be used.

(2) Slow start algorithm

Slow start algorithm: every time a transmission round passes, the congestion window is doubled.

Transmission round: The sender sends the segment and the receiver confirms it, which is a round-trip time.

The following is an example to introduce:

When the connection is just established, the congestion window value is set to 1, and the slow start threshold is 16 in this example.

Since the congestion window value is 1, the sender can only send one segment.

image-20210616223426704

After receiving the acknowledgment segment, the sender increases the congestion window value by 1 to 2. At this point the sender can send two segments.

image-20210616223610626

After receiving the acknowledgment segment, the sender increases the congestion window value by 2 to 4. At this time, the sender can send four segments.

image-20210616223746614

After receiving the acknowledgment segment, the sender increases the congestion window value by 4 to 8. At this time, the sender can send 8 segments.

image-20210616223854750

After receiving the acknowledgment segment, the sender increases the congestion window value by adding 8 to 16. At this time, the congestion window value is equal to the slow start threshold . After that, the congestion control algorithm is used instead, that is, the congestion window value can only be linearly increased by 1.

image-20210616224147489

After receiving the acknowledgment segment, the sender increases the congestion window value by 1 to 17. At this point, the sender can send 17 segments.

image-20210616224258285

As the transmission rounds increase, the congestion window value increases linearly by 1 each round. Assuming that the congestion window value is 24 now, the sender can send 24 message segments, but some of them are lost during the transmission process , which will cause the sender to timeout and retransmit these message segments . The sender judges that the network is likely to be congested , and needs to do the following work:

  • Update the slow start threshold to half of the congestion window when congestion occurs
  • Reduce the congestion window value to 1 and re-execute the slow start algorithm
image-20210616224709936

Then continue to cycle the above process

image-20210616224814850

(3) Congestion avoidance algorithm

Congestion avoidance algorithm: after each transmission round, the congestion window cwnd = cwnd + 1.

image-20201022150236926

(4) Fast retransmission

Sometimes, the loss of individual message segments is not due to network congestion , but may be due to the non-existence of the destination address or other circumstances.

But this will lead to overtime retransmission, the sender mistakenly thinks that the network is congested, the sender will set the congestion window value to 1, and mistakenly start the slow start algorithm, which reduces the transmission efficiency .

So the fast retransmission algorithm and the fast recovery algorithm appeared.

The use of fast retransmission enables the sender to know the loss of individual segments as early as possible, and retransmit as soon as possible , instead of waiting for the timeout retransmission timer to expire before retransmitting, so that the sender will not mistakenly think that it is network congestion.

To achieve fast retransmission:

  • The receiver is required not to wait until it sends the data to send the confirmation, but to send the confirmation immediately .
  • Even if out-of-sequence segments are received, duplicate acknowledgments of received segments are required immediately .
  • Once the sender receives 3 consecutive duplicate acknowledgments , it retransmits the corresponding message segment immediately instead of waiting for the timeout retransmission timer of the message segment to expire before retransmitting.

for example:

image-20210616233701322

(5) Fast recovery algorithm

Once the sender receives 3 repeated acknowledgments , it knows that only individual segments are lost, so it does not start the slow start algorithm, but executes the fast recovery algorithm.

The sender adjusts the slow start threshold and the congestion window to half of the current window , and starts to execute the congestion avoidance algorithm .

Some fast recovery is to increase the congestion window value, which is equal to the new slow start threshold +3. The reason is: since the sender has received 3 repeated acknowledgments, it means that 3 message segments have left the network and reached the receiver, so network resources will not be consumed, so the congestion window value can be expanded appropriately.

Example:

image-20201022152041751

5.6 Selection of TCP timeout retransmission time

Guess you like

Origin blog.csdn.net/OYMNCHR/article/details/119118383
Recommended