[pve-devel] r5634 - in qemu-server/pve2: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 2 13:17:29 CET 2011


Author: dietmar
Date: 2011-03-02 13:17:29 +0100 (Wed, 02 Mar 2011)
New Revision: 5634

Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/PVE/QemuServer.pm
   qemu-server/pve2/pve-bridge
Log:
add traffic shaping


Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2011-03-02 06:01:52 UTC (rev 5633)
+++ qemu-server/pve2/ChangeLog	2011-03-02 12:17:29 UTC (rev 5634)
@@ -1,3 +1,9 @@
+2011-03-02  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/QemuServer.pm (parse_net): new 'rate' option.
+
+	* pve-bridge: add traffic shaping
+
 2011-02-25  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/QemuServer.pm: changed network config systax. We now use

Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2011-03-02 06:01:52 UTC (rev 5633)
+++ qemu-server/pve2/PVE/QemuServer.pm	2011-03-02 12:17:29 UTC (rev 5634)
@@ -410,7 +410,7 @@
 my $netdesc = {
     optional => 1,
     type => 'string', format => 'pve-qm-net',
-    typetext => "MODEL=XX:XX:XX:XX:XX:XX [,bridge=<dev>]",
+    typetext => "MODEL=XX:XX:XX:XX:XX:XX [,bridge=<dev>][,rate=<mbps>]",
     description => <<EODESCR,
 Specify network devices. 
 
@@ -421,6 +421,8 @@
 
 The bridge parameter can be used to automatically add the interface to a bridge device. The Proxmox VE standard bridge is called 'vmbr0'.
 
+Option 'rate' is used to limit traffic bandwidth from and to this interface. It is specified as floating point number, unit is 'Megabytes per second'.
+
 If you specify no bridge, we create a kvm 'user' (NATed) network device, which provides DHCP and DNS services. The following addresses are used:
 
 10.0.2.2   Gateway
@@ -850,7 +852,7 @@
 
 }
 
-# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,
+# netX: e1000=XX:XX:XX:XX:XX:XX,bridge=vmbr0,rate=<mbps>
 sub parse_net {
     my ($data) = @_;
 
@@ -865,6 +867,8 @@
 	    $res->{macaddr} = $mac;
 	} elsif ($kvp =~ m/^bridge=(\S+)$/) {
 	    $res->{bridge} = $1;
+	} elsif ($kvp =~ m/^rate=(\d+(\.\d+)?)$/) {
+	    $res->{rate} = $1;
 	} else {
 	    return undef;
 	}
@@ -882,6 +886,7 @@
     my $res = "$net->{model}";
     $res .= "=$net->{macaddr}" if $net->{macaddr};
     $res .= ",bridge=$net->{bridge}" if $net->{bridge};
+    $res .= ",rate=$net->{rate}" if $net->{rate};
 
     return $res;
 }

Modified: qemu-server/pve2/pve-bridge
===================================================================
--- qemu-server/pve2/pve-bridge	2011-03-02 06:01:52 UTC (rev 5633)
+++ qemu-server/pve2/pve-bridge	2011-03-02 12:17:29 UTC (rev 5634)
@@ -2,6 +2,7 @@
 
 use strict;
 use PVE::QemuServer;
+use PVE::Tools qw(run_command);
 
 my $iface = shift;
 
@@ -26,6 +27,29 @@
 
 system ("/sbin/ifconfig $iface 0.0.0.0 promisc up") == 0 ||
     die "interface activation failed\n";
+
+if ($net->{rate}) {
+
+    my $rate = int($net->{rate}*1024*1024);
+    my $burst = 1024*1024;
+
+    system("/sbin/tc qdisc del dev $iface ingres >/dev/null 2>&1");
+    system("/sbin/tc qdisc del dev $iface root >/dev/null 2>&1");
+
+    run_command("/sbin/tc qdisc add dev $iface handle ffff: ingress");
+    run_command("/sbin/tc filter add dev $iface parent ffff: protocol ip prio 50 " . 
+		"u32 match ip src 0.0.0.0/0 police rate ${rate}bps " .
+		"burst ${burst}b drop flowid :1");
+
+    # tbf does not work for unknown reason
+    #$TC qdisc add dev $DEV root tbf rate $RATE latency 100ms burst $BURST
+
+    run_command("/sbin/tc qdisc add dev $iface root handle 1: htb default 1");
+    run_command("/sbin/tc class add dev $iface parent 1: classid 1:1 " .
+		"htb rate ${rate}bps burst ${burst}b");
+
+}
+
 system ("/usr/sbin/brctl addif $bridge $iface") == 0 ||
     die "can't add interface to bridge\n";
 




More information about the pve-devel mailing list