forcemax's

Linux Traffic Control

Linux2008. 6. 24. 10:02
일반적으로 저속의 상황을 시뮬레이션하기 위해서는 Client의 Traffic을 제한할 필요가 있다. QOS에 관련하여 알아보던 중 Incoming Traffic을 제한하는 방법은 Ingress Policing 밖에 없음을 알게되었다.

알게된 상황을 정리해 보면.

ingress policing : incoming traffic control
egress shaping : outgoing traffic control

ingress policing은 오직 한가지 방법만이 존재하며 다음 링크에서 살펴볼 수 있다.
http://blog.stevedoria.net/20050906/ingress-policing-with-linux-and-tc

내가 작성한 ingress policing script는 다음과 같다.

#!/bin/bash

TC=/sbin/tc
DEV=eth0
MAX=400

# clear all queuing on the device.
${TC} qdisc del dev ${DEV} root 2> /dev/null > /dev/null
${TC} qdisc del dev ${DEV} ingress 2> /dev/null > /dev/null

# Handle the speed of the traffic coming from network
# Add a limiter to the ingress
${TC} qdisc add dev ${DEV} handle ffff: ingress
# Set the maximum limit
${TC} filter add dev ${DEV} parent ffff: protocol ip prio 2 u32 match ip src 0.0.0.0/0 police rate ${MAX}kbps burst 100kb drop

위 스크립트는 ubuntu 8.04에서 잘 돌아간다. 내용은 incoming traffic의 속도를 400kbytes/sec로 제한하는 것이다.

debian etch에서는 위 스크립트로 동작이 안되는데 마지막 줄을 다음과 같이 수정한다.

${TC} filter add dev ${DEV} parent ffff: protocol ip prio 2 u32 match ip src 0.0.0.0/0 police rate ${MAX}kbps burst 100kb drop flowid :1