]> git.proxmox.com Git - pve-container.git/commitdiff
implement rate limiting
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 8 Mar 2016 12:55:40 +0000 (13:55 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 8 Mar 2016 14:54:29 +0000 (15:54 +0100)
src/PVE/LXC.pm
src/PVE/LXC/Config.pm
src/lxcnetaddbr

index 8de026cfac1bed4ed157365f49efe46709381050..58be169edb254202ea7a64e00aacf110122def0f 100644 (file)
@@ -586,9 +586,10 @@ sub update_net {
 
            hotplug_net($vmid, $conf, $opt, $newnet, $netid);
 
-       } elsif (&$safe_string_ne($oldnet->{bridge}, $newnet->{bridge}) ||
-                &$safe_num_ne($oldnet->{tag}, $newnet->{tag}) ||
-                &$safe_num_ne($oldnet->{firewall}, $newnet->{firewall})) {
+       } else {
+           if (&$safe_string_ne($oldnet->{bridge}, $newnet->{bridge}) ||
+               &$safe_num_ne($oldnet->{tag}, $newnet->{tag}) ||
+               &$safe_num_ne($oldnet->{firewall}, $newnet->{firewall})) {
 
                if ($oldnet->{bridge}) {
                    PVE::Network::tap_unplug($veth);
@@ -599,12 +600,19 @@ sub update_net {
                    PVE::LXC::Config->write_config($vmid, $conf);
                }
 
-               PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks});
-               foreach (qw(bridge tag firewall)) {
+               PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
+               # This includes the rate:
+               foreach (qw(bridge tag firewall rate)) {
                    $oldnet->{$_} = $newnet->{$_} if $newnet->{$_};
                }
-               $conf->{$opt} = PVE::LXC::Config->print_lxc_network($oldnet);
-               PVE::LXC::Config->write_config($vmid, $conf);
+           } elsif (&$safe_string_ne($oldnet->{rate}, $newnet->{rate})) {
+               # Rate can be applied on its own but any change above needs to
+               # include the rate in tap_plug since OVS resets everything.
+               PVE::Network::tap_rate_limit($veth, $newnet->{rate});
+               $oldnet->{rate} = $newnet->{rate}
+           }
+           $conf->{$opt} = PVE::LXC::Config->print_lxc_network($oldnet);
+           PVE::LXC::Config->write_config($vmid, $conf);
        }
     } else {
        hotplug_net($vmid, $conf, $opt, $newnet, $netid);
@@ -621,7 +629,7 @@ sub hotplug_net {
     my $eth = $newnet->{name};
 
     PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
-    PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks});
+    PVE::Network::tap_plug($veth, $newnet->{bridge}, $newnet->{tag}, $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate});
 
     # attach peer in container
     my $cmd = ['lxc-device', '-n', $vmid, 'add', $vethpeer, "$eth" ];
index ef0673cd2ffff19457a853908849c6265cb739b5..2f656e501eeaea2dd316634c83be85dca1de88ea 100644 (file)
@@ -495,6 +495,12 @@ my $netconf_desc = {
        description => "VLAN ids to pass through the interface",
        optional => 1,
     },
+    rate => {
+       type => 'number',
+       format_description => 'mbps',
+       description => "Apply rate limiting to the interface",
+       optional => 1,
+    },
 };
 PVE::JSONSchema::register_format('pve-lxc-network', $netconf_desc);
 
index c336657463d9886ef3bdb3d93ca0f7e5ee9ba3df..5cb6b0b8da11e1d94bf952ffc46f7450791608d9 100755 (executable)
@@ -41,6 +41,7 @@ my $tag = $net->{tag};
 my $firewall = $net->{firewall};
 my $bridge = $net->{bridge};
 my $trunks = $net->{trunks};
+my $rate = $net->{rate};
 
 die "missing bridge configuration" if !$bridge;
 
@@ -53,7 +54,7 @@ if (-d "/sys/class/net/$iface") {
 
     PVE::Tools::run_command("/sbin/ip link set dev $iface up mtu $bridgemtu");
     PVE::Tools::run_command("/sbin/ip addr add 0.0.0.0/0 dev $iface");
-    PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks);
+    PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate);
 }
 
 exit 0;