Disclosure of Invention
In view of this, embodiments of the present application provide a data packet sending method and apparatus, which can solve the problem that when data in the same data flow is large, more data packets are congested at a port to wait for forwarding, and implement balanced port data packet forwarding.
The embodiment of the application provides a data packet sending method, which comprises the following steps:
a first device receives a first data packet of a first data stream, wherein the first data packet is a non-first data packet of the first data stream;
the first device obtains a time difference between a receiving time of the first data packet and a receiving time or a sending time of a second data packet, wherein the second data packet is a previous data packet of the first data packet and belongs to the first data stream;
when the time difference is greater than or equal to a threshold value, the first device sends the first data packet to a second device through a first port, the first port is a port other than a second port in N ports between the first device and the second device, the second port is a port for sending the second data packet to the second device, the threshold value is determined according to the maximum link transmission delay of the ports, and N is an integer greater than or equal to 2.
Optionally, the method further comprises:
and the first equipment determines the first port from the N-1 ports according to the bandwidth utilization rate of the N-1 ports except the second port.
Optionally, the first port is a port with the lowest bandwidth utilization rate among the N-1 ports.
Optionally, the method further comprises:
and when the time difference is smaller than a threshold value, the first device sends the first data packet to the second device through the second port.
Optionally, before the first device determines the time difference according to the receiving time of the first data packet and the receiving time of the second data packet, the method further includes:
the first device obtains the receiving time of the second data packet according to the stream characteristic information of the first data stream and the corresponding relationship, wherein the corresponding relationship is the corresponding relationship between the stream characteristic information and the receiving time of the second data packet, and the stream characteristic information reflects the characteristics of the first data stream.
Optionally, after the first device receives the first packet of the first data stream, the method further includes:
the first device stores a correspondence between stream characteristic information of a first data stream and a reception time of the first data packet.
Optionally, the method further comprises:
the first equipment acquires link transmission time delay corresponding to each port in the N ports;
and the first equipment determines the maximum value of the link transmission delay corresponding to each port as the maximum link transmission delay of the N ports.
Optionally, the obtaining, by the first device, the link transmission delay corresponding to the first port includes:
the first equipment sends an Internet Control Message Protocol (ICMP) request message to the second equipment through the first port, and receives an ICMP response message sent by the second equipment according to the ICMP request message;
and the first equipment determines the link transmission time delay corresponding to the first port according to the sending time of the ICMP request message and the receiving time of the ICMP response message.
An embodiment of the present application further provides a data packet sending apparatus, where the apparatus includes:
a receiving unit, configured to receive a first data packet of a first data stream, where the first data packet is a non-first data packet of the first data stream;
an obtaining unit, configured to obtain a time difference between a receiving time of the first data packet and a receiving time or a sending time of a second data packet, where the second data packet is a previous data packet of the first data packet that belongs to the first data flow;
a sending unit, configured to send the first data packet to a second device through a first port when the time difference is greater than or equal to a threshold, where the first port is a port other than a second port among N ports between the first device and the second device, the second port is a port that sends the second data packet to the second device, the threshold is determined according to a maximum link transmission delay of the multiple ports, and N is an integer greater than or equal to 2.
Optionally, the apparatus further comprises:
and the determining unit is used for determining the first port from the N-1 ports according to the bandwidth utilization rate of the N-1 ports except the second port.
The embodiment of the application provides a data packet sending method, wherein a first device obtains a time difference between receiving time of a first data packet and receiving time or sending time of a second data packet, the first data packet and the second data packet belong to the same data flow, the second data packet is received before the first data packet, whether the time difference is larger than a threshold value or not is judged, if the time difference is larger than the threshold value, it is indicated that time delay between the first data packet and the second data packet is larger than maximum link transmission time delay of a plurality of ports, the first data packet and the second data packet can be forwarded to a second device through different ports, pressure of the second port for sending the second data packet is reduced, the problem that more data packets are congested on the second port of the second data packet to wait for forwarding is avoided, and balanced port data packet forwarding is achieved.
Detailed Description
In order to make the technical solutions of the present application better understood, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
As described in the background, for data packets of the same data flow, the communication device usually uses the same port to forward, so as to ensure the timing when each data packet in the same data flow reaches the next communication device or destination terminal, i.e. ensure that the sequence of each data packet in the same data flow is not disturbed.
However, this method does not consider the issue of the transmission pressure and the utilization rate of the ports, and when data in a certain data flow is large, the pressure of the port for forwarding the data packet is large, and when data in another data flow is small, the pressure of the port for forwarding the data packet is small, which causes the pressure for transmitting the data packet to be different between the two ports, that is, the distribution of the data packet to the ports is unbalanced. And when the data in the same data flow is larger, it may cause more data packets to be congested at the port to wait for forwarding, and even cause the port to forward the lost data packet, which is not favorable for forwarding the data packet,
based on this, an embodiment of the present application provides a data packet sending method, where a first device obtains a time difference between a receiving time of a first data packet and a receiving time or a sending time of a second data packet, where the first data packet and the second data packet belong to the same data flow, and the second data packet is received before the first data packet, and determines whether the time difference is greater than a threshold, and if the time difference is greater than the threshold, it indicates that a time delay between the first data packet and the second data packet is greater than a maximum link transmission time delay of multiple ports, and the first data packet and the second data packet may be forwarded to the second device through different ports, so as to reduce a pressure of the port sending the second data packet, avoid a problem that more data packets are congested on the port of the second data packet to wait for forwarding, and implement balanced forwarding of port data packets.
Referring to fig. 1, the figure is a flowchart of a data packet sending method according to an embodiment of the present application.
The data packet sending method provided by the embodiment comprises the following steps:
s101, a first device receives a first data packet of a first data stream, wherein the first data packet is a non-first data packet of the first data stream.
In the embodiment of the present application, the first device is any one of communication devices on a packet forwarding path, and may be a switch, for example. The data packets included in the data stream have a fixed sequence order, and the data packets in the data stream are transmitted in the fixed sequence order when being transmitted. The communication device may transmit packets of a plurality of data streams, each data stream having corresponding stream characteristic information characterizing the data stream as an identifier identifying to which data stream the packet belongs. The Flow characteristic information of the data Flow may be a unique identification (Flow ID) of the data Flow, or may be a hash value generated by a hash algorithm from a source physical (MAC) address, a destination MAC address, a source Internet Protocol (IP) address, a destination IP address, a source port number, and a destination port number of the data Flow during transmission.
In an embodiment of the present application, the first device receives a first packet of the first data stream, where the first packet is a non-first packet of the first data stream, that is, the first device has received other packets of the first data stream before receiving the first packet of the first data stream.
S102, the first device obtains a time difference between a receiving time of the first data packet and a receiving time or a sending time of a second data packet, where the second data packet is a previous data packet of the first data packet belonging to the first data stream.
In an embodiment of the application, the first device has received the second data packet of the first data stream before receiving the first data packet of the first data stream, and possibly the second data packet has been sent out by the first device. That is, the first packet and the second packet belong to the same data flow, the first data flow, and the second packet is a previous packet of the first packet received by the first device.
In the embodiment of the application, the first device obtains the receiving time of the second data packet or the sending time of the second data packet sent by the first device by obtaining the receiving time of the first data packet, and calculates the time difference, wherein the time difference is the time difference between the receiving time of the first data packet and the receiving time or the sending time of the second data packet.
After the first device receives the first packet of the first data stream, the corresponding relationship between the stream characteristic information of the first data stream and the receiving time of the first packet may be stored, and then the first device may determine the receiving time of the first packet through the stream characteristic information of the first data stream and the corresponding relationship. Specifically, the correspondence between the stream characteristic information of the first data stream and the reception time of the first data packet may be a time stamp of the data packet in the first data stream.
After the first device receives the second packet of the first data stream, the corresponding relationship between the stream characteristic information of the first data stream and the receiving time of the second packet may be stored, and then the first device may determine the receiving time of the second packet through the stream characteristic information of the first data stream and the corresponding relationship.
S103, when the time difference is greater than or equal to a threshold, the first device sends the first data packet to a second device through a first port, where the first port is a port other than a second port in N ports between the first device and the second device, the second port is a port for sending the second data packet to the second device, the threshold is determined according to a maximum link transmission delay of the multiple ports, and N is an integer greater than or equal to 2.
In an embodiment of the present application, the first device includes N ports, where the N ports can all transmit data packets to the second device, and N is an integer greater than or equal to 2.
The first device may send a second packet of the first data stream to the second device through a second port, where the second port is one of the N ports.
When a first device sends a packet of a first data stream to a second device through a port, a link transmission delay may exist between the first device and the second device, and each port corresponds to a different link transmission delay.
The maximum link transmission delay of the N ports of the first device may be determined by:
the first device obtains the link transmission delay corresponding to each port in the N ports, and then the first device determines the maximum value in the link transmission delay corresponding to each port as the maximum link transmission delay of the N ports.
As a possible implementation manner, the first device may obtain the link transmission delay corresponding to the first port in the following manner:
the first device sends an Internet Control Message Protocol (ICMP) request message to the second device through the first port, receives an ICMP response message sent by the second device according to the ICMP request message, and then determines link transmission delay corresponding to the first port according to sending time of the ICMP request message and receiving time of the ICMP response message. Specifically, the time difference between the sending time of the ICMP request message and the receiving time of the ICMP response message is 2 times of the link transmission delay corresponding to the first port.
By the above method, not only the link transmission delay of the first port but also the link transmission delay of each port of the N ports can be obtained, and the link transmission delay corresponding to other ports can be obtained by switching the first port to other ports. And when the link transmission delay of each port is obtained specifically, the link data transmission of other ports is closed to avoid the influence of other ports.
In the embodiment of the application, after the time difference between the receiving time of the first data packet and the receiving time or the sending time of the second data packet is acquired by the first device, whether the time difference is greater than or equal to the threshold value is judged. Wherein the threshold is determined according to the maximum link transmission delay of the N ports.
In an embodiment of the application, the threshold is at least greater than or equal to a maximum link transmission latency of the N ports.
If the time difference is smaller than the threshold, or the time difference is smaller than the maximum link transmission delay of the N ports, the first device still sends the first data packet to the second device through the second port, that is, the first data packet and the second data packet are sent to the second device through the same second port. This is to prevent the second device from receiving the first packet before receiving the second packet when the first packet is transmitted to the second device through the port other than the second port, which may cause an error in the order of the first packet and the second packet.
If the time difference is greater than the threshold, or the time difference is greater than the maximum link transmission delay of the N ports, the first device sends the first data packet to the second device through a port other than the second port, that is, the first data packet and the second data packet are sent through different ports. Therefore, when the sending pressure of the data packet of the second port is higher, the data packet of the first data flow can be sent through the ports except the second port in the N ports, the problem that more data packets are congested at the second port to wait for forwarding is avoided, and the balanced forwarding of the data packet of the port is realized.
Because the time difference between the receiving times of the first data packet and the second data packet is greater than the maximum link transmission delay of the plurality of ports, when the first data packet and the second data packet are sent through different ports, the second data packet is still received by the second device first, and then the first data packet is received by the second device, so that the sequence of the first data packet and the second data packet cannot be changed.
In the embodiment of the present application, after determining that the time difference between the receiving time of the first data packet and the receiving time or the sending time of the second data packet is greater than the threshold, the first data packet may not be sent from the second port of the second data packet, and may be sent through the first port.
The first port may be any one of N-1 ports except the second port, and specifically, the first port may be selected by bandwidth utilization of the N-1 ports except the second port. The bandwidth utilization rate of the port is the pressure of the port for sending the data packet, and the lower the bandwidth utilization rate is, the lower the pressure of the port for sending the data packet is.
As a possible implementation manner, the bandwidth utilization rates of N-1 ports except for the second port may be sorted from large to small, and any one of the ports M bits after the bandwidth utilization rate is determined as the first port. M is an integer greater than or equal to 2.
As another possible implementation manner, the bandwidth utilization rates of N-1 ports except for the second port may be sorted from large to small, and the port with the last bit of the bandwidth utilization rate is determined as the first port, so that the problem that more data packets are congested on the second port and wait for forwarding is avoided, and balanced port data packet sending is further achieved. M is an integer greater than or equal to 2.
In the embodiment of the present application, if it is determined that the data packet of the first data flow is not sent through the first device after the first device detects the flow characteristic information of the first data flow, the data packet of the first data flow is directly sent through the first port, so as to equalize the pressure of sending the data packet between the ports.
Fig. 2 is a schematic diagram of a data packet sending method according to an embodiment of the present application. Thefirst device 210 sends a data packet to thesecond device 220, and both thefirst device 210 and thesecond device 220 have two ports, the first port of the first device and the first port of the second device form alink 201 for data packet transmission, and the second port of the first device and the second port of the second device form alink 202 for data packet transmission.
When thefirst device 210 receives thepacket 1 of the first data flow, the flow characteristic information of the first data flow is detected, and it is determined that the packet of the first data flow is not sent by the first device, and then thepacket 1 is sent to the second device by using the port with the lower bandwidth utilization rate. If the bandwidth utilization rates of the first port and the second port are the same or no packet is sent, any one of the ports is selected to send the packet, for example, thefirst device 210 sends thepacket 1 to thesecond device 220 through the first port.
When thefirst device 210 receives thedata packet 2 of the first data stream, the time difference between the receiving time of thedata packet 2 and the receiving time or the sending time of thedata packet 1 is obtained, and the time difference is smaller than the threshold, then thedata packet 2 and thedata packet 1 are sent by using the same first port.
When thefirst device 210 receives thedata packet 3 of the first data stream, the time difference between the receiving time of thedata packet 3 and the receiving time or the sending time of thedata packet 2 is obtained, and the time difference is smaller than the threshold, then thedata packet 3 and thedata packet 2 are sent by using the same first port.
When thefirst device 210 receives the packet 4 of the first data stream, a time difference between a reception time of the packet 4 and a reception time or a transmission time of thepacket 3 is obtained, and the time difference is greater than a threshold, the packet 4 and thepacket 3 are no longer transmitted using the same first port, and the packet 4 is transmitted using a second port other than the first port among the plurality of ports between thefirst device 210 and thesecond device 220.
When thefirst device 210 receives thedata packet 5 of the first data stream, the time difference between the receiving time of thedata packet 5 and the receiving time or the sending time of the data packet 4 is obtained, and the time difference is smaller than the threshold, then thedata packet 5 and the data packet 4 are sent by using the same second port.
When thefirst device 210 receives the packet 6 of the first data stream, a time difference between a reception time of the packet 6 and a reception time or a transmission time of thepacket 5 is obtained, and the time difference is greater than a threshold, the packet 6 and thepacket 5 are no longer transmitted using the same second port, and the packet 6 is transmitted using a first port other than the second port among the plurality of ports between thefirst device 210 and thesecond device 220.
When thefirst device 210 receives thedata packet 7 of the first data stream, the time difference between the receiving time of thedata packet 7 and the receiving time or the sending time of the data packet 6 is obtained, and the time difference is smaller than the threshold, then the data packet 6 and thedata packet 5 are sent by using the same first port.
The data packet sending method provided by the embodiment of the application can be applied to an Open network operating system (Software for Open Networking in the Cloud, SONiC).
Therefore, according to the data packet sending method provided in the embodiment of the present application, the first device obtains a time difference between a receiving time of the first data packet and a receiving time or a sending time of the second data packet, where the first data packet and the second data packet belong to the same data flow, and the second data packet is received before the first data packet, and determines whether the time difference is greater than a threshold, if the time difference is greater than the threshold, it indicates that a time delay between the first data packet and the second data packet is greater than a maximum link transmission time delay of multiple ports, and the first data packet and the second data packet may be forwarded to the second device through different ports, so as to reduce a pressure of the second port sending the second data packet, avoid a problem that more data packets are congested at the second port of the second data packet and wait for forwarding, and implement balanced forwarding of the port data packets.
Based on the data packet sending method provided by the above embodiment, the embodiment of the present application further provides a data packet sending device, and the working principle of the data packet sending device is described in detail below with reference to the accompanying drawings.
Referring to fig. 3, this figure is a block diagram of a data packet sending apparatus according to an embodiment of the present application.
Thepacket transmission apparatus 300 according to the present embodiment includes:
a receivingunit 310, configured to receive a first data packet of a first data stream, where the first data packet is a non-first data packet of the first data stream;
an obtainingunit 320, configured to obtain a time difference between a receiving time of the first data packet and a receiving time or a sending time of a second data packet, where the second data packet is a previous data packet of the first data packet that belongs to the first data flow;
a sendingunit 330, configured to send the first data packet to a second device through a first port when the time difference is greater than or equal to a threshold, where the first port is a port other than a second port in N ports between the first device and the second device, the second port is a port that sends the second data packet to the second device, the threshold is determined according to a maximum link transmission delay of the multiple ports, and N is an integer greater than or equal to 2.
Optionally, the apparatus further comprises:
and the determining unit is used for determining the first port from the N-1 ports according to the bandwidth utilization rate of the N-1 ports except the second port.
When introducing elements of various embodiments of the present application, the articles "a," "an," "the," and "said" are intended to mean that there are one or more of the elements. The terms "comprising," "including," and "having" are intended to be inclusive and mean that there may be additional elements other than the listed elements.
It should be noted that, as one of ordinary skill in the art would understand, all or part of the processes of the above method embodiments may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when executed, the computer program may include the processes of the above method embodiments. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to some descriptions of the method embodiment for relevant points. The above-described apparatus embodiments are merely illustrative, and the units and modules described as separate components may or may not be physically separate. In addition, some or all of the units and modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is directed to embodiments of the present application and it is noted that numerous modifications and adaptations may be made by those skilled in the art without departing from the principles of the present application and are intended to be within the scope of the present application.