Article View: cn.comp.os.linux
Article #13917TC
From: Alvis
Date: Wed, 12 Dec 2001 01:34
Date: Wed, 12 Dec 2001 01:34
205 lines
12784 bytes
12784 bytes
Linux ���ӵĴ�����ϵͳ TC (�������ƣ�Traffic Control)��
��ϵͳ֧�ַ��ࡢ���ȡ���������롢����������Ƶȡ�����ϵͳ������
ר�õĴ�����ϵͳ��������
1. ��Ĺ��ɿ�
tc ���������Ĺ��ɿ飺
���й涨��queueing discipline �����ࣨclass���ͷ�������Cl-
assifiers��
���й涨���Կ����豸������/��ݰ��������
���й涨�ڷ�װ������������ҪTC�������ͷ����������������
��������Ŀǰ����һЩ�豸���й涨�������������豸����������
�У�CBQ�������ȼ���CSZ��Clark-Shenker-Zhang���ȡ�CBQ ��һ�ֳ�
�����У������ܹ���������У���������CBQ����
�����豸���й涨�����?�������ɹ���rule�����ɣ���Щ����
���Թ����Ǹ�����ӵ�е���ݡ����磬ij�����ȫ����ݰ��ܵ� 1Mbps
�������ȣ�������ҹ������6���һ��ʱ�����������ߴ� 3 Mbps��
һЩ���й涨�������ϣ�����FIFO���Ƚ��ȳ�����RED�����
����̽�⣩��SFQ�����ƽ���У�������Ͱ��Token Bucket�������
�豸��δ���й涨����ʹ�û��FIFO�����⣬ CBQ��CSZ������
��Ҳ�������࣬�Լ�������ࡣ�����ʹ��TC���������ɵؽ���dz�
���ӵ��������ơ�������Ķ��й涨���Գ�Ϊ����й涨��class qu-
eueing disciplines����һ��أ�����й涨����������ݺͶ��У�
�ܾ����ӳ١������������·��������İ�������������������
���Ұ�����ӳ�䵽���й涨�������ࡣ
��Щ������ͨ�����ṩ���������ԣ�ָ��ѡ���Ѱ�ӳ�䵽��
�ķ�����Ŀǰ��TC����ʹ�õĹ������У�fwmark��������u32��������
����·�ɵķ�������RSVP���������ֱ�����IPV6��IPV4���ȣ����У�fw-
mark��������������ʹ�� Linux netfilter����ѡ����������u32����
����������ѡ����� ANY ͷ������ �����еķ���ǽ�����������磬ip-
chains���������������
TC����λ���ںˣ���ͬ�Ĺ��ܿ���ܱ���Ϊģ�飬Ҳ��ֱ�ӱ���ںˡ�
���ں˴����ģ���ͨ�ź��������û�������tc��ɡ�
2. ʾ��
2.1 �����ں�
����Ҫȷ��ѡ�� Kernel/User netlink socket����Ϊֻ������ tc ��
��ͨ�� netlink ���ں�ͨѶ��
Ȼ�Ѷ��й涨�ͷ�����������ںˡ������а�����
QoS or fair queueing, CBQ packet scheduler, CSZ packet scheduler,
the simplest PRIO pseudoscheduler, RED queue, SFQ queue, TBF queue,
QoS support, rate estimator, packet classifier API, routing-tables-
based classifier, U32 classifier, special RSVP classifier �� special
RSVP classifier for IPv6��
Ȼ����Ǵ����֪�ı���Ͱ�װ����ˡ�
2.2 ����
[������] ---��E3��T3 �ȡ�--- [Linux ·����] --- [Office+ISP]
eth1 eth0
��ͼ�е� Linux ·�����������ӿڣ�������֮Ϊ eth0 �� eth1��eth1 ����
��·������eth0 ���ӵ�������˾����ǽ���ڵ������ϡ�
��������ֻ�����Ʒ��͵����ݣ�����������Ҫ�������ġ������ܷdz�����
�Ĺ������ǿ���ͨ��ı䷢�ʹ��������ƴ������ʡ�ͨ���� eth0 �ϵĶ�
�У����ǿ���ȷ���ͻ������أ�download�����ʣ�ͨ���� eth1 �ϵĶ��У���
�ǿ���ȷ�����ǹ�˾�Լ����û������أ�upload�����ʡ�
����˵����˾���ӵ����������·���Ϊ 10 �ף�ͬʱ�����ⲿ�ͻ���˾��
���û�����Ҫ����ʱ�����Ǿ���Ҫһ�ֲ��ԣ������й����Э����CBQ �Ϳ�����
�����ǵ�Ҫ��
�������������ࣺ'ISP' �� 'Office'�����ǿ��Ծ������ͻ��� 8 �Ĵ�?
Office�û��� 2 �Ĵ�?
�������ȷ������µ����
# tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt
1000
�京���ǣ����������� eth0 �Ķ��й涨��root ��ʾ���Ǹ�root���涨��
����handle���趨Ϊ 10:����
������Ϊ CBQ�����Ϊ 10 M��ƽ����СΪ 1000 �ֽڡ�
������ɸ��ࣨroot class����
# tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit
\
rate 10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000
����������ʵ����ǰһ�������и��ĺ��塣���У�1514 �� MTU ��ֵ��
������� ISP �ࣺ
# tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth
10Mbit \
rate 8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000
bounded
���Ƿ����� 8 �Ĵ��������� bounded ��ʾ����ܳ���÷�ֵ��
������� Office �ࣺ
# tc class add dev eth0 parent 10:1 classid 10:200 cbq bandwidth
10Mbit \
rate 2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000
bounded
Ϊ�˸�����������ǵ����������ͼ��ʾ��
+-------------[10: 10Mbit]-------------------------+
|+-------------[10:1 root 10Mbit]-----------------+|
|| ||
|| +-----[10:100 8Mbit]---------+ [10:200 2Mbit] ||
|| | | | | ||
|| | ISP | | Office | ||
|| | | | | ||
|| +----------------------------+ +------------+ ||
|| ||
|+------------------------------------------------+|
+--------------------------------------------------+
�����Ѿ����ں�֪ͨ�����ǵ��࣬���ǻ���Ҫ�����ں���ι�����У�������ʾ
��
# tc qdisc add dev eth0 parent 10:100 sfq quantum 1514b perturb 15
# tc qdisc add dev eth0 parent 10:200 sfq quantum 1514b perturb 15
�������ʹ�������ƽ���У�sfq��������� CPU ���ڽ��ٵ�����£�����
��
���ǿ��Խ��ܵġ�����һЩ���й涨���ܸ�ã���Ҫռ�ý϶�� CPU ��Դ������
Ͱ
������Ҳ����ʹ�á�
���滹��һ����Ҫ���������ں����������ӳ���ϵ��
# tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip
\
dst 150.151.23.24 flowid 10:200
# tc filter add dev eth0 parent 10:0 protocol ip prio 25 u32 match ip
\
dst 150.151.0.0/16 flowid 10:100
������Ǽٶ� Office λ�ڷ���ǽ 150.151.23.24 �ĺ��棬���� IP ��ַ��
����
ISP��u32 ƥ����һ�ֱȽϼ�ƥ�䣬���ǿ���ʹ�� netfilter ��ɸ�Ӹ��ӵ�
ƥ��
����
�����Ѿ����������ش�?���������ش��ķ��䣺
# tc qdisc add dev eth1 root handle 20: cbq bandwidth 10Mbit avpkt
1000
# tc class add dev eth1 parent 20:0 classid 20:1 cbq bandwidth 10Mbit
\
rate 10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000
# tc class add dev eth1 parent 20:1 classid 20:100 cbq bandwidth
10Mbit \
rate 8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000
bounded
# tc class add dev eth1 parent 20:1 classid 20:200 cbq bandwidth
10Mbit \
rate 2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000
bounded
# tc qdisc add dev eth1 parent 20:100 sfq quantum 1514b perturb 15
# tc qdisc add dev eth1 parent 20:200 sfq quantum 1514b perturb 15
# tc filter add dev eth1 parent 20:0 protocol ip prio 100 u32 match ip
\
src 150.151.23.24 flowid 20:200
# tc filter add dev eth1 parent 20:0 protocol ip prio 25 u32 match ip
\
src 150.151.0.0/16 flowid 20:100
����ǰ���������һ�£����ԾͲ������Ľ����ˡ�
ע��
��ǰ��������У�����ע�����ʹ ISP �ͻ��������ߣ����ǵ� Office �û�
Ҳ
��Ȼֻ�� 2 M �Ĵ�?�����൱�˷ѵġ����ǿ���ɾ�� 'bounded' ��������
����֮��Ϳ�������ô���ˡ����ǣ�ijЩ��Ҳ�?ϣ������������ô�?��
�磬
һ����·�ϵ�������Ϊ������ֵ�ISP �����������������£����ǿ��Լ��Ϲؼ�
��
'isolated'��
3. ������
Ŀǰ��Linux ���ṩ�� QoS�����������������в���ϵͳ����ӡ������Ƶġ�
���⣬
BSD �� ALTQ Ӧ��˵Ҳ�൱���?���ǣ��ڸ����ԡ�����ԺͿ���չ�Եȷ���Ҫ��
��Lin-
ux һ��ء��Ҳ�̫�����IJ�Ʒ�Ƿ��ṩ���ⷽ��Ĺ��ܡ�Sun �� Solaris ��
����CBQ
�� RSVP �Ĺ��ܡ�
Linux Ҳ֧�� IETF diffserv ������
Linux �� QoS �����ڶ������������������ Linux ���г�ռ���ʡ�
Technical Details
Message-ID:
<9v6ca6$csv$1@mail.cn99.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news-out.spamkiller.net!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!news.cn99.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: 10b277,46a2bc06983e9fa3,start X-Google-Attributes: gid10b277,public X-Google-ArrivalTime: 2001-12-11 17:36:14 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news-out.spamkiller.net!propagator-la!news-in-la.newsfeeds.com!news-in.superfeed.net!news.cn99.com!not-for-mail From: "Alvis" <alvis@public.fhnet.cn.net> Newsgroups: cn.comp.os.linux Subject: TC Date: Wed, 12 Dec 2001 09:34:14 +0800 Organization: Bentium Ltd. (CN99) Lines: 207 Message-ID: <9v6ca6$csv$1@mail.cn99.com> NNTP-Posting-Host: 61.149.1.146 X-Trace: mail.cn99.com 1008120966 13215 61.149.1.146 (12 Dec 2001 01:36:06 GMT) X-Complaints-To: usenet@news.cn99.com NNTP-Posting-Date: Wed, 12 Dec 2001 01:36:06 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200