Simon Mater's patch to support gbits and gbps in rate/burst specifications

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2020-10-09 09:39:01 -07:00
parent 6681191c88
commit 69f0d4d881
No known key found for this signature in database
GPG Key ID: 96E6B3F2423A4D10
4 changed files with 69 additions and 11 deletions

View File

@ -149,12 +149,14 @@ sub initialize( $ ) {
sub rate_to_kbit( $ ) {
my $rate = $_[0];
return 0 if $rate eq '-';
return $1 if $rate =~ /^((\d+)(\.\d+)?)kbit$/i;
return $1 * 1000 if $rate =~ /^((\d+)(\.\d+)?)mbit$/i;
return $1 * 8000 if $rate =~ /^((\d+)(\.\d+)?)mbps$/i;
return $1 * 8 if $rate =~ /^((\d+)(\.\d+)?)kbps$/i;
return ($1/125) if $rate =~ /^((\d+)(\.\d+)?)(bps)?$/;
return 0 if $rate eq '-';
return $1 if $rate =~ /^((\d+)(\.\d+)?)kbit$/i;
return $1 * 1000 if $rate =~ /^((\d+)(\.\d+)?)mbit$/i;
return $1 * 1000000 if $rate =~ /^((\d+)(\.\d+)?)gbit$/i;
return $1 * 8000000 if $rate =~ /^((\d+)(\.\d+)?)gbps$/i;
return $1 * 8000 if $rate =~ /^((\d+)(\.\d+)?)mbps$/i;
return $1 * 8 if $rate =~ /^((\d+)(\.\d+)?)kbps$/i;
return ($1/125) if $rate =~ /^((\d+)(\.\d+)?)(bps)?$/;
fatal_error "Invalid Rate ($rate)";
}
@ -212,7 +214,7 @@ sub process_in_bandwidth( $ ) {
} else {
if ( $in_band =~ /:/ ) {
( $in_band, $burst ) = split /:/, $in_rate, 2;
fatal_error "Invalid burst ($burst)" unless $burst =~ /^\d+(k|kb|m|mb|mbit|kbit|b)?$/;
fatal_error "Invalid burst ($burst)" unless $burst =~ /^\d+(k|kb|m|mb|g|gb|gbit|mbit|kbit|b)?$/;
$in_burst = $burst;
}
@ -324,7 +326,7 @@ sub process_simple_device() {
my $command = "run_tc qdisc add dev $physical root handle $number: tbf rate ${out_bandwidth}kbit";
if ( supplied $burst ) {
fatal_error "Invalid burst ($burst)" unless $burst =~ /^\d+(?:\.\d+)?(k|kb|m|mb|mbit|kbit|b)?$/;
fatal_error "Invalid burst ($burst)" unless $burst =~ /^\d+(?:\.\d+)?(k|kb|m|mb|g|gb|gbit|mbit|kbit|b)?$/;
$command .= " burst $burst";
} else {
$command .= ' burst 10kb';
@ -340,12 +342,12 @@ sub process_simple_device() {
$command .= ' mpu 64'; #Assume Ethernet
if ( supplied $peak ) {
fatal_error "Invalid peak ($peak)" unless $peak =~ /^\d+(?:\.\d+)?(k|kb|m|mb|mbit|kbit|b)?$/;
fatal_error "Invalid peak ($peak)" unless $peak =~ /^\d+(?:\.\d+)?(k|kb|m|mb|g|gb|gbit|mbit|kbit|b)?$/;
$command .= " peakrate $peak";
}
if ( supplied $minburst ) {
fatal_error "Invalid minburst ($minburst)" unless $minburst =~ /^\d+(?:\.\d+)?(k|kb|m|mb|mbit|kbit|b)?$/;
fatal_error "Invalid minburst ($minburst)" unless $minburst =~ /^\d+(?:\.\d+)?(k|kb|m|mb|g|gb|gbit|mbit|kbit|b)?$/;
$command .= " minburst $minburst";
}

View File

@ -54,6 +54,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbps</emphasis></term>
<listitem>
<para>Gigabytes per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">kbit</emphasis></term>
@ -70,6 +78,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbit</emphasis></term>
<listitem>
<para>Gigabits per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">bps</emphasis> or <emphasis
role="bold">number</emphasis></term>

View File

@ -61,6 +61,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbps</emphasis></term>
<listitem>
<para>Gigabytes per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">kbit</emphasis></term>
@ -77,6 +85,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbit</emphasis></term>
<listitem>
<para>Gigabits per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">bps</emphasis> or <emphasis
role="bold">number</emphasis></term>

View File

@ -59,6 +59,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbps</emphasis></term>
<listitem>
<para>Gigabytes per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">kbit</emphasis></term>
@ -75,6 +83,14 @@
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">gbit</emphasis></term>
<listitem>
<para>Gigabits per second.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">bps</emphasis> or <emphasis
role="bold">number</emphasis></term>
@ -88,7 +104,7 @@
<term>k or kb</term>
<listitem>
<para>Kilo bytes.</para>
<para>Kilobytes.</para>
</listitem>
</varlistentry>
@ -99,6 +115,14 @@
<para>Megabytes.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>g or gb</term>
<listitem>
<para>Gigabytes.</para>
</listitem>
</varlistentry>
</variablelist>
</listitem>