Message transmission method, system, device, equipment and readable storage medium
By storing the target message in the system memory of the network device and using the message management header to locate equal-length fragments for transmission, the resource waste and delay problems of network devices when transmitting large messages are solved, and more efficient message transmission is achieved.
Patent Information
- Application Number
- CN202310762087.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-26
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2043-06-26
AI Technical Summary
When network devices transmit packets larger than the maximum transmission unit (MTU), CPU resources and memory bandwidth are wasted, and significant transmission delays occur, impacting upper-layer service performance.
The target message is stored in the system memory of the network device, and memory space is allocated in the stack memory to store the message management header. Each equal-length fragment is located through the message management header for sending, and the memory is automatically reclaimed after the sending is completed, reducing memory resource application and copying.
It reduces the consumption of CPU resources and memory bandwidth, shortens message transmission delay, and improves transmission performance.
Smart Images

Figure CN116743888B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a message transmission method, system, device, equipment and readable storage medium. Background Art
[0002] The maximum transmission unit (MTU) is an attribute used to define the maximum length of a message transmitted in a network. When a network device needs to transmit a message longer than the MTU, the message needs to be fragmented, and the network device that receives the message reassembles the fragmented message.
[0003] In the related art, when a network device fragments a message to be transmitted, it applies to the operating system for multiple fragmented message memory spaces, and copies the fragments of the message to be transmitted to the memory corresponding to the fragmented message data segment before sending it, resulting in a waste of CPU resources and memory bandwidth resources. At the same time, there is a large transmission delay, which affects the performance of upper-layer services. Summary of the Invention
[0004] In view of this, in order to solve the above technical problems, the present application provides a message transmission method, system, device, equipment and readable storage medium.
[0005] Specifically, this application is implemented through the following technical solutions:
[0006] According to a first aspect of an embodiment of the present application, a message transmission method is provided, which is applied to a network device, and the method includes:
[0007] Obtain a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer;
[0008] Allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer and not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message;
[0009] Obtain the starting memory position and data length in each message management header in turn, and send the fragmented message corresponding to each message management header in turn based on the starting memory position and data length; after the M fragmented messages are sent, determine whether the last fragmented message of the target message has been sent. If not, store the message management header corresponding to the fragmented message after the fragmented message has been sent through the memory space, and return to execute the operation of obtaining the starting memory position and data length in each message management header in turn until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
[0010] According to a second aspect of an embodiment of the present application, a message transmission method is provided, which is applied to a network device, and the method includes:
[0011] Upon receiving a fragment message sent by a peer network device, if the state of the network device is a first state, determining whether the fragment message includes a fragment management header, and if so, parsing verification data from the fragment management header, and if it is determined based on the verification data that the fragment message is the first fragment message, applying for new memory space in the system memory of the network device, removing the fragment management header from the fragment message, storing the fragment message after the fragment management header is removed in the new memory space, and changing the state of the network device to a second state;
[0012] If the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0013] According to a third aspect of an embodiment of the present application, there is provided a message transmission system, the system comprising a first network device and a second network device;
[0014] The first network device is configured to obtain a target message and store the target message in a system memory of the network device, where the target message includes K fragment messages, each of which has the same length, where K is a positive integer; allocate M memory spaces in a stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, where each message management header corresponds to one fragment message, where M is a positive integer and is not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message;
[0015] The first network device is configured to sequentially obtain a starting memory location and a data length in each message management header, and sequentially send a fragment message corresponding to each message management header based on the starting memory location and the data length; after the M fragment messages are sent, determine whether the last fragment message of the target message has been sent; if not, store the message management header corresponding to the fragment message after the fragment message has been sent in the memory space, and return to sequentially execute the operation of obtaining the starting memory location and the data length in each message management header until the last fragment message of the K fragment messages is sent, so that the opposite network device receives the K fragment messages;
[0016] The second network device is configured to, upon receiving a fragment message sent by the opposite network device, determine, if the state of the network device is the first state, whether the fragment message includes a fragment management header; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and change the state of the network device to the second state;
[0017] If the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0018] According to a fourth aspect of an embodiment of the present application, a message transmission device is provided, applied to a network device, the device comprising:
[0019] A message acquisition module, configured to acquire a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer;
[0020] A management header allocation module is configured to allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message through the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer and not greater than K; wherein the message management header includes at least the starting memory location and data length of the fragment message;
[0021] A message sending module is used to sequentially obtain the starting memory position and data length in each message management header, and sequentially send the fragmented message corresponding to each message management header based on the starting memory position and data length; after the M fragmented messages are sent, it is determined whether the last fragmented message of the target message has been sent. If not, the message management header corresponding to the fragmented message after the fragmented message has been sent is stored in the memory space, and the operation of sequentially obtaining the starting memory position and data length in each message management header is returned to execute until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
[0022] According to a fifth aspect of an embodiment of the present application, a message transmission device is provided, applied to a network device, the device comprising:
[0023] a first state processing module, configured to, upon receiving a fragment message sent by a peer network device, determine, if the state of the network device is the first state, whether the fragment message includes a fragment management header; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and modify the state of the network device to the second state;
[0024] The second state processing module is used to determine whether the fragment message is the last fragment message if the state of the network device is the second state; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0025] According to the sixth aspect of an embodiment of the present application, an electronic device is provided, comprising: a memory and a processor; the memory is used to store a computer program; and the processor is used to execute the above-mentioned message transmission method by calling the computer program.
[0026] According to a seventh aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned message transmission method is implemented.
[0027] The technical solutions provided by the embodiments of the present application may have the following beneficial effects:
[0028] The embodiment of the present application applies for message management header memory from a pre-opened stack memory, and modifies the data in the message management header in sequence to point to the storage location of each equal-length fragment in the message to be sent, thereby achieving the goal of directly locating and sending the data in the message management header, and automatically recovering the message management header memory after each fragment of the message to be sent is sent. This reduces the CPU resource and memory bandwidth resource consumption caused by the fragment message memory resource application and fragment copying in the related technology, and the message transmission delay is reduced by the non-fragmented message copying sending process.
[0029] It should be understood that the above general description and the detailed description below are merely exemplary and explanatory and cannot limit the present application. In addition, any embodiment in the present application does not necessarily achieve all the effects described above. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0031] Figure 1 This is a schematic diagram of message fragment copying in the related art shown in an exemplary embodiment of the present application;
[0032] Figure 2 This is a flow chart of a message transmission method shown in an exemplary embodiment of the present application;
[0033] Figure 3-1 This is a schematic diagram of a management header modification process for allocating a message management header, shown in an exemplary embodiment of the present application;
[0034] Figure 3-2 This is a schematic diagram of a management header modification process for allocating two message management headers, shown in an exemplary embodiment of the present application;
[0035] Figure 4 This is a flow chart of another message transmission method shown in an exemplary embodiment of the present application;
[0036] Figure 5 This is a schematic diagram of message fragment copying in a DPDK-based message sending scenario in a related technology shown in an exemplary embodiment of the present application;
[0037] Figure 6 This is a flowchart of a DPDK-based message transmission method shown in an exemplary embodiment of the present application;
[0038] Figure 7 This is a schematic diagram of a management header modification process for allocating a message management header based on DPDK, shown in an exemplary embodiment of the present application;
[0039] Figure 8 This is a flowchart of another DPDK-based message transmission method shown in an exemplary embodiment of the present application;
[0040] Figure 9 This is a structural diagram of a message transmission device shown in an exemplary embodiment of the present application;
[0041] Figure 10 is a structural diagram of another message transmission device shown in an exemplary embodiment of the present application;
[0042] Figure 11 It is a hardware schematic diagram of an electronic device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0043] Here, exemplary embodiments are described in detail, with examples illustrated in the accompanying drawings. When the following description refers to the drawings, identical numerals in different figures represent identical or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0044] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. As used in this application and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0045] The Maximum Transmission Unit (MTU) is the maximum packet size a network can transmit, measured in bytes. The MTU size determines the maximum number of bytes a sender can send at a time. If a packet is larger than the MTU supported by the transmission line, the packet is fragmented into fragments smaller than or equal to the MTU before being sent to the outbound interface.
[0046] In the related art, when fragmenting a message to be transmitted, the operating system is first requested to allocate memory space for each fragmented message, and the message data of each fragment length corresponding to the data segment of the message to be transmitted is copied to the corresponding fragmented message memory before being sent. For example, the sending end device sends a target message with a data payload length of 20,000 bytes. The default MTU of Ethernet is 9,000 bytes. The target message needs to be divided into 3 fragments and sent in sequence. Specifically, Figure 1As shown, the length of each fragment message is less than or equal to 9000. Since each fragment contains a fixed 20-byte fragment header, the data segment of the target message (the same as the "data payload") is divided into message fragments with lengths of 8980, 8980, and 2040 bytes respectively, and each of the message fragments is copied to the data segment memory location of the three applied fragment messages in turn; wherein, the fragment header is used by the receiving end to reassemble the message after receiving all the fragment messages.
[0047] The above-mentioned message fragmentation and reassembly method will lead to a waste of CPU resources and memory bandwidth resources, and at the same time there will be a large transmission delay, which will affect the performance of upper-layer services.
[0048] To solve the above problems, this application provides a message transmission method, see Figure 2 As shown, the message transmission method is applied to a network device, and the network device is used to send fragmented messages. The message transmission method may include the following steps:
[0049] S101, obtaining a target message and storing the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer;
[0050] The target message refers to the message obtained by fragmenting the data packet to be sent with the newly added fragment management header. The target message contains K message fragments of equal length. During the fragmentation process, if the length of the last message fragment is less than the set message fragment length, data is added to the end of the message fragment to make the length of all fragments the same. Figure 3-1 As shown, the target message includes a fragment management header, a data packet to be sent consisting of frag_0, frag_1, and frag_2, and a pad for filling the tail length, and contains three message fragments of equal length, K1, K2, and K3.
[0051] The fragment management header is used to describe the fragment information in the target message, so that the device receiving the target message can verify according to the fragment management header to confirm whether the received message fragment is the first message fragment in the target message.
[0052] The length of each fragmented message is less than or equal to the maximum data packet length that the network device can send. The maximum data length can be the default maximum length that the device can send, a value set based on actual transmission requirements, or the maximum data packet length supported by the network card. For example, when transmitting ultra-long messages between the main control board and baseband board of a 5G base station, the Ethernet card device supports the transmission of large packets of up to 9000 bytes, and the length of each message fragment can be set to 8500 bytes.
[0053] In some embodiments, the target message can be obtained in the following manner, which may specifically include the steps of: adding a fragment management header before the obtained message to be fragmented, and obtaining the message after the newly added fragment management header as the first message; generating the target message based on the first message, wherein the first fragment message of the target message includes the fragment management header, and the fragment management header is used to enable the opposite network device to identify that the current fragment message is the first fragment message of the target message based on the fragment management header.
[0054] Among them, the message to be fragmented is a message containing unencapsulated data packets to be sent, such as a message whose total length of the data packets to be sent generated by the sending end is 20,000 bytes; the fragment management header may include four fields: the number of fragments, the whole packet length, the tail padding length and the fragment header identifier. The whole packet length refers to the length of the message after the newly added fragment management header before the message to be fragmented, that is, the length of the first message; the tail padding length refers to the data length that needs to be supplemented to the last message fragment when the first message is fragmented according to the preset fragment length so that all message fragments are equal in length; the fragment header identifier is used to indicate the existence of the fragment management header, that is, if the message fragment contains the fragment header identifier, then the fragment is considered to contain the fragment management header.
[0055] When the network device obtains the message to be fragmented, it requests system memory space of a target length from the operating system for storing the fragment management header and the message to be fragmented. The target length is the sum of the preset byte length of the fragment management header and the length of the message to be fragmented. Based on the message to be fragmented, including the fragment management header, the network device fragments the message starting from the fragment management header according to the preset message fragment length. If the length of the last message fragment is less than the preset message fragment length, the network device pads the fragments with tail data so that the K message fragments obtained by fragmentation are of equal length. The network device then determines the message containing the K message fragments of equal length as the target message and fills the data in the fragment management header with the target message.
[0056] S102, allocating M memory spaces in the stack memory, storing M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message;
[0057] The stack memory is automatically allocated and released by the operating system. It is the memory space opened up for the local variables of the function when the thread executes a function call. The stack space is automatically reclaimed at the end of the function call, and there is no need to consume CPU execution instructions to complete the memory release. The present application opens up stack memory when the thread executes to send message fragments, and applies for M memory spaces from the stack memory. Each memory space is used to store a message management header. The memory corresponding to the M message management headers can be continuous in space, and the order of the message management headers can be determined in order from small to large memory position. The message management header is used to describe the memory position of each message fragment in the target message, so that the network device can obtain the message fragment of the target message at the memory position indicated by the management header based on the message management header stored in the memory space.
[0058] The M can be a preset value, or it can be adjusted and reset by the user according to the number of fragments of the target message. In the embodiment of the present application, M is set to 1 or M is set to 2 to illustrate the message fragment transmission process of setting the memory space of one or more message management headers. This is only an exemplary value, and the actual value of M is not limited in this application.
[0059] After applying for memory space for M message management headers from the stack memory, the starting memory location and data length of the message management headers stored in the M memory spaces are modified in sequence, so that each message management header points to the first to M fragment messages of the target message in sequence. Figure 3-1 As shown, if M is set to 1 by default, a memory space for a message management header is allocated in the stack memory, and the starting memory position of the message management header stored in the memory space is modified to point to the first message fragment K1 of the target message, and the data length of the stored message management header is the byte length of K1; Figure 3-2 As shown, if M is set to 2, memory space for two message management headers is allocated in the stack memory, and the starting memory position and data length of the message management headers stored in the two memory spaces are modified in turn, so that the first message management header points to the storage position of the first message fragment K1 of the target message, and the second message management header points to the storage position of the second message fragment K2 of the target message.
[0060] S103, obtain the starting memory position and data length in each message management header in turn, and send the fragmented message corresponding to each message management header in turn based on the starting memory position and data length; after the M fragmented messages are sent, determine whether the last fragmented message of the target message has been sent, if not, store the message management header corresponding to the fragmented message after the fragmented message has been sent through the memory space, and return to execute the operation of obtaining the starting memory position and data length in each message management header in turn until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
[0061] Among them, for each message management header, the network device can determine the system memory location of the message fragment of the target message associated with the message management header by obtaining the starting memory location and data length in the message management header in the order of the message management header, and read the message fragment in the memory location, and put the message fragment into the sending queue or send it to the opposite network device.
[0062] After completing the sending of the message fragments indicated by the message management headers of the M memory spaces, that is, the sending of the 1st to Mth message fragments of the target message has been completed, the number of message fragments sent can be counted and compared with the number of fragments of the target message to determine whether the Mth fragment sent is the last fragment of the target message. Figure 3-2 For example, M takes the value of 2, the first message fragment K1 and the second message fragment K2 of the target message have been sent, and the number of fragments sent is less than the number of fragments of the target message. The second fragment sent is not the last fragment of the target message, and it is necessary to continue to modify the message fragment after the second message fragment K2 of the target message in the message management header.
[0063] When the number of message fragments sent is the same as the number of fragments of the target message, the last message fragment currently sent is considered to be the last message fragment of the target message, and the target message is confirmed to be sent, and the memory space of the allocated M message management headers is automatically recovered.
[0064] In an embodiment of the present application, the "last-in-first-out" disorder problem of messages during transmission is solved by obtaining message fragments of equal length, so that the sending order of each fragmented message is consistent with the order in which the opposite network device receiving the fragmented message receives each fragmented message, which facilitates the opposite network device receiving the fragmented message to reassemble the fragments in the order of reception; compared with the related art, the embodiment of the present application only applies for a message management header and points to the system memory location of each message fragment by modifying the data in the message management header, so that the network device can directly determine and obtain the message fragment based on the message management header, and the message management header comes from the stack memory and can be automatically recycled without the need for CPU instruction recycling, thereby reducing the high CPU occupancy caused by memory application and message fragment copying in the related art, reducing the waste of memory bandwidth resources and message transmission delay, and improving transmission performance.
[0065] In some embodiments, in the process of obtaining the target message, after adding a fragment management header before the message to be fragmented, generating the target message based on the message after the newly added fragment management header, that is, the first message, may include the following steps: determining the total length of the target message based on the preset message fragment length and number K; obtaining the padded length of the last fragment message based on the total length of the target message and the length of the first message; adding padding data of the padded length after the first message to obtain the target message, wherein the padded data is a random value in the system memory.
[0066] That is, given the length L1 of the first message and fragmenting it according to the preset message fragment length L2, the rounded-up value of the quotient of the first message length L1 and the preset message fragment length L2 can be determined to be K. The product of the preset message fragment length L2 and K is then determined to be the total length L3 of the target message. Based on this, the difference between the total length L3 of the target message and the length L1 of the first message is determined to be the padding length L of the last fragmented message.
[0067] In another embodiment, the padded length of the last fragmented message can also be determined in the following manner. Specifically, the first message is fragmented according to the preset message fragment length L2, and the memory starting position of the last message fragment and the length L4 of the fragment can be determined. When L4 is less than the preset message fragment length L2, the difference between L2 and L4 is determined to be the padded length L of the last fragmented message.
[0068] When adding padding data of the padding length after the last fragmented message, the system memory of the padding length L can be directly selected after the memory end position of the last message fragment, and the original data in the memory can be determined as the padding data, without filling the system memory of the padding length L with 0 or other values through CPU instructions.
[0069] In an embodiment of the present application, by determining the tail padding length of the last message fragment of the target message, the length of the last message fragment is aligned and supplemented using the original random value in the system memory based on the padding length, so that each message fragment is of equal length, thereby solving the disorder problem that may exist due to inconsistent fragment message lengths in the related technology, and using the original random data in the system memory as padding data saves CPU resources and memory space.
[0070] In some embodiments, the message management header includes a data start address pointer and a data length, the data start address pointer is used to point to the starting memory location of the fragment message in the system memory, and the data length is the data length of the fragment message;
[0071] After the message fragments pointed to by the message management header are sent in sequence, the message management header corresponding to the fragmented message after the fragmented message has been sent can be stored in the memory space in step S103 by the following method:
[0072] If the number of remaining fragments N after the fragmented message has been sent is greater than or equal to M, then the data start address pointers in the M memory spaces are modified to point to the starting memory locations of the M fragmented messages after the fragmented message has been sent, and the data lengths in the M memory spaces are modified to be the data lengths of the M fragmented messages after the fragmented message has been sent;
[0073] If the number of remaining fragmented messages N after the fragmented message has been sent is less than M, the data starting address pointers in the 1st to Nth memory spaces in the M memory spaces are modified to point to the starting memory positions of the N fragmented messages after the fragmented message has been sent, and the data lengths in the 1st to Nth memory spaces are modified to the data lengths of the N fragmented messages after the fragmented message has been sent.
[0074] The fragmented message sent refers to the message fragment indicated by the last message management header in the M memory spaces obtained during the current message sending process. Figure 3-2 The figure shows the message fragment K2 during the first round of message sending.
[0075] by Figure 3-1For example, the target message contains three message fragments K1, K2, and K3, and M takes the value of 1. In step S102, a memory space for a message management header is allocated to the stack memory. By modifying the data starting address pointer and data length in the message management header stored in the memory space, the message management header points to the first message fragment K1 of the target message, thereby realizing the sending of the first message fragment K1, and judging that K1 is not the last fragment message of the target message, then: it is determined that the number of fragment message fragments N after the currently sent fragment message (sent fragment message) K1 is 2, which is greater than the number of message management headers, then the data of the message management header stored in the memory space is modified to point to the message fragment K2 after K1, and after K2 is sent, the data of the message management header stored in the memory space is modified to point to the message fragment K3 after K2. When K3 is sent, the number of sent message fragments is equal to the number of fragments of the target message, then it is confirmed that the sending of the last message fragment is completed.
[0076] Or, Figure 3-2 For example, the target message contains three message fragments K1, K2, and K3, and M takes the value of 2. In step S102, the stack memory is requested to allocate memory space for two message management headers. By modifying the data starting address pointer and data length of the first message management header in the memory space so that the message management header points to the first message fragment K1 of the target message, and modifying the data of the second message management header to point to the second message fragment K2, the message fragments K1 and K2 are sent. If it is determined that the last message fragment K2 sent is not the last fragment message of the target message, it is necessary to continue to modify the message management header stored in the memory space:
[0077] Specifically, it is determined that the number of fragmented message fragments N after the currently sent fragmented message K2 is 1, which is less than the number of memory spaces M corresponding to the message management header, then the data in the first message management header stored in the memory space is modified to point to the message fragment K3 after K2, and after K3 is sent, the last message fragment of the target message that has been sent is determined.
[0078] Or, if the target message contains five message fragments K1, K2, K3, K4, and K5, and M takes the value of 3, then after the message fragments K1, K2, and K3 are sent, when it is determined that the last message fragment K3 sent is not the last fragment message of the target message, it is necessary to continue to modify the message management header stored in the memory space. Specifically, it is determined that the number of fragmented message fragments N after the currently sent fragmented message K3 is 2, which is less than the number of message management headers M, then the data in the first message management header stored in the memory space is modified to point to the first message fragment K4 after K3, and the data in the second message management header stored in the memory space is modified to point to the second message fragment K5 after K3, and after sending message fragments K4 and K5 in sequence, it is confirmed that the last message fragment of the message has been sent.
[0079] The embodiment of the present application also provides another message transmission method, which is applied to a network device, wherein the network device is used to receive message fragments of a message to be transmitted sent by the above message transmission method, such as Figure 4 As shown, the method may include the following implementation steps:
[0080] S201, upon receiving a fragment message sent by a peer network device, if the state of the network device is a first state, determining whether the fragment message includes a fragment management header, and if so, parsing verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, applying for new memory space in the system memory of the network device, removing the fragment management header from the fragment message, storing the fragment message after the fragment management header is removed in the new memory space, and changing the state of the network device to a second state;
[0081] Among them, the network device described in the embodiment of the application is set to the first state by default; the fragment management header is a structure used to describe the fragment information of the message added by the sender of the fragment message in front of the data packet when the sender obtains the data packet to be sent. The fragment management header may include four fields: the number of fragments, the length of the entire packet, the length of the tail padding and the fragment header identifier. The meaning of the four fields can be found in the above embodiment.
[0082] When the network device is in the first state, a management header check is performed on the received fragment message. That is, the data at a preset position in the message fragment is obtained. If the data matches the preset fragment header identification data, it can be confirmed that the fragment message includes a fragment management header. If the data fails to match the preset fragment header identification data, it is determined that the fragment message does not include the fragment management header. For example, if the data from bytes 1 to 6 of the fragment message is matched, if the data is "0x8888" and matches the preset fragment header identification data, then the fragment message is considered to include a fragment management header.
[0083] When determining whether the fragment message includes a fragment management header, if the fragment management header is not included, the fragment message is directly discarded; if the fragment management header is included, verification data is parsed from the fragment management header, and further, based on the verification data, it is determined whether the fragment message is the first fragment message. If not, the fragment message is discarded.
[0084] When applying for new memory space in the system memory of the network device, the size of the new memory space may be determined based on the entire packet length in the fragment management header and the preset byte length of the fragment management header. For example, if the entire packet length is 20020 and the byte length of the fragment management header is 20 bytes, then a new memory space of 20000 bytes is applied to the system for storing the fragmented message without the fragment management header.
[0085] S202, if the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space that stores the received fragment message; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0086] That is, when the network device receives a fragment message in the second state, it is confirmed that the fragment message is a fragment message other than the first fragment message of the target message from the sending end device, such as Figure 3-1 K2 and K3 in the fragment management header. First, determine whether the received fragment message is the last fragment message. This can be done by comparing the number of received fragment messages with the number of fragments in the fragment management header. The number of received fragment messages can include the currently received fragment message. If the number of received fragments is the same as the number of fragments in the fragment management header, then the fragment message is considered to be the last fragment message of the target message; if not, then the fragment message is not the last fragment message of the target message.
[0087] For example, still Figure 3-1 Taking the target message in as an example, if K2 is received, the number of received fragment messages is 2. It is confirmed that it is not the last fragment message of the target message, and K2 is stored after the storage position where K1 is located, and is stored continuously with K1; if K3 is received, the number of received fragment messages is 3. It is confirmed that it is the last fragment message of the target message, then for K3, after removing the padding data pad in K3, frag_2 is stored after the storage position where K2 is located, and is stored continuously with K2.
[0088] Switching the receiving end from the second state to the first state indicates that all fragment messages of a target message have been received and the receiving end is ready to receive the fragment message of the next target message.
[0089] In an embodiment of the present application, for a target message from a sending network device containing K message fragments of equal length, the first state and the second state of the receiving end confirm the reception of fragmented messages at different positions, and the message storage in the corresponding state is executed, so that the receiving network device can reassemble the fragments according to the order in which each fragmented message is received; compared with the related art of reassembling the message according to the fragment header indication information of each fragmented message, the cache delay before the reassembly of the fragmented message is reduced, and the transmission performance is improved.
[0090] In some embodiments, the verification data includes at least the first fragment number and the entire packet length; when it is determined that the currently received fragment message includes a fragment management header, after parsing the verification data from the fragment management header in step S201, determining whether the fragment message is the first fragment message based on the verification data can be implemented in the following manner, specifically including:
[0091] Determine the second number of fragments based on the entire packet length and the message length of the fragmented message, and judge whether the first number of fragments and the second number of fragments are the same; if so, determine that the fragmented message is the first fragmented message; if not, determine that the fragmented message is not the first fragmented message.
[0092] The verification data may be data extracted from a corresponding position in the fragment message according to a preset position, for example, the fragment header identifier is located at bytes 1 to 6, the number of the first fragment is located at bytes 7 to 8, and the length of the entire packet is located at bytes 9 to 16.
[0093] To determine whether the above two numbers of fragments are the same, determine the value of the quotient of the entire packet length and the message length of the fragment message rounded up as the calculated second number of fragments, and compare the calculated second number of fragments with the first number of fragments in the verification data.
[0094] In an embodiment of the present application, a double check method is used to determine whether the received fragment message is the first fragment message through fragment management header identification and verification data judgment. If any one of the checks fails, the fragment message is directly discarded to ensure that the message can be received accurately and the fragment messages can be reassembled in the order in which the messages are received to obtain the restored message.
[0095] In some embodiments, before removing the fragment management header from the fragment message, the following steps are further included: applying for storage space from the system memory and storing the padded length carried in the fragment management header in the storage space; based on this, removing the supplementary data from the fragment message may include the following implementation steps:
[0096] The padding length of the last fragment message carried by the fragment management header is obtained from the storage space, and according to the message length of the fragment message and the padding length, the padding data of the padding length in the fragment message is determined and removed from the fragment message.
[0097] That is, in step S201, for the slice management header, a storage location is applied to the system memory for storing the tail padding length data in the slice management header, and all the data in the entire slice management header can also be stored. When the last slice message is received, the starting byte position of the padding data in the slice message can be determined based on the length of the slice message and the tail padding length, and the byte data from the first byte of the slice message to the previous byte of the starting byte position can be stored. For example, if the last slice message is 9000 bytes long and the tail padding length is 1200, then the bytes from the first to the 7800th of the slice message are stored, which represents the removal of the tail padding data of the slice message.
[0098] In an embodiment of the present application, the tail padding data of the last one of the equal-length fragmented messages sent by the sending end is removed, so that the fragmented messages are reorganized in the order of message reception and the tail padding data is removed, the message from the sending end is accurately restored, and the accurate reception of the message is achieved.
[0099] The following describes the embodiment of the present application in detail in conjunction with specific application scenarios.
[0100] 5G base stations require a large number of extremely long messages to be transmitted between the main control board and baseband board, requiring low latency and high performance. The main control board and baseband board are connected via an Ethernet port, and messages are sent via Ethernet cards. Typically, the required message lengths range from 0 to 200,000. Most current Ethernet cards support large packets with a maximum length of 9,000 bytes. For extremely long packets significantly longer than 9,000, the current solution is to split the packets into smaller packets at the sender and reassemble them at the receiver for transmission.
[0101] In related technologies, when the main control board and the baseband board transmit an extra-long packet, the sending end splits the extra-long packet into multiple fragmented packets and sends the fragmented packets through DPDK. Figure 5As shown, when sending the fragmented packet, a continuous memory space is first applied to the system memory of the sending device as an mbuf memory pool. The mbuf memory pool includes multiple mbuf objects, each mbuf object includes a DPDK Ethernet message management header rte_mbuf and a data segment. All mbuf object elements correspond to a continuous memory segment as a whole. The sending end applies to the memory pool to obtain or release the mbuf object through the alloc or free operation. When sending each fragmented packet, an mbuf object is obtained from the memory pool, the fragmented packet is copied to the mbuf object data segment, and a fragment header is added before the fragmented packet of the data segment, so that the receiving end can reassemble the fragmented packet according to the fragment header, but this increases CPU resource consumption. Since a fragment header must be added before each fragmented packet of the data segment, it is impossible to directly modify the data in rte_mbuf to point to the memory address where the fragmented packet is located; the above-mentioned mbuf object application or release process, as well as the fragmented packet copying process, result in high CPU occupancy and waste of memory bandwidth resources, affecting business performance.
[0102] Therefore, for the above scenario, the embodiment of the present application proposes a message transmission method applied to the DPDK sending ultra-long packet scenario, which is applied to the sending end of the message, such as the main control board or baseband board of a 5G base station. Figure 6 As shown, the message transmission method specifically includes the following steps:
[0103] S301, when receiving the overlong message to be fragmented, reserve space before the message header of the overlong message to add a fragment management header, wherein the fragment management header includes four fields: number of fragments, total packet length, tail padding length, and fragment header identifier;
[0104] Among them, the whole packet length refers to the message length after the overlong message includes the fragment management header; the packet tail padding length refers to the data length that needs to be supplemented for the last message fragment when the message after the overlong message includes the fragment management header is fragmented according to the preset fragment length so that all message fragments are equal in length; the fragment header identifier is used to indicate the existence of the fragment management header, that is, if the fragment contains the fragment header identifier, then the fragment is considered to contain the fragment management header, and the fragment can be considered to be the first message fragment.
[0105] When the overlong message is received, an application is made to the system memory for an overlong message storage location containing reserved space based on the length of the overlong message and the length of the space reserved for adding the fragment management header, and the overlong message is stored. A continuous section of reserved space before the overlong message is used to add the fragment management header.
[0106] Compared with the related art in which a fragment header for the fragment is added before the message fragment of the mbuf object data segment, the embodiment of the present application only adds a fragment management header before the super long message to realize the description of the fragment information of the super long message, saving CPU resources and memory consumption.
[0107] S302: Determine the number of fragments based on the length of the message including the fragment management header and the preset message fragment length, determine the packet tail padding length based on the length of the last message fragment, perform data padding on the last message fragment, determine the message including the fragment management header and having completed the packet tail padding as the target message, and store the message in the system memory of the network device;
[0108] If the packet length including the fragment management header and the preset packet fragment length are known, the quotient of the two is rounded up to an integer, which is the number of fragments. For example, if the packet length is 80,000 and the preset packet fragment length is 9, the number of fragments is 80,000 / 9,000, which is rounded up to an integer, which is 9.
[0109] After determining the number of fragments, it can be determined that the tail length of the last message fragment is 8000. To make all message fragments of equal length, data with a length of 1000 is added to the tail of the packet of the last message fragment. The tail of the last message fragment is aligned and supplemented, and the supplemented data is not padded with 0 or other values. The original data in the memory is used as the tail alignment supplement data, which can avoid unnecessary CPU resource consumption.
[0110] When a network card sends message fragments, a later-sent, smaller fragment may arrive at the receiving end before an earlier-sent, larger fragment. This out-of-order arrival can cause the order of the message fragments received by the message receiving end to be inconsistent with the order in which the fragments were sent, resulting in the receiving end being unable to correctly reassemble the target message. Therefore, the present embodiment pads the last message fragment of the target message to ensure that each message fragment sent from the message sending end is of equal length, so that the receiving end can reassemble the target message according to the order in which the message fragments were received.
[0111] S303, when sending the target message, applying for a memory space of a DPDK Ethernet message management header rte_mbuf from the stack memory, modifying the data in the management header to directly point to the memory storage location of the first fragment in the target message, the first fragment including the fragment management header, and the data including the starting address and data length;
[0112] like Figure 7As shown, the Ethernet message management header rte_mbuf 0 is requested from the stack memory, and the data field in rte_mbuf 0, which describes the DPDK Ethernet message data segment information, is modified to point to the memory location of the first fragment K1, that is, the fragment containing the fragment management header and frag_0. For example, if the starting address of the target message is 100, the ending address is 81100, and the preset message fragment length is 9000, then the starting address pointer in the rte_mbuf points to the memory starting address 100 and the data length is 9000.
[0113] S304, reading the memory storage location pointed to by the data in the rte_mbuf by sending a message through DPDK, and sending the message fragments to the message receiving end;
[0114] In an embodiment of the application, the modified data used to describe the DPDK Ethernet message data segment information is submitted to the Ethernet device hardware descriptor queue, and the network card device at the message sending end obtains the memory location pointed to by the data from the hardware descriptor, and reads the message fragment stored in the memory location to the network card sending queue, and sends the message fragment to the receiving end.
[0115] S305, after the message fragment is sent, it is determined whether the currently sent message fragment is the last message fragment of the target message. If not, the data in the rte_mbuf is modified to point to the internal storage location of the next message fragment of the currently sent message fragment, and the process returns to step S304; if so, the target message is sent, and the stack memory occupied by the rte_mbuf is automatically reclaimed.
[0116] like Figure 7 As shown, after the first message fragment K1 of the target message is sent, rte_mbuf 0 is modified to point to the memory storage location of the second message fragment K2, so that the second message fragment K2 is sent. The loop is executed until the last message fragment K3, i.e., the fragment including frag_2 and the padded length, is sent.
[0117] In an embodiment of the present application, compared with the solution in the related art of applying for an mbuf object including an rte_mbuf and a data segment from a memory pool through an instruction, and copying consecutive message fragments to the memory where the data segments in each mbuf object are located when sending message fragments, this embodiment allocates stack space for the local variables of the current function when the thread executes the relevant function of sending the target message. When sending the message fragment, only one Ethernet message management header rte_mbuf is applied to the stack memory, and the data used to describe the data segment is associated with the message fragment memory location of the target message. When sending, the network card driver can directly locate the memory address where the target message is located, avoiding the memory application for the data segment and the copying of the message fragment, reducing the message transmission delay and memory bandwidth resource consumption; at the same time, the Ethernet message management header applies to the stack memory once and multiple times for fragment sending, and is automatically released after the target message is sent, that is, when the relevant function call ends, avoiding the inefficient application and release of heap memory in the related art, saving CPU resources and memory resource consumption.
[0118] Corresponding to the above-mentioned message transmission method applied to the message sending end, the embodiment of the present application also provides a message transmission method applied to the message receiving end in the above-mentioned scenario, wherein the message receiving end is used to receive the message fragments sent by the above-mentioned message transmission method from the sending end. The message transmission method is implemented by the following process, such as Figure 8 As shown:
[0119] The receiving end of the message is set to two states, the SYNC state and the DATA state as shown in the figure. The receiving end is set to the SYNC state by default.
[0120] When receiving a fragment message, the receiving end determines the current state of the receiving end. If the receiving end is in the SYNC state, the received fragment message is subjected to a fragment management header check, i.e., it is determined whether the fragment message contains a fragment management header and whether the fragment header is legal, so as to determine whether the message is the first fragment message of the target message from the sending end. If the management header check passes, the message data segment after the fragment management header is stored in the newly applied memory space, and the receiving end is switched to the DATA state. If the check fails, the fragment message is directly discarded.
[0121] Among them, the fragment management header refers to the fragment management header added by the sending end before the overlong message to describe the message fragmentation information. The fragment management header includes a fragment header identification constant, the number of fragments, the whole packet length and the packet tail padding length; the fragment management header verification includes the following process: obtaining the corresponding field in the fragment message according to the preset fixed byte position, if the field value of the field does not contain the aforementioned fragment header identification constant, it is determined that the message is not the first fragment message, and the fragment message is directly discarded; if it contains the aforementioned fragment header identification constant, it is confirmed that the fragment management header is included, and further, the whole packet length field in the fragment management header is obtained, and based on the whole packet length and the length of the current fragment message, the result of the division between the two is calculated based on the integer value and whether it is the same as the fragment value in the fragment management header. If they are the same, it is determined that the fragment header is legal and the message is determined to be the first fragment message. If they are not the same, it is determined that the fragment header is illegal and the fragment message is directly discarded.
[0122] If the receiving end is in the DATA state, it is determined whether the currently received fragment message is the last fragment message. Specifically, it can be determined by counting the received fragment messages and comparing them with the number of fragments carried in the fragment management header; if not, the message data segment of the fragment message is stored behind the storage position of the last received fragment message in the memory space; if so, the data of the padded length corresponding to the tail of the fragment message is removed according to the packet tail padded length carried in the fragment management header, and the data segments of the remaining fragment messages are stored behind the storage position of the last received fragment message in the memory space, the receiving end state is switched to the SYNC state, and preparation is made to receive the fragment message of the next target message.
[0123] In an embodiment of the present application, for the fragmented messages of the target message sent by the message sending end using the above-mentioned message transmission method, two state switches are used at the receiving end to distinguish whether the currently received message is the first fragmented message of the target message or a non-first fragmented message, and the message storage methods corresponding to the two states are executed, each fragmented message is stored in sequence according to the order in which the message is received, and when the last fragmented message is received, the supplementary data at the end of the packet is taken out and stored to obtain a restored message of the fragmented message. Compared with the solution in the related art in which the receiving end reorders the message according to the fragment header before each message fragment after receiving all the message fragments, the message processing flow of the receiving end provided by this embodiment does not need to reorder all the fragments. After directly storing each message fragment in the order in which the message fragments are received, the message before the fragment can be obtained, thereby reducing the delay caused by the message fragments being cached at the receiving end before being reassembled, and improving the upper-layer service performance.
[0124] Corresponding to the two aforementioned message transmission methods, an embodiment of the present application also provides a message transmission system, wherein the message transmission system includes a first network device and a second network device; the first network device and the second network device serve as a sending device of the message and a receiving device of the message, respectively.
[0125] The first network device is configured to obtain a target message and store the target message in a system memory of the network device, where the target message includes K fragment messages, each of which has the same length, where K is a positive integer; allocate M memory spaces in a stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, where each message management header corresponds to one fragment message, where M is a positive integer and is not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message;
[0126] The first network device is configured to sequentially obtain a starting memory location and a data length in each message management header, and sequentially send a fragment message corresponding to each message management header based on the starting memory location and the data length; after the M fragment messages are sent, determine whether the last fragment message of the target message has been sent; if not, store the message management header corresponding to the fragment message after the fragment message has been sent in the memory space, and return to sequentially execute the operation of obtaining the starting memory location and the data length in each message management header until the last fragment message of the K fragment messages is sent, so that the opposite network device receives the K fragment messages;
[0127] The second network device is configured to, upon receiving a fragment message sent by the opposite network device, determine, if the state of the network device is the first state, whether the fragment message includes a fragment management header; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and change the state of the network device to the second state;
[0128] If the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0129] In an embodiment of the present application, the first network device and the second network device respectively adopt a different message transmission method, which realizes the accurate sending and receiving process of reading the equal-length fragmented messages indicated by the message management header and sending, receiving the equal-length fragmented messages and reassembling and restoring the messages in the order of reception, thereby reducing the message transmission delay, reducing the CPU occupancy rate and memory bandwidth resource consumption.
[0130] Corresponding to the embodiment of the first message transmission method described above, see Figure 9 As shown, the present application also provides an embodiment of a message transmission device, which is applied to a network device and includes:
[0131] A message acquisition module 910 is configured to acquire a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each of which has the same length, where K is a positive integer;
[0132] A management header allocation module 920 is configured to allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, each message management header corresponding to a fragment message, where M is a positive integer not greater than K; wherein the message management header includes at least the starting memory location and data length of the fragment message;
[0133] The message sending module 930 is used to obtain the starting memory position and data length in each message management header in turn, and send the fragmented message corresponding to each message management header in turn based on the starting memory position and data length; after the M fragmented messages are sent, it is determined whether the last fragmented message of the target message has been sent. If not, the message management header corresponding to the fragmented message after the fragmented message has been sent is stored in the memory space, and the operation of obtaining the starting memory position and data length in each message management header in turn is returned to execute until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
[0134] In some embodiments, the message acquisition module includes:
[0135] A fragment management header adding module is used to add a fragment management header before the obtained message to be fragmented, and obtain the message after the newly added fragment management header as the first message;
[0136] A target message generation module is used to generate the target message based on the first message, wherein the first fragment message of the target message includes the fragment management header, and the fragment management header is used to enable the opposite network device to identify that the current fragment message is the first fragment message of the target message based on the fragment management header.
[0137] In some embodiments, the target message generation module is specifically configured to:
[0138] The total length of the target message is determined based on the preset message fragment length and number K; the padding length of the last fragment message is obtained based on the total length of the target message and the length of the first message; and the padding data of the padding length is added after the first message to obtain the target message, wherein the padding data is a random value in the system memory.
[0139] In some embodiments, the message management header includes a data start address pointer and a data length, the data start address pointer is used to point to the starting memory location of the fragment message in the system memory, and the data length is the data length of the fragment message;
[0140] The message sending module is specifically used for:
[0141] If the number of remaining fragments N after the fragmented message has been sent is greater than or equal to M, then the data start address pointers in the M memory spaces are modified to point to the starting memory locations of the M fragmented messages after the fragmented message has been sent, and the data lengths in the M memory spaces are modified to be the data lengths of the M fragmented messages after the fragmented message has been sent;
[0142] If the number of remaining fragmented messages N after the fragmented message has been sent is less than M, the data starting address pointers in the 1st to Nth memory spaces in the M memory spaces are modified to point to the starting memory positions of the N fragmented messages after the fragmented message has been sent, and the data lengths in the 1st to Nth memory spaces are modified to the data lengths of the N fragmented messages after the fragmented message has been sent.
[0143] Corresponding to the embodiment of the second message transmission method described above, see Figure 10 As shown, the present application also provides another embodiment of a message transmission device, which is applied to a network device and includes:
[0144] The first state processing module 1010 is configured to, upon receiving a fragment message sent by a peer network device, determine whether the fragment message includes a fragment management header if the state of the network device is the first state; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and change the state of the network device to the second state;
[0145] The second state processing module 1020 is used to determine whether the fragment message is the last fragment message when the state of the network device is the second state; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
[0146] In some embodiments, the verification data includes at least the first number of fragments and the entire packet length; the first status processing module is used to determine whether the fragment message includes a fragment management header, including: obtaining data at a preset position in the fragment message, and if the obtained data successfully matches a preset fragment header identifier, determining that the fragment message includes a fragment management header;
[0147] The first status processing module is used to parse the verification data from the fragment management header and determine whether the fragment message is the first fragment message based on the verification data, including: determining the second number of fragments based on the entire packet length and the message length of the fragment message, and judging whether the first number of fragments and the second number of fragments are the same; if yes, determining that the fragment message is the first fragment message; if not, determining that the fragment message is not the first fragment message.
[0148] In some embodiments, the fragment management header further includes a padded length of the last fragment message; and before removing the fragment management header from the fragment message, the first status processing module further includes: applying for storage space from a system memory, and storing the padded length carried in the fragment management header in the storage space;
[0149] When used to remove the supplementary data from the fragment message, the first status processing module includes: obtaining the padded length of the last fragment message from the storage space, and removing the supplementary data of the padded length from the back of the fragment message.
[0150] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0151] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0152] The embodiment of the present application also provides an electronic device, the structural diagram of the electronic device is as follows Figure 11 As shown, the electronic device 1100 includes at least one processor 1101, a memory 1102 and a bus 1103, and the at least one processor 1101 is electrically connected to the memory 1102; the memory 1102 is configured to store at least one computer-executable instruction, and the processor 1101 is configured to execute the at least one computer-executable instruction, thereby performing the steps of any message transmission method provided in any embodiment or any optional implementation method in the present application.
[0153] Furthermore, the processor 1101 may be a Field-Programmable Gate Array (FPGA) or other devices with logic processing capabilities, such as a Microcontroller Unit (MCU) or a Central Processing Unit (CPU).
[0154] An embodiment of the present application also provides another readable storage medium storing a computer program, which is used to implement the steps of any message transmission method provided in any embodiment or any optional implementation method of the present application when executed by a processor.
[0155] The readable storage media provided in the embodiments of the present application include, but are not limited to, any type of disk (including floppy disks, hard disks, optical disks, CD-ROMs, and magneto-optical disks), ROM (Read-Only Memory), RAM (Random Access Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory, magnetic cards, or optical cards. In other words, readable storage media include any medium that can store or transmit information in a readable form by a device (e.g., a computer).
[0156] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential sequence to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.
[0157] Although this specification contains many specific implementation details, these should not be construed as limiting the scope of any invention or the scope of what is claimed, but rather are intended primarily to describe features of specific embodiments of particular inventions. Certain features described in this specification in the context of multiple embodiments may also be implemented in combination in a single embodiment. On the other hand, various features described in the context of a single embodiment may also be implemented separately in multiple embodiments or in any suitable subcombination.
[0158] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A message transmission method, characterized in that: Applied to a network device, the method includes: Obtain a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer; Allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer and not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message; Obtaining the starting memory location and data length in each message management header in sequence, and sending the fragmented message corresponding to each message management header in sequence based on the starting memory location and data length; After the M fragmented messages are sent, it is determined whether the last fragmented message of the target message has been sent. If not, the message management header corresponding to the fragmented message after the fragmented message has been sent is stored in the memory space, and the operation of obtaining the starting memory position and data length in each message management header in turn is returned to execute until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
2. The method according to claim 1, characterized in that The acquiring of the target message comprises: Add a fragment management header before the obtained message to be fragmented, and obtain the message after the newly added fragment management header as the first message; The target message is generated based on the first message, wherein the first fragment message of the target message includes the fragment management header, and the fragment management header is used to enable the opposite network device to identify that the current fragment message is the first fragment message of the target message based on the fragment management header.
3. The method according to claim 2, characterized in that The generating the target message based on the first message includes: Determine the total length of the target message based on the preset message fragment length and number K; Obtaining a padded length of the last fragment message based on the total length of the target message and the length of the first message; Padding data of the padding length is added after the first message to obtain the target message, wherein the padding data is a random value in the system memory.
4. The method according to claim 1, wherein The message management header includes a data starting address pointer and a data length, the data starting address pointer is used to point to the starting memory location of the fragment message in the system memory, and the data length is the data length of the fragment message; The storing, in the memory space, a message management header corresponding to the fragmented message after the fragmented message has been sent, includes: If the number of remaining fragments N after the fragmented message has been sent is greater than or equal to M, then the data start address pointers in the M memory spaces are modified to point to the starting memory locations of the M fragmented messages after the fragmented message has been sent, and the data lengths in the M memory spaces are modified to be the data lengths of the M fragmented messages after the fragmented message has been sent; If the number of remaining fragmented messages N after the fragmented message has been sent is less than M, the data starting address pointers in the 1st to Nth memory spaces in the M memory spaces are modified to point to the starting memory positions of the N fragmented messages after the fragmented message has been sent, and the data lengths in the 1st to Nth memory spaces are modified to the data lengths of the N fragmented messages after the fragmented message has been sent.
5. A message transmission method, characterized in that: Applied to a network device, the method includes: Upon receiving a fragment message sent by a peer network device, if the state of the network device is a first state, determining whether the fragment message includes a fragment management header, and if so, parsing verification data from the fragment management header, and if it is determined based on the verification data that the fragment message is the first fragment message, applying for new memory space in the system memory of the network device, removing the fragment management header from the fragment message, storing the fragment message after the fragment management header is removed in the new memory space, and changing the state of the network device to a second state; If the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
6. The method according to claim 5, characterized in that The determining whether the fragment message includes a fragment management header includes: Acquire data at a preset position in the fragment message, and if the acquired data successfully matches a preset fragment header identifier, determine that the fragment message includes a fragment management header; The verification data includes at least the number of first fragments and the length of the entire packet; and the parsing of the verification data from the fragment management header and determining whether the fragment message is the first fragment message based on the verification data includes: Determining a second number of fragments based on the entire packet length and the message length of the fragmented message, and determining whether the first number of fragments is the same as the second number of fragments; If yes, it is determined that the fragment message is the first fragment message; if no, it is determined that the fragment message is not the first fragment message.
7. The method according to claim 5, characterized in that The fragment management header also includes the padded length of the last fragment message; before removing the fragment management header from the fragment message, the method further includes: applying for storage space from the system memory and storing the padded length carried in the fragment management header in the storage space; The removing of the supplementary data from the fragment message includes: The padded length of the last fragment message is obtained from the storage space, and the supplementary data of the padded length is removed from the back of the fragment message.
8. A message transmission system, characterized in that: The system includes a first network device and a second network device; The first network device is used to obtain a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer; Allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message in the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer and not greater than K; wherein the message management header includes at least a starting memory location and a data length of the fragment message; The first network device is configured to sequentially obtain a starting memory location and a data length in each message management header, and sequentially send a fragment message corresponding to each message management header based on the starting memory location and the data length; after the M fragment messages are sent, determine whether the last fragment message of the target message has been sent; if not, store the message management header corresponding to the fragment message after the fragment message has been sent in the memory space, and return to sequentially execute the operation of obtaining the starting memory location and the data length in each message management header until the last fragment message of the K fragment messages is sent, so that the opposite network device receives the K fragment messages; The second network device is configured to, upon receiving a fragment message sent by the opposite network device, determine, if the state of the network device is the first state, whether the fragment message includes a fragment management header; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and change the state of the network device to the second state; If the state of the network device is the second state, determine whether the fragment message is the last fragment message; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
9. A message transmission device, characterized in that: Applied to network equipment, the device includes: A message acquisition module, configured to acquire a target message and store the target message in a system memory of the network device, wherein the target message includes K fragment messages, each fragment message has the same length, and K is a positive integer; A management header allocation module is configured to allocate M memory spaces in the stack memory, and store M message management headers corresponding to the first M fragment messages of the target message through the M memory spaces, each message management header corresponding to one fragment message, where M is a positive integer and not greater than K; wherein the message management header includes at least the starting memory location and data length of the fragment message; A message sending module is used to sequentially obtain the starting memory position and data length in each message management header, and sequentially send the fragmented message corresponding to each message management header based on the starting memory position and data length; after the M fragmented messages are sent, it is determined whether the last fragmented message of the target message has been sent. If not, the message management header corresponding to the fragmented message after the fragmented message has been sent is stored in the memory space, and the operation of sequentially obtaining the starting memory position and data length in each message management header is returned to execute until the last fragmented message of the K fragmented messages is sent, so that the opposite network device receives the K fragmented messages.
10. The device according to claim 9, characterized in that The message acquisition module includes: A fragment management header adding module is used to add a fragment management header before the obtained message to be fragmented, and obtain the message after the newly added fragment management header as the first message; a target message generation module, configured to generate the target message based on the first message, wherein the first fragment message of the target message includes the fragment management header, and the fragment management header is configured to enable the opposite network device to identify that the current fragment message is the first fragment message of the target message based on the fragment management header; or The target message generation module is specifically used for: Determining the total length of the target message based on a preset message fragment length and number K; obtaining a padding length of the last fragment message based on the total length of the target message and the length of the first message; adding padding data of the padding length after the first message to obtain the target message, wherein the padding data is a random value in the system memory; or, The message management header includes a data starting address pointer and a data length, the data starting address pointer is used to point to the starting memory location of the fragment message in the system memory, and the data length is the data length of the fragment message; The message sending module is specifically used for: If the number of remaining fragments N after the fragmented message has been sent is greater than or equal to M, then the data start address pointers in the M memory spaces are modified to point to the starting memory locations of the M fragmented messages after the fragmented message has been sent, and the data lengths in the M memory spaces are modified to be the data lengths of the M fragmented messages after the fragmented message has been sent; If the number of remaining fragmented messages N after the fragmented message has been sent is less than M, the data starting address pointers in the 1st to Nth memory spaces in the M memory spaces are modified to point to the starting memory positions of the N fragmented messages after the fragmented message has been sent, and the data lengths in the 1st to Nth memory spaces are modified to the data lengths of the N fragmented messages after the fragmented message has been sent.
11. A message transmission device, characterized in that: Applied to network equipment, the device includes: a first state processing module, configured to, upon receiving a fragment message sent by a peer network device, determine, if the state of the network device is the first state, whether the fragment message includes a fragment management header; if so, parse verification data from the fragment management header; if it is determined based on the verification data that the fragment message is the first fragment message, apply for new memory space in the system memory of the network device, remove the fragment management header from the fragment message, store the fragment message after the fragment management header is removed in the new memory space, and modify the state of the network device to the second state; The second state processing module is used to determine whether the fragment message is the last fragment message if the state of the network device is the second state; if not, store the fragment message behind the previous fragment message in the current memory space; if yes, remove the supplementary data from the fragment message, and store the fragment message after removing the supplementary data behind the previous fragment message in the current memory space, and modify the state of the network device to the first state.
12. The device according to claim 11, characterized in that The first status processing module is used to determine whether the fragment message includes a fragment management header, including: obtaining data at a preset position in the fragment message, and if the obtained data successfully matches a preset fragment header identifier, determining that the fragment message includes a fragment management header; The verification data includes at least a first number of fragments and a whole packet length; the first state processing module is used to parse the verification data from the fragment management header, and determine whether the fragment message is the first fragment message based on the verification data, including: determining a second number of fragments based on the whole packet length and the message length of the fragment message, and judging whether the first number of fragments and the second number of fragments are the same; if yes, determining that the fragment message is the first fragment message; if not, determining that the fragment message is not the first fragment message; or, The fragment management header also includes the padded length of the last fragment message; before the first status processing module is used to remove the fragment management header from the fragment message, it also includes: applying for storage space from the system memory and storing the padded length carried in the fragment management header in the storage space; When used to remove the supplementary data from the fragment message, the first status processing module includes: obtaining the padded length of the last fragment message from the storage space, and removing the supplementary data of the padded length from the back of the fragment message.
13. An electronic device, characterized in that: include: Memory, processor; The memory is used to store computer programs; The processor is used to call the computer program to implement the message transmission method as described in any one of claims 1-4 and / or 5-7.
14. A readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the message transmission method as described in any one of claims 1-4 and / or 5-7 is implemented.
Citation Information
Patent Citations
A data message processing method and device
CN109726144A
Fragment sending method, fragment receiving method and corresponding device
CN113595940A