In-depth explanation of RPC services | different layers of network protocols

2023.04.07

In-depth explanation of RPC services | different layers of network protocols

This series of articles starts from the historical background of RPC, involving RPC core principles, RPC implementation, JSF implementation, etc., and analyzes its internal world through graphic analogy, so that everyone can have a macroscopic understanding of RPC design ideas.

Author: Wang Yuzhan JD Health

Network protocol

Why do you need a network protocol?

A network protocol is a set of rules, standards or conventions established for data exchange in a computer network.

A microcomputer user communicates with an operator of a mainframe in the network. Because the character sets used by the two data terminals are different, the commands entered by the operators do not know each other. In order to be able to communicate, it is stipulated that each terminal must first convert the characters in its own character set into characters in the standard character set before entering the network for transmission, and after reaching the destination terminal, convert them into characters in the terminal character set. Just like we speak a certain language, there is also a language between computers on the network, which is the network protocol. Different computers must use the same network protocol to communicate.

Which protocols are required for a request?

1. To transmit data, how do you know the address of the corresponding machine first? The specific machine can be confirmed through IP (the IP layer protocol of the network layer).

2. After finding the target machine, you need to know which program on the machine accepts this request? The specific program (TCP layer protocol of the transport layer) can be determined through the port.

3. After confirming the program, how to distinguish different requests, and how to associate each request with the corresponding response? (RPC protocol at the application layer) are distinguished by message id.

4. The above are finally supported by optical cables, cables, wireless channels, etc. at the physical layer. How to control the transmission of signals above the physical layer also requires PPP protocols, ARP protocols, etc.

Introduction to Protocols at Different Layers

application layer protocol

HTTP protocol

Hypertext Transfer Protocol (Hyper Text Transfer Protocol, HTTP) is a simple request-response protocol, which usually runs on top of TCP. It specifies what kind of messages the client may send to the server and what kind of responses it may get.

HTTPS protocol

Full name: Hyper Text Transfer Protocol over SecureSocket Layer, which is an HTTP channel aimed at security. On the basis of HTTP, the security of the transmission process is guaranteed through transmission encryption and identity authentication. HTTPS adds SSL on the basis of HTTP, and the security basis of HTTPS is SSL, so the detailed content of encryption requires SSL. HTTPS has a different default port than HTTP and an encryption/authentication layer (between HTTP and TCP). The system provides authentication and encrypted communication methods. It is widely used in security-sensitive communications on the World Wide Web, such as transaction payments.

RPC protocol

A protocol for requesting services from remote computer programs over a network without requiring knowledge of the underlying network technology.

RTMP协议

全称:Real Time Messaging Protocol(实时消息传输协议)。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。支持该协议的软件包括Adobe Media Server/Ultrant Media Server/red5等。RTMP与HTTP一样,都属于TCP/IP四层模型的应用层。

P2P协议

点对点技术又称对等互联网络技术,是一种网络新技术,依赖网络中参与者的计算能力和带宽,而不是把依赖都聚集在较少的几台服务器上。P2P网络通常用于通过Ad Hoc连接来连接节点。这类网络可以用于多种用途,各种档案分享软件已经得到了广泛的使用。P2P技术也被使用在类似VoIP等实时媒体业务的数据通信中。

DNS协议

DNS是一种可以将域名和IP地址相互映射的以层次结构分布的数据库系统。DNS系统采用递归查询请求的方式来响应用户的查询,为互联网的运行提供关键性的基础服务。目前绝大多数的防火墙和网络都会开放DNS服务,DNS数据包不会被拦截,因此可以基于DNS协议建立隐蔽信道,从而顺利穿过防火墙,在客户端和服务器之间传输数据。

GTP协议

全称:GPRS隧道协议(GPRSTunnelingProtocol),可以分解成三种独立的协议,GTP-C(控制面)、GTP-U(用户面)及GTP'(计费传输)。GTP-C用于GPRS核心网络中,用于不同网络节点之间的信令数据。GTP-U 用于承载用户数据。 GTP可以用在UDP或TCP上,GTP v1仅用于UDP上。用于 GPRS(2.5代通信技术)、UMTS(3G移动通信技术)、LTE(3G与4G技术之间的过渡) 和 5G 网络。

DHCP协议

全称:Dynamic Host Configuration Protocol(动态主机配置协议),通常被应用在大型的局域网络环境中,主要作用是集中地管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。

其它协议

FTP·、Gopher IMAP4 、 IRC 、 NNTP 、XMPP 、POP3 、SIP 、SMTP 、SNMP 、SSH 、TELNET 、RTCP 、RTP 、RTSP 、 SDP 、 SOAP 、STUN 、 NTP 、SSDP 、BGP等。

传输层协议

TCP传输控制协议

全称:Transmission Control Protocol,是一种面向连接的、可靠的、基于字节流的传输层通信协议,TCP旨在适应支持多网络应用的分层协议层次结构。 连接到不同但互连的计算机通信网络的主计算机中的成对进程之间依靠TCP提供可靠的通信服务。TCP假设它可以从较低级别的协议获得简单的,可能不可靠的数据报服务。 原则上,TCP应该能够在从硬线连接到分组交换或电路交换网络的各种通信系统之上操作。

网络层协议

IP协议

IP指网际互连协议,Internet Protocol的缩写,是TCP/IP体系中的网络层协议。设计IP的目的是提高网络的可扩展性:一是解决互联网问题,实现大规模、异构网络的互联互通;二是分割顶层网络应用和底层网络技术之间的耦合关系,以利于两者的独立发展。根据端到端的设计原则,IP只为主机提供一种无连接、不可靠的、尽力而为的数据包传输服务。

链路层协议

PPP协议

点对点协议(Point to Point Protocol,PPP)为在点对点连接上传输多协议数据包提供了一个标准方法。PPP 最初设计是为两个对等节点之间的 IP 流量传输提供一种封装协议。在 TCP-IP 协议集中它是一种用来同步调制连接的数据链路层协议(OSI模式中的第二层),替代了原来非标准的第二层协议,即 SLIP。除了 IP 以外 PPP 还可以携带其它协议,包括 DECnet 和 Novell 的 Internet 网包交换协议(IPX)。

每层协议之间的关系



发送端的流程

1.发送端将用户数据抛给RPC层时,RPC协议将用户的数据(消息体)加上RPC头部,然后抛给下一层“传输层“

2.”传输层”收到“应用层”的数据后,不会考虑上一次的协议是啥,它会将整个传递进来的数据作为‘消息体’,加上TCP头部后继续向下一层“网路层”抛。

3.”网络层“收到数据后,也不会考虑上一次的协议是啥,会将整个传递进来的数据作为‘消息体’并加上IP头部,继续继续抛向下一层”数据链路层“。

4.”数据链路层“同样加上MAC头部,最后由物理层通过光电信号传输到接收端。

接收端的流程

1.接受端收到数据后,”数据链路层“开始解析,识别以太网头部,取出数据后向上抛给”网络层“。

2.”网络层“识别IP头部后,取出数据,向上抛给”传输层“。

3.”传输层“收到数据后,识别TCP头部,取出数据后继续向上抛给”应用层“。

4.”应用层“识别RPC协议头部,最终取出发送端的用户数据。

每层协议的设计

TCP协议

设计的目的

在网络发展的过程中,IP协议提供了让彼此相连的主机之间能够进行数据传送。但是IP协议无法让接收信息的主机知道从远处传送来的数据究竟要给到哪一个进程进行处理。TCP(传输控制协议)就是为了解决进程间的通信问题而发展出来的协议。

1.源端口号和目标端口号:没有这两个端口号。数据就不知道应该发给哪个应用。

2.包的序列号:为什么要给包编号呢?是为了解决乱序的问题。不编好号怎么确认哪个应该先来,哪个应该后到呢。

3.确认序列号:发出去的包应该有确认,要不然我怎么知道对方有没有收到呢?如果没有收到就应该重新发送,直到送达。这个可以解决不丢包的问题。

4.状态位:SYN 是发起一个连接,ACK 是回复,RST 是重新连接,FIN 是结束连接等。TCP 是面向连接的,因而双方要维护连接的状态,这些带状态位的包的发送,会引起双方的状态变更。

5.窗口大小:TCP 要做流量控制,通信双方各声明一个窗口,标识自己当前能够的处理能力,发的太快处理不过来,发的太慢就会有空闲,使用窗口大小来达到一个最佳的处理水平。​