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
"""
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)