Detailed Description
The technical solutions in the embodiments of the present invention are clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention provides a general safe communication method based on an MVB bus, which is a communication protocol agreed by two communication parties and runs on an MVB link layer.
Two physical ports are arranged on both communication sides: a source port for writing data, and a sink port for reading data; each physical port is divided into a control port and a data port, a source port of one communication party has a corresponding sink port of the same type on the other communication party, and each type of port adopts a preset communication data format for data communication;
after the communication session is established between the two communication parties, data transmission can be carried out;
the sending party determines a sending strategy according to the data length allowed in the communication data format and the size of the message to be sent:
if the message to be sent does not exceed the allowed data length, sending the message to a receiver through a local source port according to a preset communication data format; after receiving the message through the local corresponding sink port, the receiving party sends a confirmation message to the sink port corresponding to the sending party through the source port of the local control port type;
if the message to be sent exceeds the allowed data length, dividing the message to be sent into a plurality of sub-messages with fixed length, setting the sending sequence number of each sub-message according to the communication data format, sending the sub-message through a local source port, and after receiving the sub-message through a local corresponding sink port, sending confirmation to the sink port corresponding to the sending party through the source port of the local control port type according to the sending sequence number of the sub-message; then, the sender sends the next sub-message through the local source port; and the receiver receives all the sub-messages and then assembles the sub-messages according to the sending sequence numbers.
The present invention will be described in detail below in terms of communication ports, communication states, communication mechanisms, and secure communication maintenance mechanisms.
I, communication port.
1. A physical port.
In the embodiment of the invention, the MVB port is divided into two types of physical ports: a source port for writing data, and a sink port for reading data. For both communication parties, a sender writes data on a source port and reads data on a sink port, that is, for any communication party, the source port necessarily corresponds to the sink port on an opposite node, and vice versa.
Illustratively, transport entity a has a source port a1 and a sink port a2, and transport entity B has a source port B1 and a sink port B2; when the transmission entity A serves as a sender and the transmission entity B serves as a receiver, the transmission entity A sends data to be sent to a sink port B2 corresponding to the transmission entity B through a source port A1; when the transmission entity B serves as a sender and the transmission entity A serves as a receiver, the transmission entity B sends data to be sent to a sink port A2 corresponding to the transmission entity A through a source port B1; that is, source port a1 and sink port B2, and source port B1 and sink port a2 correspond.
2. Logical ports and associated communication data formats.
Each physical port is divided into two types, namely a control port and a data port, that is, the source port and the sink port can be logically a control port or a data port; however, the source port and the sink port corresponding to both communication parties have the same logic type.
Illustratively, in the previous example, the source port a1 corresponds to the sink port B2, both of which may be control ports, and the source port B1 corresponds to the sink port a2, both of which may be data ports.
1) Controlling the communication data format of the port.
In the embodiment of the invention, after a communication party receives a message, the communication party needs to reply the confirmation through the source port of the control port type, so that the control port is mandatory in both communication directions, namely at least one source port and one sink port in the physical ports of any communication party are of the control port type.
Illustratively, communication entity a has three sink ports a 1-A3 and one source port a4, and corresponding communication entity B has three source ports B1-B3 and one sink port B4. Wherein, A1-A4 and B1-B4 correspond to each other one by one according to the serial numbers. According to the setting, the source port a4 of the communication entity a must be a control port, and the corresponding sink port B4 of the communication entity B is also a control port; however, the sink ports a 1-A3 of the communication entity a and the source ports B1-B3 of the communication entity B may have a corresponding set of sink ports and source ports as control ports, for example, the sink port A3 and the source port B3 may be set as control ports.
As shown in fig. 1, the communication data format (32 bytes) of the control port mainly includes: 22 bytes of application data, 4 bytes of control information, and 6 bytes of port security information; wherein:
22 bytes of application data for transmitting messages to be sent;
the 4 bytes of control information include: 2 bytes of message length, 1 byte of sub-packet number, 3 bits of sending sequence number, 3 bits of confirming sequence number and 2 bits of connection state; where the message length represents the full message length being transmitted, ranging from 0 to 65535 bytes; the sub-packet number indicates the position of the transmitted sub-message represented by the sending sequence number in the whole message stream; the range of the sending sequence number is 0 to 7, the receiving party is used for assembling the data of all the ports into complete sub-packet data according to the sequence number, the sending sequence number is added with 1 every time the sending sequence number is updated, when the sending sequence number reaches 8, the sending sequence number is started from 0 again, the sequence numbers of all the ports must be consistent, and then the complete message can be considered to be received, otherwise, the sequence numbers are ignored; confirming that the range of the sending sequence number is 0 to 7, and indicating the finally received complete sub-package data; the connection state is as follows: indicating a communication state;
the port security information includes: a2 byte timestamp and a4 byte CRC; the time stamp is the lower 16 bits of the 32-bit system time stamp, and the upper 16 bits are hidden information which is not transmitted actually; the check range of the CRC includes the complete 32-bit timestamp and port number.
2) Communication data format of data port
In the embodiment of the invention, the data port is not mandatory.
As shown in fig. 2, the communication data format (32 bytes) of the data port includes: 25 bytes of application data, 1 byte of sending sequence number and 6 bytes of port security information; wherein:
25 bytes of application data for transmitting messages to be sent;
sending sequence number: the range is 0 to 7, the receiver is used for assembling the data of all the ports into complete sub-packet data according to the sequence number, the sequence number is added with 1 every time the sending sequence number is updated, when the sending sequence number reaches 8, the sequence numbers of all the ports are consistent again from 0, and the complete message can be considered to be received, otherwise, the sequence numbers are ignored;
the port security information includes: a2 byte timestamp and a4 byte CRC; the time stamp is the lower 16 bits of the 32 system bit time stamp, and the upper 16 bits are hidden information which is not transmitted actually; the check range of the CRC includes the complete 32-bit timestamp and port number.
In the two communication data formats, the transmission sequence number of 0 means that the transmission sequence number is currently in a non-transmission state, so that the transmission sequence number of the first transmitted sub-message is 1, and if the number of the transmitted sub-messages is large, the transmission sequence number of the next sub-message starts from 1 again after reaching the transmission sequence number of 7.
And II, communication state.
In the embodiment of the invention, data transmission is allowed only after the communication session is established between the two communication parties.
In order to establish and maintain a communication session, the connection state between two communicating parties includes four types: get ready, start and running, the two communication parties determine their new connection states according to the current connection state and the far-end connection state, where running indicates that the communication session is established, the other three states all indicate that the communication session is not established (communication is disconnected), and the state transition of the communication session is as shown in fig. 3.
And thirdly, communication mechanism.
After the two communication parties establish the communication session, the two communication parties can carry out data transmission. The sending party determines the sending policy according to the size of the message to be sent and the allowed data length in the communication data format, as defined above, the communication data format of the control port may contain 22 bytes of application data, the communication data format of the data port may contain 25 bytes of application data, and the sending party determines the allowed data length in the corresponding communication data format according to the logic type of the local source port.
If the message to be sent does not exceed the allowed data length, the message to be sent is sent in a lump, the message length is filled in as the actual message length, and the idle data byte is filled in 0.
If the message to be sent exceeds the allowed data length, the message to be sent is divided into a plurality of sub-messages with fixed length, the message length of the last sub-message is filled in as the actual message length, and the idle data byte is filled in 0. At start-up, the message length is up to 0 until the first sub-message is sent.
The sending sequence number of the first message or the sub-message sent by the sender is set to be 1. For the divided sub-messages, after receiving a complete sub-message, the receiving end side should confirm to the sending side according to the sending sequence number of the sub-message, and the sending side can continue to send the next sub-packet after receiving the confirmation. And adding 1 to the sending sequence numbers of the subsequent sub-messages in sequence, and if the receiving party finds that the sending sequence numbers of the sub-messages are not added with 1 in sequence, judging that the communication fails.
If the communication state enters the disconnection state again, the sending sequence number is set to 0.
And fourthly, a safety communication maintaining mechanism.
In the embodiment of the present invention, when two transparent transport entities communicate based on the above scheme, the sending of the application message is supported to be non-periodic, and it may not be necessary to send any message most of the time. However, for secure communication, it is necessary to be able to detect whether communication is abnormal, so after both communication parties establish a communication session, even if no actual message needs to be sent, the security information of all ports is periodically updated, i.e. the time stamp and the CRC are periodically updated, so as to ensure that both communication parties can detect whether communication is normal.
The source port and the sink port security maintenance mechanisms are respectively as follows:
1. source port security maintenance mechanism.
For the source port, if there is no message to send, it also needs to send the security information before time T2;
defining: t2 ═ T1+ STT-2 ═ T0
Wherein, T2 is a reference time for which the security information of the source port needs to be updated again, T1 is a time for writing data last time, STT is a security tolerance time, and T0 is a maximum value of the execution period and the bus polling period.
2. Sink port security maintenance mechanism.
For the sink port, if the communication mode is non-periodic, the data of the sink port needs to be read once before the time T4;
defining: t4 ═ T3+ STT-2 ═ T0
Wherein, T4 is the reference time when the data needs to be read again, and T3 is the time when the data is read last time.
According to the scheme of the embodiment of the invention, the message receiving and sending with variable length are realized by using the control port and the data port; the integrity and the real-time performance of the information are realized by using a defined communication mechanism; by using a secure communication retention mechanism, a security check of the communication connection is achieved.
The following describes an application process of the MVB bus-based general secure communication method according to an embodiment of the present invention with reference to a specific example.
As shown in fig. 4, two communication parties are a communication entity a and a communication entity B, each of which uses four physical ports (MVB ports) for communication, and 3 sink ports and 1 source port are set on the communication entity a: sink port a1, sink port a2, sink port A3, and source port a 4; corresponding to this, 3 source ports and 1 sink port are set on the communication entity B: source port a1, source port a2, source port A3, and sink port a 4. The corresponding relationship of the ports is as follows: A1-B1, A2-B2, A3-B3 and A4-B4.
Simultaneously defining: the sink port A1 and the source port B1 are data ports, and data port data are used between the two ports for communication; the sink port A2 and the source port B2 are data ports, and data port data are used between the two ports for communication; the sink port A3 and the source port B3 are control ports, and control port data are used for communication between the two ports; the source port a4 and the sink port a4 are control ports, and control port data is used for communication between the two ports. In order to realize bidirectional communication based on the MVB, two tasks of reading and writing are started on two communication entities A and B of two communication parties.
Communication process
1) Communication entity a acts as the sender and communication entity B acts as the receiver.
The communication entity A divides a message (m bytes) to be sent into a plurality of sub-messages with fixed length, the sub-messages are sent out through a source port A4 at one time, after the communication entity B receives a complete sub-message at a corresponding sink port B4, the communication entity B confirms a sending sequence number of the received sub-message to the communication entity A through the source port B3, and after the communication entity A receives the confirmation of a receiving party B through the sink port A3, the communication entity A can send the next sub-message. The communication entity A adds 1 to the sending sequence number every time the communication entity A sends a sub message; and after the communication entity B receives all the sub-messages, assembling all the sub-messages into a complete message according to the sending sequence numbers.
2) Communication entity B acts as the sender and communication entity a acts as the receiver.
A communication entity B divides a message (n bytes) to be sent into a plurality of sub-messages with fixed lengths, the sub-messages are sent out through a source port B1/B2/B3 at one time, the communication entity A confirms a sending sequence number of the received sub-message to a sending party B through the source port A4 after receiving the complete sub-message at a corresponding sink port A1/A2/A3 (the sending sequence numbers of all ports are consistent and the complete message is considered to be received, otherwise, the sending sequence number is ignored), and the communication entity B sends the next sub-message after receiving the confirmation of the communication entity A through the sink port B4; the communication entity B adds 1 to the sending sequence number every time the communication entity B sends a sub-message; and after the communication entity A receives all the sub-messages, assembling all the sub-messages into a complete message according to the sending sequence numbers.
In the application of the universal secure communication protocol in this embodiment, each sending direction is guaranteed to have one control port, and according to the size of the transmission data and the requirement of the transmission speed, the CPU load capacity is considered, the number of data ports is defined, and effective communication between both communication parties is realized.
Through the above description of the embodiments, it is clear to those skilled in the art that the above embodiments can be implemented by software, and can also be implemented by software plus a necessary general hardware platform. With this understanding, the technical solutions of the embodiments can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.), and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods according to the embodiments of the present invention.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.