From ff490d2dcbab96d04060d02d01d703284fb5d9ba Mon Sep 17 00:00:00 2001 From: root Date: Tue, 26 Jan 2010 12:42:27 +0200 Subject: [PATCH] fixes to TrafficControl.py; updated rules for traffic shaping --- bt_comm/xml/TrafficControl.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bt_comm/xml/TrafficControl.py b/bt_comm/xml/TrafficControl.py index 27d8be2..2c28f08 100644 --- a/bt_comm/xml/TrafficControl.py +++ b/bt_comm/xml/TrafficControl.py @@ -44,26 +44,28 @@ class TrafficControl: def get_upload_limit_commands(self): upload_limit_commands = [] - upload_limit_commands.append("tc qdisc add dev %s root handle 1: htb default 90" % (self.vm_iface)) - upload_limit_commands.append("tc class add dev %s parent 1: classid 1:1 htb rate %dkb ceil %dkb" % (self.vm_iface, self.upload_limit, self.upload_limit)) - upload_limit_commands.append("tc qdisc add dev %s parent 1:1 handle 10: sfq perturb 10" % (self.vm_iface)) - upload_limit_commands.append("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s match ip dport %d 0xffff classid 1:1" % (self.vm_iface, self.vm_address, self.vm_port)) + upload_limit_commands.append("tc qdisc add dev %s root handle 1: htb default 90" % (self.host_iface)) + upload_limit_commands.append("tc class add dev %s parent 1: classid 1:1 htb rate %dkbps ceil %dkbps" % (self.host_iface, self.upload_limit, self.upload_limit)) + upload_limit_commands.append("tc class add dev %s parent 1:1 classid 1:10 htb rate %dkbps ceil %dkbps" % (self.host_iface, self.upload_limit, self.upload_limit)) + upload_limit_commands.append("tc qdisc add dev %s parent 1:10 handle 10: sfq perturb 10" % (self.host_iface)) + upload_limit_commands.append("tc filter add dev %s parent 1:0 protocol ip u32 match ip sport %d 0xffff flowid 1:10" % (self.host_iface, self.vm_port)) return upload_limit_commands def get_download_limit_commands(self): download_limit_commands = [] - download_limit_commands.append("tc qdisc add dev %s root handle 1: htb default 90" % (self.host_iface)) - download_limit_commands.append("tc class add dev %s parent 1: classid 1:1 htb rate %dkb ceil %dkb" % (self.host_iface, self.download_limit, self.download_limit)) - download_limit_commands.append("tc qdisc add dev %s parent 1:1 handle 10: sfq perturb 10" % (self.host_iface)) - download_limit_commands.append("tc filter add dev %s parent 1:0 protocol ip u32 match ip src %s classid 1:1" % (self.host_iface, self.vm_address)) + download_limit_commands.append("tc qdisc add dev %s root handle 1: htb default 90" % (self.vm_iface)) + download_limit_commands.append("tc class add dev %s parent 1: classid 1:1 htb rate %dkbps ceil %dkbps" % (self.vm_iface, self.download_limit, self.download_limit)) + download_limit_commands.append("tc class add dev %s parent 1:1 classid 1:10 htb rate %dkbps ceil %dkbps" % (self.vm_iface, self.download_limit, self.download_limit)) + download_limit_commands.append("tc qdisc add dev %s parent 1:10 handle 10: sfq perturb 10" % (self.vm_iface)) + download_limit_commands.append("tc filter add dev %s parent 1:0 protocol ip u32 match ip dst %s/32 flowid 1:10" % (self.vm_iface, self.vm_address)) return download_limit_commands def get_flush_commands(self): flush_commands = [] - flush_commands.append("tc qdisc del dev %s root handle 1:" % (self.host_iface)) - flush_commands.append("tc qdisc del dev %s root handle 1:" % (self.vm_iface)) + flush_commands.append("tc qdisc del dev %s root" % (self.host_iface)) + flush_commands.append("tc qdisc del dev %s root" % (self.vm_iface)) return flush_commands @@ -81,8 +83,8 @@ def main(): """ tc = TrafficControl("openvz") - tc.config("141.85.224.201", 10150, "eth0", - "172.16.10.0", 10150, "venet0") + tc.config("141.85.224.201", 22, "eth1", + "172.16.10.1", 22, "venet0") tc.set_upload_limit(512) tc.set_download_limit(256) -- 2.20.1