A flow control method for managing data flows on a computer network, adapted to be implemented by a network device that is configured to process the data flows and that communicates with at least one upstream node and at least one downstream node, the network device receiving packets from the at least one upstream node and forwarding the packets to the at least one downstream node, each of the packets belonging to one of the data flows, the network device including a plurality of per-flow buffer usage (FBU) counters that respectively correspond to the data flows, a default egress queue (DEQ), and a plurality of pause egress queues (PEQs), the DEQ and the PEQs respectively corresponding to a plurality of priority levels, the flow control method comprising steps of:
- for each of the FBU counters, repeatedly obtaining a value that is recorded by the FBU counter and that indicates a total of packet sizes of packets which belong to one of the data flows that corresponds to the FBU counter, which are enqueued into one of the DEQ and the PEQs and which are not yet transmitted to the at least one downstream node;
- for each of the FBU counters, when it is determined that the value of the FBU counter is greater than a per-flow pause threshold, sending a first transmitted pause frame followed by a first transmitted migrate frame to one of the at least one upstream node that is outputting one of the data flows which corresponds to the FBU counter, the first transmitted migrate frame indicating a flow identifier (FID) that corresponds to the one of the data flows which corresponds to the FBU counter, the first transmitted pause frame indicating a first indicated one of the priority levels that corresponds to the one of the data flows which corresponds to the FBU counter, and a first pause duration that corresponds to the first indicated one of the priority levels;
- when it is determined that an incoming packet received from the at least one downstream node is a first received pause frame, according to a second pause duration and a second indicated one of the priority levels indicated by the first received pause frame, stopping dequeuing one of the PEQs that corresponds to the second indicated one of the priority levels for the second pause duration;
- when it is determined that an incoming packet received from the at least one downstream node is a first received migrate frame, according to an FID indicated by the first received migrate frame, enqueuing a to-be-forwarded packet that belongs to one of the data flows which corresponds to the FID indicated by the first received migrate frame into one of the PEQs that corresponds to one of the priority levels which corresponds to the one of the data flows that corresponds to the FID, rather than enqueuing the to-be-forwarded packet into the DEQ;
- for each of the FBU counters, when it is determined that a previous value of the FBU counter was greater than the per-flow pause threshold and a current value of the FBU counter is smaller than a per-flow resume threshold, sending a first transmitted resume frame followed by a first transmitted migrate-back frame to one of the at least one upstream node that is outputting one of the data flows that corresponds to the FBU counter, the first transmitted resume frame indicating one of the priority levels that corresponds to the one of the data flows which corresponds to the FBU counter, the first transmitted migrate-back frame indicating an FID that corresponds to the one of the data flows which corresponds to the FBU counter;
- when it is determined that an incoming packet received from the at least one downstream node is a first received resume frame that indicates one of the priority levels, resuming dequeuing one of the PEQs that corresponds to the one of the priority levels until the one of the PEQs is empty, and then dequeuing the DEQ;
- and
- when it is determined that an incoming packet received from the at least one downstream node is a first received migrate-back frame, according to an FID indicated by the first received migrate-back frame, enqueuing into the DEQ a to-be-forwarded packet that belongs to one of the data flows which corresponds to the FID indicated by the first received migrate-back frame, rather than enqueuing the to-be-forwarded packet into one of the PEQs.