WO2015058490A1 - Method and apparatus for forwarding packet - Google Patents

Method and apparatus for forwarding packet Download PDF

Info

Publication number
WO2015058490A1
WO2015058490A1 PCT/CN2014/074126 CN2014074126W WO2015058490A1 WO 2015058490 A1 WO2015058490 A1 WO 2015058490A1 CN 2014074126 W CN2014074126 W CN 2014074126W WO 2015058490 A1 WO2015058490 A1 WO 2015058490A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
packet
total length
length
message body
Prior art date
Application number
PCT/CN2014/074126
Other languages
French (fr)
Chinese (zh)
Inventor
姜恩龙
吴建芳
翟春莹
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2015058490A1 publication Critical patent/WO2015058490A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass

Definitions

  • the present invention relates to the field of Internet technologies, and in particular, to a packet forwarding method and apparatus. Background technique
  • a method for removing a packet that does not need to be parsed in a packet flow is as follows: The transport layer transmits all the packets in the packet flow to the application layer, and when the application layer receives the packet that does not need to be parsed, According to the state of the internal record of the packet, the packet skipping action is performed, the packet is forwarded to the network, and then the next packet is parsed.
  • the application layer needs to judge and analyze each packet in the packet flow, which not only reduces the parsing efficiency of the application layer, but also reduces the efficiency of packet forwarding.
  • the embodiment of the invention provides a method and a device for forwarding a packet, which can not only improve the efficiency of forwarding packets, but also reduce the burden of parsing packets by the application layer.
  • a first aspect of the embodiments of the present invention discloses a packet forwarding method, and the method includes: receiving a packet sent by a network layer, determining whether the packet is a first packet of a packet flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer; when the packet is not the first packet of the packet, the packet is determined to be the first packet of the packet in the packet flow; When the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; when the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer.
  • the determining, by the packet, whether the packet is the first packet of the message in the packet flow includes:
  • the packet when the packet is the first packet of the message in the packet flow, after forwarding the packet to the application layer, also includes:
  • the method further includes:
  • the third message body When the sum of the total length and the length of the first message body is less than or equal to the total length of the second message body, the method further includes:
  • the stored total length of the third message body is updated to be the sum of the total length of the third message body and the length of the first message body.
  • the obtaining the length of the first message body carried by the packet includes:
  • the length of the network layer header of the packet is subtracted from the total length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
  • the sixth implementation manner in the first aspect includes:
  • the length of the first message body carried by the packet is obtained by subtracting the length of the transport layer header of the packet by using the total length of the packet.
  • the determining whether the packet is the first packet of the packet flow includes:
  • Determining whether the quintuple of the packet has been stored If the quintuple of the packet is not stored, the packet is the first packet of the packet stream.
  • the method when the packet is the first packet of the packet flow, the method further includes:
  • the quintuple of the message is stored.
  • a second aspect of the embodiments of the present invention discloses a packet forwarding apparatus, where the apparatus includes: a receiving unit, configured to receive a packet sent by a network layer; and a determining unit, configured to determine, by the receiving unit, a packet received by the receiving unit Whether the text is the first packet of the packet flow; when determining that the packet is not the first packet of the packet flow, determining whether the packet is the first packet of the message in the packet flow; and the forwarding unit is determined by the determining unit When the packet is the first packet of the packet, the packet is forwarded to the application layer; when the determining unit determines that the packet is the first packet of the message in the packet, the packet is forwarded to the application layer. And when the determining unit determines that the packet is not the first packet of the message in the packet flow, forwarding the packet to the network layer.
  • the method further includes an acquiring unit, where the acquiring unit is configured to obtain a length of the first message body carried by the packet, and obtain the stored message of the packet The total length of the second message body; obtaining the total length of the third message body of the transmitted portion of the message to which the message belongs;
  • the determining unit is specifically configured to:
  • the packet is a packet when the sum of the length of the first message body acquired by the acquiring unit and the total length of the third message body acquired by the acquiring unit is greater than the total length of the second message body acquired by the acquiring unit
  • the first packet of the message in the stream
  • the computing unit and the first updating unit are further included.
  • the determining unit determines that the packet is the first packet of the message in the packet flow, after the forwarding unit forwards the packet to the application layer,
  • the receiving unit is further configured to receive a length of a message header in the packet sent by the application layer, where the calculating unit is configured to use the total length of the first message body acquired by the acquiring unit, and the obtained by the acquiring unit a third message body length, further subtracting a total length of the second message body obtained by the acquiring unit, and subtracting a length of the message header in the message received by the receiving unit to obtain a total length of the fifth message body;
  • An update unit is configured to update the total length of the third message body to the total length of the fifth message body calculated by the calculation unit.
  • the second update unit is further included, and the total length of the sixth message body sent by the layer
  • the total length of the sixth message body indicates the total length of the message body of the message to which the message belongs;
  • the second update unit is configured to update the total length of the second message body to a total length of the sixth message body received by the receiving unit.
  • a fourth implementation manner of the second aspect When the determining unit determines that the sum of the length of the first message body acquired by the acquiring unit and the total length of the third message body acquired by the acquiring unit is less than or equal to the total length of the second message body acquired by the acquiring unit,
  • the third update unit is configured to update the total length of the third message body to a sum of a total length of the third message body and a length of the first message body.
  • the fifth implementation in the second aspect In combination with the first implementation of the second aspect or the second implementation of the second aspect or the third implementation of the second aspect or the fourth implementation of the second aspect, the fifth implementation in the second aspect In the way,
  • the receiving unit is further configured to receive a total length of the packet sent by the network layer and a network layer header length of the packet;
  • the obtaining unit is further configured to: acquire a transport layer header length of the packet; receive by using a receiving unit The length is the length of the first message body carried by the packet.
  • the obtaining unit is further configured to:
  • the determining, by the determining unit, whether the packet is the first packet of the packet flow includes: if not, the packet is a packet flow First package.
  • the method further includes: when the packet is the first packet of the packet flow,
  • the storage unit stores the quintuple of the message.
  • each packet in the packet flow is the first packet of the message in the packet flow. If it is the first packet of the message, it is submitted to the application layer for parsing; if it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, there will be a large number of packets that do not need to be parsed. Direct forwarding to the network not only improves the efficiency of forwarding packets, but also reduces the burden on the application layer to parse packets.
  • FIG. 1 is a flowchart of a method for accelerating application layer parsing according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a method for accelerating application layer parsing according to another embodiment of the present invention
  • FIG. 3 is a flowchart of a method for accelerating application layer parsing according to another embodiment of the present invention
  • FIG. A device structure diagram for accelerating application layer analysis
  • FIG. 5 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention
  • FIG. 6 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention.
  • FIG. 7 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention.
  • FIG. 8 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention.
  • FIG. 9 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention.
  • FIG. 1 describes that each packet in a packet stream is determined to be forwarded to an application layer or forwarded to a network. Specifically include:
  • the quintuple of the message includes an IP (Internet Protocol) address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • IP Internet Protocol
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the first packet When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
  • the quintuple of the packet needs to be stored.
  • it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
  • the packet When the packet is not the first packet of the packet flow, determine whether the packet is the first packet of the message in the packet flow. When the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
  • the specific method for determining whether the packet is the first packet of the packet in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message body of the message
  • the total length, the message is a message that has transmitted part of the content to the application layer; the total length of the third message body of the stored part of the message to which the message belongs is obtained; the total length of the third message body and the When the sum of the lengths of the first message body is greater than the total length of the second message body, determining that the message is the first packet of the message in the packet flow; and the sum of the total length of the third message body and the length of the first message body is less than or When it is equal to the total length of the second message body, it is determined that the message is not the first packet of the message in the message stream.
  • Get the length of the first message body carried by the packet The total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet. The length of the header, and then the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
  • Get the length of the first message body carried by the packet The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
  • one message may contain the content of one message, which may contain the contents of two messages.
  • the total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer.
  • the total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
  • the message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
  • the packet When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs.
  • Analysis In order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the packet is forwarded to the network layer.
  • the packet When the packet is not the first packet of the packet in the packet flow, the packet does not include the header of the message to which the packet belongs, so the packet does not need to be parsed, and the packet can be forwarded to the network layer. Improve forwarding efficiency and reduce the analytical burden of the application layer.
  • the packet forwarding method can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • FIG. 1 Another method for packet forwarding according to an embodiment of the present invention is described in FIG. 1
  • the quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the first packet When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
  • the quintuple of the packet needs to be stored.
  • it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
  • the specific method for determining whether the packet is the first packet of the message in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message of the message
  • the total length of the third message body of the transmitted portion of the message to which the message belongs is obtained; when the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body, The packet is the first packet of the message in the packet flow.
  • the packet is not in the packet stream.
  • the first package of the message is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message of the message.
  • Get the length of the first message body carried by the packet The total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet. The length of the transport layer header of the packet is further subtracted from the length of the header to obtain the length of the first message body carried by the packet.
  • Get the length of the first message body carried by the packet The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
  • one message may contain the content of one message, which may contain the contents of two messages.
  • the total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer.
  • the total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
  • the message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
  • the packet When the packet is not the first packet of the message in the packet flow, the packet does not contain the first row and the header field of the message, so it does not need to be parsed and can be directly forwarded to the network layer. 205.
  • the packet When the packet is the first packet of the message in the packet flow, forward the packet to the application layer, and switch to 206.
  • the packet When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs. Parsing, in order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the quintuple of the packet needs to be stored to provide a basis for determining whether the subsequent packet is the first packet of the packet.
  • Receive a length of a message header in the packet sent by the application layer add a length of the first message body, a total length of the third message body, a total length of the second message body, and subtract the message in the packet.
  • the length of the header gets the total length of the fifth message body.
  • the length of the first message body plus the total length of the third message body minus the total length of the second message body is obtained by using the message length of other messages carried by the message, and then the length of the message header of the other message is obtained.
  • the total length of the fifth message body carried by the message is obtained.
  • the message contains the contents of other messages, indicating that one message ends, another message begins.
  • the packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
  • the 208 Receive a total length of the sixth message body sent by the application layer, and update the total length of the second message body by using the total length of the sixth message body.
  • the total length of the sixth message body indicates the total message body of the message to which the message belongs. length.
  • the total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the message includes the content of two messages, and is obtained by parsing the message content length field included in the message. Is the content of one of the messages. Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that the next time the total length of the second message body is obtained, Is the total length of the second message body that has been updated.
  • the packet forwarding method can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it will be forwarded directly to the network, because the first packet is less, the non-first packet There are many texts. The large number of packets that do not need to be parsed can be directly forwarded to the network. This improves the efficiency of forwarding packets and reduces the burden of parsing packets at the application layer.
  • FIG. 3 illustrates another method for packet forwarding according to an embodiment of the present invention.
  • the quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the first packet When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
  • the quintuple of the packet needs to be stored.
  • it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
  • the specific method for determining whether the packet is the first packet of the message in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message of the message
  • the total length of the third message body of the transmitted portion of the message to which the message belongs is obtained; when the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body, The packet is the first packet of the message in the packet flow.
  • the packet is not in the packet stream.
  • the first package of the message Get the length of the first message body carried by the packet.
  • the total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet.
  • the length of the transport layer header of the packet is further subtracted from the length of the header to obtain the length of the first message body carried by the packet.
  • Get the length of the first message body carried by the packet The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
  • one message may contain the content of one message, which may contain the contents of two messages.
  • the total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer.
  • the total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
  • the message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
  • the packet When the packet is not the first packet of the message in the packet flow, forward the packet to the network layer, and go to 309.
  • the packet When the packet is not the first packet of the message in the packet flow, the packet does not contain the first row and the header field of the message, so it does not need to be parsed and can be directly forwarded to the network layer.
  • the packet When the packet is the first packet of the message in the packet flow, forward the packet to the application layer and transfer the packet to 306.
  • the packet When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs. Parsing, in order to obtain the required information, common information such as user distribution, hot application and business usage.
  • the quintuple of the packet needs to be stored to provide a basis for determining whether the subsequent packet is the first packet of the packet.
  • Receive a length of a message header in the packet sent by the application layer add a length of the first message body, a total length of the third message body, a total length of the second message body, and subtract the message in the packet. Head length The total length of the fifth message body is obtained.
  • the length of the first message body plus the total length of the third message body minus the total length of the second message body is obtained by using the message length of other messages carried by the message, and then the length of the message header of the other message is obtained.
  • the total length of the fifth message body carried by the message is obtained.
  • the message contains the contents of other messages, indicating that one message ends, another message begins.
  • the packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
  • the total length of the sixth message body indicates the total message body of the message to which the message belongs. length.
  • the total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the message includes the content of two messages, and is obtained by parsing the message content length field included in the message. Is the content of one of the messages. Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that the next time the total length of the second message body is obtained, Is the total length of the second message body that has been updated.
  • the total length of the stored third message body needs to be updated. Adding a message body length carried by the message to the stored total length of the message body of the message to which the message belongs, and updating the stored message stream with the added sum to transmit the partial content to the application layer
  • the total length of the message body of the message to which the message belongs is used to provide a judgment basis for subsequent messages of the message to which the message belongs.
  • each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, the application layer is submitted. If the first packet of the message is not forwarded, it will be directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, a large number of packets that do not need to be parsed are directly forwarded to the network. The efficiency of the text can also reduce the burden on the application layer to parse the message.
  • a device 40 for packet forwarding according to an embodiment of the present invention is described below with reference to FIG. As shown in FIG. 4, the device 40 includes:
  • the receiving unit 401 the determining unit 402, and the forwarding unit 403.
  • the receiving unit 401 is configured to receive a packet sent by the network layer.
  • the receiving unit 401 is configured to receive a packet sent by the network layer.
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the determining unit 402 is configured to determine whether the packet received by the receiving unit 401 is the first packet of the packet flow; when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow. First package.
  • the determining unit 402 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream.
  • the quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
  • the determining unit 402 further determines the packet, so as to determine whether the packet is the first packet of the message in the packet flow, the method is: obtaining the length of the first message body carried by the packet; and acquiring the stored message The total length of the second message body; the total length of the third message body of the transmitted part of the message to which the message belongs is obtained; the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body The length of the message is determined to be the first packet of the message in the packet flow. When the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body, the message is determined. Not the first packet of the message in the message stream.
  • the message header of the message may include a first line and a header field, and may also include a first line, and may also include a header field.
  • the packet When the determining unit 403 determines that the packet is not the first packet of the message in the packet stream, the packet does not include the packet.
  • the message header of the message belongs to the message. Therefore, the packet does not need to be parsed, and the forwarding unit 403 forwards the packet to the network layer, thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
  • the device for forwarding a packet can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • device 50 includes:
  • the receiving unit 501 is configured to receive a packet sent by the network layer.
  • the determining unit 502 is configured to determine whether the packet received by the receiving unit 501 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 501 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 501 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 501 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the determining unit 502 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream.
  • the quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
  • the obtaining unit 504 when the determining unit 502 determines whether the packet is the first packet of the message in the packet flow, obtains the length of the first message body carried by the packet; and obtains the total length of the second message body of the stored message; The stored total length of the transmitted portion of the message to which the message belongs to the third message body of the application layer.
  • the obtaining unit 504 obtains the first message body length carried by the packet.
  • the receiving unit 501 is further configured to receive the total length of the packet sent by the network layer and the network layer header length of the packet.
  • the obtaining unit 504 obtains the transport layer header length of the packet, and receives the length of the transport layer header by using the receiving unit 501.
  • the total length of the packet is subtracted from the network layer header length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the packet carrying the packet.
  • the length of a message body is derived from the network layer header length of the packet.
  • the obtaining unit 504 obtains the length of the first message body carried by the packet.
  • the total length of the packet that has been sent to the transport layer and the length of the packet transport layer header are obtained, and the total length of the packet is subtracted from the total length of the transport layer header of the packet to obtain the first packet carrying the packet.
  • the length of the message body is obtained.
  • one message may contain the content of one message, and may also contain the contents of two messages.
  • the obtaining unit 504 obtains the total length of the second message body of the stored message.
  • the total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
  • the obtaining unit 504 acquires the total length of the third message body of the message to which the stored message stream has been transmitted.
  • the message content of the message has been transmitted to the application layer.
  • the length of the content of the message is the total length of the third message body, because a message needs to be divided into several messages for transmission. Before the message, other messages belonging to the message have already transmitted a part of the message content to the application layer.
  • the determining unit 502 determines whether the packet is the first packet of the message in the packet flow, and the determining unit 502 determines whether the sum of the first message body length acquired by the obtaining unit 504 and the total length of the third message body acquired by the obtaining unit 504 is greater than The total length of the second message body obtained by the obtaining unit 504.
  • the determining unit 502 determines that the sum of the first message body length acquired by the obtaining unit 504 and the total length of the third message body acquired by the obtaining unit 503 is greater than the total length of the second message body acquired by the obtaining unit 504, and determines that the message is 4 The first packet of the message in the essay stream.
  • the forwarding unit 505 when the determining unit 502 determines that the packet is the first packet of the packet flow, forwards the packet to the application layer; when the determining unit 502 determines that the packet is the first packet of the message in the packet flow, the application unit The process forwards the message, and when the determining unit 502 determines that the message is not the first packet of the message in the packet flow, the packet is forwarded to the network.
  • the forwarding unit 505 forwards the packet to the application layer because the first packet contains the message header of the message to which the packet belongs.
  • the application layer parses the message header of the message to obtain the required information, such as the distribution of the household, the hotspot application, and the usage of the service.
  • the message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
  • the determining unit 502 determines that the message is not the first packet of the message in the packet flow, the message does not contain the message.
  • the message header is not required to be parsed, and the forwarding unit 505 forwards the packet to the network layer, thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
  • the accepting unit 501 is further configured to receive a length of a message header in the message sent by the application layer.
  • the calculating unit 506 is configured to use the total length of the first message body acquired by the obtaining unit 504, and the length of the third message body acquired by the acquiring unit, and subtract the total length of the second message body acquired by the acquiring unit, and subtract the receiving
  • the length of the message header in the message received by the unit 501 is the total length of the fifth message body.
  • the calculation unit 506 obtains, by using the total length of the first message body, the length of the third message body, and the total length of the second message body, the message length of other messages carried by the message, and then uses the message to carry the message.
  • the length of the message of the other message minus the length of the message header in the message received by the receiving unit 501 is obtained to obtain the total length of the fifth message body.
  • the first updating unit 507 updates the total length of the third message body to the calculating unit 506 to calculate the fifth message body length.
  • the message contains the contents of other messages, indicating that one message ends, another message begins.
  • the packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
  • the receiving unit 501 is further configured to receive a sixth message body length, where the total length of the sixth message body indicates a total length of the message body of the message to which the message belongs, and the message refers to a message that has not been completely transmitted to the application layer.
  • the forwarding unit 505 forwards the packet to the application layer, and after receiving the packet, the application layer parses the packet. Because the packet contains the contents of two messages, the application layer parses the message carried by the packet to obtain the total length of the sixth message body.
  • the second updating unit 508 updates the total length of the second message body by using the total length of the sixth message body received by the receiving unit 501.
  • Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that when the total length of the second message body is acquired next time, the obtained The total length of the second message body that has been updated.
  • the total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the total length of the sixth message body is the total length of the message body of the message to which the message belongs. Messages that have not been fully transferred to the application layer. Since the message is the first packet of other messages, the total length of the sixth message body is the total length of the other messages.
  • each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit to the application layer. If it is not the first packet of the message, it will be directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, a large number of packets that do not need to be parsed are directly forwarded to the network. The efficiency can also reduce the burden on the application layer to parse the message.
  • device 60 includes:
  • the receiving unit 601 is configured to receive a packet sent by the network layer.
  • the determining unit 602 is configured to determine whether the packet received by the receiving unit 601 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 601 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 601 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the first pack is configured to determine whether the packet received by the receiving unit 601 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow.
  • the determining unit 602 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream.
  • the quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
  • the packet stream includes at least one message, and one message can be carried by at least one message.
  • the first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
  • the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
  • the storage unit 603 stores the quintuple of the packet when the determining unit 602 determines that the packet is the first packet of the packet stream.
  • the obtaining unit 604 when the determining unit 602 determines whether the packet is the first packet of the message in the packet flow, obtains the length of the first message body carried by the packet; and obtains the total length of the second message body of the stored message; The stored total length of the transmitted portion of the message to which the message belongs to the third message body of the application layer.
  • the obtaining unit 604 obtains the length of the first message body carried by the packet.
  • the receiving unit 601 is further configured to receive the total length of the packet sent by the network layer and the network layer header length of the packet.
  • the acquiring unit 604 obtains the transport layer header length of the packet, and receives the length of the transport layer header by using the receiving unit 601. The total length of the packet is subtracted from the network layer header length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
  • the obtaining unit 604 obtains the first message body length carried by the packet.
  • the total length of the packet that has been sent to the transport layer and the length of the packet transport layer header are obtained, and the total length of the packet is subtracted from the total length of the transport layer header of the packet to obtain the first packet carrying the packet.
  • the length of the message body Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, and may also contain the contents of two messages.
  • the obtaining unit 604 obtains the total length of the second message body of the stored message.
  • the total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
  • the obtaining unit 604 acquires the total length of the third message body of the message to which the stored message stream has been transmitted.
  • the message content of the message has been transmitted to the application layer.
  • the length of the content of the message is the total length of the third message body, because a message needs to be divided into several messages for transmission. Before the message, other messages belonging to the message have already transmitted a part of the message content to the application layer.
  • the determining unit 602 determines whether the packet is the first packet of the message in the packet flow, and the determining unit 602 determines whether the sum of the first message body length acquired by the obtaining unit 604 and the total length of the third message body acquired by the obtaining unit 504 is greater than The total length of the second message body obtained by the obtaining unit 504.
  • the determining unit 602 determines that the sum of the first message body length acquired by the obtaining unit 604 and the total length of the third message body acquired by the obtaining unit 603 is greater than the total length of the second message body acquired by the obtaining unit 604, and determines that the message is 4 The first packet of the message in the essay stream.
  • the forwarding unit 605 when the determining unit 602 determines that the packet is the first packet of the packet flow, forwards the packet to the application layer; when the determining unit 602 determines that the packet is the first packet of the message in the packet flow, the application unit The process forwards the message, and when the determining unit 602 determines that the message is not the first packet of the message in the packet flow, the packet is forwarded to the network.
  • the forwarding unit 605 forwards the packet to the application layer because the first packet contains the message header of the message to which the packet belongs.
  • the application layer parses the message header of the message to obtain the required information, such as the distribution of the household, the hotspot application, and the usage of the service.
  • the message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
  • the determining unit 602 determines that the packet is not the first packet of the message in the packet stream, the packet does not include the header of the message, so the packet does not need to be parsed, and the forwarding unit 605 forwards the packet to the network layer. , thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
  • the third update unit 606 when the determining unit 602 determines that the packet is not the first packet of the message in the packet flow, the total length of the third message body is updated to be the total length of the third message body and the length of the first message body. with. Since the content of the message carried by the packet belongs to a message completely, the content carried by the packet belongs to the content of the sent message of the packet, and therefore the total length of the stored third message body needs to be updated.
  • the third update unit 606 adds the message body length carried by the message to the stored total length of the message body of the message to which the message belongs, and updates the stored message stream with the added sum. The total length of the message body of the message to which the message belongs is used to determine whether the subsequent message is the first packet of the packet flow or the first packet of the message in the packet flow.
  • the accepting unit 601 is further configured to receive a length of a message header in the packet sent by the application layer.
  • the calculating unit 607 is configured to use the total length of the first message body acquired by the acquiring unit 604, plus the length of the third message body acquired by the acquiring unit, and subtract the total length of the second message body acquired by the acquiring unit, and subtract the receiving
  • the length of the message header in the message received by the unit 601 is the total length of the fifth message body.
  • the calculation unit 607 obtains, by using the total length of the first message body, the length of the third message body, and the total length of the second message body, the message length of other messages carried by the message, and then uses the message to carry the message.
  • the length of the message of the other message minus the length of the message header in the message received by the receiving unit 601 is the total length of the fifth message body.
  • the first updating unit 608 updates the total length of the third message body to the calculating unit 607 to calculate the fifth message body length.
  • the message contains the contents of other messages, indicating that one message ends, another message begins.
  • the packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
  • the receiving unit 601 is further configured to receive a sixth message body length, where the total length of the sixth message body indicates a total length of the message body of the message to which the message belongs, and the message refers to a message that has not been completely transmitted to the application layer.
  • the forwarding unit 605 forwards the packet to the application layer, and after receiving the packet, the application layer parses the packet. Because the packet contains the contents of two messages, the application layer parses the message carried by the packet to obtain the total length of the sixth message body.
  • the second updating unit 609 updates the total length of the second message body by using the total length of the sixth message body received by the receiving unit 601.
  • Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that when the total length of the second message body is acquired next time, the obtained The total length of the second message body that has been updated.
  • the total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the total length of the sixth message body is the report.
  • the total length of the message body of the message to which the text belongs. This message refers to the message that has not been completely transmitted to the application layer. Since the message is the first packet of other messages, the total length of the sixth message body is the total length of the other messages.
  • the device for forwarding a packet can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • FIG. 7 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 701 (eg, a CPU), a memory 702, at least one network interface 703, and at least one communication bus 704 for implementing these Connection communication between devices.
  • the processor 701 is configured to execute executable modules, such as computer programs, stored in the memory 702.
  • the memory 702 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory such as at least one disk memory.
  • the communication connection between the network device and at least one other network element is implemented by at least one network interface 703 (which may be wired or wireless), and may use an internet, a wide area network, a local area network, a metropolitan area network, or the like.
  • the memory 702 stores a program 7021, and the program 7021 can be executed by the processor 701.
  • the program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet flow, the packet is forwarded to the application layer; when the packet is not the first packet of the packet flow, it is determined whether the packet is the first packet of the message in the packet flow; When the first packet of the message in the packet flow is forwarded, the packet is forwarded to the application layer. When the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer.
  • the specific implementation steps are the same as those in the embodiment shown in FIG. 1, and are not described herein again.
  • the device for forwarding a packet can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • FIG. 8 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 801 (eg, a CPU), a memory 802, at least one network interface 803, and at least one communication bus 804 for implementing these Connection communication between devices.
  • the processor 801 is configured to execute executable modules, such as computer programs, stored in the memory 802.
  • the memory 802 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory (non-volatile memory). Memory ), such as at least one disk storage.
  • the communication connection between the network device and at least one other network element is implemented by at least one network interface 803 (which may be wired or wireless), and may use an Internet, a wide area network, a local area network, a metropolitan area network, or the like.
  • the memory 802 stores a program 8021, and the program 8021 can be executed by the processor 801.
  • the program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer, and the quintuple of the packet is stored. When the packet is not the first packet of the packet, the packet is determined to be a packet flow. The first packet of the message; when the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; the length of the message header in the packet sent by the application layer is received, and the first message body is used.
  • the device for forwarding a packet can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • FIG. 9 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 901 (eg, a CPU), a memory 902, at least one network interface 903, and at least one communication bus 904 for implementing these Connection communication between devices.
  • the processor 901 is operative to execute executable modules, such as computer programs, stored in the memory 902.
  • the memory 902 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory such as at least one disk memory.
  • the communication connection between the network device and at least one other network element is implemented by at least one network interface 903 (which may be wired or wireless), and may use an internet, a wide area network, a local area network, a metropolitan area network, or the like.
  • the memory 902 stores a program 9021, and the program 9021 can be executed by the processor 901.
  • the program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer, and the quintuple of the packet is stored. When the packet is not the first packet of the packet, the packet is determined to be a packet flow.
  • the first package of the message When the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer, and the total length of the third message body is updated to be the sum of the total length of the third message body and the length of the first message body; When the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; the length of the message header in the packet sent by the application layer is received, and the total length of the first message body is added to the length of the third message body.
  • the total length of the sixth message body indicates the total length of the message body of the message to which the message belongs.
  • the device for forwarding a packet can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM: Read Random Memory), or a random access memory (RAM).
  • ROM Read Random Memory
  • RAM random access memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The present invention relates to the technical field of the Internet, and provided are a method and apparatus for forwarding a packet. The method comprises: receiving a packet sent by the network layer, and judging whether the packet is the first package of a packet flow; when the packet is the first package of the packet flow, forwarding the packet to the application layer; when the packet is not the first package of the packet flow, judging whether the packet is the first package of a message in the packet flow; when the packet is the first package of the message in the packet flow, forwarding the packet to the application layer; and when the packet is not the first package of the message in the packet flow, forwarding the packet to the network layer. By means of the present invention, whether each packet in a packet flow is the first package of a message in the packet flow can be judged, and if yes, it is submitted to the application layer for resolution; and if not, each packet is forwarded to a network directly. Forwarding a large number of packets that are not required to be resolved to a network can not only improve the efficiency of forwarding a packet, but also can reduce the burden of the application layer resolving the packet.

Description

一种报文转发的方法 ¾1¾置 技术领域  A method for message forwarding 3⁄41⁄4 setting
本发明涉及互联网技术领域, 具体涉及一种报文转发的方法及装置。 背景技术  The present invention relates to the field of Internet technologies, and in particular, to a packet forwarding method and apparatus. Background technique
随着互联网的不断发展, 网络流量的精细化管理得到越来越多的应用, 常 见的有报文识别、 流量控制、 数据统计等。 当运行商想要了解业务的使用情况、 热点应用情况以及用户分布情况等信息以便展开针对性的增值服务时, 就需要 对报文进行数据解析, 从而获得分组网络中的详细数据。 但是目前情况下, 在 做数据解析时, 通常是应用层对包含有首行和头域的报文进行解析, 但是应用 层在处理报文的过程中, 会遇到很多不包含首行和头域的报文, 从而降低应用 层解析报文和转发报文的效率。  With the continuous development of the Internet, the fine management of network traffic has been increasingly applied. Message recognition, flow control, and data statistics are common. When the operator wants to know the usage of the service, the application of the hotspot, and the distribution of the user, in order to expand the targeted value-added services, the data needs to be parsed to obtain detailed data in the packet network. However, in the current situation, when doing data parsing, the application layer usually parses the packet containing the first row and the header field. However, in the process of processing the packet, the application layer encounters many without including the first row and the header. The packets of the domain are used to reduce the efficiency of the application layer to parse packets and forward packets.
面对这一问题, 剔除报文流中不需要解析的报文显得尤为重要。 现有技术 中剔除报文流中不需要解析的报文的一种方法具体为: 传输层将报文流中的报 文全部传输到应用层, 当应用层收到不需要解析的报文时, 根据报文内部记录 的状态, 执行跳包动作, 将该报文转发到网络, 然后进行下一个报文的解析。  Faced with this problem, it is especially important to eliminate packets that do not need to be parsed in the message stream. In the prior art, a method for removing a packet that does not need to be parsed in a packet flow is as follows: The transport layer transmits all the packets in the packet flow to the application layer, and when the application layer receives the packet that does not need to be parsed, According to the state of the internal record of the packet, the packet skipping action is performed, the packet is forwarded to the network, and then the next packet is parsed.
从上面方案可以看出: 由于应用层需要对报文流中每个报文进行判断和分 析, 不仅降低了应用层的解析效率, 还降低了报文转发的效率。 发明内容  As shown in the above solution, the application layer needs to judge and analyze each packet in the packet flow, which not only reduces the parsing efficiency of the application layer, but also reduces the efficiency of packet forwarding. Summary of the invention
本发明实施例提供了一种报文转发的方法及装置, 不仅可以提高转发报文 的效率, 还可以减轻应用层解析报文的负担。  The embodiment of the invention provides a method and a device for forwarding a packet, which can not only improve the efficiency of forwarding packets, but also reduce the burden of parsing packets by the application layer.
本发明实施例的第一方面公开了报文转发的方法和装置, 所述方法包括: 接收网络层发送的报文, 判断所述报文是否为报文流的首包; 在所述报文 是报文流的首包时, 向应用层转发所述报文; 在所述报文不是报文流的首包时, 判断所述报文是否为报文流中消息的首包; 在所述报文是报文流中消息的首包 时, 向应用层转发所述报文; 在所述报文不是报文流中消息的首包时, 向网络 层转发所述报文。  A first aspect of the embodiments of the present invention discloses a packet forwarding method, and the method includes: receiving a packet sent by a network layer, determining whether the packet is a first packet of a packet flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer; when the packet is not the first packet of the packet, the packet is determined to be the first packet of the packet in the packet flow; When the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; when the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer.
结合第一方面, 在第一方面的第一种实现方式中, 所述判断所述报文是否 为报文流中消息的首包包括:  With reference to the first aspect, in a first implementation manner of the first aspect, the determining, by the packet, whether the packet is the first packet of the message in the packet flow includes:
获取所述报文承载的第一消息体长度; 获取存储的所述报文所属消息的第 二消息体总长度; 获取存储的所述报文所属消息已传输部分的第三消息体总长 度; 在所述第三消息体总长度与所述第一消息体长度之和大于所述第二消息体 总长度时, 确定所述报文为报文流中消息的首包; 在所述第三消息体总长度与 所述第一消息体长度之和小于或等于所述第二消息体总长度时, 确定所述报文 不是 文流中消息的首包。 Obtaining a length of a first message body carried by the packet; acquiring a first message of the stored message The total length of the second message body; the total length of the third message body of the transmitted portion of the message to which the message belongs is obtained; the sum of the total length of the third message body and the length of the first message body is greater than the second Determining, in the total length of the message body, the packet is a first packet of the message in the packet flow; and the sum of the total length of the third message body and the length of the first message body is less than or equal to the total of the second message body When the length is determined, it is determined that the message is not the first packet of the message in the stream.
结合第一方面的第一种实现方式, 在第一方面的第二种实现方式中, 在所 述报文是报文流中消息的首包时, 在向应用层转发所述报文后, 还包括:  With the first implementation of the first aspect, in the second implementation manner of the first aspect, when the packet is the first packet of the message in the packet flow, after forwarding the packet to the application layer, Also includes:
接收应用层发送的所述报文中的消息头的长度, 用所述第一消息体长度加 上所述第三消息体总长度, 再减去所述第二消息体总长度, 再减去所述报文中 消息头的长度得到第五消息体总长度;  Receiving a length of a message header in the packet sent by the application layer, adding a length of the first message body to a total length of the third message body, and subtracting a total length of the second message body, and then subtracting The length of the message header in the packet is the total length of the fifth message body;
将所述第三消息体总长度更新为所述第五消息体总长度。  Updating the total length of the third message body to the total length of the fifth message body.
结合第一方面的第一种实现方式或第一方面的第二种实现方式, 在第一方 面的第三种实现方式中, 所述在向应用层转发所述报文后, 还包括:  With the first implementation of the first aspect or the second implementation of the first aspect, in a third implementation manner of the first aspect, after the forwarding the packet to the application layer, the method further includes:
接收应用层发送的第六消息体总长度, 并用所述第六消息体总长度更新所 述第二消息体总长度, 所述第六消息体总长度表示的是所述报文所属消息的消 息体总长度。  Receiving a total length of the sixth message body sent by the application layer, and updating the total length of the second message body by using the total length of the sixth message body, where the total length of the sixth message body indicates a message of the message to which the message belongs Total length of the body.
结合第一方面的第一种实现方式或第一方面的第二种实现方式或第一方面 的第三种实现方式, 在第一方面的第四种实现方式中, 在所述第三消息体总长 度与所述第一消息体长度之和小于或等于所述第二消息体总长度时, 所述方法 还包括:  With reference to the first implementation manner of the first aspect or the second implementation manner of the first aspect, or the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect, the third message body When the sum of the total length and the length of the first message body is less than or equal to the total length of the second message body, the method further includes:
将存储的第三消息体总长度更新为所述第三消息体总长度与所述第一消息 体长度之和。  The stored total length of the third message body is updated to be the sum of the total length of the third message body and the length of the first message body.
结合第一方面的第一种实现方式或者第一方面第二种实现方式或者第一方 面第三种实现方式或第一方面的第四种实现方式, 在第一方面的第五种实现方 式中, 所述获取所述报文承载的第一消息体长度包括:  In combination with the first implementation of the first aspect or the second implementation of the first aspect or the third implementation of the first aspect or the fourth implementation of the first aspect, in a fifth implementation manner of the first aspect The obtaining the length of the first message body carried by the packet includes:
接收网络层发送的所述报文的总长度和所述报文的网络层头长度; 获取所述报文的传输层头长度;  Receiving a total length of the packet sent by the network layer and a network layer header length of the packet; and acquiring a transport layer header length of the packet;
用所述报文的总长度减去所述报文的网络层头长度, 再减去所述报文的传 输层头长度得到所述报文承载的第一消息体长度。  The length of the network layer header of the packet is subtracted from the total length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
结合第一方面的第一种实现方式或者第一方面第二种实现方式或者第一方 面第三种实现方式或第一方面的第四种实现方式, 在第一方面的第六种实现方 式中, 所述获取所述报文承载的第一消息体长度包括: In combination with the first implementation of the first aspect or the second implementation of the first aspect or the third implementation of the first aspect or the fourth implementation of the first aspect, the sixth implementation manner in the first aspect The obtaining the length of the first message body carried by the packet includes:
获取所述报文的总长度;  Obtaining the total length of the message;
获取所述报文的传输层头长度;  Obtaining a transport layer header length of the packet;
用所述报文的总长度减去减去所述报文的传输层头长度得到所述报文承载 的第一消息体长度。  The length of the first message body carried by the packet is obtained by subtracting the length of the transport layer header of the packet by using the total length of the packet.
结合第一方面或者第一方面的第一种实现方式或者第一方面第二种实现方 式或者第一方面第三种实现方式或第一方面的第四种实现方式或第一方面的第 五种实现方式或第一方面的第六种实现方式, 在第一方面的第七种实现方式中, 所述判断所述报文是否为报文流的首包包括:  The first aspect or the first implementation of the first aspect or the second implementation of the first aspect or the third implementation of the first aspect or the fourth implementation of the first aspect or the fifth implementation of the first aspect The implementation manner or the sixth implementation manner of the first aspect, in the seventh implementation manner of the first aspect, the determining whether the packet is the first packet of the packet flow includes:
判断所述报文的五元组是否已被存储, 若所述报文的五元组没有被存储, 则所述报文为报文流的首包。  Determining whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream.
结合第一方面的第七种实现方式, 在第一方面的第八种实现方式中, 在所 述报文为报文流的首包时, 还包括:  With the seventh implementation of the first aspect, in the eighth implementation manner of the first aspect, when the packet is the first packet of the packet flow, the method further includes:
将所述报文的五元组进行存储。  The quintuple of the message is stored.
本发明实施例的第二方面公开了一种报文转发的装置, 所述装置包括: 接收单元, 用于接收网络层发送的报文; 判断单元, 用于判断所述接收单 元接收到的报文是否为报文流的首包; 在判断所述报文不是报文流的首包时, 判断所述报文是否为报文流中消息的首包; 转发单元, 在所述判断单元判断所 述报文为报文流首包时, 向应用层转发所述报文; 在所述判断单元判断所述报 文为报文流中消息的首包时, 向应用层转发所述报文; 在所述判断单元判断所 述报文不是报文流中消息的首包时, 向网络层转发所述报文。  A second aspect of the embodiments of the present invention discloses a packet forwarding apparatus, where the apparatus includes: a receiving unit, configured to receive a packet sent by a network layer; and a determining unit, configured to determine, by the receiving unit, a packet received by the receiving unit Whether the text is the first packet of the packet flow; when determining that the packet is not the first packet of the packet flow, determining whether the packet is the first packet of the message in the packet flow; and the forwarding unit is determined by the determining unit When the packet is the first packet of the packet, the packet is forwarded to the application layer; when the determining unit determines that the packet is the first packet of the message in the packet, the packet is forwarded to the application layer. And when the determining unit determines that the packet is not the first packet of the message in the packet flow, forwarding the packet to the network layer.
结合第二方面, 在第二方面的第一种实现方式中, 还包括获取单元, 所述获取单元用于获取所述报文承载的第一消息体长度; 获取存储的所述 报文所属消息的第二消息体总长度; 获取存储的所述报文所属消息已传输部分 的第三消息体总长度;  With reference to the second aspect, in a first implementation manner of the second aspect, the method further includes an acquiring unit, where the acquiring unit is configured to obtain a length of the first message body carried by the packet, and obtain the stored message of the packet The total length of the second message body; obtaining the total length of the third message body of the transmitted portion of the message to which the message belongs;
所述判断单元具体用于:  The determining unit is specifically configured to:
在所述获取单元获取的第一消息体长度与所述获取单元获取的第三消息体 总长度之和大于所述获取单元获取的第二消息体总长度时, 确定所述报文是报 文流中消息的首包;  Determining that the packet is a packet when the sum of the length of the first message body acquired by the acquiring unit and the total length of the third message body acquired by the acquiring unit is greater than the total length of the second message body acquired by the acquiring unit The first packet of the message in the stream;
在所述获取单元获取的第一消息体长度与获取单元获取的第三消息体总长 度之和小于或等于获取单元获取的第二消息体总长度时, 确定所述报文不是报 文流中消息的首包。 Determining that the packet is not a report when the sum of the length of the first message body acquired by the acquiring unit and the total length of the third message body acquired by the acquiring unit is less than or equal to the total length of the second message body acquired by the acquiring unit. The first packet of the message in the stream.
结合第二方面的第一种实现方, 在第二方面的第二种实现方式中, 还包括 计算单元和第一更新单元,  With reference to the first implementation of the second aspect, in a second implementation manner of the second aspect, the computing unit and the first updating unit are further included.
在所述判断单元确定所述报文是报文流中消息的首包时, 在所述转发单元 向应用层转发所述报文后,  When the determining unit determines that the packet is the first packet of the message in the packet flow, after the forwarding unit forwards the packet to the application layer,
所述接收单元还用于接收应用层发送的所述报文中的消息头的长度; 所述计算单元用于用所述获取单元获取的第一消息体总长度加上所述获取 单元获取的第三消息体长度, 再减去所述获取单元获取的第二消息体总长度, 再减去所述接收单元接收到的报文中消息头的长度得到第五消息体总长度; 所述第一更新单元用于将所述第三消息体总长度更新为用所述计算单元计 算得到的所述第五消息体总长度。  The receiving unit is further configured to receive a length of a message header in the packet sent by the application layer, where the calculating unit is configured to use the total length of the first message body acquired by the acquiring unit, and the obtained by the acquiring unit a third message body length, further subtracting a total length of the second message body obtained by the acquiring unit, and subtracting a length of the message header in the message received by the receiving unit to obtain a total length of the fifth message body; An update unit is configured to update the total length of the third message body to the total length of the fifth message body calculated by the calculation unit.
结合第二方面的第一种实现方式或第二方面的第二种实现方式, 在第二方 面的第三种实现方式中, 还包括第二更新单元; 用层发送的第六消息体总长度, 所述第六消息体总长度表示的是所述报文所属 消息的消息体总长度;  With reference to the first implementation manner of the second aspect or the second implementation manner of the second aspect, in a third implementation manner of the second aspect, the second update unit is further included, and the total length of the sixth message body sent by the layer The total length of the sixth message body indicates the total length of the message body of the message to which the message belongs;
所述第二更新单元用于将所述第二消息体总长度更新为所述接收单元接收 到的第六消息体总长度。  The second update unit is configured to update the total length of the second message body to a total length of the sixth message body received by the receiving unit.
结合第二方面的第一种实现方式或第二方面的第二中实现方式或第二方面 的第三种实现方式, 在第二方面的第四种实现方式中, 还包括第三更新单元, 在所述判断单元判断获取单元获取的所述第一消息体长度与获取单元获取的所 述的第三消息体总长度之和小于或等于获取单元获取的所述第二消息体总长度 时,  With reference to the first implementation manner of the second aspect, or the second implementation manner of the second aspect, or the third implementation manner of the second aspect, in a fourth implementation manner of the second aspect, When the determining unit determines that the sum of the length of the first message body acquired by the acquiring unit and the total length of the third message body acquired by the acquiring unit is less than or equal to the total length of the second message body acquired by the acquiring unit,
所述第三更新单元用于将所述第三消息体总长度更新为所述第三消息体总 长度与所述第一消息体长度之和。  The third update unit is configured to update the total length of the third message body to a sum of a total length of the third message body and a length of the first message body.
结合第二方面的第一种实现方式或第二方面的第二中实现方式或第二方面 的第三种实现方式或第二方面的第四种实现方式, 在第二方面的第五种实现方 式中,  In combination with the first implementation of the second aspect or the second implementation of the second aspect or the third implementation of the second aspect or the fourth implementation of the second aspect, the fifth implementation in the second aspect In the way,
所述接收单元还用于接收网络层发送的所述报文的总长度和所述报文的网 络层头长度;  The receiving unit is further configured to receive a total length of the packet sent by the network layer and a network layer header length of the packet;
所述获取单元还用于: 获取所述报文的传输层头长度; 用接收单元接收到 长度得到所述报文承载的第一消息体长度。 The obtaining unit is further configured to: acquire a transport layer header length of the packet; receive by using a receiving unit The length is the length of the first message body carried by the packet.
结合第二方面的第一种实现方式或第二方面的第二中实现方式或第二方面 的第三种实现方式或第二方面的第四种实现方式, 在第二方面的第六种实现方 式中, 所述获取单元还用于:  With reference to the first implementation of the second aspect or the second implementation of the second aspect or the third implementation of the second aspect or the fourth implementation of the second aspect, the sixth implementation in the second aspect In the mode, the obtaining unit is further configured to:
获取所述报文的总长度; 获取所述报文的传输层头长度; 用所述报文的总 长度减去减去所述报文的传输层头长度得到所述报文承载的第一消息体长度。  Obtaining a total length of the packet; obtaining a transport layer header length of the packet; and using the total length of the packet minus the length of the transport layer header of the packet to obtain the first packet carrying The length of the message body.
结合第二方面或第二方面的第一种实现方式或第二方面的第二中实现方式 或第二方面的第三种实现方式或第二方面的第四种实现方式或第二方面的第五 种实现方式, 在第二方面的第七种实现方式中, 所述判断单元判断所述报文是 否为报文流的首包包括: 没有被存储, 则所述报文为报文流的首包。  The second aspect or the first implementation of the second aspect or the second implementation of the second aspect or the third implementation of the second aspect or the fourth implementation of the second aspect or the second aspect In a fifth implementation manner, in a seventh implementation manner of the second aspect, the determining, by the determining unit, whether the packet is the first packet of the packet flow, includes: if not, the packet is a packet flow First package.
结合第二方面的第七种实现方式, 在第二方面的第八种实现方式中, 还包 括存储单元, 在所述报文为报文流的首包时,  With reference to the seventh implementation manner of the second aspect, in an eighth implementation manner of the second aspect, the method further includes: when the packet is the first packet of the packet flow,
所述存储单元将所述报文的五元组进行存储。  The storage unit stores the quintuple of the message.
从本发明实施例提供的以上技术方案可以看出, 使用本发明实施例提供的 报文转发的方法及装置, 可以判断报文流中每一个报文是否为报文流中消息的 首包, 若是消息的首包, 则提交应用层进行解析; 若不是消息的首包, 则直接 转发到网络中, 由于首包较少, 非首包的报文较多, 将大量不需要解析的报文 直接转发到网络中不仅可以提高转发报文的效率, 还能够减轻应用层解析报文 的负担。  It can be seen from the foregoing technical solutions provided by the embodiments of the present invention that, by using the packet forwarding method and apparatus provided by the embodiments of the present invention, it can be determined whether each packet in the packet flow is the first packet of the message in the packet flow. If it is the first packet of the message, it is submitted to the application layer for parsing; if it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, there will be a large number of packets that do not need to be parsed. Direct forwarding to the network not only improves the efficiency of forwarding packets, but also reduces the burden on the application layer to parse packets.
附图说明 DRAWINGS
为了更清楚地说明本发明实施例中的技术方案, 下面将对实施例描述中所 需要使用的附图作简单地介绍, 显而易见地, 下面描述中的附图仅仅是本发明 的一些实施例, 对于本领域普通技术人员来讲, 在不付出创造性劳动性的前提 下, 还可以根据这些附图获得其他的附图。  In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly described. It is obvious that the drawings in the following description are only some embodiments of the present invention. It will be apparent to those skilled in the art that other drawings may be obtained from these drawings without the inventive labor.
图 1为本发明一个实施例提供的加速应用层解析的方法流程图;  FIG. 1 is a flowchart of a method for accelerating application layer parsing according to an embodiment of the present invention;
图 2 为本发明另一个实施例提供的加速应用层解析的方法流程图; 图 3 为本发明另一个实施例提供的加速应用层解析的方法流程图; 图 4 为本发明一个实施例提供的加速应用层解析的装置结构图; 图 5为本发明另一个实施例提供的加速应用层解析的装置结构图; 图 6为本发明另一个实施例提供的加速应用层解析的装置结构图; FIG. 2 is a flowchart of a method for accelerating application layer parsing according to another embodiment of the present invention; FIG. 3 is a flowchart of a method for accelerating application layer parsing according to another embodiment of the present invention; FIG. A device structure diagram for accelerating application layer analysis; FIG. 5 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention; FIG. 6 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention;
图 7为本发明另一个实施例提供的加速应用层解析的装置结构图;  FIG. 7 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention; FIG.
图 8为本发明另一个实施例提供的加速应用层解析的装置结构图;  FIG. 8 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention; FIG.
图 9为本发明另一个实施例提供的加速应用层解析的装置结构图。  FIG. 9 is a structural diagram of an apparatus for accelerating application layer parsing according to another embodiment of the present invention.
具体实施方式 detailed description
下面将结合本发明实施例中的附图, 对本发明实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而不是 全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没有作出创造 性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。  BRIEF DESCRIPTION OF THE DRAWINGS The technical solutions in the embodiments of the present invention will be described in detail with reference to the accompanying drawings. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present invention without creative work are within the scope of the present invention.
下面根据图 1, 描述本发明实施例的一种报文转发的方法, 该方法描述的是 在传输层判断报文流中的每一个报文是向应用层转发还是向网络中转发, 该方 法具体包括:  A method for packet forwarding according to an embodiment of the present invention is described below with reference to FIG. 1, which describes that each packet in a packet stream is determined to be forwarded to an application layer or forwarded to a network. Specifically include:
101、 接收网络层发送的报文, 判断该报文是否是报文流的首包。  101. Receive a packet sent by the network layer, and determine whether the packet is the first packet of the packet flow.
接收网络层发送的报文, 判断该报文的五元组是否已被存储, 若该报文的 五元组没有被存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是报文流的首包。 其中, 报文的五元组包括源网络协议(IP, Internet Protocol )地址、 源端口、 目的 IP地址、 目的端口和传输层协议号。  Receiving a packet sent by the network layer, determining whether the quintuple of the packet has been stored, and if the quintuple of the packet is not stored, the packet is the first packet of the packet flow; if the packet is If the quintuple has been stored, the message is not the first packet of the message stream. The quintuple of the message includes an IP (Internet Protocol) address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
102、 在该报文是报文流的首包时, 向应用层转发该报文。  102. When the packet is the first packet of the packet flow, forward the packet to the application layer.
在该报文为报文流的首包时, 由于首包中包含该报文所属消息的消息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便 获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务的使 用情况等。 其中, 消息的消息头可以包括首行和头域, 也可以包括首行, 也可 以包括头域。  When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage. The message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
在该报文为报文流的首包时, 需要将该报文的五元组进行存储。 在接收到 报文流的后续报文时, 可以根据存储的该报文的五元组, 判断后续报文不是报 文流的首包。  When the packet is the first packet of the packet flow, the quintuple of the packet needs to be stored. When receiving the subsequent packet of the packet flow, it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
103、 在该报文不是报文流的首包时, 判断该报文是否是报文流中消息的首 包。 在该报文不是报文流的首包时, 需要对该报文进行进一步判断, 判断该报 文是否为报文流中消息的首包。 对该报文进行进一步判断, 从而确定该报文是 否为报文流中消息的首包的具体方法为: 获取该报文承载的第一消息体长度; 获取存储的该消息的第二消息体总长度, 该消息为已传输部分内容至应用层的 消息; 获取存储的该报文所属消息的已传输部分内容至应用层的第三消息体总 长度; 在该第三消息体总长度与该第一消息体长度之和大于该第二消息体总长 度时, 确定该报文为报文流中消息的首包; 在该第三消息体总长度与该第一消 息体长度之和小于或等于该第二消息体总长度时, 确定该报文不是报文流中消 息的首包。 103. When the packet is not the first packet of the packet flow, determine whether the packet is the first packet of the message in the packet flow. When the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow. The specific method for determining whether the packet is the first packet of the packet in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message body of the message The total length, the message is a message that has transmitted part of the content to the application layer; the total length of the third message body of the stored part of the message to which the message belongs is obtained; the total length of the third message body and the When the sum of the lengths of the first message body is greater than the total length of the second message body, determining that the message is the first packet of the message in the packet flow; and the sum of the total length of the third message body and the length of the first message body is less than or When it is equal to the total length of the second message body, it is determined that the message is not the first packet of the message in the message stream.
获取该报文承载的第一消息体长度。 其中, 要获取网络层发送的该报文的 总长度和该报文的网络层头长度; 要获取该报文的传输层头长度; 用该报文的 总长度减去该报文的网络层头长度, 再减去该报文的传输层头长度得到该报文 承载的第一消息体长度。  Get the length of the first message body carried by the packet. The total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet. The length of the header, and then the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
获取该报文承载的第一消息体长度。 其中, 获取该报文在传输层的总长度 以及该报文传输层头长度, 用该报文的总长度减去该报文的传输层头长度得到 该报文承载的第一消息体长度。  Get the length of the first message body carried by the packet. The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
由于一条消息至少由一条报文承载, 而且报文流中的消息是连续的, 那么 一条报文中可能包含一条消息的内容, 可能包含两个消息的内容。  Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, which may contain the contents of two messages.
获取存储的该消息的第二消息体总长度, 该消息为已传输部分内容至应用 层的消息。 其中, 第二消息体总长度是指该报文所属消息的总长度, 如果该消 息由多条报文承载, 那么多条报文承载的消息长度之和就是该消息的总长度。 其中, 如果该报文承载了两条消息的内容, 那么获取存储的该消息的第二消息 体总长度中的该消息是指已有部分内容传输至应用层, 并且总长度已经被存储 的消息。  The total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer. The total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
获取存储的报文流已传输至应用层的该报文所属消息的第三消息体总长 度。 其中, 由于一条消息需要分成若干条报文进行传输, 在该报文之前, 属于 该消息的其他报文已经传输一部分消息内容至应用层, 这部分消息内容的长度 就是第三消息体总长度。  Obtain the total length of the third message body of the message to which the stored message stream has been transmitted to the application layer. The message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
104、 在该报文是报文流中消息的首包时, 向应用层转发该报文。  104. When the packet is the first packet of the message in the packet flow, forward the packet to the application layer.
在该报文是报文流中消息的首包时, 由于首包中包含该报文所属消息的消 息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务 的使用情况等。 When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs. Analysis, In order to obtain the required information, common information such as user distribution, hot application and business usage.
105、 在该报文不是报文流中消息的首包时, 向网络层转发该报文。  105. When the packet is not the first packet of the message in the packet flow, the packet is forwarded to the network layer.
在该报文不是报文流中消息的首包时, 该报文不包含该报文所属消息的消 息头, 因此不需要对该报文进行解析, 可以将该报文向网络层转发, 从而提高 转发效率, 减少应用层的解析负担。  When the packet is not the first packet of the packet in the packet flow, the packet does not include the header of the message to which the packet belongs, so the packet does not need to be parsed, and the packet can be forwarded to the network layer. Improve forwarding efficiency and reduce the analytical burden of the application layer.
从上可知, 使用本发明实施例提供的报文转发的方法, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the packet forwarding method provided by the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
如图 2描述本发明实施例的另一种报文转发的方法。  Another method for packet forwarding according to an embodiment of the present invention is described in FIG.
201、 接收网络层发送的报文, 判断该报文是否是报文流的首包。  201. Receive a packet sent by the network layer, and determine whether the packet is the first packet of the packet flow.
接收网络层发送的报文, 判断该报文的五元组是否已被存储, 若该报文的 五元组没有被存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是报文流的首包。 其中, 报文的五元组包括源 IP地址、 源端口、 目的 IP地址、 目的端口和传输层协议号。  Receiving a packet sent by the network layer, determining whether the quintuple of the packet has been stored, and if the quintuple of the packet is not stored, the packet is the first packet of the packet flow; if the packet is If the quintuple has been stored, the message is not the first packet of the message stream. The quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
202、 在该报文是报文流的首包时, 向应用层转发该报文, 并存储该报文的 五元组。  202. When the packet is the first packet of the packet flow, forward the packet to the application layer, and store the quintuple of the packet.
在该报文为报文流的首包时, 由于首包中包含该报文所属消息的消息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便 获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务的使 用情况等。 其中, 消息的消息头可以包括首行和头域, 也可以包括首行, 也可 以包括头域。  When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage. The message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
在该报文为报文流的首包时, 需要将该报文的五元组进行存储。 在接收到 报文流的后续报文时, 可以根据存储的该报文的五元组, 判断后续报文不是报 文流的首包。  When the packet is the first packet of the packet flow, the quintuple of the packet needs to be stored. When receiving the subsequent packet of the packet flow, it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
203、 在该报文不是报文流的首包时, 判断该报文是否是报文流中消息的首 包, 若该报文不是报文流中消息的首包, 转向 204, 若该报文是报文流中消息的 首包, 转向 205。 203. When the packet is not the first packet of the packet flow, determine whether the packet is the first packet of the message in the packet flow. If the packet is not the first packet of the message in the packet flow, go to 204, if the packet Text is the message in the message stream First package, turn to 205.
在该报文不是报文流的首包时, 需要对该报文进行进一步判断, 判断该报 文是否为报文流中消息的首包。 对该报文进行进一步的判断, 从而确定该报文 是否为报文流中消息的首包的具体方法为: 获取该报文承载的第一消息体长度; 获取存储的该消息的第二消息体总长度; 获取存储的该报文所属消息已传输部 分的第三消息体总长度; 在该第三消息体总长度与该第一消息体长度之和大于 该第二消息体总长度时, 该报文为报文流中消息的首包; 在该第三消息体总长 度与该第一消息体长度之和小于或等于该第二消息体总长度时, 该报文不是报 文流中消息的首包。  When the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow. The specific method for determining whether the packet is the first packet of the message in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message of the message The total length of the third message body of the transmitted portion of the message to which the message belongs is obtained; when the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body, The packet is the first packet of the message in the packet flow. When the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body, the packet is not in the packet stream. The first package of the message.
获取该报文承载的第一消息体长度。 其中, 要获取网络层发送的该报文的 总长度和该报文的网络层头长度; 要获取该报文的传输层头长度; 用该报文的 总长度减去该报文的网络层头长度再减去该报文的传输层头长度得到该报文承 载的第一消息体长度。  Get the length of the first message body carried by the packet. The total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet. The length of the transport layer header of the packet is further subtracted from the length of the header to obtain the length of the first message body carried by the packet.
获取该报文承载的第一消息体长度。 其中, 获取该报文在传输层的总长度 以及该报文传输层头长度, 用该报文的总长度减去该报文的传输层头长度得到 该报文承载的第一消息体长度。  Get the length of the first message body carried by the packet. The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
由于一条消息至少由一条报文承载, 而且报文流中的消息是连续的, 那么 一条报文中可能包含一条消息的内容, 可能包含两个消息的内容。  Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, which may contain the contents of two messages.
获取存储的该消息的第二消息体总长度, 该消息为已传输部分内容至应用 层的消息。 其中, 第二消息体总长度是指该报文所属消息的总长度, 如果该消 息由多条报文承载, 那么多条报文承载的消息长度之和就是该消息的总长度。 其中, 如果该报文承载了两条消息的内容, 那么获取存储的该消息的第二消息 体总长度中的该消息是指已有部分内容传输至应用层, 并且总长度已经被存储 的消息。  The total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer. The total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
获取存储的报文流已传输至应用层的该报文所属消息的第三消息体总长 度。 其中, 由于一条消息需要分成若干条报文进行传输, 在该报文之前, 属于 该消息的其他报文已经传输一部分消息内容至应用层, 这部分消息内容的长度 就是第三消息体总长度。  Obtain the total length of the third message body of the message to which the stored message stream has been transmitted to the application layer. The message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
204、 在该报文不是报文流中消息的首包时, 向网络层转发该报文。  204. When the packet is not the first packet of the message in the packet flow, forward the packet to the network layer.
在该报文不是报文流中消息的首包时, 该报文中没有包含消息的首行和头 域, 因此不需要解析, 可以直接向网络层转发。 205、 在该报文是报文流中消息的首包时, 向应用层转发该报文, 转入 206。 在该报文是报文流中消息的首包时, 由于首包中包含该报文所属消息的消 息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务 的使用情况等。 When the packet is not the first packet of the message in the packet flow, the packet does not contain the first row and the header field of the message, so it does not need to be parsed and can be directly forwarded to the network layer. 205. When the packet is the first packet of the message in the packet flow, forward the packet to the application layer, and switch to 206. When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs. Parsing, in order to obtain the required information, common information such as user distribution, hot application and business usage.
由于该报文为报文流的首包, 需要将该报文的五元组进行存储, 为判断后 续报文是否为报文流首包提供依据。  As the packet is the first packet of the packet, the quintuple of the packet needs to be stored to provide a basis for determining whether the subsequent packet is the first packet of the packet.
206、 接收应用层发送的该报文中消息头的长度, 用该第一消息体长度加上 该第三消息体总长度减去该第二消息体总长度, 再减去该报文中消息头的长度 得到第五消息体总长度。  206. Receive a length of a message header in the packet sent by the application layer, add a length of the first message body, a total length of the third message body, a total length of the second message body, and subtract the message in the packet. The length of the header gets the total length of the fifth message body.
用该第一消息体长度加上该第三消息体总长度减去该第二消息体总长度得 到的是该报文承载的其他消息的消息长度, 再该其他消息的消息头的长度, 得 到该报文承载的第五消息体总长度。  Using the length of the first message body plus the total length of the third message body minus the total length of the second message body is obtained by using the message length of other messages carried by the message, and then the length of the message header of the other message is obtained. The total length of the fifth message body carried by the message.
207、 将该第三消息体总长度更新为该第五消息体总长度。  207. Update the total length of the third message body to the total length of the fifth message body.
由于该报文包含了其他消息的内容, 表明一个消息结束, 另一个消息开始。 该报文承载了两个消息的内容, 因此, 需要将已传输的消息体长度进行更新, 用该报文承载第五消息体总长度更新存储的已传输的第三消息体总长度, 为该 其他消息的后续报文的判断提供依据。  Since the message contains the contents of other messages, indicating that one message ends, another message begins. The packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
208、 接收应用层发送的第六消息体总长度, 并用该第六消息体总长度更新 该第二消息体总长度, 该第六消息体总长度表示的是该报文所属消息的消息体 总长度。  208. Receive a total length of the sixth message body sent by the application layer, and update the total length of the second message body by using the total length of the sixth message body. The total length of the sixth message body indicates the total message body of the message to which the message belongs. length.
接收应用层发送的第六消息体总长度, 用该第六消息体总长度更新该第二 消息体总长度。 其中, 该第六消息体总长度是由应用层通过解析该报文的消息 内容长度字段获得, 该报文中包含两条消息的内容, 通过解析该报中包含的消 息内容长度字段, 获得的是其中一条消息的内容。 其中, 用该第六消息体总长 度更新该第二消息体总长度包括用该第六消息体总长度替换或者覆盖第二消息 体总长度, 使得下次获取第二消息体总长度时, 获取的是已经更新过的第二消 息体总长度。  Receiving a total length of the sixth message body sent by the application layer, and updating the total length of the second message body by using the total length of the sixth message body. The total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the message includes the content of two messages, and is obtained by parsing the message content length field included in the message. Is the content of one of the messages. Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that the next time the total length of the second message body is obtained, Is the total length of the second message body that has been updated.
从上可知, 使用本发明实施例提供的报文转发的方法, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。 It can be seen from the above that the packet forwarding method provided by the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it will be forwarded directly to the network, because the first packet is less, the non-first packet There are many texts. The large number of packets that do not need to be parsed can be directly forwarded to the network. This improves the efficiency of forwarding packets and reduces the burden of parsing packets at the application layer.
如图 3描述本发明实施例的另一种报文转发的方法。  FIG. 3 illustrates another method for packet forwarding according to an embodiment of the present invention.
301、 接收网络层发送的报文, 判断该报文是否是报文流的首包。  301. Receive a packet sent by the network layer, and determine whether the packet is the first packet of the packet flow.
接收网络层发送的报文, 判断该报文的五元组是否已被存储, 若该报文的 五元组没有被存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是报文流的首包。 其中, 报文的五元组包括源 IP地址、 源端口、 目的 IP地址、 目的端口和传输层协议号。  Receiving a packet sent by the network layer, determining whether the quintuple of the packet has been stored, and if the quintuple of the packet is not stored, the packet is the first packet of the packet flow; if the packet is If the quintuple has been stored, the message is not the first packet of the message stream. The quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
302、 在该报文是报文流的首包时, 向应用层转发该报文, 并存储该报文的 五元组。  302. When the packet is the first packet of the packet flow, forward the packet to the application layer, and store the quintuple of the packet.
在该报文为报文流的首包时, 由于首包中包含该报文所属消息的消息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便 获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务的使 用情况等。 其中, 消息的消息头可以包括首行和头域, 也可以包括首行, 也可 以包括头域。  When the packet is the first packet of the packet, the first packet includes the header of the message to which the packet belongs, and the packet needs to be forwarded to the application layer, and the application layer parses the header of the message to which the packet belongs. In order to obtain the required information, common information such as user distribution, hot application and business usage. The message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
在该报文为报文流的首包时, 需要将该报文的五元组进行存储。 在接收到 报文流的后续报文时, 可以根据存储的该报文的五元组, 判断后续报文不是报 文流的首包。  When the packet is the first packet of the packet flow, the quintuple of the packet needs to be stored. When receiving the subsequent packet of the packet flow, it may determine that the subsequent packet is not the first packet of the packet flow according to the stored quintuple of the packet.
303、 在该报文不是报文流的首包时, 判断该报文是否是报文流中消息的首 包, 若该报文不是报文流中消息的首包, 转向 304, 若该报文是报文流中消息的 首包, 转向 305。  303. When the packet is not the first packet of the packet flow, determine whether the packet is the first packet of the message in the packet flow. If the packet is not the first packet of the message in the packet flow, go to 304, if the packet The text is the first packet of the message in the message stream, and it turns to 305.
在该报文不是报文流的首包时, 需要对该报文进行进一步判断, 判断该报 文是否为报文流中消息的首包。 对该报文进行进一步的判断, 从而确定该报文 是否为报文流中消息的首包的具体方法为: 获取该报文承载的第一消息体长度; 获取存储的该消息的第二消息体总长度; 获取存储的该报文所属消息已传输部 分的第三消息体总长度; 在该第三消息体总长度与该第一消息体长度之和大于 该第二消息体总长度时, 该报文为报文流中消息的首包; 在该第三消息体总长 度与该第一消息体长度之和小于或等于该第二消息体总长度时, 该报文不是报 文流中消息的首包。 获取该报文承载的第一消息体长度。 其中, 要获取网络层发送的该报文的 总长度和该报文的网络层头长度; 要获取该报文的传输层头长度; 用该报文的 总长度减去该报文的网络层头长度再减去该报文的传输层头长度得到该报文承 载的第一消息体长度。 When the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow. The specific method for determining whether the packet is the first packet of the message in the packet flow is: obtaining the length of the first message body carried by the packet; and obtaining the stored second message of the message The total length of the third message body of the transmitted portion of the message to which the message belongs is obtained; when the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body, The packet is the first packet of the message in the packet flow. When the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body, the packet is not in the packet stream. The first package of the message. Get the length of the first message body carried by the packet. The total length of the packet sent by the network layer and the network layer header length of the packet are obtained; the length of the transport layer header of the packet is obtained; and the network layer of the packet is subtracted from the total length of the packet. The length of the transport layer header of the packet is further subtracted from the length of the header to obtain the length of the first message body carried by the packet.
获取该报文承载的第一消息体长度。 其中, 获取该报文在传输层的总长度 以及该报文传输层头长度, 用该报文的总长度减去该报文的传输层头长度得到 该报文承载的第一消息体长度。  Get the length of the first message body carried by the packet. The length of the packet in the transport layer and the length of the packet transport layer header are obtained, and the length of the transport layer header of the packet is subtracted from the total length of the packet to obtain the length of the first message body carried by the packet.
由于一条消息至少由一条报文承载, 而且报文流中的消息是连续的, 那么 一条报文中可能包含一条消息的内容, 可能包含两个消息的内容。  Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, which may contain the contents of two messages.
获取存储的该消息的第二消息体总长度, 该消息为已传输部分内容至应用 层的消息。 其中, 第二消息体总长度是指该报文所属消息的总长度, 如果该消 息由多条报文承载, 那么多条报文承载的消息长度之和就是该消息的总长度。 其中, 如果该报文承载了两条消息的内容, 那么获取存储的该消息的第二消息 体总长度中的该消息是指已有部分内容传输至应用层, 并且总长度已经被存储 的消息。  The total length of the second message body of the stored message is obtained, and the message is a message that has transmitted part of the content to the application layer. The total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
获取存储的报文流已传输至应用层的该报文所属消息的第三消息体总长 度。 其中, 由于一条消息需要分成若干条报文进行传输, 在该报文之前, 属于 该消息的其他报文已经传输一部分消息内容至应用层, 这部分消息内容的长度 就是第三消息体总长度。  Obtain the total length of the third message body of the message to which the stored message stream has been transmitted to the application layer. The message content needs to be divided into several pieces of messages for transmission. Before the message, the other messages belonging to the message have already transmitted a part of the message content to the application layer. The length of the part of the message content is the total length of the third message body.
304、在该报文不是报文流中消息的首包时,向网络层转发该报文,转入 309。 在该报文不是报文流中消息的首包时, 该报文中没有包含消息的首行和头 域, 因此不需要解析, 可以直接向网络层转发。  304. When the packet is not the first packet of the message in the packet flow, forward the packet to the network layer, and go to 309. When the packet is not the first packet of the message in the packet flow, the packet does not contain the first row and the header field of the message, so it does not need to be parsed and can be directly forwarded to the network layer.
305、 在该报文是报文流中消息的首包时, 向应用层转发该报文转入 306。 在该报文是报文流中消息的首包时, 由于首包中包含该报文所属消息的消 息头, 需要向应用层转发该报文, 由应用层对报文所属消息的消息头进行解析, 以便获得所需要的信息, 常见的信息如用户分布情况、 热点应用情况以及业务 的使用情况等。  305. When the packet is the first packet of the message in the packet flow, forward the packet to the application layer and transfer the packet to 306. When the packet is the first packet of the message in the packet flow, the packet needs to be forwarded to the application layer because the packet includes the header of the message to which the packet belongs, and the application layer performs the message header of the message to which the packet belongs. Parsing, in order to obtain the required information, common information such as user distribution, hot application and business usage.
由于该报文为报文流的首包, 需要将该报文的五元组进行存储, 为判断后 续报文是否为报文流首包提供依据。  As the packet is the first packet of the packet, the quintuple of the packet needs to be stored to provide a basis for determining whether the subsequent packet is the first packet of the packet.
306、 接收应用层发送的该报文中消息头的长度, 用该第一消息体长度加上 该第三消息体总长度减去该第二消息体总长度, 再减去该报文中消息头的长度 得到第五消息体总长度。 306. Receive a length of a message header in the packet sent by the application layer, add a length of the first message body, a total length of the third message body, a total length of the second message body, and subtract the message in the packet. Head length The total length of the fifth message body is obtained.
用该第一消息体长度加上该第三消息体总长度减去该第二消息体总长度得 到的是该报文承载的其他消息的消息长度, 再该其他消息的消息头的长度, 得 到该报文承载的第五消息体总长度。  Using the length of the first message body plus the total length of the third message body minus the total length of the second message body is obtained by using the message length of other messages carried by the message, and then the length of the message header of the other message is obtained. The total length of the fifth message body carried by the message.
307、 将该第三消息体总长度更新为该第五消息体总长度。  307. Update the total length of the third message body to the total length of the fifth message body.
由于该报文包含了其他消息的内容, 表明一个消息结束, 另一个消息开始。 该报文承载了两个消息的内容, 因此, 需要将已传输的消息体长度进行更新, 用该报文承载第五消息体总长度更新存储的已传输的第三消息体总长度, 为该 其他消息的后续报文的判断提供依据。  Since the message contains the contents of other messages, indicating that one message ends, another message begins. The packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
308、 接收应用层发送的第六消息体总长度, 并用该第六消息体总长度更新 该第二消息体总长度, 该第六消息体总长度表示的是该报文所属消息的消息体 总长度。  308. Receive a total length of the sixth message body sent by the application layer, and update the total length of the second message body by using the total length of the sixth message body. The total length of the sixth message body indicates the total message body of the message to which the message belongs. length.
接收应用层发送的第六消息体总长度, 用该第六消息体总长度更新该第二 消息体总长度。 其中, 该第六消息体总长度是由应用层通过解析该报文的消息 内容长度字段获得, 该报文中包含两条消息的内容, 通过解析该报中包含的消 息内容长度字段, 获得的是其中一条消息的内容。 其中, 用该第六消息体总长 度更新该第二消息体总长度包括用该第六消息体总长度替换或者覆盖第二消息 体总长度, 使得下次获取第二消息体总长度时, 获取的是已经更新过的第二消 息体总长度。  Receiving a total length of the sixth message body sent by the application layer, and updating the total length of the second message body by using the total length of the sixth message body. The total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the message includes the content of two messages, and is obtained by parsing the message content length field included in the message. Is the content of one of the messages. Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that the next time the total length of the second message body is obtained, Is the total length of the second message body that has been updated.
309、 将该第三消息体总长度更新为该第三消息体总长度与该第一消息体长 度之和。  309. Update the total length of the third message body to the sum of the total length of the third message body and the length of the first message body.
由于该报文承载的消息内容完全属于一条消息, 并且该报文承载的内容属 于已发送的该报所属消息的内容, 因此需要将存储的第三消息体总长度进行更 新。 将该报文承载的消息体长度与存储的已传输的该报文所属消息的消息体总 长度相加, 并用该相加之和更新存储的报文流已传输部分内容至应用层的该报 文所属消息的消息体总长度, 为该报文所属消息的后续报文提供判断依据。  Since the content of the message carried by the message completely belongs to a message, and the content carried by the message belongs to the content of the message to which the message belongs, the total length of the stored third message body needs to be updated. Adding a message body length carried by the message to the stored total length of the message body of the message to which the message belongs, and updating the stored message stream with the added sum to transmit the partial content to the application layer The total length of the message body of the message to which the message belongs is used to provide a judgment basis for subsequent messages of the message to which the message belongs.
从上可知, 使用本发明实施例提供的报文转发的方法及装置, 可以判断报 文流中每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用 层进行解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首 包的报文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发 报文的效率, 还能够减轻应用层解析报文的负担。 下面根据图 4描述本发明实施例的一种报文转发的装置 40。 如图 4所示, 装 置 40包括: It can be seen that, by using the packet forwarding method and device provided by the embodiment of the present invention, it can be determined whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, the application layer is submitted. If the first packet of the message is not forwarded, it will be directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, a large number of packets that do not need to be parsed are directly forwarded to the network. The efficiency of the text can also reduce the burden on the application layer to parse the message. A device 40 for packet forwarding according to an embodiment of the present invention is described below with reference to FIG. As shown in FIG. 4, the device 40 includes:
接收单元 401, 判断单元 402, 转发单元 403。  The receiving unit 401, the determining unit 402, and the forwarding unit 403.
接收单元 401, 用于接收网络层发送的报文。  The receiving unit 401 is configured to receive a packet sent by the network layer.
接收单元 401用于接收网络层发送的报文。  The receiving unit 401 is configured to receive a packet sent by the network layer.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
判断单元 402, 用于判断该接收单元 401接收到的报文是否为报文流的首包; 在该报文不是报文流的首包时, 判断该报文是否为报文流中消息的首包。  The determining unit 402 is configured to determine whether the packet received by the receiving unit 401 is the first packet of the packet flow; when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow. First package.
判断单元 402判断该报文的五元组是否已被存储, 若该报文的五元组没有被 存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是 报文流的首包。 其中, 报文的五元组包括源 IP地址、 源端口、 目的 IP地址、 目的 端口和传输层协议号。  The determining unit 402 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream. The quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
在判断单元 402判定该报文不是报文流的首包时, 需要对该报文进行进一步 判断, 判断该报文是否为报文流中消息的首包。  When the determining unit 402 determines that the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
判断单元 402对该报文进行进一步的判断, 从而确定该报文是否为报文流中 消息的首包的具体方法为: 获取该报文承载的第一消息体长度; 获取存储的该 消息的第二消息体总长度; 获取存储的该报文所属消息已传输部分的第三消息 体总长度; 在该第三消息体总长度与该第一消息体长度之和大于该第二消息体 总长度时, 确定该报文为报文流中消息的首包; 在该第三消息体总长度与该第 一消息体长度之和小于或等于该第二消息体总长度时, 确定该报文不是报文流 中消息的首包。  The determining unit 402 further determines the packet, so as to determine whether the packet is the first packet of the message in the packet flow, the method is: obtaining the length of the first message body carried by the packet; and acquiring the stored message The total length of the second message body; the total length of the third message body of the transmitted part of the message to which the message belongs is obtained; the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body The length of the message is determined to be the first packet of the message in the packet flow. When the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body, the message is determined. Not the first packet of the message in the message stream.
转发单元 403, 在判断单元 402判断该报文为报文流的首包时, 向应用层转 发该报文; 在判断单元 402判断该报文为报文流中消息的首包时, 向应用层转发 该报文, 在判断单元 402判断该报文不是报文流中消息的首包时, 向网络中转发 该报文。  The forwarding unit 403, when the determining unit 402 determines that the packet is the first packet of the packet flow, forwards the packet to the application layer; when the determining unit 402 determines that the packet is the first packet of the message in the packet flow, the application unit The layer forwards the packet, and when the determining unit 402 determines that the packet is not the first packet of the message in the packet stream, the packet is forwarded to the network.
在判断单元 402判断该报文为报文流的首包或者报文流中消息的首包时, 由 于该报文包含了该报文所属消息的消息头, 需要应用层对该消息的消息头进行 解析, 因此转发单元 403向应用层转发该报文。 其中, 消息的消息头可以包括首 行和头域, 也可以包括首行, 也可以包括头域。  When the determining unit 402 determines that the packet is the first packet of the packet flow or the first packet of the message in the packet flow, since the packet includes the message header of the message to which the packet belongs, the application layer needs the message header of the message. The parsing is performed, so the forwarding unit 403 forwards the message to the application layer. The message header of the message may include a first line and a header field, and may also include a first line, and may also include a header field.
在判断单元 403判断该报文不是报文流中消息的首包时, 该报文不包含该报 文所属消息的消息头, 因此不需要对该报文进行解析, 转发单元 403将该报文向 网络层转发, 从而提高转发效率, 减少应用层的解析负担。 When the determining unit 403 determines that the packet is not the first packet of the message in the packet stream, the packet does not include the packet. The message header of the message belongs to the message. Therefore, the packet does not need to be parsed, and the forwarding unit 403 forwards the packet to the network layer, thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the device for forwarding a packet according to the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
下面根据图 5描述本发明实施例的另一种报文转发的装置 50。 如图 5所示, 装置 50包括:  Another apparatus 50 for message forwarding according to an embodiment of the present invention will be described below with reference to FIG. As shown in Figure 5, device 50 includes:
接收单元 501, 判断单元 502, 存储单元 503, 获取单元 504, 转发单元 505, 计算单元 506, 第一更新单元 507, 第二更新单元 508。  The receiving unit 501, the determining unit 502, the storing unit 503, the obtaining unit 504, the forwarding unit 505, the calculating unit 506, the first updating unit 507, and the second updating unit 508.
接收单元 501, 用于接收网络层发送的报文。  The receiving unit 501 is configured to receive a packet sent by the network layer.
判断单元 502, 用于判断该接收单元 501接收到的报文是否是为报文流的首 包; 在该报文不是报文流的首包时, 判断该报文是否为报文流中消息的首包。  The determining unit 502 is configured to determine whether the packet received by the receiving unit 501 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow. The first pack.
判断单元 502判断该报文的五元组是否已被存储, 若该报文的五元组没有被 存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是 报文流的首包。 其中, 报文的五元组包括源 IP地址、 源端口、 目的 IP地址、 目的 端口和传输层协议号。  The determining unit 502 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream. The quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
在判断单元 502判定该报文不是报文流的首包时, 需要对该报文进行进一步 判断, 判断该报文是否为报文流中消息的首包。  When the determining unit 502 determines that the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
存储单元 503, 在判断单元 502判断该报文是报文流的首包时, 将该报文的 五元组进行存储。  The storage unit 503, when the determining unit 502 determines that the message is the first packet of the message stream, stores the quintuple of the message.
获取单元 504, 在判断单元 502判断该报文是否为报文流中消息的首包时, 获取该报文承载的第一消息体长度; 获取存储的该消息的第二消息体总长度; 获取存储的该报文所属消息的已传输部分内容至应用层的第三消息体总长度。  The obtaining unit 504, when the determining unit 502 determines whether the packet is the first packet of the message in the packet flow, obtains the length of the first message body carried by the packet; and obtains the total length of the second message body of the stored message; The stored total length of the transmitted portion of the message to which the message belongs to the third message body of the application layer.
获取单元 504获取该报文承载的第一消息体长度。 其中, 接收单元 501还用 于接收网络层发送的所述报文的总长度和所述报文的网络层头长度; 获取单元 504获取所述报文的传输层头长度, 并用接收单元 501接收到的该报文的总长度 减去该报文的网络层头长度再减去该报文的传输层头长度得到该报文承载的第 一消息体长度。 The obtaining unit 504 obtains the first message body length carried by the packet. The receiving unit 501 is further configured to receive the total length of the packet sent by the network layer and the network layer header length of the packet. The obtaining unit 504 obtains the transport layer header length of the packet, and receives the length of the transport layer header by using the receiving unit 501. The total length of the packet is subtracted from the network layer header length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the packet carrying the packet. The length of a message body.
获取单元 504获取该报文承载的第一消息体长度。 其中, 要获取已经发送到 传输层的该报文的总长度以及该报文传输层头长度, 用该报文的总长度减去该 报文的传输层头长度得到该报文承载的第一消息体长度。  The obtaining unit 504 obtains the length of the first message body carried by the packet. The total length of the packet that has been sent to the transport layer and the length of the packet transport layer header are obtained, and the total length of the packet is subtracted from the total length of the transport layer header of the packet to obtain the first packet carrying the packet. The length of the message body.
由于一条消息至少由一条报文承载, 而且报文流中的消息是连续的, 那么 一条报文中可能包含一条消息的内容, 也可能包含两个消息的内容。  Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, and may also contain the contents of two messages.
获取单元 504获取存储的该消息的第二消息体总长度。 其中, 第二消息体总 长度是指该报文所属消息的总长度, 如果该消息由多条报文承载, 那么多条报 文承载的消息长度之和就是该消息的总长度。 其中, 如果该报文承载了两条消 息的内容, 那么获取存储的该消息的第二消息体总长度中的该消息是指已有部 分内容传输至应用层, 并且总长度已经被存储的消息。  The obtaining unit 504 obtains the total length of the second message body of the stored message. The total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
获取单元 504获取存储的报文流已传输的该报文所属消息的第三消息体总 长度。 其中, 由于一条消息需要分成若干条报文进行传输, 在该报文之前, 属 于该消息的其他报文已经传输一部分消息内容至应用层, 这部分消息内容的长 度就是第三消息体总长度。  The obtaining unit 504 acquires the total length of the third message body of the message to which the stored message stream has been transmitted. The message content of the message has been transmitted to the application layer. The length of the content of the message is the total length of the third message body, because a message needs to be divided into several messages for transmission. Before the message, other messages belonging to the message have already transmitted a part of the message content to the application layer.
判断单元 502判断该报文是否是报文流中消息的首包具体包括: 判断单元 502判断获取单元 504获取的第一消息体长度与获取单元 504获取的第三消息体 总长度之和是否大于获取单元 504获取的第二消息体总长度。  The determining unit 502 determines whether the packet is the first packet of the message in the packet flow, and the determining unit 502 determines whether the sum of the first message body length acquired by the obtaining unit 504 and the total length of the third message body acquired by the obtaining unit 504 is greater than The total length of the second message body obtained by the obtaining unit 504.
在判断单元 502判断获取单元 504获取的第一消息体长度与获取单元 503获 取的第三消息体总长度之和大于获取单元 504获取的第二消息体总长度时, 确定 该才艮文为 4艮文流中消息的首包。  The determining unit 502 determines that the sum of the first message body length acquired by the obtaining unit 504 and the total length of the third message body acquired by the obtaining unit 503 is greater than the total length of the second message body acquired by the obtaining unit 504, and determines that the message is 4 The first packet of the message in the essay stream.
转发单元 505, 在判断单元 502判断该报文为报文流的首包时, 向应用层转 发该报文; 在判断单元 502判断该报文为报文流中消息的首包时, 向应用程转发 该报文, 在判断单元 502判断该报文不是报文流中消息的首包时, 向网络中转发 该报文。  The forwarding unit 505, when the determining unit 502 determines that the packet is the first packet of the packet flow, forwards the packet to the application layer; when the determining unit 502 determines that the packet is the first packet of the message in the packet flow, the application unit The process forwards the message, and when the determining unit 502 determines that the message is not the first packet of the message in the packet flow, the packet is forwarded to the network.
在该判断单元 502判断该报文为报文流的首包或者报文流中消息的首包时, 由于首包中包含该报文所属消息的消息头, 转发单元 505向应用层转发该报文, 由应用层对该报文所述消息的消息头进行解析, 以便获得所需要的信息, 常见 的信息如户分布情况、 热点应用情况以及业务的使用情况等。 其中, 消息的消 息头可以包括首行和头域, 也可以包括首行, 也可以包括头域。  When the determining unit 502 determines that the packet is the first packet of the packet flow or the first packet of the message in the packet flow, the forwarding unit 505 forwards the packet to the application layer because the first packet contains the message header of the message to which the packet belongs. The application layer parses the message header of the message to obtain the required information, such as the distribution of the household, the hotspot application, and the usage of the service. The message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
在判断单元 502判断该报文不是报文流中消息的首包时, 该报文不包含消息 的消息头, 因此不需要对该报文进行解析,转发单元 505将该报文向网络层转发, 从而提高转发效率, 减少应用层的解析负担。 When the determining unit 502 determines that the message is not the first packet of the message in the packet flow, the message does not contain the message. The message header is not required to be parsed, and the forwarding unit 505 forwards the packet to the network layer, thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
该接受单元 501还用于接收应用层发送的该报文中消息头的长度。  The accepting unit 501 is further configured to receive a length of a message header in the message sent by the application layer.
计算单元 506, 用于用该获取单元 504获取的第一消息体总长度加上该获取 单元获取的第三消息体长度, 减去该获取单元获取的第二消息体总长度, 在减 去接收单元 501接收到的该报文中消息头的长度得到第五消息体总长度。  The calculating unit 506 is configured to use the total length of the first message body acquired by the obtaining unit 504, and the length of the third message body acquired by the acquiring unit, and subtract the total length of the second message body acquired by the acquiring unit, and subtract the receiving The length of the message header in the message received by the unit 501 is the total length of the fifth message body.
计算单元 506用获取单元 504第一消息体总长度加上该第三消息体长度减去 该第二消息体总长度获得的是该报文承载的其他消息的消息长度, 再用该报文 承载的其他消息的消息长度减去该接收单元 501接收到的该报文中消息头的长 度得到第五消息体总长度。  The calculation unit 506 obtains, by using the total length of the first message body, the length of the third message body, and the total length of the second message body, the message length of other messages carried by the message, and then uses the message to carry the message. The length of the message of the other message minus the length of the message header in the message received by the receiving unit 501 is obtained to obtain the total length of the fifth message body.
第一更新单元 507, 将该第三消息体总长度更新为计算单元 506计算得到第 五消息体长度。  The first updating unit 507 updates the total length of the third message body to the calculating unit 506 to calculate the fifth message body length.
由于该报文包含了其他消息的内容, 表明一个消息结束, 另一个消息开始。 该报文承载了两个消息的内容, 因此, 需要将已传输的消息体长度进行更新, 用该报文承载第五消息体总长度更新存储的已传输的第三消息体总长度, 为该 其他消息的后续报文的判断提供依据。  Since the message contains the contents of other messages, indicating that one message ends, another message begins. The packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
接收单元 501, 还用于接收第六消息体长度, 该第六消息体总长度表示的是 该报文所属消息的消息体总长度, 该消息是指尚未全部传输至应用层的消息。  The receiving unit 501 is further configured to receive a sixth message body length, where the total length of the sixth message body indicates a total length of the message body of the message to which the message belongs, and the message refers to a message that has not been completely transmitted to the application layer.
转发单元 505向应用层转发该报文, 应用层接收到该报文后, 对该报文进行 解析。 由于该报文包含两条消息的内容, 应用层对该报文承载的消息进行解析, 获得第六消息体总长度。  The forwarding unit 505 forwards the packet to the application layer, and after receiving the packet, the application layer parses the packet. Because the packet contains the contents of two messages, the application layer parses the message carried by the packet to obtain the total length of the sixth message body.
第二更新单元 508, 用接收单元 501接收到的第六消息体总长度更新该第二 消息体总长度。  The second updating unit 508 updates the total length of the second message body by using the total length of the sixth message body received by the receiving unit 501.
用该第六消息体总长度更新该第二消息体总长度包括用该第六消息体总长 度替换或者覆盖第二消息体总长度, 使得下次获取第二消息体总长度时, 获取 的是已经更新过的第二消息体总长度。 其中, 该第六消息体总长度是由应用层 通过解析该报文的消息内容长度字段获得, 该第六消息体总长度表示的是该报 文所属消息的消息体总长度, 该消息是指尚未全部传输至应用层的消息。 由于 该报文为其他消息的首包, 该第六消息体总长度为该其他消息的总长度。  Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that when the total length of the second message body is acquired next time, the obtained The total length of the second message body that has been updated. The total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the total length of the sixth message body is the total length of the message body of the message to which the message belongs. Messages that have not been fully transferred to the application layer. Since the message is the first packet of other messages, the total length of the sixth message body is the total length of the other messages.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。 It can be seen that, by using the packet forwarding device provided by the embodiment of the present invention, it can be determined whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit to the application layer. If it is not the first packet of the message, it will be directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, a large number of packets that do not need to be parsed are directly forwarded to the network. The efficiency can also reduce the burden on the application layer to parse the message.
下面根据图 6描述本发明实施例的一种报文转发的装置 60。 如图 6所示, 装 置 60包括:  Next, a device 60 for message forwarding according to an embodiment of the present invention will be described with reference to FIG. As shown in Figure 6, device 60 includes:
接收单元 601, 判断单元 602, 存储单元 603, 获取单元 604, 转发单元 605, 第三更新单元 606, 计算单元 607, 第一更新单元 608, 第二更新单元 609。  The receiving unit 601, the determining unit 602, the storing unit 603, the obtaining unit 604, the forwarding unit 605, the third updating unit 606, the calculating unit 607, the first updating unit 608, and the second updating unit 609.
接收单元 601, 用于接收网络层发送的报文。  The receiving unit 601 is configured to receive a packet sent by the network layer.
判断单元 602, 用于判断该接收单元 601接收到的报文是否是为报文流的首 包; 在该报文不是报文流的首包时, 判断该报文是否为报文流中消息的首包。  The determining unit 602 is configured to determine whether the packet received by the receiving unit 601 is the first packet of the packet flow, and when the packet is not the first packet of the packet flow, determine whether the packet is a message in the packet flow. The first pack.
判断单元 602判断该报文的五元组是否已被存储, 若该报文的五元组没有被 存储, 则该报文为报文流的首包; 若该报文的五元组已被存储, 则该报文不是 报文流的首包。 其中, 报文的五元组包括源 IP地址、 源端口、 目的 IP地址、 目的 端口和传输层协议号。  The determining unit 602 determines whether the quintuple of the packet has been stored. If the quintuple of the packet is not stored, the packet is the first packet of the packet stream; if the quintuple of the packet has been If it is stored, the packet is not the first packet of the packet stream. The quintuple of the packet includes a source IP address, a source port, a destination IP address, a destination port, and a transport layer protocol number.
其中, 一条报文流至少包括一条消息, 一条消息可以由至少一个报文承载。 报文流的首包既是报文流的第一个报文, 也是一条消息的第一条报文。  The packet stream includes at least one message, and one message can be carried by at least one message. The first packet of the packet flow is the first packet of the packet flow and the first packet of the message.
在判断单元 602判定该报文不是报文流的首包时, 需要对该报文进行进一步 判断, 判断该报文是否为报文流中消息的首包。  When the determining unit 602 determines that the packet is not the first packet of the packet flow, the packet needs to be further judged to determine whether the packet is the first packet of the message in the packet flow.
存储单元 603, 在判断单元 602判断该报文是报文流的首包时, 将该报文的 五元组进行存储。  The storage unit 603 stores the quintuple of the packet when the determining unit 602 determines that the packet is the first packet of the packet stream.
获取单元 604, 在判断单元 602判断该报文是否为报文流中消息的首包时, 获取该报文承载的第一消息体长度; 获取存储的该消息的第二消息体总长度; 获取存储的该报文所属消息的已传输部分内容至应用层的第三消息体总长度。  The obtaining unit 604, when the determining unit 602 determines whether the packet is the first packet of the message in the packet flow, obtains the length of the first message body carried by the packet; and obtains the total length of the second message body of the stored message; The stored total length of the transmitted portion of the message to which the message belongs to the third message body of the application layer.
获取单元 604获取该报文承载的第一消息体长度。 其中, 接收单元 601还用 于接收网络层发送的所述报文的总长度和所述报文的网络层头长度; 获取单元 604获取所述报文的传输层头长度, 并用接收单元 601接收到的该报文的总长度 减去该报文的网络层头长度再减去该报文的传输层头长度得到该报文承载的第 一消息体长度。  The obtaining unit 604 obtains the length of the first message body carried by the packet. The receiving unit 601 is further configured to receive the total length of the packet sent by the network layer and the network layer header length of the packet. The acquiring unit 604 obtains the transport layer header length of the packet, and receives the length of the transport layer header by using the receiving unit 601. The total length of the packet is subtracted from the network layer header length of the packet, and the length of the transport layer header of the packet is subtracted to obtain the length of the first message body carried by the packet.
获取单元 604获取该报文承载的第一消息体长度。 其中, 要获取已经发送到 传输层的该报文的总长度以及该报文传输层头长度, 用该报文的总长度减去该 报文的传输层头长度得到该报文承载的第一消息体长度。 由于一条消息至少由一条报文承载, 而且报文流中的消息是连续的, 那么 一条报文中可能包含一条消息的内容, 也可能包含两个消息的内容。 The obtaining unit 604 obtains the first message body length carried by the packet. The total length of the packet that has been sent to the transport layer and the length of the packet transport layer header are obtained, and the total length of the packet is subtracted from the total length of the transport layer header of the packet to obtain the first packet carrying the packet. The length of the message body. Since a message is carried by at least one message, and the message in the message stream is continuous, one message may contain the content of one message, and may also contain the contents of two messages.
获取单元 604获取存储的该消息的第二消息体总长度。 其中, 第二消息体总 长度是指该报文所属消息的总长度, 如果该消息由多条报文承载, 那么多条报 文承载的消息长度之和就是该消息的总长度。 其中, 如果该报文承载了两条消 息的内容, 那么获取存储的该消息的第二消息体总长度中的该消息是指已有部 分内容传输至应用层, 并且总长度已经被存储的消息。  The obtaining unit 604 obtains the total length of the second message body of the stored message. The total length of the second message body refers to the total length of the message to which the message belongs. If the message is carried by multiple messages, the sum of the message lengths carried by the multiple messages is the total length of the message. If the message carries the contents of the two messages, the message in the total length of the second message body that obtains the stored message refers to the message that the existing part of the content is transmitted to the application layer, and the total length has been stored. .
获取单元 604获取存储的报文流已传输的该报文所属消息的第三消息体总 长度。 其中, 由于一条消息需要分成若干条报文进行传输, 在该报文之前, 属 于该消息的其他报文已经传输一部分消息内容至应用层, 这部分消息内容的长 度就是第三消息体总长度。  The obtaining unit 604 acquires the total length of the third message body of the message to which the stored message stream has been transmitted. The message content of the message has been transmitted to the application layer. The length of the content of the message is the total length of the third message body, because a message needs to be divided into several messages for transmission. Before the message, other messages belonging to the message have already transmitted a part of the message content to the application layer.
判断单元 602判断该报文是否是报文流中消息的首包具体包括: 判断单元 602判断获取单元 604获取的第一消息体长度与获取单元 504获取的第三消息体 总长度之和是否大于获取单元 504获取的第二消息体总长度。  The determining unit 602 determines whether the packet is the first packet of the message in the packet flow, and the determining unit 602 determines whether the sum of the first message body length acquired by the obtaining unit 604 and the total length of the third message body acquired by the obtaining unit 504 is greater than The total length of the second message body obtained by the obtaining unit 504.
在判断单元 602判断获取单元 604获取的第一消息体长度与获取单元 603获 取的第三消息体总长度之和大于获取单元 604获取的第二消息体总长度时, 确定 该才艮文为 4艮文流中消息的首包。  The determining unit 602 determines that the sum of the first message body length acquired by the obtaining unit 604 and the total length of the third message body acquired by the obtaining unit 603 is greater than the total length of the second message body acquired by the obtaining unit 604, and determines that the message is 4 The first packet of the message in the essay stream.
转发单元 605, 在判断单元 602判断该报文为报文流的首包时, 向应用层转 发该报文; 在判断单元 602判断该报文为报文流中消息的首包时, 向应用程转发 该报文, 在判断单元 602判断该报文不是报文流中消息的首包时, 向网络中转发 该报文。  The forwarding unit 605, when the determining unit 602 determines that the packet is the first packet of the packet flow, forwards the packet to the application layer; when the determining unit 602 determines that the packet is the first packet of the message in the packet flow, the application unit The process forwards the message, and when the determining unit 602 determines that the message is not the first packet of the message in the packet flow, the packet is forwarded to the network.
在该判断单元 602判断该报文为报文流的首包或者报文流中消息的首包时, 由于首包中包含该报文所属消息的消息头, 转发单元 605向应用层转发该报文, 由应用层对该报文所述消息的消息头进行解析, 以便获得所需要的信息, 常见 的信息如户分布情况、 热点应用情况以及业务的使用情况等。 其中, 消息的消 息头可以包括首行和头域, 也可以包括首行, 也可以包括头域。  When the determining unit 602 determines that the packet is the first packet of the packet flow or the first packet of the message in the packet flow, the forwarding unit 605 forwards the packet to the application layer because the first packet contains the message header of the message to which the packet belongs. The application layer parses the message header of the message to obtain the required information, such as the distribution of the household, the hotspot application, and the usage of the service. The message header of the message may include a first line and a header field, and may also include a first line, or may include a header field.
在判断单元 602判断该报文不是报文流中消息的首包时, 该报文不包含消息 的消息头, 因此不需要对该报文进行解析,转发单元 605将该报文向网络层转发, 从而提高转发效率, 减少应用层的解析负担。  When the determining unit 602 determines that the packet is not the first packet of the message in the packet stream, the packet does not include the header of the message, so the packet does not need to be parsed, and the forwarding unit 605 forwards the packet to the network layer. , thereby improving forwarding efficiency and reducing the analysis burden of the application layer.
第三更新单元 606, 在判断单元 602判断该报文不是报文流中消息的首包时, 将该第三消息体总长度更新为该第三消息体总长度与该第一消息体长度之和。 由于该报文承载的消息内容完全属于一条消息, 因此该报文承载的内容属 于已发送的该报所属消息的内容, 因此需要将存储的第三消息体总长度进行更 新。 第三更新单元 606将该报文承载的消息体长度与存储的已传输的该报文所属 消息的消息体总长度相加, 并用该相加之和更新存储的报文流已传输的该报文 所属消息的消息体总长度, 为判断后续报文是否为报文流首包或者报文流中消 息的首包提供依据。 The third update unit 606, when the determining unit 602 determines that the packet is not the first packet of the message in the packet flow, the total length of the third message body is updated to be the total length of the third message body and the length of the first message body. with. Since the content of the message carried by the packet belongs to a message completely, the content carried by the packet belongs to the content of the sent message of the packet, and therefore the total length of the stored third message body needs to be updated. The third update unit 606 adds the message body length carried by the message to the stored total length of the message body of the message to which the message belongs, and updates the stored message stream with the added sum. The total length of the message body of the message to which the message belongs is used to determine whether the subsequent message is the first packet of the packet flow or the first packet of the message in the packet flow.
该接受单元 601还用于接收应用层发送的该报文中消息头的长度。  The accepting unit 601 is further configured to receive a length of a message header in the packet sent by the application layer.
计算单元 607, 用于用该获取单元 604获取的第一消息体总长度加上该获取 单元获取的第三消息体长度, 减去该获取单元获取的第二消息体总长度, 在减 去接收单元 601接收到的该报文中消息头的长度得到第五消息体总长度。  The calculating unit 607 is configured to use the total length of the first message body acquired by the acquiring unit 604, plus the length of the third message body acquired by the acquiring unit, and subtract the total length of the second message body acquired by the acquiring unit, and subtract the receiving The length of the message header in the message received by the unit 601 is the total length of the fifth message body.
计算单元 607用获取单元 604第一消息体总长度加上该第三消息体长度减去 该第二消息体总长度获得的是该报文承载的其他消息的消息长度, 再用该报文 承载的其他消息的消息长度减去该接收单元 601接收到的该报文中消息头的长 度得到第五消息体总长度。  The calculation unit 607 obtains, by using the total length of the first message body, the length of the third message body, and the total length of the second message body, the message length of other messages carried by the message, and then uses the message to carry the message. The length of the message of the other message minus the length of the message header in the message received by the receiving unit 601 is the total length of the fifth message body.
第一更新单元 608, 将该第三消息体总长度更新为计算单元 607计算得到第 五消息体长度。  The first updating unit 608 updates the total length of the third message body to the calculating unit 607 to calculate the fifth message body length.
由于该报文包含了其他消息的内容, 表明一个消息结束, 另一个消息开始。 该报文承载了两个消息的内容, 因此, 需要将已传输的消息体长度进行更新, 用该报文承载第五消息体总长度更新存储的已传输的第三消息体总长度, 为该 其他消息的后续报文的判断提供依据。  Since the message contains the contents of other messages, indicating that one message ends, another message begins. The packet carries the content of the two messages. Therefore, the length of the transmitted message body needs to be updated, and the total length of the transmitted third message body is updated by using the packet to carry the total length of the fifth message body. The judgment of subsequent messages of other messages provides a basis.
接收单元 601, 还用于接收第六消息体长度, 该第六消息体总长度表示的是 该报文所属消息的消息体总长度, 该消息是指尚未全部传输至应用层的消息。  The receiving unit 601 is further configured to receive a sixth message body length, where the total length of the sixth message body indicates a total length of the message body of the message to which the message belongs, and the message refers to a message that has not been completely transmitted to the application layer.
转发单元 605向应用层转发该报文, 应用层接收到该报文后, 对该报文进行 解析。 由于该报文包含两条消息的内容, 应用层对该报文承载的消息进行解析, 获得第六消息体总长度。  The forwarding unit 605 forwards the packet to the application layer, and after receiving the packet, the application layer parses the packet. Because the packet contains the contents of two messages, the application layer parses the message carried by the packet to obtain the total length of the sixth message body.
第二更新单元 609, 用接收单元 601接收到的第六消息体总长度更新该第二 消息体总长度。  The second updating unit 609 updates the total length of the second message body by using the total length of the sixth message body received by the receiving unit 601.
用该第六消息体总长度更新该第二消息体总长度包括用该第六消息体总长 度替换或者覆盖第二消息体总长度, 使得下次获取第二消息体总长度时, 获取 的是已经更新过的第二消息体总长度。 其中, 该第六消息体总长度是由应用层 通过解析该报文的消息内容长度字段获得, 该第六消息体总长度表示的是该报 文所属消息的消息体总长度, 该消息是指尚未全部传输至应用层的消息。 由于 该报文为其他消息的首包, 该第六消息体总长度为该其他消息的总长度。 Updating the total length of the second message body by using the total length of the sixth message body includes replacing or covering the total length of the second message body with the total length of the sixth message body, so that when the total length of the second message body is acquired next time, the obtained The total length of the second message body that has been updated. The total length of the sixth message body is obtained by the application layer by parsing the message content length field of the message, and the total length of the sixth message body is the report. The total length of the message body of the message to which the text belongs. This message refers to the message that has not been completely transmitted to the application layer. Since the message is the first packet of other messages, the total length of the sixth message body is the total length of the other messages.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the device for forwarding a packet according to the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
图 7描述了本发明另一个实施例提供的报文转发设备的结构, 包括至少一个 处理器 701 (例如 CPU ) , 存储器 702, 至少一个网络接口 703, 和至少一个通信 总线 704, 用于实现这些装置之间的连接通信。 处理器 701用于执行存储器 702中 存储的可执行模块, 例如计算机程序。 存储器 702可能包含高速随机存取存储器 ( RAM: Random Access Memory ),也可能还包括非不稳定的存储器( non-volatile memory ), 例如至少一个磁盘存储器。 通过至少一个网络接口 703 (可以是有线 或者无线) 实现该网络设备与至少一个其他网元之间的通信连接, 可以使用互 联网, 广域网、 本地网、 城域网等。  FIG. 7 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 701 (eg, a CPU), a memory 702, at least one network interface 703, and at least one communication bus 704 for implementing these Connection communication between devices. The processor 701 is configured to execute executable modules, such as computer programs, stored in the memory 702. The memory 702 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory such as at least one disk memory. The communication connection between the network device and at least one other network element is implemented by at least one network interface 703 (which may be wired or wireless), and may use an internet, a wide area network, a local area network, a metropolitan area network, or the like.
在一些实施方式中,存储器 702存储了程序 7021,程序 7021可以被处理器 701 执行, 这个程序包括: 接收网络层发送的报文, 判断该报文是否为报文流的首 包; 在该报文为报文流的首包时, 向应用层转发该报文; 在该报文不是报文流 的首包时, 判断该报文是否为报文流中消息的首包; 在该报文是报文流中消息 的首包时, 向应用层转发该报文; 在该报文不是报文流中消息的首包时, 向网 络层转发该报文。 具体的实施步骤与图 1所示的实施例相同, 此处不再赘述。  In some embodiments, the memory 702 stores a program 7021, and the program 7021 can be executed by the processor 701. The program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet flow, the packet is forwarded to the application layer; when the packet is not the first packet of the packet flow, it is determined whether the packet is the first packet of the message in the packet flow; When the first packet of the message in the packet flow is forwarded, the packet is forwarded to the application layer. When the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer. The specific implementation steps are the same as those in the embodiment shown in FIG. 1, and are not described herein again.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the device for forwarding a packet according to the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
图 8描述了本发明另一个实施例提供的报文转发设备的结构, 包括至少一个 处理器 801 (例如 CPU ) , 存储器 802, 至少一个网络接口 803, 和至少一个通信 总线 804, 用于实现这些装置之间的连接通信。 处理器 801用于执行存储器 802中 存储的可执行模块, 例如计算机程序。 存储器 802可能包含高速随机存取存储器 ( RAM: Random Access Memory ),也可能还包括非不稳定的存储器( non-volatile memory ), 例如至少一个磁盘存储器。 通过至少一个网络接口 803 (可以是有线 或者无线) 实现该网络设备与至少一个其他网元之间的通信连接, 可以使用互 联网, 广域网、 本地网、 城域网等。 FIG. 8 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 801 (eg, a CPU), a memory 802, at least one network interface 803, and at least one communication bus 804 for implementing these Connection communication between devices. The processor 801 is configured to execute executable modules, such as computer programs, stored in the memory 802. The memory 802 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory (non-volatile memory). Memory ), such as at least one disk storage. The communication connection between the network device and at least one other network element is implemented by at least one network interface 803 (which may be wired or wireless), and may use an Internet, a wide area network, a local area network, a metropolitan area network, or the like.
在一些实施方式中,存储器 802存储了程序 8021,程序 8021可以被处理器 801 执行, 这个程序包括: 接收网络层发送的报文, 判断该报文是否为报文流的首 包; 在该报文为报文流的首包时, 向应用层转发该报文, 并存储该报文的五元 组; 在该报文不是报文流的首包时, 判断该报文是否为报文流中消息的首包; 在该报文是报文流中消息的首包时, 向应用层转发该报文; 接收应用层发送的 该报文中消息头的长度, 用该第一消息体总长度加上该第三消息体长度减去该 第二消息体总长度, 再减去该报文中的消息头的长度得到第五消息体总长度; 将该第三消息体总长度更新为第五消息体总长度; 接收应用层发送的第六消息 体总长度, 并用该第六消息体总长度更新该第二消息体总长度, 该第六消息体 总长度表示的是该报文所属消息的消息体总长度。 具体的实施步骤与图 2所示的 实施例相同, 此处不再赘述。  In some embodiments, the memory 802 stores a program 8021, and the program 8021 can be executed by the processor 801. The program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer, and the quintuple of the packet is stored. When the packet is not the first packet of the packet, the packet is determined to be a packet flow. The first packet of the message; when the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; the length of the message header in the packet sent by the application layer is received, and the first message body is used. Adding the length of the third message body minus the total length of the second message body, and subtracting the length of the message header in the message to obtain the total length of the fifth message body; updating the total length of the third message body to the first The total length of the fifth message body is received, and the total length of the sixth message body sent by the application layer is received, and the total length of the second message body is updated by the total length of the sixth message body. The total length of the sixth message body indicates the message to which the message belongs. Total message body lengthThe specific implementation steps are the same as those in the embodiment shown in FIG. 2, and details are not described herein again.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the device for forwarding a packet according to the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
图 9描述了本发明另一个实施例提供的报文转发设备的结构, 包括至少一个 处理器 901 (例如 CPU ) , 存储器 902, 至少一个网络接口 903, 和至少一个通信 总线 904, 用于实现这些装置之间的连接通信。 处理器 901用于执行存储器 902中 存储的可执行模块, 例如计算机程序。 存储器 902可能包含高速随机存取存储器 ( RAM: Random Access Memory ),也可能还包括非不稳定的存储器( non-volatile memory ), 例如至少一个磁盘存储器。 通过至少一个网络接口 903 (可以是有线 或者无线) 实现该网络设备与至少一个其他网元之间的通信连接, 可以使用互 联网, 广域网、 本地网、 城域网等。  FIG. 9 illustrates a structure of a message forwarding device according to another embodiment of the present invention, including at least one processor 901 (eg, a CPU), a memory 902, at least one network interface 903, and at least one communication bus 904 for implementing these Connection communication between devices. The processor 901 is operative to execute executable modules, such as computer programs, stored in the memory 902. The memory 902 may include a high speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory such as at least one disk memory. The communication connection between the network device and at least one other network element is implemented by at least one network interface 903 (which may be wired or wireless), and may use an internet, a wide area network, a local area network, a metropolitan area network, or the like.
在一些实施方式中,存储器 902存储了程序 9021,程序 9021可以被处理器 901 执行, 这个程序包括: 接收网络层发送的报文, 判断该报文是否为报文流的首 包; 在该报文为报文流的首包时, 向应用层转发该报文, 并存储该报文的五元 组; 在该报文不是报文流的首包时, 判断该报文是否为报文流中消息的首包; 在报文不是报文流中消息的首包时, 向网络层转发, 并将该第三消息体总长度 更新为该第三消息体总长度与该第一消息体长度之和; 在该报文是报文流中消 息的首包时, 向应用层转发该报文; 接收应用层发送的该报文中消息头的长度, 用该第一消息体总长度加上该第三消息体长度减去该第二消息体总长度, 再减 去该报文中的消息头的长度得到第五消息体总长度; 将该第三消息体总长度更 新为第五消息体总长度; 接收应用层发送的第六消息体总长度, 并用该第六消 息体总长度更新该第二消息体总长度, 该第六消息体总长度表示的是该报文所 属消息的消息体总长度。 具体的实施步骤与图 3所示的实施例相同, 此处不再赘 述。 In some embodiments, the memory 902 stores a program 9021, and the program 9021 can be executed by the processor 901. The program includes: receiving a message sent by the network layer, determining whether the message is a first packet of the message flow; When the packet is the first packet of the packet, the packet is forwarded to the application layer, and the quintuple of the packet is stored. When the packet is not the first packet of the packet, the packet is determined to be a packet flow. The first package of the message; When the packet is not the first packet of the packet in the packet flow, the packet is forwarded to the network layer, and the total length of the third message body is updated to be the sum of the total length of the third message body and the length of the first message body; When the packet is the first packet of the message in the packet flow, the packet is forwarded to the application layer; the length of the message header in the packet sent by the application layer is received, and the total length of the first message body is added to the length of the third message body. Subtracting the total length of the second message body, and subtracting the length of the message header in the packet to obtain a total length of the fifth message body; updating the total length of the third message body to the total length of the fifth message body; receiving the application layer The total length of the sixth message body is sent, and the total length of the second message body is updated by the total length of the sixth message body. The total length of the sixth message body indicates the total length of the message body of the message to which the message belongs. The specific implementation steps are the same as those in the embodiment shown in FIG. 3, and details are not described herein again.
从上可知, 使用本发明实施例提供的报文转发的装置, 可以判断报文流中 每一个报文是否为报文流中消息的首包, 若是消息的首包, 则提交应用层进行 解析; 若不是消息的首包, 则直接转发到网络中, 由于首包较少, 非首包的报 文较多, 将大量不需要解析的报文直接转发到网络中不仅可以提高转发报文的 效率, 还能够减轻应用层解析报文的负担。  It can be seen from the above that the device for forwarding a packet according to the embodiment of the present invention can determine whether each packet in the packet flow is the first packet of the message in the packet flow, and if it is the first packet of the message, submit the application layer for parsing. If it is not the first packet of the message, it is directly forwarded to the network. Since there are fewer first packets and more packets than the first packet, forwarding a large number of packets that do not need to be parsed directly to the network can improve the forwarding of packets. Efficiency can also reduce the burden on the application layer to parse messages.
需要说明的是, 对于前述的各方法实施例, 为了简单描述, 故将其都表述 为一系列的动作组合, 但是本领域技术人员应该知悉, 本发明并不受所描述的 动作顺序的限制, 因为依据本发明, 某些步骤可以釆用其他顺序或者同时进行。 其次, 本领域技术人员也应该知悉, 说明书中所描述的实施例均属于优选实施 例, 所涉及的动作和模块并不一定是本发明所必须的。  It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the present invention is not limited by the described action sequence. Because in accordance with the present invention, certain steps may be performed in other sequences or concurrently. In addition, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
上述装置和系统内的各模块之间的信息交互、 执行过程等内容, 由于与本 发明方法实施例基于同一构思, 具体内容可参见本发明方法实施例中的叙述, 此处不再赘述。  For the information exchange, the execution process, and the like between the above-mentioned devices and the modules in the system, the content is the same as that of the method embodiment of the present invention. For details, refer to the description in the method embodiment of the present invention, and details are not described herein again.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程, 是可以通过计算机程序来指令相关的硬件来完成, 上述的程序可存储于一计算 机可读取存储介质中, 该程序在执行时, 可包括如上述各方法的实施例的流程。 其中, 上述的存储介质可为磁碟、 光盘、 只读存储记忆体(ROM: Read-Only Memory ) 或随机存储记忆体 ( RAM: Random Access Memory ) 等。 例的说明只是用于帮助理解本发明的方法及其思想; 同时, 对于本领域的一般 技术人员, 依据本发明的思想, 在具体实施方式及应用范围上均会有改变之处, 综上所述, 本说明书内容不应理解为对本发明的限制。  A person skilled in the art can understand that all or part of the process of implementing the above embodiments can be completed by a computer program to instruct related hardware, and the above program can be stored in a computer readable storage medium. When executed, the flow of an embodiment of the methods as described above may be included. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM: Read Random Memory), or a random access memory (RAM). The description of the examples is only for helping to understand the method and the idea of the present invention; at the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific embodiments and application scopes. The description is not to be construed as limiting the invention.

Claims

权 利 要 求 Rights request
1、 一种报文转发的方法, 其特征在于, 所述方法包括: 1. A message forwarding method, characterized in that the method includes:
接收网络层发送的报文, 判断所述报文是否是报文流的首包; Receive the message sent by the network layer and determine whether the message is the first packet of the message flow;
在所述报文是报文流的首包时, 向应用层转发所述报文; When the message is the first packet of the message flow, forward the message to the application layer;
在所述报文不是报文流的首包时, 判断所述报文是否是报文流中消息的首 包; When the message is not the first packet of the message flow, determine whether the message is the first packet of the message in the message flow;
在所述报文是报文流中消息的首包时, 向应用层转发所述报文; When the message is the first packet of the message in the message flow, forward the message to the application layer;
在所述报文不是报文流中消息的首包时, 向网络层转发所述报文。 When the message is not the first packet of the message in the message flow, the message is forwarded to the network layer.
2、 如权利要求 1所述的报文转发的方法, 其特征在于, 所述判断所述报文 是否为报文流中消息的首包包括: 2. The method of message forwarding according to claim 1, characterized in that, determining whether the message is the first packet of a message in the message flow includes:
获取所述报文承载的第一消息体长度; Obtain the length of the first message body carried by the message;
获取存储的所述报文所属消息的第二消息体总长度; Obtain the total length of the stored second message body of the message to which the message belongs;
获取存储的所述报文所属消息已传输部分的第三消息体总长度; Obtain the stored total length of the third message body of the transmitted part of the message to which the message belongs;
在所述第三消息体总长度与所述第一消息体长度之和大于所述第二消息体 总长度时, 确定所述报文为报文流中消息的首包; When the sum of the total length of the third message body and the length of the first message body is greater than the total length of the second message body, determine that the message is the first packet of the message in the message flow;
在所述第三消息体总长度与所述第一消息体长度之和小于或等于所述第二 消息体总长度时, 确定所述报文不是报文流中消息的首包。 When the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body, it is determined that the message is not the first packet of the message in the message flow.
3、 如权利要求 2所述的报文转发的方法, 其特征在于, 在所述报文是报文 流中消息的首包时, 在向应用层转发所述报文后, 所述方法还包括: 3. The method of message forwarding according to claim 2, wherein when the message is the first packet of a message in the message flow, after forwarding the message to the application layer, the method further: include:
接收应用层发送的所述报文中的消息头的长度, 用所述第一消息体长度加 上所述第三消息体总长度, 再减去所述第二消息体总长度, 再减去所述报文中 消息头的长度得到第五消息体总长度; Receive the length of the message header in the message sent by the application layer, add the first message body length to the total length of the third message body, and then subtract the total length of the second message body, and then subtract The length of the message header in the message is used to obtain the total length of the fifth message body;
将所述第三消息体总长度更新为所述第五消息体总长度。 The total length of the third message body is updated to the total length of the fifth message body.
4、 如权利要求 2或 3所述的报文转发的方法, 其特征在于, 所述在向应用层 转发所述报文后, 还包括: 4. The message forwarding method according to claim 2 or 3, characterized in that, after forwarding the message to the application layer, it further includes:
接收应用层发送的第六消息体总长度, 并用所述第六消息体总长度更新所 述第二消息体总长度, 所述第六消息体总长度表示的是所述报文所属消息的消 息体总长度。 Receive the total length of the sixth message body sent by the application layer, and update the total length of the second message body with the total length of the sixth message body, where the total length of the sixth message body represents the message to which the message belongs. total body length.
5、 如权利要求 2所述的报文转发的方法, 其特征在于, 在所述第三消息体 总长度与所述第一消息体长度之和小于或等于所述第二消息体总长度时, 所述 方法还包括: 将所述第三消息体总长度更新为所述第三消息体总长度与所述第一消息体 长度之和。 5. The message forwarding method according to claim 2, wherein the sum of the total length of the third message body and the length of the first message body is less than or equal to the total length of the second message body. , the method also includes: The total length of the third message body is updated to the sum of the total length of the third message body and the length of the first message body.
6、 如权利要求 2至 5任一所述的报文转发的方法, 其特征在于, 所述获取所 述报文承载的第一消息体长度包括: 6. The message forwarding method according to any one of claims 2 to 5, characterized in that said obtaining the length of the first message body carried by the message includes:
接收网络层发送的所述报文的总长度和所述报文的网络层头长度; 获取所述报文的传输层头长度; Receive the total length of the message sent by the network layer and the network layer header length of the message; obtain the transport layer header length of the message;
用所述报文的总长度减去所述报文的网络层头长度, 再减去所述报文的传 输层头长度得到所述报文承载的第一消息体长度。 The length of the network layer header of the message is subtracted from the total length of the message, and then the length of the transport layer header of the message is subtracted to obtain the length of the first message body carried by the message.
7、 如权利要求 2至 5任一所述的报文转发的方法, 其特征在于, 所述获取所 述报文承载的第一消息体长度包括: 7. The message forwarding method according to any one of claims 2 to 5, characterized in that said obtaining the length of the first message body carried by the message includes:
获取所述报文的总长度; Get the total length of the message;
获取所述报文的传输层头长度; Obtain the transport layer header length of the message;
用所述报文的总长度减去减去所述报文的传输层头长度得到所述报文承载 的第一消息体长度。 The length of the first message body carried by the message is obtained by subtracting the length of the transport layer header of the message from the total length of the message.
8、 如权利要求 1至 7任一所述的报文转发的方法, 其特征在于, 所述判断所 述报文是否为报文流的首包包括: 8. The message forwarding method according to any one of claims 1 to 7, wherein the determining whether the message is the first packet of the message flow includes:
判断所述报文的五元组是否已被存储, 若所述报文的五元组没有被存储, 则所述报文为报文流的首包。 Determine whether the quintuple of the message has been stored. If the quintuple of the message has not been stored, the message is the first packet of the message flow.
9、 如权利要求 8所述的报文转发的方法, 其特征在于, 在所述报文为报文 流的首包时, 还包括: 9. The method of message forwarding according to claim 8, characterized in that, when the message is the first packet of the message flow, it also includes:
将所述报文的五元组进行存储。 Store the five-tuple of the message.
10、 一种报文转发的装置, 其特征在于, 所述装置包括: 10. A device for forwarding messages, characterized in that the device includes:
接收单元, 用于接收网络层发送的报文; The receiving unit is used to receive messages sent by the network layer;
判断单元, 用于判断所述接收单元接收到的报文是否为报文流的首包; 在 判断所述报文不是报文流的首包时, 判断所述报文是否为报文流中消息的首包; 转发单元, 在所述判断单元判断所述报文为报文流首包时, 向应用层转发 所述报文; 在所述判断单元判断所述报文为报文流中消息的首包时, 向应用层 转发所述报文; 在所述判断单元判断所述报文不是报文流中消息的首包时, 向 网络层转发所述报文。 A judgment unit, used to judge whether the message received by the receiving unit is the first packet of the message flow; when judging that the message is not the first packet of the message flow, judge whether the message is the first packet of the message flow. The first packet of the message; the forwarding unit, when the judgment unit judges that the message is the first packet of the message flow, forwards the message to the application layer; when the judgment unit judges that the message is in the message flow When the judgment unit determines that the message is not the first packet of the message in the message flow, the message is forwarded to the network layer.
11、 如权利要求 10所述的报文转发的装置, 其特征在于, 还包括获取单元, 所述获取单元用于获取所述报文承载的第一消息体长度; 获取存储的所述 报文所属消息的第二消息体总长度; 获取存储的所述报文所属消息已传输部分 的第三消息体总长度; 11. The device for message forwarding according to claim 10, further comprising an acquisition unit, the acquisition unit being used to acquire the length of the first message body carried by the message; The total length of the second message body of the message to which the message belongs; Obtaining the total length of the stored third message body of the transmitted part of the message to which the message belongs;
所述判断单元具体用于: The judgment unit is specifically used for:
在所述获取单元获取的第一消息体长度与所述获取单元获取的第三消息体 总长度之和大于所述获取单元获取的第二消息体总长度时, 确定所述报文为报 文流中消息的首包; When the sum of the length of the first message body obtained by the obtaining unit and the total length of the third message body obtained by the obtaining unit is greater than the total length of the second message body obtained by the obtaining unit, it is determined that the message is a message The first packet of the message in the stream;
在所述获取单元获取的第一消息体长度与获取单元获取的第三消息体总长 度之和小于或等于获取单元获取的第二消息体总长度时, 确定所述报文不是报 文流中消息的首包。 When the sum of the length of the first message body obtained by the obtaining unit and the total length of the third message body obtained by the obtaining unit is less than or equal to the total length of the second message body obtained by the obtaining unit, it is determined that the message is not in the message stream The first packet of the message.
12、 如权利要求 11所述的报文转发的装置, 其特征在于, 还包括计算单元 和第一更新单元, 在所述判断单元确定所述报文是报文流中消息的首包时, 在 所述转发单元向应用层转发所述报文后, 12. The device for message forwarding according to claim 11, further comprising a calculation unit and a first update unit, when the judgment unit determines that the message is the first packet of a message in the message flow, After the forwarding unit forwards the message to the application layer,
所述接收单元还用于接收应用层发送的所述报文中的消息头的长度; 所述计算单元用于用所述获取单元获取的第一消息体总长度加上所述获取 单元获取的第三消息体长度, 再减去所述获取单元获取的第二消息体总长度, 再减去所述接收单元接收到的报文中消息头的长度得到第五消息体总长度; 所述第一更新单元用于将所述第三消息体总长度更新为用所述计算单元计 算得到的所述第五消息体总长度。 The receiving unit is also used to receive the length of the message header in the message sent by the application layer; the calculating unit is used to add the total length of the first message body obtained by the obtaining unit to the total length obtained by the obtaining unit. The length of the third message body is obtained by subtracting the total length of the second message body obtained by the obtaining unit and subtracting the length of the message header in the message received by the receiving unit to obtain the total length of the fifth message body; An update unit is used to update the total length of the third message body to the total length of the fifth message body calculated by the calculation unit.
13、 如权利要求 11或 12所述的报文转发的装置, 其特征在于, 还包括第二 更新单元; 用层发送的第六消息体总长度, 所述第六消息体总长度表示的是所述报文所属 消息的消息体总长度; 13. The message forwarding device according to claim 11 or 12, further comprising a second update unit; the total length of the sixth message body sent by the layer, and the total length of the sixth message body represents The total length of the message body of the message to which the message belongs;
所述第二更新单元用于将所述第二消息体总长度更新为所述接收单元接收 到的第六消息体总长度。 The second update unit is configured to update the second message body total length to the sixth message body total length received by the receiving unit.
14、 如权利要求 11至 13任一所述的报文转发的装置, 其特征在于, 还包括 第三更新单元, 在所述判断单元判断获取单元获取的所述第一消息体长度与获 取单元获取的所述的第三消息体总长度之和小于或等于获取单元获取的所述第 二消息体总长度时, 14. The device for message forwarding according to any one of claims 11 to 13, characterized in that it further includes a third update unit, and the judging unit judges that the length of the first message body obtained by the obtaining unit is the same as the length of the first message body obtained by the obtaining unit. When the obtained total length of the third message body is less than or equal to the total length of the second message body obtained by the obtaining unit,
所述第三更新单元用于将所述第三消息体总长度更新为所述第三消息体总 长度与所述第一消息体长度之和。 The third update unit is configured to update the total length of the third message body to the sum of the total length of the third message body and the length of the first message body.
15、 如权利要求 11至 14任一所述的报文转发的装置, 其特征在于, 所述接收单元还用于接收网络层发送的所述报文的总长度和所述报文的网 络层头长度; 15. The device for forwarding messages according to any one of claims 11 to 14, characterized in that the receiving unit is further configured to receive the total length of the message sent by the network layer and the network layer of the message. head length;
所述获取单元还用于: 获取所述报文的传输层头长度; 用接收单元接收到 长度得到所述报文承载的第一消息体长度。 The obtaining unit is also used to: obtain the length of the transport layer header of the message; use the length received by the receiving unit to obtain the length of the first message body carried by the message.
16、 如权利要求 11至 14任一所述的报文转发的装置, 其特征在于, 所述获 取单元还用于: 16. The device for forwarding messages according to any one of claims 11 to 14, characterized in that the acquisition unit is also used to:
获取所述报文的总长度; 获取所述报文的传输层头长度; 用所述报文的总 长度减去减去所述报文的传输层头长度得到所述报文承载的第一消息体长度。 Obtain the total length of the message; Obtain the transport layer header length of the message; Subtract the transport layer header length of the message from the total length of the message to obtain the first value carried by the message. Message body length.
17、 如权利要求 10至 16任一所述的报文转发的装置, 其特征在于, 所述判 断单元判断所述报文是否为报文流的首包包括: 没有被存储, 则所述报文为报文流的首包。 17. The device for forwarding messages according to any one of claims 10 to 16, characterized in that the judgment unit determines whether the message is the first packet of the message flow by: not being stored, then the message The packet is the first packet of the message flow.
18、 如权利要求 17所述的报文转发的装置, 其特征在于, 还包括存储单元, 在所述报文为报文流的首包时, 18. The device for forwarding messages according to claim 17, further comprising a storage unit, when the message is the first packet of the message flow,
所述存储单元将所述报文的五元组进行存储。 The storage unit stores the five-tuple of the message.
PCT/CN2014/074126 2013-10-25 2014-03-26 Method and apparatus for forwarding packet WO2015058490A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310511205.1 2013-10-25
CN201310511205.1A CN103561007B (en) 2013-10-25 2013-10-25 The method and device that a kind of message forwards

Publications (1)

Publication Number Publication Date
WO2015058490A1 true WO2015058490A1 (en) 2015-04-30

Family

ID=50015157

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/074126 WO2015058490A1 (en) 2013-10-25 2014-03-26 Method and apparatus for forwarding packet

Country Status (2)

Country Link
CN (1) CN103561007B (en)
WO (1) WO2015058490A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103561007B (en) * 2013-10-25 2016-10-05 华为技术有限公司 The method and device that a kind of message forwards

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6463071B1 (en) * 1998-08-17 2002-10-08 3Com Corporation Method and system to communicate prioritized traffic via fixed length data communication frames
CN101110772A (en) * 2007-08-13 2008-01-23 杭州华三通信技术有限公司 Device and method for handling message
CN102325124A (en) * 2011-05-23 2012-01-18 北京网康科技有限公司 Flow-guiding function-supported application identification equipment and method
CN103561007A (en) * 2013-10-25 2014-02-05 华为技术有限公司 Method and device for forwarding messages

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7325070B1 (en) * 2002-08-26 2008-01-29 Network Appliance, Inc. Sub-application layer data transfer in a network comprising a layered architecture
CN102215231A (en) * 2011-06-03 2011-10-12 华为软件技术有限公司 Data forwarding method and gateway

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6463071B1 (en) * 1998-08-17 2002-10-08 3Com Corporation Method and system to communicate prioritized traffic via fixed length data communication frames
CN101110772A (en) * 2007-08-13 2008-01-23 杭州华三通信技术有限公司 Device and method for handling message
CN102325124A (en) * 2011-05-23 2012-01-18 北京网康科技有限公司 Flow-guiding function-supported application identification equipment and method
CN103561007A (en) * 2013-10-25 2014-02-05 华为技术有限公司 Method and device for forwarding messages

Also Published As

Publication number Publication date
CN103561007A (en) 2014-02-05
CN103561007B (en) 2016-10-05

Similar Documents

Publication Publication Date Title
US9584398B2 (en) Methods and apparatus to utilize route parameter sets for exchanging routes in a communication network
US20240007376A1 (en) Network Performance Parameter Sending Method, Network Performance Calculation Method, and Network Node
US11979322B2 (en) Method and apparatus for providing service for traffic flow
WO2019128950A1 (en) Packet processing method, network node, and system
EP2874116A1 (en) Communication method between content requester and content provider for providing content and real-time streaming content in content name-based content centric network
JP6269999B2 (en) Packet processing method and apparatus
US10791051B2 (en) System and method to bypass the forwarding information base (FIB) for interest packet forwarding in an information-centric networking (ICN) environment
EP2996309B1 (en) Interest keep alives at intermediate routers in a ccn
US10505759B2 (en) Access layer-2 virtual private network from layer-3 virtual private network
US20160112337A1 (en) Dynamically Offloading Flows from a Service Chain
US20230208721A1 (en) Determining network topology based on packet traffic
US20240106751A1 (en) Method and apparatus for processing detnet data packet
WO2023221452A1 (en) Packet processing system and method, device, and storage medium
US20160119848A1 (en) Method for service data management, apparatus, and system
EP3166263B1 (en) Routing calculation method and device for trill isis
EP2717519A2 (en) Method and apparatus for transferring bootstrap message
JP5935897B2 (en) COMMUNICATION NODE, COMMUNICATION SYSTEM, CONTROL DEVICE, PACKET TRANSFER METHOD, AND PROGRAM
WO2015058490A1 (en) Method and apparatus for forwarding packet
WO2015096734A1 (en) Downlink transmission method for service data, and packet data gateway
US20220329518A1 (en) Mechanisms for packet path tracing and per-hop delay measurement in segment routing with multiprotocol label switching (sr-mpls) networks
CN114157730A (en) Message duplicate removal method and device
WO2017088718A1 (en) Method and apparatus for transmitting control message
US10367725B2 (en) Network programming
WO2012167477A1 (en) Ipv6 message processing method and device
CN114285791B (en) Data transmission method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14856320

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14856320

Country of ref document: EP

Kind code of ref document: A1