Hope this report will help to unlock your problem:
http://sci.tamucc.edu/~cams/projects/407.pdf
Another code with a marking scheme for QoS purpose : http://www.cs.technion.ac.il/Courses/Computer-Networks-Lab/projects/spring2008/WRED1/Final%20Submission/final.html