1

TCP/IP Hierarchy

image.png

  • Application layer: each application can define (use) various such protocols
  • Transport layer: ensure that the sent data can reach the target host and complete the data transmission
  • Network layer: fill in the packet address and select the data transmission path
  • Data link layer: Integrate links of different connection methods to shield network differences
  • Physical layer: specific connection method, wired, wireless, optical fiber...

How TCP/IP works

image.png

image.png

Features of the TCP/IP Hierarchy

  • The upper layer relies on the ability to adjoin the lower layer, and the lower layer only serves the direct adjacency to the upper layer
  • The upper layer does not know the working mechanism of the lower layer, and the lower layer does not care about the data content transmitted by the upper layer
  • Without cross-layer services, the roles in the hierarchy are indispensable

image.png

In-depth understanding of the network layer (IP layer)

  • IP addressing: IP addresses are network-layer addresses used to identify hosts on the network
  • Routing control: Control how data reaches the host (eg: which routers need to be forwarded)
  • Connectionless: Packets are passed on the network based on IP addresses (no connection to the destination host is required)
 Mac 地址:数据链路层所使用的硬件地址
Mac 地址与网络无关,出厂时写入到网络设备中
当主机从网络上每收到一个数据帧时,首先检查数据中的 MAC 地址。如果是发往本机的数据帧则收下,之后进行其他的处理;否则就将此帧丢弃,不再进行其他的处理。

IP address and MAC address

  • The IP address is dynamic and does not belong to a specific hardware (the MAC address belongs to the specific hardware)
  • The IP address is the address used by the network layer (for delivering packets across the network)
  • The MAC address is the address used by the data link layer (to determine which host in the destination network is receiving data)
  • The router records the mapping relationship between the host IP address and the MAC address in the network (the ARP protocol is completed)

IP Routing Control

  • In order to send data to the target host, all hosts maintain a routing table
  • The routing table records which router the IP packet should be sent to next

image.png

IP data forwarding

  • IP packet forwarding uses a "best effort" policy

    • "Best effort" means "will work hard", but does not guarantee results
    • When forwarding, the data legitimacy will be checked through additional information, but no retransmission will be performed if an exception occurs
    • Forwarding in units of packets, no guarantee of arrival (after sending, it will sink into the sea of networks)
Does the TCP/IP network hierarchy provide reliable data transfer?

Transmission Control Protocol

  • TCP provides reliable data transmission over the protocol implementation

    • TCP does not have the concept of "packet", which realizes streaming (data such as water, no head and no tail)
    • There is a service status inside TCP, which can accurately know whether the data has been sent successfully , whether it has been received...
    • TCP can perform blocking control in behavior (when the network environment deteriorates, it can adjust the data transmission speed)

TCP connection establishment

https://www.bilibili.com/video/BV1kV411j7hA/?aid=418245176&bvid=BV1kV411j7hA&cid=343076847&page=1

image.png

Q: After the three interactions are over, the connection is established, why is it three times?
A: Prevent old duplicate connections from causing connection confusion issues
 比如在网络环境比较复杂的情况,客户端可能会连续发送多次请求。如果只设计成两次握手的情况,服务端只能一接收请求,然后返回请求信息,也不知道客户端是否请求成功。这些过期请求的话就会造成网络连接的混乱。
所以设计成三次握手的情况,客户端在接收到服务端SEQ+1的返回消息之后,就会知道这个连接是历史连接,所以会发送报文给服务端,告诉服务端。
所以TCP设计成三次握手的目的就是为了避免重复连接。
然后可以设计成四次握手?五次握手?不可以?答案是也是可以的,不过为了节省资源,三次握手就可以符合实际情况,所以就没必要设计成四次握手、五次握手等等情况

image.png

Inherent flaws in TCP (DDoS attacks)

  • After the client receives SYN,ACK , it will not reply to the last ACK message
  • This will cause the server to consume resources without actually communicating
  • When multiple puppet clients make "connection requests" to the server at the same time, the server resources will be exhausted

image.png

TCP connection disconnected

image.png

Q: After the four interactions are over, the connection is disconnected, why is it four times?
Answer: Because TCP is full-duplex communication
 第一次挥手:当主动方发送断开连接的请求(即FIN报文)给被动方时,仅仅代表主动方不会再发送数据报文了,但主动方仍可以接收数据报文。
第二次挥手:被动方此时有可能还有相应的数据报文需要发送,因此需要先发送ACK报文,告知主动方“我知道你想断开连接的请求了”。这样主动方便不会因为没有收到应答而继续发送断开连接的请求(即FIN报文)
第三次挥手:被动方在处理完数据报文后,便发送给主动方FIN报文;这样可以保证数据通信正常可靠地完成。发送完FIN报文后,被动方进入LAST_ACK阶段(超时等待)。
第四挥手:如果主动方及时发送ACK报文进行连接中断的确认,这时被动方就直接释放连接,进入可用状态。

image.png

The characteristics of UDP: completely inherit the working method of the network layer

  • No need to connect, directly specify the IP address and port to send data
  • Listen to a fixed port, as long as there is data, all receive
  • Regardless of network conditions, as long as there is data, all can be sent
  • Don't care if the data arrives

Where to use UDP

  • Insensitive to data, occasions requiring real-time (such as: live broadcast, real-time games)
  • Occasions with a better network environment (eg: IoT home)
  • Occasions that require deep customization of the protocol (such as: "UDP protocol without packet loss")

Difference between TCP and UDP

  • TCP: Did the bottle go to the mouth? Did the bottle go to the mouth? Did the bottle go to the mouth? OK, here's some water for you.
  • UDP: Give it to you, give it to you, I don't care if you drink it or not.

image.png


TianSong
734 声望138 粉丝

阿里山神木的种子在3000年前已经埋下,今天不过是看到当年注定的结果,为了未来的自己,今天就埋下一颗好种子吧