我正在尝试对从某个进程组生成的数据包进行优先级排序,以便首先从PC中选择要传输的数据包。我的目标是通过使用cgroups和tc来实现这一点,但它似乎不起作用。
首先我在ubuntu上设置cgroup,如下所示:
modprobe cls_cgroup # load this module to get net_cls
mkdir /sys/fs/cgroup/net_cls # mount point
mount -t cgroup net_cls -onet_cls /sys/fs/cgroup/net_cls/
mkdir /sys/fs/cgroup/net_cls/foo # new cgroup
echo 0x00010001 > /sys/fs/cgroup/foo/net_cls.classid # echo in a class id
echo 2348 > /sys/fs/cgroup/net_cls/foo/tasks # echo in pid of firefox
tc qdisc add dev eth0 root handle 1: pri
tc qdisc add dev eth0 parent 1:1 handle 10: sfq
tc qdisc add dev eth0 parent 1:2 handle 20: sfq
tc qdisc add dev eth0 parent 1:3 handle 30: sfq在firefox中浏览并运行后,
tc -s qdisc ls dev eth0我明白了,
qdisc prio 1: root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 29351 bytes 154 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 10: parent 1:1 limit 127p quantum 1514b divisor 1024
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 20: parent 1:2 limit 127p quantum 1514b divisor 1024
Sent 27873 bytes 143 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
qdisc sfq 30: parent 1:3 limit 127p quantum 1514b divisor 1024
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0 相反,我希望流量在句柄10中流动,我做错了什么?
发布于 2013-07-03 04:04:15
要做到这一点,正确的方法需要通知tc您将使用cgroups。这一点已经在3.10内核的Ubuntu 12.04上得到了验证。
确保您具有net_cls支持
$ cat /proc/cgroups
#subsys_name hierarchy num_cgroups enabled
cpuset 1 2 1
cpu 1 2 1
cpuacct 1 2 1
memory 1 2 1
net_cls 1 2 1
blkio 1 2 1如果不是,
编译支持net_cls的内核
只需将所有这些选项放入您的.config中。这些似乎不存在于menuconfig中。
CONFIG_NET_CLS=y
CONFIG_NET_CLS_BASIC=m
CONFIG_NET_CLS_TCINDEX=m
CONFIG_NET_CLS_ROUTE4=m
CONFIG_NET_CLS_FW=m
CONFIG_NET_CLS_U32=m
CONFIG_NET_CLS_RSVP=m
CONFIG_NET_CLS_RSVP6=m
CONFIG_NET_CLS_FLOW=m
CONFIG_NET_CLS_CGROUP=y
CONFIG_NET_CLS_ACT=y
CONFIG_NET_CLS_IND=y然后制作并安装。
确保您有/etc/fstab条目
# echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
# reboot创建测试cgroup并设置它
如果没有设置cpuset,一些cgroup设置会报错。您还必须将您的主要和次要tc类ID转换为十六进制0xAAAABBBB,其中AAAA是主要的,BBBB是次要的。
# mkdir /sys/fs/cgroup/clstest
# /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.mems
# /bin/echo 0 > /sys/fs/cgroup/clstest/cpuset.cpus
# /bin/echo 0x100001 > /sys/fs/cgroup/clstest/net_cls.classid配置tc
# tc qdisc add dev eth2 root handle 10: htb
# tc class add dev eth2 parent 10: classid 10:1 htb rate 10mbit
# tc filter add dev eth2 parent 10: protocol ip prio 10 handle 1: cgroup将任务回显到cgroup中
(但一次只能使用一个)
# echo $FIREFOX_PID > /sys/fs/cgroup/clstest/tasks修改tc类
# tc class change dev eth2 parent 10: classid 10:1 htb rate 40mbit编辑:
我一直无法使此工作与入口。只有出口(上载)似乎在工作。tc似乎没有使用带有入口的cgroup选项。
发布于 2013-06-24 22:31:03
您应该向想要控制的流量添加类和过滤器(假设您想要控制HTTP流量)。
# tc class add dev eth0 parent 1:1 classid 1:1 htb rate 500mbit ceil 800mbit burst 10k prio 10
# tc filter add dev eth0 parent 1:1 protocol ip prio 10 u32 match ip dport 80 0xffff flowid 1:1然后,您可以使用iptraf验证连接速率。
https://stackoverflow.com/questions/9904016
复制相似问题