summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2023-01-04 17:54:24 +0100
committerChristian Poessinger <christian@poessinger.com>2023-01-04 17:55:48 +0100
commitae8935ce62e55ad047b51bebef8a1d9124ed1826 (patch)
tree2c8b698630431c4790673d1e8ded2e45bea0f9c7
parentf5af95be4f66380d213771b975c63361e27616ef (diff)
downloadvyos-1x-ae8935ce62e55ad047b51bebef8a1d9124ed1826.tar.gz
vyos-1x-ae8935ce62e55ad047b51bebef8a1d9124ed1826.zip
qos: T4284: add bandwidth percentage value
-rw-r--r--interface-definitions/include/qos/bandwidth-auto.xml.i6
-rw-r--r--interface-definitions/include/qos/bandwidth.xml.i6
-rw-r--r--python/vyos/qos/base.py5
-rwxr-xr-xsrc/migration-scripts/qos/1-to-242
4 files changed, 20 insertions, 39 deletions
diff --git a/interface-definitions/include/qos/bandwidth-auto.xml.i b/interface-definitions/include/qos/bandwidth-auto.xml.i
index 260bd4f7b..a86f28296 100644
--- a/interface-definitions/include/qos/bandwidth-auto.xml.i
+++ b/interface-definitions/include/qos/bandwidth-auto.xml.i
@@ -33,9 +33,13 @@
<format>&lt;number&gt;tbit</format>
<description>Terabits per second</description>
</valueHelp>
+ <valueHelp>
+ <format>&lt;number&gt;%%</format>
+ <description>Percentage of interface link speed</description>
+ </valueHelp>
<constraint>
<validator name="numeric" argument="--positive"/>
- <regex>(auto|\d+(bit|kbit|mbit|gbit|tbit))</regex>
+ <regex>(auto|\d+(bit|kbit|mbit|gbit|tbit)|(100|\d(\d)?)%)</regex>
</constraint>
</properties>
<defaultValue>auto</defaultValue>
diff --git a/interface-definitions/include/qos/bandwidth.xml.i b/interface-definitions/include/qos/bandwidth.xml.i
index 62ea93b67..f2848f066 100644
--- a/interface-definitions/include/qos/bandwidth.xml.i
+++ b/interface-definitions/include/qos/bandwidth.xml.i
@@ -26,9 +26,13 @@
<format>&lt;number&gt;tbit</format>
<description>Terabits per second</description>
</valueHelp>
+ <valueHelp>
+ <format>&lt;number&gt;%</format>
+ <description>Percentage of interface link speed</description>
+ </valueHelp>
<constraint>
<validator name="numeric" argument="--positive"/>
- <regex>\d+(bit|kbit|mbit|gbit|tbit)</regex>
+ <regex>(\d+(bit|kbit|mbit|gbit|tbit)|(100|\d(\d)?)%)</regex>
</constraint>
</properties>
</leafNode>
diff --git a/python/vyos/qos/base.py b/python/vyos/qos/base.py
index d039bbb0f..96f189b1a 100644
--- a/python/vyos/qos/base.py
+++ b/python/vyos/qos/base.py
@@ -116,11 +116,14 @@ class QoSBase:
'tbit' : 1000000000000,
}
- if rate == 'auto':
+ if rate == 'auto' or rate.endswith('%'):
speed = read_file(f'/sys/class/net/{self._interface}/speed')
if not speed.isnumeric():
Warning('Interface speed cannot be determined (assuming 10 Mbit/s)')
speed = 10
+ if rate.endswith('%'):
+ percent = rate.rstrip('%')
+ speed = int(speed) * int(percent) // 100
return int(speed) *1000000 # convert to MBit/s
rate_numeric = int(''.join([n for n in rate if n.isdigit()]))
diff --git a/src/migration-scripts/qos/1-to-2 b/src/migration-scripts/qos/1-to-2
index 6f4c08a50..41026cbd6 100755
--- a/src/migration-scripts/qos/1-to-2
+++ b/src/migration-scripts/qos/1-to-2
@@ -98,49 +98,19 @@ config.set(['qos'])
config.copy(base, ['qos', 'policy'])
config.delete(base)
-# TODO
-# - remove burst from network emulator
-
-def change_cli_bandwidth(config, path):
- if config.exists(path + ['bandwidth']):
- bw = config.return_value(path + ['bandwidth'])
- if bw.endswith('%'):
- bw = bandwidth_percent_to_val(interface, bw.rstrip('%'))
- config.set(path + ['bandwidth'], value=bw)
- return
-
# Now map the interface policy binding to the new CLI syntax
+if len(iface_config):
+ config.set(['qos', 'interface'])
+ config.set_tag(['qos', 'interface'])
+
for interface, interface_config in iface_config.items():
+ config.set(['qos', 'interface', interface])
+ config.set_tag(['qos', 'interface', interface])
if 'ingress' in interface_config:
config.set(['qos', 'interface', interface, 'ingress'], value=interface_config['ingress'])
if 'egress' in interface_config:
config.set(['qos', 'interface', interface, 'egress'], value=interface_config['egress'])
- # QoS policy <-> interface binding is now established - we now can adjust some
- # CLI values like bandwidth in percent
- for direction in ['ingress', 'egress']:
- if direction not in interface_config:
- continue
- # Convert % bandwidth values to absolute values
- for policy in config.list_nodes(['qos', 'policy']):
- for policy_name in config.list_nodes(['qos', 'policy', policy]):
- if policy_name == interface_config[direction]:
- policy_base = ['qos', 'policy', policy, policy_name]
- # This is for the toplevel bandwidth node on a policy
- change_cli_bandwidth(config, policy_base)
-
- # This is for class based bandwidth value
- if config.exists(policy_base + ['class']):
- for cls in config.list_nodes(policy_base + ['class']):
- cls_base = policy_base + ['class', cls]
- change_cli_bandwidth(config, cls_base)
-
- # This is for the bandwidth value specified under the
- # policy "default" tree
- if config.exists(policy_base + ['default']):
- default_base = policy_base + ['default']
- change_cli_bandwidth(config, default_base)
-
# Remove "burst" CLI node from network emulator
netem_base = ['qos', 'policy', 'network-emulator']
if config.exists(netem_base):