Method and device for realizing communication between nodes
Technical Field
The present invention relates to the technical field of communication networks, and in particular, to a method and an apparatus for implementing communication between nodes.
Background
In existing communication networks, each communication device is referred to as a node; alternatively, the communication device itself is provided with data processing functions by a plurality of service disks, each of which is also referred to as a node.
Currently, when communication between nodes is realized, data is generally copied into a socket cache and then read by an application program. However, the socket caching operation of the implementation method is complicated, and the communication efficiency is reduced; in addition, the problems of lock introduction processing, interrupt processing and the like exist, so that the complexity of the system is increased, the efficiency of a network part is influenced, and the communication efficiency of the whole system is reduced.
Therefore, how to effectively improve the communication efficiency when implementing the inter-node communication is a problem to be urgently solved by those skilled in the art.
Disclosure of Invention
The present invention is to overcome the above drawbacks of the background art, and provides a method and an apparatus for implementing inter-node communication, which can effectively improve the communication efficiency of inter-node communication when implementing inter-node communication.
In order to achieve the above object, the present invention provides a method for implementing communication between nodes, the method comprising the steps of:
step S1, organizing the communication nodes according to logic hierarchy, making the logic hierarchy of the communication nodes comprise a management layer, a link layer and a bearing layer; wherein:
the management layer is used for providing an operation interface for a specified link for a user, and comprises a link creation interface and a data transceiving interface; the link layer is used for establishing a link and transmitting and receiving user data to the management layer and transmitting and receiving messages to the bearing layer; the bearing layer is borne on the logic channel, receives and sends messages by relying on the borne logic channel, reports the received messages to the link layer and provides the messages for sending to the link layer, and one bearing layer is responsible for sending and receiving the messages of a plurality of link layers;
moreover, a transmission buffer queue is adopted between a management layer as a home terminal and a link layer for association, and a confirmation queue is adopted between the link layer and a bearing layer for association; a receiving buffer queue is adopted between a bearing layer as an opposite end and a link layer for correlation, and an uplink queue is adopted between the link layer and a management layer for correlation;
step S2, establishing a link for communication between the local end communication node and the opposite end communication node by using the link layer through the link establishing interface provided by the management layer;
step S3, sending message to opposite communication node through the data sending interface provided by the management layer of local communication node; when sending messages, the management layer puts the messages to be sent into a sending buffer queue of a specified link and informs the link layer, and the link layer adopts a segmented sending mode, puts the messages to be sent into a confirmation queue and sends the messages to an opposite-end communication node through a bearing layer;
step S4, receiving the message through a data receiving interface provided by a management layer of the opposite-end communication node; when receiving the message, the received message is put into a receiving buffer queue of the link and notified to the link layer through the bearing layer, the received message is put into an uplink queue of the link by the link layer, and the management layer acquires the received message data from the uplink queue.
On the basis of the above technical solution, in step S2, establishing a link for performing communication between the local-end communication node and the opposite-end communication node by using a link layer specifically includes the following steps:
step S201, the local terminal communication node sends a link establishment message to the opposite terminal communication node by using a link layer;
step S202, after receiving the link establishment message, the opposite end communication node sends a link establishment response message and starts a link heartbeat mechanism;
step S203, after receiving the link establishment response message, the home terminal communication node stops sending the link establishment request message, sets the link state as the link establishment state, and starts a link heartbeat mechanism to complete the establishment of the communication link.
On the basis of the technical scheme, the link layer fills data of a message to be sent into payloads of a plurality of link message fragments, encapsulates the plurality of link message fragments into a carrying message and puts the carrying message into a validation queue.
On the basis of the above technical solution, in step S3, the link layer uses a segmented transmission method to put a message to be sent into a confirmation queue and send the message to the opposite-end communication node through the bearer layer, which specifically includes the following steps:
step S301, link layer checks to confirm whether there is space in the queue for storing message to be sent, if yes, the message to be sent is obtained from the sending buffer queue, and step S302 is switched to; otherwise, re-executing S301;
step S302, judging whether a bearing message is to be sent or not at present, and if so, turning to step S303; otherwise, go to step S305;
step S303, checking whether the payload length of the current bearer message to be sent exceeds the length of a preset bearer message, if not, turning to step S306, and if so, turning to step S304;
step S304, putting the current bearer message to be sent into a confirmation queue, clearing the bearer message to be sent, and turning to step S305;
step S305, creating a new bearer message to be sent, and then turning to step S302;
step S306, distributing a link message fragment from the current bearer message to be sent, filling the obtained data of the message to be sent into the link message fragment, and turning to step S307;
step S307, determining whether the number of unproven queues in the validation queue exceeds a specified preset value, where the number of unproven queues is the dequeue number-validated number of the validation queue, the dequeue number of the validation queue is the total number of the sent bearer packets, and the validated number is the number of the bearer packets that have received a response; if yes, returning to the step S302, and if not, turning to the step S308;
step S308, acquiring a bearer message from the confirmation queue, judging whether the opposite-end communication node is congested, if not, sending the bearer message to the opposite-end communication node through a sending interface provided by a bearer layer, and increasing the dequeue number of the confirmation queue; if so, the process returns to step S307.
On the basis of the above technical solution, in step S4, the bearer layer puts the received packet into a receive buffer queue of the link and notifies the link layer, and the link layer puts the received packet into an uplink queue of the link, which specifically includes the following steps:
step S401, the bearing layer checks whether the received bearing message is legal or not, and if not, the packet is lost; if the received message is legal, the bearing message is put into a receiving buffer queue of the link and a link layer is informed;
step S402, the link layer checks whether the receiving of the bearing message in the receiving buffer queue is finished, if not, the step S403 is switched to; if the reception is finished, go to step S411;
step S403, acquiring a bearer message from the receiving buffer queue, and turning to step S404;
step S404, checking whether the type of the obtained bearing message is a data message type, if so, turning to step S405; otherwise, go to step S410;
s405, checking whether the sequence number of the bearing message is consistent with the packet receiving sequence of the link layer, and if so, turning to S406; otherwise, returning to step S402;
step S406, judging whether all link message fragments contained in the bearer message are completely recombined, if so, returning to the step S402; otherwise, go to step S407;
step S407, acquiring a link message fragment of the bearer message, and turning to step S408;
step S408, judging whether the serial number of the link message fragment is consistent with the serial number of the last bearing message, if not, establishing a new link message to be received, and then turning to step S409; if yes, directly switching to the step S409;
step S409, reassembling the link message fragments with the same sequence number into a link message to be received, putting the link message to be received into an uplink queue of a link, emptying the link message to be received, and turning to step S406;
step S410, sending a data response message to the home terminal communication node, processing a bearing message of a non-data message type, and returning to the step S402;
and step S411, sending a data response message to the local terminal communication node.
On the basis of the technical scheme, the operation interface provided by the management layer for the user further comprises a class Select operation interface and a link state and statistical query operation interface.
On the basis of the technical scheme, the link layer also provides a heartbeat mechanism for detecting the link state and supports the functions of congestion control, flow control and maximum buffer control.
On the basis of the above technical solution, the bearer layer is further configured to read information of a logical channel in a configuration file, where the content of the configuration file includes a logical channel type and communication port information.
On the basis of the above technical solution, the bearer layer may be borne on a plurality of logical channels, where the plurality of logical channels include UDP, MAC physical layer, and I2C bus.
The invention also provides a device for realizing the communication between the nodes based on the method, which is arranged in each communication node and comprises a logic layered structure establishing module, a communication link establishing module, a message sending processing module and a message receiving processing module;
the logical hierarchy creation module is to: organizing the communication nodes according to logic hierarchy, so that the logic hierarchy of the communication nodes comprises a management layer, a link layer and a bearing layer;
the communication link establishment module is to: establishing a link for communication between a local-end communication node and an opposite-end communication node by using a link layer through a link establishing interface provided by a management layer;
the message sending and processing module is used for: when the local terminal is used as the local terminal, the message is sent to the opposite-end communication node through a data sending interface provided by the management layer; when sending messages, the management layer puts the messages to be sent into a sending buffer queue of a specified link and informs the link layer, and the link layer adopts a segmented sending mode, puts the messages to be sent into a confirmation queue and sends the messages to an opposite-end communication node through a bearing layer;
the message receiving and processing module is used for: when the terminal is used as an opposite terminal, receiving the message through a data receiving interface provided by the management layer; when receiving the message, the received message is put into a receiving buffer queue of the link and notified to the link layer through the bearing layer, the received message is put into an uplink queue of the link by the link layer, and the management layer acquires the received message data from the uplink queue. The invention has the beneficial effects that:
(1) in the invention, the logical layered structure of the communication node is designed into a management layer, a link layer and a bearing layer. The management layer is used for providing an operation interface of a designated link for a user, and comprises a link creation interface and a data receiving and transmitting interface; the link layer is used for establishing a link and transmitting and receiving user data to the management layer and transmitting and receiving messages to the bearing layer; the bearing layer is borne on the logic channel, receives and sends messages by relying on the borne logic channel, reports the received messages to the link layer and provides the messages for sending to the link layer, and one bearing layer is responsible for sending and receiving the messages of a plurality of link layers; and the management layer, the link layer and the bearing layer are all designed to adopt queues for associated caching, so that the communication efficiency is improved, the problems of lock processing, interrupt processing and the like can be avoided, the system complexity is low, and the communication efficiency of the whole system is high.
(2) In the invention, a link layer fills data of a message to be sent into payloads of a plurality of link message fragments, encapsulates the plurality of link message fragments into a bearing message and puts the bearing message into a confirmation queue; and the sending end node sends the message in a segmented manner, and the receiving end receives the message in a recombined manner, so that the throughput of the bearing layer can be effectively improved.
(3) In the invention, in order to meet the function expansion requirement of communication between nodes and enable the functions of each communication node to be more powerful, the management layer provides an operation interface of a designated link for a user and also comprises a class Select operation interface and a query operation interface of link state and statistics; the link layer also provides a heartbeat mechanism for detecting the link state and supports congestion control, flow control, maximum cache control and the like; the bearer layer is also used for reading information of the logical channels in the configuration file, and the like.
(4) In the invention, the bearing layer can be borne on various logic channels, including UDP, MAC physical layer, I2C bus, etc., and the application scene is wide.
(5) In the invention, one bearing layer can be responsible for the sending and receiving of a plurality of link layer data, so a plurality of link layer processing tasks can be set for processing the receiving and sending messages, thereby further improving the communication efficiency.
Drawings
FIG. 1 is a flow chart of a method for implementing inter-node communication in an embodiment of the present invention;
FIG. 2 is a schematic block diagram of a logical hierarchy of communication nodes in an embodiment of the present invention;
FIG. 3 is a detailed flowchart of establishing a communication link according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a package structure of a bearer packet according to an embodiment of the present invention;
fig. 5 is a specific flowchart of sending a packet to an opposite-end communication node by a link layer in the embodiment of the present invention;
fig. 6 is a specific flowchart of the embodiment of the present invention in which the bearer layer places a packet into the receive buffer queue and the link layer places a packet into the uplink queue;
fig. 7 is a block diagram of an apparatus for implementing inter-node communication according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the figures and the embodiments.
Referring to fig. 1, an embodiment of the present invention provides a method for implementing inter-node communication, where the method includes the following steps:
step S1, creating a logical hierarchical structure: as shown in fig. 2, the communication nodes are organized according to logical hierarchies, so that the logical hierarchy of the communication nodes includes a management layer, a link layer and a bearer layer; wherein:
the management layer is used for providing an operation interface for a specified link for a user, and comprises a link creation interface and a data transceiving interface; the link layer is used for establishing a link and transmitting and receiving user data to the management layer and transmitting and receiving messages to the bearing layer; the bearing layer can be borne on various logic channels, receives and transmits messages by relying on the borne logic channels, reports the received messages to the link layer and provides the messages for the link layer to be sent, and one bearing layer is responsible for sending and receiving data of a plurality of link layers;
moreover, a transmission buffer queue is adopted between a management layer as a home terminal (a transmitting terminal) and a link layer for association, and a confirmation queue is adopted between the link layer and a bearing layer for association; the bearing layer as the opposite end (receiving end) is associated with the link layer by adopting a receiving buffer queue, and the link layer is associated with the management layer by adopting an uplink queue.
Furthermore, in order to meet the function expansion requirement of communication between nodes, the functions of each communication node are more powerful. In this embodiment, the operation interface for providing the specified link to the user by the management layer further includes a class Select operation interface and a query operation interface for link state and statistics. The link layer also provides a heartbeat mechanism for detecting link states and supports congestion control, flow control, maximum buffer control, etc. The bearer layer is further configured to read information of the logical channel in the configuration file, create the bearer layer, and receive the packet, where the content of the configuration file includes information of the type of the logical channel and the communication port. Moreover, the bearer layer may be carried on a plurality of logical channels, which include a UDP (User data Protocol), a MAC (Media Access Control) physical layer, an I2C (Inter-Integrated Circuit) bus, and the like, and the application scenarios are wide.
Step S2, establishing a communication link between the local terminal and the opposite terminal: and establishing a link for the communication between the local end communication node and the opposite end communication node by using the link layer through a link establishing interface provided by the management layer.
Specifically, as shown in fig. 3, the establishing a link between the local-end communication node and the opposite-end communication node by using the link layer in step S2 specifically includes the following steps:
step S201, the local terminal communication node sends a link establishment message to the opposite terminal communication node by using a link layer;
step S202, after receiving the link establishment message, the opposite end communication node sends a link establishment response message and starts a link heartbeat mechanism;
step S203, after receiving the link establishment response message, the home terminal communication node stops sending the link establishment request message, sets the link state as the link establishment state, and starts a link heartbeat mechanism, thereby completing establishment of the communication link.
Step S3, the home terminal communication node sends a message: as shown in fig. 2, a user sends a message to an opposite-end communication node through a data sending interface provided by a management layer of the local-end communication node; when the local-end communication node sends a message, the management layer puts the message to be sent into a sending buffer queue of a specified link and informs the link layer, and the link layer adopts a segmented sending mode, puts the message to be sent into a confirmation queue and sends the message to the opposite-end communication node through a sending interface provided by the bearing layer.
It can be understood that, in order to enhance the throughput of the bearer layer and further improve the communication efficiency, in this embodiment, the link layer fills the data of the message to be sent into the payloads of the multiple link message fragments, and encapsulates the multiple link message fragments into one bearer message, and puts the bearer message into the validation queue. Specifically, the format structure of the multiple link packets encapsulated into the bearer packet is shown in fig. 4, where a bearer packet header records a local end link identifier, an opposite end link identifier, a sending sequence, a link packet frame number, payload length information, and the like; the link message header records information such as the serial number, the current frame length and the like of the bearer message, and link message fragments with the same serial number are reassembled at a receiving end. On this basis, as shown in fig. 5, in step S3, the link layer uses a segmented transmission method to put the message to be sent into the confirmation queue and send the message to the opposite-end communication node through the transmission interface provided by the bearer layer, which specifically includes the following steps:
step S301, link layer checks to confirm whether there is space in the queue for storing message to be sent, if yes, the message to be sent is obtained from the sending buffer queue, and step S302 is switched to; otherwise, re-executing S301;
step S302, judging whether the bearing message is to be sent currently (whether the bearing message is to be sent by checking the link layer object or not), if so, turning to step S303; otherwise, go to step S305;
step S303, checking whether the payload length of the current bearer message to be sent exceeds the length of a preset bearer message, if not, turning to step S306, and if so, turning to step S304;
step S304, putting the current bearer message to be sent into a confirmation queue, clearing the bearer message to be sent, and turning to step S305;
step S305, creating a new bearer message to be sent, and then turning to step S302;
step S306, distributing a link message fragment from the current bearer message to be sent, filling the obtained data of the message to be sent into the link message fragment, and turning to step S307;
step S307, determining whether the number of unproven numbers in the validation queue exceeds a specified preset value (the specified preset value may be set and adjusted according to specific situations), where the number of unproven numbers is the number of dequeues of the validation queue (i.e. the total number of sent bearer packets) -the validated number, and the validated number is the number of bearer packets that have received a response; if yes, returning to the step S302, and if not, turning to the step S308; it can be understood that, each time the opposite end communication node receives the bearer packet, it will send a corresponding response data packet, and after the local end communication node receives the response corresponding to the sent bearer packet, it indicates that the bearer packet is verified, and then the corresponding verified number will be incremented. Only when the number which is not confirmed in the queue does not exceed a specified preset value, the carrying message is sent, so that the purpose of effectively controlling the sending of the carrying message is achieved, and the communication effect is improved;
step S308, after obtaining the bearer message from the confirmation queue, judging whether the opposite communication node is congested, if not, sending the bearer message to the opposite communication node through a sending interface provided by a bearer layer, and increasing the dequeue number of the confirmation queue; if so, the process returns to step S307.
Step S4, the opposite end communication node receives the packet: as shown in fig. 2, the peer user receives a packet through a data receiving interface provided by a management layer of the peer communication node; when the opposite end communication node receives the message, the received message is put into a receiving buffer queue of the link and is informed to the link layer through a receiving interface provided by the bearing layer, the link layer puts the received message into an uplink queue of the link, and the management layer acquires the received message data from the uplink queue.
It can also be understood that, in this embodiment, since the packet received by the bearer layer is a bearer packet and the data of the original packet is stored in the payloads of the multiple link packet fragments, in order to obtain the data of the original packet, the link layer at the opposite end reassembles and receives the link packet fragments in the bearer packet. On this basis, as shown in fig. 6, in step S4, the bearer layer puts the received packet into the receive buffer queue of the link and notifies the link layer, and the link layer puts the received packet into the uplink queue of the link, which specifically includes the following steps:
step S401, the bearing layer checks whether the received bearing message is legal or not, and if not, the packet is lost; if the received message is legal, the bearing message is put into a receiving buffer queue of the link and a link layer is informed;
step S402, the link layer checks whether the receiving of the bearing message in the receiving buffer queue is finished, if not, the step S403 is switched to; otherwise, go to step S411;
step S403, acquiring a bearer message from the receiving buffer queue, and turning to step S404;
step S404, checking whether the type of the obtained bearing message is a data message type, if so, turning to step S405; otherwise, go to step S410;
s405, checking whether the sequence number of the bearing message is consistent with the packet receiving sequence of the link layer, and if so, turning to S406; otherwise, returning to step S402;
step S406, judging whether all link message fragments contained in the bearer message are completely recombined, if so, returning to the step S402; otherwise, go to step S407;
step S407, acquiring a link message fragment of the bearer message, and turning to step S408;
step S408, judging whether the serial number of the link message fragment is consistent with the serial number of the last bearing message, if not, establishing a new link message to be received, and then turning to step S409; if yes, directly switching to the step S409;
step S409, reassembling the link message fragments with the same sequence number into a link message to be received, putting the link message to be received into an uplink queue of a link, emptying the link message to be received, and turning to step S406;
step S410, sending a data response message to the local communication node, wherein the confirmed number in the confirmation queue of the local communication node is increased progressively; processing the bearing message of the non-data message type, and returning to the step S402;
step S411, sending a data response message to the local communication node, wherein the confirmed number in the confirmation queue of the local communication node is increased progressively.
It can be appreciated that, in order to further save communication overhead and improve communication efficiency. In actual operation, after the bearer packet is received, the link layer may encapsulate the acknowledgement information into a data response packet for batch acknowledgement, which represents that the previous bearer packet has been completely received, thereby improving the processing efficiency of the communication node at the receiving end and effectively saving communication overhead.
Referring to fig. 7, an embodiment of the present invention further provides a device for implementing inter-node communication based on the foregoing method, where the device is disposed in each communication node, and includes a logic hierarchical structure creation module, a communication link establishment module, a message sending processing module, and a message receiving processing module;
the logical hierarchy creation module is to: organizing the communication nodes according to logic hierarchy, so that the logic hierarchy of the communication nodes comprises a management layer, a link layer and a bearing layer;
the communication link establishment module is to: establishing a link for communication between a local-end communication node and an opposite-end communication node by using a link layer through a link establishing interface provided by a management layer;
the message sending and processing module is used for: when the local terminal is used as the local terminal, the message is sent to the opposite-end communication node through a data sending interface provided by the management layer; when sending messages, the management layer puts the messages to be sent into a sending buffer queue of a specified link and informs the link layer, and the link layer adopts a segmented sending mode, puts the messages to be sent into a confirmation queue and sends the messages to an opposite-end communication node through a bearing layer;
the message receiving and processing module is used for: when the terminal is used as an opposite terminal, receiving the message through a data receiving interface provided by the management layer; when receiving the message, the received message is put into a receiving buffer queue of the link and notified to the link layer through the bearing layer, the received message is put into an uplink queue of the link by the link layer, and the management layer acquires the received message data from the uplink queue.
It can be understood that the specific flow of the actual operation performed by each module in the apparatus for implementing inter-node communication corresponds to the specific operation steps in the method for implementing inter-node communication, and is not described herein again.
It should be noted that: in the above embodiment, when the device implements inter-node communication, only the division of the functional modules is illustrated, and in practical applications, the function distribution may be completed by different functional modules according to needs, that is, the internal structure of the system is divided into different functional modules to complete all or part of the functions described above.
The present invention is not limited to the above-described embodiments, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements are also considered to be within the scope of the present invention.
Those not described in detail in this specification are within the skill of the art.