This is the sixth day of my participation in Gwen Challenge

Transport layer communication Overview

Process of communication

At the IP layer, two hosts communicate with each other

From the transport layer, the real endpoint of communication is not the host but the process within the host

Host A communicates with host B by means that A program running on host A communicates with another program running on host B

Reliable channel

When the transport layer uses connection-oriented TCP, it is equivalent to a reliable channel

Unreliable channel

When the transport layer uses connectionless UDP, it is equivalent to an unreliable channel

UDP TCP
Connectionless protocol to provide connectionless services; The data unit it transmits is UDP message or user datagram. Support unicast, multicast, broadcast; Failure to provide reliable delivery; Simple and suitable for many applications. Connection-oriented protocols that provide connection-oriented services; The data unit it transmits is TCP packets. Support unicast, do not support multicast and broadcast; Providing reliable services; Complex for most applications

UDP protocol is used

  • DNS – Domain name resolution protocol
  • DHCP – Dynamic Host configuration protocol
  • RIP – Routing selection protocol

TCP protocol is used

  • HTTP – Hypertext Transfer protocol
  • SMTP – Electronic Network transmission protocol
  • FTP – File transfer protocol

Software ports and hardware ports

The abstract protocol port between the protocol stacks is the software port

Ports on routers or switches are hardware ports

A hardware port is an interface through which different hardware devices interact

Software port is an address where various protocol processes of the application layer interact with transport entities

Ports are marked with a 16-bit port that allows up to 65535 different port numbers.

Ports are used to identify processes in the application layer of the computer.

The same port number on different computers is irrelevant

Therefore, two processes in the computer to communicate with each other, both to know each other’s IP address, find each other’s computer, and to know each other’s port number, find each other’s computer application process.

Common familiar port number

53: DNS

25: SMTP

20/21: FTP

23: Telnet

80: HTTP

443: HTTPS

User datagram protocol UDP

The function of UDP

Reuse and reuse capabilities

Error detection capabilities

The characteristics of UDP

  1. No connection, no need to establish a connection before sending data, reducing the cost and delay before sending data

  2. Best effort delivery does not guarantee reliable delivery

  3. In the packet oriented mode, UDP delivers a complete packet at a time without merging or splitting the packets transmitted from the application layer

  4. Without congestion control, network congestion does not reduce the sending rate of the source host

  5. Supports one-to-one, one-to-many, many-to-one and many-to-many interactive communication

  6. The first overhead is small, only 8 bytes

Transmission control protocol TCP

The characteristics of TCP

  1. connection-oriented
  2. Ensure reliable delivery
  3. Only one to one support
  4. Provides full duplex communication
  5. Word oriented stream

Socket = (IP address: port number)

The socket = (192.168.1.10:8080)

TCP connection, the relationship between IP address and socket

A TCP connection is an abstraction provided by protocol software

The endpoint of a TCP connection is an abstract socket, i.e. (IP address: port number)

The same IP address can have multiple TCP connections

The same port number can also appear on multiple TCP connections

How reliable transmission works

Stop waiting protocol

Stop waiting. Stop sending each packet and wait for confirmation. Send the next packet after receiving confirmation.

Number. Number each packet and acknowledgement sent

Automatic retransmission request. Sender sets a timeout timer for each packet sent. If the timeout timer expires, the sender automatically retransmits the packet.

Simple, but channel utilization is low

Continuous ARQ protocol

The sender can send more than one packet at a time

Use the sliding window protocol to control the number and number of packets that both sender and receiver can send and receive

With each acknowledgement, the sender slides the send window forward

The recipient generally adopts the cumulative confirmation method

The rollback N method is used for retransmission

The header format of the TCP packet segment

Source port – 2 bytes.

Destination port – 2 bytes.

Ordinal field – 4 bytes. Each byte in the TCP connection data stream is numbered. The value of the ordinal field refers to the ordinal number of the first byte of the data sent in the paragraph.

Acknowledgement number field – The sequence number of the first byte of the next segment of data expected to be received from the other party

Data offset – up to 4 bits. Indicates the distance between the start of the TCP packet segment and the start of the TCP packet segment.

Reserved field – takes up 6 bits. Reserved for future use, the current value is 0

Emergency URG – A value of 1 indicates that the emergency pointer field is valid. It tells the system that there is urgent data in this message segment and to transmit it as soon as possible

Acknowledgment ACK – The acknowledgment number field is valid only when it is 1. When the value is 0, the confirmation number is invalid

Push PSH-receive TCP receives a packet segment when PSH=1 and delivers it to the receiving application process as soon as possible, rather than waiting until the entire cache is filled up.

Reset RST – When the value is 1, a serious TCP connection error occurs and the connection must be released and then re-established

Synchronous SYN – A value of 1 indicates a connection request or connection accept message.

Terminate the FIN – Used to release a connection. When the value is 1, it indicates that the data on the sender end of the packet segment is sent and the transport connection needs to be released.

Window field – 2 bytes. The basis on which to set the sending window.

Check and – take 2 bytes. The scope of validation and field validation includes the header and data parts. When calculating the checksum, a 12-byte dummy header is added to the front of the TCP packet segment.

Emergency pointer field – 16 bits. Indicates the number of bytes of emergency data in the column.

Option field – Variable length. TCP initially provides only one option, the maximum packet segment length (MSS).

Fill field – this is so that the header length is a multiple of 4 bytes

The implementation of TCP reliable transmission

The send window indicates that the data in the window can be continuously sent out without receiving an acknowledgement

Receive window: Only data that falls into the window can be received

Send cache: The sender’s application process writes the byte stream to the TCP send cache

The send window is usually only part of the send cache

The role of the send cache

  1. The sending application sends data to the sender TCP to be sent
  2. TCP has sent data but has not received an acknowledgement

Receive cache: The receiving application process reads the byte stream from TCP’s receive cache

The role of the receive cache

  1. Data that arrives sequentially but has not yet been read by the receiving application
  2. Data arriving out of order

TCP traffic control

Ensure that the sending rate of the sender is not too fast, so that the receiver can receive data in time, and do not use network congestion

The sliding window mechanism is used to realize flow control on TCP connection

Controls the sending time of TCP packets

  1. The first mechanism is that TCP maintains a variable equal to the maximum message segment length MSS. As long as the data stored in the cache reaches MSS bytes, it is assembled into a TCP packet segment and sent out
  2. The second mechanism is that the application process of the sender specifies the segment of packets to be sent, that is, the push operation supported by TCP
  3. The third mechanism is to load the existing cache data into a message segment (length less than MSS) and send it when a timer expires.

TCP congestion control

Factors causing network congestion

  • The capacity of the point cache is too small
  • The link capacity is insufficient. Procedure
  • The processing rate of the processor is too slow
  • Congestion itself can exacerbate congestion

Difference between congestion control and flow control

Congestion control: Prevents too much data from being injected into the network to prevent overload of routers or links on the network. Is a global process that involves all factors associated with degrading network transport performance

Flow control: inhibit the rate at which the sender sends data so that the receiver can receive data in time. It’s point-to-point traffic control, it’s an end-to-end problem

Open loop control and closed loop control

Open loop control: in the design of the network, considerate in advance, strive to avoid congestion

Closed-loop control: based on the concept of feedback loop; Take control measures according to the current network running status.

Several measures belonging to closed-loop control

  1. Monitor network systems to detect when and where congestion occurs
  2. Communicate congestion information to a place where action can be taken
  3. Adjust the operation of the network system to solve problems

Monitor network congestion indicators

  1. Percentage of packets discarded due to lack of cache space
  2. Average queue length
  3. Number of packets for timeout retransmission
  4. Average packet delay
  5. Standard deviation of packet delay

Ideas to solve congestion

Add available network resources

Reduce user demand for resources

TCP congestion control method

TCP adopts window-based congestion control.

The TCP sender maintains a congestion window

The sender uses the congestion window to adjust the amount of data to be sent according to the congestion of the network

The size of the sending window depends not only on the receiving window but also on the congestion of the network

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

Principles for controlling congestion Windows

As long as there is no congestion on the network, the congestion window can be larger to send more packets and improve network utilization

If congestion occurs or is likely to occur on the network, reduce the number of packets injected into the network by reducing the congestion window

Congestion judgment

The retransmission timer timed out. – The network is congested

Received three duplicate ACKS – indicates possible network congestion

TCP congestion control algorithm

Slow start

Congestion avoidance

Fast retransmission

Fast recovery

TCP transport connection management

The three stages of a TCP connection

Connection is established

Data transfer

Connection release

Client-server approach

The TCP connection is established in client server mode

The adoption process that initiates the connection is called the client

An application process that passively waits for a connection to be established is called a server

Three handshakes to establish a connection

  1. The client first sends a packet with the SYN flag to the server
  2. After receiving the packet, the server sends back a packet with SYN and ACK flags to confirm receipt
  3. The client sends back a packet with an ACK flag, which means I know you received it

Four waves to release the connection

  1. The client sends a FIN to indicate that I’m closing the connection
  2. When the server receives the FIN from the client, it sends an ACK to the client indicating that I know you want to close the connection
  3. The server sends a FIN to indicate that I am also closing the connection
  4. When the client receives the FIN from the server, it sends an ACK to the server, indicating that I know you want to close the connection, and the connection is released