Data forwarding method, data buffering method, apparatus, and related device
A data forwarding method includes, after congestion of an egress queue is relieved, a network device that receives a packet from an upstream node, and determines whether a storage device associated with the egress queue buffers a previous packet that belongs to a same data flow as the packet. When the storage device does not buffer the previous packet, the network device schedules the packet to the egress queue, to forward the packet to a downstream node, where the storage device is configured to receive, during congestion of the egress queue, a packet sent by the network device.
1 . A method implemented by a network device, the method comprising:
receiving, from an upstream node, one or more packets during congestion of an egress queue of the network device;
buffering the one or more packets in a storage device associated with the egress queue;
receiving, from the upstream node, a first packet after the congestion is relieved;
obtaining a first flowkey of the first packet, wherein the first flowkey indicates a first data flow to which the first packet belongs;
determining, based on the first flowkey, whether a previous packet belonging to the first data flow is buffered in the storage device; and
scheduling the first packet to the egress queue to forward the first packet to a downstream node when the previous packet is not buffered in the storage device.
2 . The method of claim 1 , further comprising sending the first packet to the storage device for buffering when the previous packet is buffered in the storage device.
3 . The method of claim 1 , further comprising:
receiving a second packet; and
buffering the second packet in the storage device during congestion of the egress queue.
4 . The method of claim 1 , further comprising recording a quantity of packets of each data flow that are buffered in the storage device.
5 . The method of claim 4 , further comprising recording, in a flow table, the quantity of the packets of each data flow that are buffered in the storage device, wherein the flow table comprises at least one entry, and wherein each of the at least one entry comprises a flowkey and a packet quantity corresponding to the flowkey.
6 . The method of claim 5 , further comprising:
querying, based on the first flowkey, the flow table to obtain the packet quantity corresponding to the first data flow in the flow table;
determining that the previous packet is not buffered in the storage device when the packet quantity is equal to zero; and
determining that the previous packet is buffered in the storage device when the packet quantity is greater than zero.
7 . A network device comprising:
a memory configured to store computer instructions; and
a processor coupled to the memory and configured to execute the computer instructions to cause the network device to:
receive, from an upstream node, a one or more packets during congestion of an egress queue of the network device;
buffer the one or more packets in a storage device associated with the egress queue;
receive, from the upstream node, a first packet after the congestion is relieved;
obtain a first flowkey of the first packet, wherein the first flowkey indicates a first data flow to which the first packet belongs;
determine, based on the first flowkey, whether a previous packet belonging to the first data flow is buffered in the storage device; and
schedule the first packet to the egress queue to forward the first packet to a downstream node when the previous packet is not buffered in the storage device.
8 . The network device of claim 7 , wherein the processor is further configured to execute the computer instructions to cause the network device to: send the first packet to the storage device for buffering when the previous packet is buffered in the storage device.
9 . The network device of claim 7 , wherein the processor is further configured to execute the computer instructions to cause the network device to:
receive a second packet; and
buffer the second packet in the storage device during congestion of the egress queue.
10 . The network device of claim 7 , wherein the processor is further configured to execute the computer instructions to cause the network device to record a quantity of packets of each data flow that are buffered in the storage device.
11 . The network device of claim 10 , wherein the processor is further configured to execute the computer instructions to cause the network device to further record, in a flow table, the quantity of the packets of each data flow that are buffered in the storage device, wherein the flow table comprises at least one entry, and wherein each of the at least one entry comprises a flowkey and a packet quantity corresponding to the flowkey.
12 . The network device of claim 11 , wherein the processor is further configured to execute the computer instructions to cause the network device to:
query, based on the first flowkey, the flow table to obtain the packet quantity corresponding to the first data flow in the flow table;
determine that the previous packet is not buffered in the storage device when the second packet quantity is equal to zero; and
determine that the previous packet is buffered in the storage device when the second packet quantity is greater than zero.