A method for implementing efficient OPC UA communication based on improved KCP

By improving the KCP protocol to replace the transport layer communication of OPC UA and combining it with the UDP protocol, the problems of TCP upgrade difficulties, delayed ACK responses and congestion control in industrial networks are solved, achieving more efficient and stable data transmission to meet the needs of industrial applications.

CN116647605BActive Publication Date: 2025-09-19SHAOXING SHUYI TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310656812.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-05
Publication Date
2025-09-19
Estimated Expiration
2043-06-05

AI Technical Summary

Technical Problem

The traditional TCP protocol has problems in industrial networks, such as difficulty in upgrading, increased network traffic caused by delayed ACK response strategies, transmission delays caused by congestion control, and poor adaptability to high-speed networks, which affect communication efficiency and accuracy.

Method used

The improved KCP protocol is used to replace the transport layer communication of OPC UA. Combined with the UDP protocol, the communication efficiency is improved by randomly initializing the sequence number, recording the timestamp to prevent the sequence number wrapping, using piggybacked confirmation messages to reduce the data transmission volume, and redesigning the KCP protocol data segment header.

Benefits of technology

Significantly improve the performance and stability of OPC UA communications in complex network environments, reduce communication delays, and ensure the accuracy and efficiency of data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116647605B_ABST
    Figure CN116647605B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for implementing efficient OPCUA communication based on improved KCP. The present invention utilizes KCP and UDP in combination to replace the TCP transport protocol in the original transport layer. The communication architecture of the client and the server is as follows: the application request is first converted into an OPCUA message by the OPCUA communication stack, and then transmitted to the KCP communication stack. The KCP communication stack encapsulates the fragments into KCP data packets and sends them to the wide area network. Once the KCP communication stack receives the KCP data packet from the wide area network, the KCP communication stack reassembles the KCP data packet into an OPCUA message. Finally, the OPCUA message is converted into a common and easy-to-process message format by the OPCUA communication stack. The KCP communication improvements include the design of the KCP protocol data segment header, the use of randomly initialized sequence numbers to ensure communication security, the recording of timestamps to prevent sequence number wraparound, and the use of piggybacked confirmation messages to reduce the amount of data transmitted. Compared with common OPCUA communications, the present invention can ensure lower communication delays and has greater practical significance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of industrial Internet and relates to an OPC UA communication method. Especially in the case of poor network conditions, the method can not only reduce the decline in communication efficiency, but also ensure the accurate transmission of data. Background Art

[0002] As the standard of Industry 4.0, OPC UA solves the platform limitation problem of OPC standard. This communication protocol is located above the application layer, and its transport layer uses TCP protocol for connection. However, the traditional TCP protocol has some problems, such as

[0003] (1) The implementation of TCP is often embedded in the system kernel. If new functions need to be implemented, the system kernel needs to be modified. Upgrading is very difficult and is prone to other unknown errors.

[0004] (2) The delayed ACK response strategy adopted by TCP may cause the sender to wait longer than the timeout retransmission time. In this case, the receiver does not receive the ACK and the sender must resend the data packet, which increases network traffic and reduces network efficiency.

[0005] (3) TCP congestion control avoids network congestion and ensures network reliability and performance, but it may also cause network transmission delays. Since data needs to be sent after waiting for confirmation messages, the transmission time is increased.

[0006] Furthermore, TCP's congestion control is poorly adapted to high-speed networks, limiting the sending rate at the outset of data transmission, thereby impacting overall network throughput. Using connectionless, unreliable UDP connections at the transport layer makes it difficult to guarantee deterministic data transmission, a critical drawback in industries where accuracy is paramount. Summary of the Invention

[0007] The purpose of the present invention is to address the deficiencies of the prior art and propose an implementation method for efficient OPC UA communication based on improved KCP. The present invention addresses the defects of traditional TCP or UDP by replacing the TCP protocol in the OPC UA protocol. The OPC UA server adopts the UDP communication protocol solution between transport layers, and adds a KCP protocol on the basis of UDP. KCP wastes part of the bandwidth in exchange for a transmission speed that is 30%-40% faster than TCP, and significantly reduces the transmission delay. The implementation method can improve data transmission efficiency and reduce communication delay, thereby ensuring the normal operation and efficient operation of the entire system. This protocol has certain value for industrial production and business operations.

[0008] This paper proposes a new method for implementing efficient OPC UA communication based on improved KCP, and redesigns part of the KCP protocol according to the actual situation of OPC UA. The technical solution includes the following steps:

[0009] Step (1) Initialize the OPC UA server according to the configuration information and try to establish a connection between the OPC UA client and the KCP.

[0010] The OPC UA client maps the IP address and port number to a 32-bit unsigned integer using the FNV hash algorithm to serve as the session ID.

[0011] KCP sends a connection request message to the OPC UA server listening port.

[0012] After receiving the connection request, the listening port of the OPC UA server creates a new communication port for the OPC UA client and returns a confirmation message using the communication port.

[0013] Step (2) After the OPC UA client receives the confirmation message from the OPC UA client communication port, it indicates that the connection is successfully established. The OPC UA client sends a Hello message, which contains information about the maximum message size, data block size and quantity.

[0014] Once the OPC UA server receives the Hello message, it returns an Acknowledge message to the OPC UA client.

[0015] The Acknowledge message contains information about the maximum message size, data block size and number that the server can handle, and the protocol version number supported by the server.

[0016] If the OPC UA client and server can reach an agreement through the Hello message and Acknowledge message, the connection is considered successful; otherwise, the connection fails.

[0017] If the OPC UA server or OPC UA client receives the corresponding data message multiple times, an error will be reported and the KCP connection will be closed. If the OPC UA server does not receive the Hello message, the OPC UA server will automatically disconnect the KCP connection after a custom time interval.

[0018] Step (3) After receiving the Acknowledge message from the OPC UA server, the OPC UA client sends the OPC UA client's security policy, security mode, digital certificate, and random number information as an Open Secure Channel message. The OPC UA server verifies whether the client's digital certificate and security policy meet the requirements. If verified, it returns an Open Secure Channel Response message. The OPC UA client and OPC UA server generate a symmetric key using the random number for encrypted communication.

[0019] Step (4) After opening the secure channel, the OPC UA client sends a Create Session Request message to the OPC UA server. This message contains the client's application name, URI, session name, session timeout, maximum request message size, and a single-use random number (Nonce). After receiving the Create Session Request message, the OPC UA server signs the random number (Nonce) to prove to the client that it is the target server. It also verifies that the Create Session Request message complies with the specification. If verified, it returns a Create Session Response message with the signature information.

[0020] Step (5) After the OPC UA client receives the Create Session Response message from the server, it uses the authentication token to generate a signature and sends an Activate Session Request message to the server. This message contains the client's signature and user identity information. The OPC UA server verifies whether the client's signature and user identity are valid. If verified, it sends an Activate Session Response message to the client and allocates a set of available subscription ID and node ID resources to the client. The OPC UA client and server can then perform data reading and writing, subscription and publishing operations through this session message.

[0021] Step (6) improves the traditional KCP transmission communication from four aspects, namely, re-improving the design of the KCP protocol data segment header, using randomly initialized sequence numbers to ensure communication security, recording timestamps to prevent sequence number wraparound, and using piggybacked confirmation messages to reduce the amount of data transmission.

[0022] The detailed implementation of the further step (6) is as follows:

[0023] Re-improving the KCP protocol data segment header design will be Figure 3 Detailed description is given in .

[0024] The improved KCP stipulates that each connection must randomly generate an initial sequence number. To ensure the randomness and unpredictability of the sequence number, the improved KCP sequence number adopts a dynamic change scheme, including time, port number, and IP address as initialization input, as shown in the following formula 1:

[0025] (1)

[0026] The current timestamp value time divided by 4 indicates that the sequence number increases by 1 every four microseconds. Calculated by the client's IP address and port number using the FNV hash algorithm.

[0027] The KCP sequence number is represented by a four-byte unsigned integer, which means that when it exceeds A value of -1 causes sequence number wraparound. Therefore, when improving KCP communication, the receiver saves the timestamp of the start packet of the current receive window, denoted as rts. The receiver compares the timestamp value of the newly received packet with the rts value. If time is smaller than rts, the packet has expired and the receiver discards it.

[0028] The improved KCP adds a new message type: the Data & Acknowledgement message. When a KCP sends an Acknowledgement Response message, if there is a data message currently being sent to the other party, the acknowledgment information in the Acknowledgement Response message is appended to the beginning of the data message, thereby reducing the amount of data transmitted. To prevent confusion between Data & Acknowledgement messages and regular data messages, a sequence is designed in the cmd segment of the message header to indicate that the message is a Data & Acknowledgement message. The data portion of a Data & Acknowledgement message should begin 24 bytes after the normal data portion.

[0029] The beneficial effects of the present invention are as follows:

[0030] Using TCP for communication, the bottom layer of the OPC UA three-layer communication architecture—the transport layer within the seven-layer network architecture—can ensure data accuracy, but communication efficiency can be significantly reduced under poor network conditions. This paper proposes an improved KCP-based OPC UA communication protocol that combines KCP and UDP at the transport layer. Compared to the original OPC UA protocol, this protocol demonstrates superior performance in complex network environments, effectively improving the performance and stability of OPC UA communication, thereby better meeting the needs of practical applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is based on the OPC UA communication architecture of the improved KCP;

[0032] Figure 2 It is the detailed communication sequence of OPC UA based on the improved KCP;

[0033] Figure 3 There are three different message header designs;

[0034] Figure 4 Comparison of average communication delays between OPC UA servers and clients using TCP and KCP respectively;

[0035] Figure 5 Figure 2 is a cumulative distribution graph of requests between OPC UA servers and clients using TCP and KCP respectively. DETAILED DESCRIPTION

[0036] The present invention will be further described below with reference to the accompanying drawings and examples.

[0037] The present invention discloses a method for implementing efficient OPC UA communication based on an improved KCP. The present invention utilizes a combination of KCP and UDP to replace the TCP transport protocol in the original transport layer. The communication architecture between the client and the server is as follows: the application request is first converted into an OPC UA message by the OPC UA communication stack, and then transmitted to the KCP communication stack. The KCP communication stack fragments and encapsulates it into KCP data packets and sends it to the wide area network. Once the KCP communication stack receives the KCP data packet from the wide area network, the KCP communication stack reassembles the KCP data packet into an OPC UA message. Finally, the OPC UA message is converted into a common and easy-to-process message format by the OPC UA communication stack. At the same time, the following four improvements are made to traditional KCP communication, namely, re-improving the design of the KCP protocol data segment header, using a randomly initialized sequence number to ensure communication security, recording a timestamp to prevent sequence number wraparound, and using piggybacked confirmation messages to reduce the amount of data transmitted. Experiments have shown that the OPC UA communication solution based on the improved KCP can ensure lower communication delay compared with the common OPC UA communication, which has great practical significance.

[0038] Figure 1 The KCP-based OPC UA basic communication architecture consists of the OPC UA communication stack and the KCP communication stack. The OPC UA communication stack converts application requests into OPC UA messages. The OPC UA message is then passed to the KCP communication stack, which fragments and encapsulates it into KCP packets and sends them over the wide area network (WAN). Upon receiving the KCP packets from the WAN, the KCP communication stack reassembles them into OPC UA messages. The OPC UA communication stack then converts the OPC UA message into a data format understandable by the application and notifies the application for processing.

[0039] Figure 2 This is the detailed communication sequence of OPC UA based on KCP, and is also the main process of OPC UA communication based on KCP. The communication process is steps (1) to (5) described above, mainly including establishing a KCP connection, Hello call and Acknowledge response, opening a secure channel, creating a session, and activating a session. The specific implementation steps of the OPC UA communication connection based on the improved KCP are as follows:

[0040] 1. The KCP communication connection is managed by the UA_Connection object, which consists of a socket for UDP communication, a KCP object responsible for fragmenting and retransmitting packets, and a timer for executing updates. The UA_Connection uses a timer to determine when to call update. The timer iterates through the data segments in the send buffer, recording the time closest to the current moment and determining the next time to call update. KCP communication periodically checks the reception and transmission of packets by calling the update function.

[0041] 2. The flush function, called within update, sends the KCP data packet to the WAN. It first sends the pending acknowledgment messages in ack_list to the communication peer. ack_list is a linked list storing acknowledgment messages to be sent to the communication peer. Whenever the KCP receives a data packet, it inserts its recorded sequence number and timestamp into the linked list. When sending the acknowledgment message, it also checks whether there is a data packet to be sent. If so, it combines the data and acknowledgment messages and sends them to the WAN.

[0042] 3. The sender determines whether to send a Probe Window message based on the value of remote_receive_window, which stores the receiver's receive window size. When remote_receive_window is zero, the sender continues sending Probe Window messages according to probe_interval until it receives a Response Window message from the receiver. The probe_interval value is the interval between sending Probe Window messages.

[0043] The reason for sending a Probe Window message is that when remote_receive_window is zero, the sender must wait for a Response Window message from the receiver to update remote_receive_window in order to continue sending data to the receiver. Even if the receiver resends such a message after the receive window is restored, the Response Window message may be lost during network transmission, preventing the sender from updating the receive window size on the other end. In this situation, if the sender does not actively send a Probe Window message, it will continue to wait for the receiver's Response Window message. The receiver will assume that the sender has successfully received the Response Window message and update remote_receive_window, continuing to wait for data packets from the sender. This waiting deadlock between the two parties will prevent data transmission.

[0044] 4. Finally, the send window size needs to be updated. The send window value is the minimum of the user-set send window sizes (send_window) and remote_receive_window. The send window size is used to calculate the sequence number at the end of the window. KCP packets in the send queue with sequence numbers less than this value are transferred to the send buffer. The newly added KCP packets in the send buffer are then sent. A check is performed to determine whether the sent KCP packets have triggered the timeout retransmission mechanism or the fast retransmission mechanism. If so, they are resent.

[0045] Figure 3 This is a design of three different message headers. KCP messages can be divided into four categories: confirmation and response messages, user data messages, detection window messages, and response window messages. The present invention redesigns the data header formats of these messages according to different application scenarios. Figure 3 (a) To confirm the header format of the response message, only the ts and sn fields are retained for accurate RTT calculation and confirmation of data packet receipt. The len and frg fields that are not related to the relative order of the data are deleted. Figure 3 (b) is the data message header format. This type of message header is exactly the same as the original message header. Figure 3 (c) shows the header format of the Probe Window message and the Response Window message. When the sender discovers that the remote receive window is zero, the Probe Window message is periodically sent until the Response Window message is received. Therefore, the irrelevant ts and sn fields can be directly removed from this type of message. Each message type has the unack, cmd, and wnd fields in the header. Unack is used to quickly update the send window. cmd is used to distinguish the message type. Wnd is used to inform the remote receive window size of the communication peer.

[0046] Figure 4 The study used the improved KCP-based OPC UA protocol and the TCP-based OPC UA protocol to communicate in different network environments, recording the communication latency in milliseconds. The figure compares the average communication latency of the two protocols at different packet loss rates, with a network latency of 100 milliseconds. It is clear that the KCP-based OPC UA protocol has higher communication efficiency than the TCP-based OPC UA protocol. Furthermore, as the packet loss rate increases, the increase in communication latency is smaller for the KCP-based OPC UA protocol than for the TCP-based OPC UA protocol.

[0047] Figure 5Figure 5(a) shows the cumulative distribution of the two protocols under different packet loss rates. The x-axis of the cumulative distribution graph represents communication latency in milliseconds. The y-axis represents the percentage of requests with a latency below a certain value. Figure 5(a) shows only one point because, when the packet loss rate is zero, both the KCP-based OPC UA protocol and the TCP-based OPC UA protocol guarantee one-time successful data transmission. That is, the transmission time is equal to the network latency, resulting in no change in the communication latency between the two protocols. As the packet loss rate increases, the communication efficiency of the two protocols diverges. Figures 5(b), 5(c), and 5(d) show that, compared to the TCP-based OPC UA protocol, the improved KCP-based OPC UA protocol has a higher number of requests with lower latency, and this gap widens as the packet loss rate increases.

Claims

1. A method for implementing efficient OPC UA communication based on improved KCP, characterized in that Instead of the TCP protocol in the OPC UA protocol, the OPC UA server uses the UDP communication protocol for communication between transport layers, and adds an improved KCP protocol based on UDP; The improved KCP protocol also improves traditional KCP transmission communication in four aspects, namely, re-improving the design of the KCP protocol data segment header, using randomly initialized sequence numbers to ensure communication security, recording timestamps to prevent sequence number wraparound, and using piggybacked confirmation messages to reduce data transmission volume.

2. The method for implementing efficient OPC UA communication based on improved KCP according to claim 1 is characterized in that The steps include: Step (1) Initialize the OPC UA server according to the configuration information and try to establish a connection between the OPC UA client and the improved KCP; The OPC UA client maps the IP address and port number to a 32-bit unsigned integer using the FNV hash algorithm to serve as the session ID. KCP sends a connection request message to the OPC UA server listening port; After receiving the connection request, the listening port of the OPC UA server creates a new communication port for the OPC UA client and returns a confirmation message using the communication port. Step (2) After the OPC UA client receives a confirmation message from the OPC UA client communication port, it indicates that the connection is successfully established; the OPC UA client sends a Hello message, and once the OPC UA server receives the Hello message, it returns an Acknowledge message to the OPC UA client; If the OPC UA client and server can reach an agreement through the Hello message and Acknowledge message, the connection is considered successful, otherwise the connection fails; Step (3) After receiving the Acknowledge message from the OPC UA server, the OPC UA client sends the OPC UA client's security policy, security mode, digital certificate, and random number information as an Open Secure Channel message; the OPC UA server verifies whether the client's digital certificate and security policy meet the requirements. If the verification is successful, it returns an Open Secure Channel Response message; the OPC UA client and the OPC UA server generate a symmetric key using the random number for encrypted communication; Step (4) After opening the secure channel, the OPC UA client sends a CreateSession Request message to the OPC UA server. After receiving the Create Session Request message, the OPC UA server signs the random number Nonce in the message. If it passes the verification, it returns a Create Session Response message. Step (5) After the OPC UA client receives the Create Session Response message from the server, it uses the authentication token to generate a signature and sends an Activate Session Request message to the server, which contains the client's signature and user identity information; the OPC UA server verifies whether the client's signature and user identity are valid. If the verification is successful, it sends an Activate Session Response message to the client and allocates a set of available subscription ID and node ID resources to the client; the OPC UA client and server can then perform data reading and writing, subscription and publishing operations through the session message.

3. The method for implementing efficient OPC UA communication based on improved KCP according to claim 2 is characterized in that The Hello message in step (2) contains information about the maximum message size, data block size, and number.

4. The method for implementing efficient OPC UA communication based on improved KCP according to claim 2 is characterized in that The Acknowledge message in step (2) contains information about the maximum message size, data block size and number that the server can handle, and the protocol version number supported by the server.

5. The method for realizing efficient OPC UA communication based on improved KCP according to claim 3 or 4, characterized in that If the OPC UA server or OPC UA client receives the corresponding data message multiple times, an error will be reported and the KCP connection will be closed. If the OPC UA server does not receive the Hello message, the OPC UA server will automatically disconnect the KCP connection after a custom time interval.

6. The method for realizing efficient communication of OPC UA based on improved KCP according to claim 5 is characterized in that The Create Session Request message in step (4) contains the client's application name, URI, session name, session timeout, maximum request message size, and a random number Nonce that can only be used once.

7. The method for implementing efficient OPC UA communication based on improved KCP according to claim 2 is characterized in that The improved KCP is implemented as follows: The improved KCP stipulates that each connection must randomly generate an initial sequence number. The improved KCP sequence number adopts a dynamic change scheme, including time, port number, and IP address as initialization input, as shown in the following formula 1: (1) The current timestamp value time divided by 4 means that the sequence number increases by 1 every four microseconds; Calculated by the client's IP address and port number using the FNV hash algorithm; When improving KCP communication, the receiver will save the timestamp of the starting data packet of the current receiving window, recorded as rts; the receiver will compare the timestamp value time in the data packet just received with the rts value; if time is smaller than rts, it means that the data packet has expired and the receiver will discard the data packet.

8. The method for realizing efficient communication of OPC UA based on improved KCP according to claim 7 is characterized in that The improved KCP adds a new message type, namely data and confirmation message; when the KCP sends a confirmation response message, if there is currently a data message that needs to be sent to the other party, the confirmation response message and the data message will be merged into a data and confirmation message.

9. The method for realizing efficient OPC UA communication based on improved KCP according to claim 8, characterized in that A sequence is designed in the cmd segment of the message header to indicate that the message is a data and confirmation message. In this case, the data part of the message starts after 24 bytes of the normal data part.

Citation Information

Patent Citations

  • Method for improving SSL handshake protocol

    CN101860546A

  • Application virtualization security communication method in autonomous and controllable environment

    CN109347809A