The invention discloses a data packet processing method based on token bucket algorithm. The data packet processing method comprises the following steps: setting token buckets C, P and B with the current token numbers of TC, TP and TB respectively; receiving a data packet with X bytes; setting the data packet to red if the data packet is red; determining whether TB is less than X if the data packet is blue and, if so, setting the data packet to red, otherwise, setting the data packet to blue and reducing X from TC, TP and TB; determining whether TP is less than X if the data packet is not red nor blue and, if so, setting the data packet to read, otherwise, setting the data packet to yellow if the data packet is yellow, and reducing X from PX; and determining whether TC is less than X if the data packet is green and, if so, setting the data packet to yellow and reducing X from TP, otherwise, setting the data packet to blue, and reducing X from TC and TP. The invention further discloses a data packet processing method based on the token bucket algorithm.