SRIOV VF: Add min_tx_rate and max_tx_rate

Add missing options to configure min_tx_rate and max_tx_rate
for virtual functions.

Change-Id: I34a0c3a86114aefbdcd68ddc187dd3e7566a66d9
Signed-off-by: Christophe Fontaine <cfontain@redhat.com>
This commit is contained in:
Christophe Fontaine 2020-03-31 12:31:38 +02:00
parent 3b3bd43def
commit 78c7b1317d
10 changed files with 103 additions and 18 deletions

View File

@ -26,6 +26,8 @@
],
"vlan_id": 100,
"qos": 2,
"min_tx_rate": 10,
"max_tx_rate": 100,
"spoofcheck": true,
"macaddr": "00:78:90:80:cc:30",
"trust": true,
@ -44,6 +46,8 @@
"promisc": true,
"vlan_id": 116,
"qos": 3,
"min_tx_rate": 0,
"max_tx_rate": 0,
"spoofcheck": false
}
],
@ -65,6 +69,8 @@
"vfid": 2,
"vlan_id": 112,
"qos": 4,
"min_tx_rate": 0,
"max_tx_rate": 0,
"primary": true,
"trust": true,
"promisc": true,
@ -76,6 +82,8 @@
"vfid": 2,
"vlan_id": 112,
"qos": 4,
"min_tx_rate": 0,
"max_tx_rate": 0,
"trust": true,
"promisc": true,
"spoofcheck": false
@ -96,6 +104,8 @@
"vfid": 3,
"vlan_id": 113,
"qos": 5,
"min_tx_rate": 0,
"max_tx_rate": 0,
"spoofcheck": true,
"trust": true,
"promisc": false,
@ -107,6 +117,8 @@
"vfid": 3,
"vlan_id": 113,
"qos": 5,
"min_tx_rate": 0,
"max_tx_rate": 0,
"spoofcheck": true,
"trust": true,
"promisc": false

View File

@ -46,6 +46,13 @@ network_config:
# specified priority bits in the VLAN tag. Requires vlan_id
# Default value is 0.
qos: 2
# change the allowed minimum transmit bandwidth, in Mbps, for the specified VF.
# Minimum TXRATE should be always <= Maximum TXRATE.
# Setting this parameter to 0 disables rate limiting.
min_tx_rate: 10
# change the allowed maximum transmit bandwidth, in Mbps, for the specified VF.
# Setting this parameter to 0 disables rate limiting.
max_tx_rate: 100
# MAC spoofing is a method of altering the MAC address
# The MAC address anti-spoofing when enabled protects from malicious MAC
# address spoofing. It should be disabled for 802.3ad bonds.

View File

@ -659,7 +659,9 @@ class OvsBridge(_BaseOpts):
spoofcheck=iface.spoofcheck,
trust=iface.trust, state=iface.state,
macaddr=iface.macaddr, promisc=iface.promisc,
pci_address=iface.pci_address)
pci_address=iface.pci_address,
min_tx_rate=iface.min_tx_rate,
max_tx_rate=iface.max_tx_rate)
@staticmethod
def from_json(json):
@ -1027,7 +1029,9 @@ class LinuxBond(_BaseOpts):
spoofcheck=iface.spoofcheck,
trust=iface.trust, state=iface.state,
macaddr=iface.macaddr, promisc=iface.promisc,
pci_address=iface.pci_address)
pci_address=iface.pci_address,
min_tx_rate=iface.min_tx_rate,
max_tx_rate=iface.max_tx_rate)
@staticmethod
def from_json(json):
@ -1111,7 +1115,9 @@ class OvsBond(_BaseOpts):
vlan_id=iface.vlan_id, qos=iface.qos,
spoofcheck=iface.spoofcheck,
trust=iface.trust, state=iface.state,
macaddr=iface.macaddr, promisc=iface.promisc)
macaddr=iface.macaddr, promisc=iface.promisc,
min_tx_rate=iface.min_tx_rate,
max_tx_rate=iface.max_tx_rate)
@staticmethod
def from_json(json):
@ -1337,7 +1343,9 @@ class OvsDpdkPort(_BaseOpts):
spoofcheck=iface.spoofcheck,
trust=iface.trust, state=iface.state,
macaddr=iface.macaddr, promisc=iface.promisc,
pci_address=iface.pci_address)
pci_address=iface.pci_address,
min_tx_rate=iface.min_tx_rate,
max_tx_rate=iface.max_tx_rate)
@staticmethod
def from_json(json):
@ -1411,7 +1419,7 @@ class SriovVF(_BaseOpts):
defroute=True, dhclient_args=None, dns_servers=None,
nm_controlled=False, onboot=True, domain=None, vlan_id=0,
qos=0, spoofcheck=None, trust=None, state=None, macaddr=None,
promisc=None):
promisc=None, min_tx_rate=0, max_tx_rate=0):
addresses = addresses or []
routes = routes or []
rules = rules or []
@ -1432,6 +1440,8 @@ class SriovVF(_BaseOpts):
self.device = device
self.vlan_id = int(vlan_id)
self.qos = int(qos)
self.min_tx_rate = int(min_tx_rate)
self.max_tx_rate = int(max_tx_rate)
self.spoofcheck = spoofcheck
self.trust = trust
self.state = state
@ -1449,7 +1459,9 @@ class SriovVF(_BaseOpts):
state=state,
macaddr=macaddr,
promisc=promisc,
pci_address=pci_address)
pci_address=pci_address,
min_tx_rate=min_tx_rate,
max_tx_rate=max_tx_rate)
@staticmethod
def get_on_off(config):
@ -1472,6 +1484,13 @@ class SriovVF(_BaseOpts):
if qos != 0 and vlan_id == 0:
msg = "Vlan tag not set for QOS - VF: %s:%d" % (device, vfid)
raise InvalidConfigException(msg)
min_tx_rate = json.get('min_tx_rate', 0)
max_tx_rate = json.get('max_tx_rate', 0)
if max_tx_rate > 0 and min_tx_rate > max_tx_rate:
msg = ("vf %s:%d: min_tx_rate(%d) > max_tx_rate(%d)" %
(device, vfid, min_tx_rate, max_tx_rate))
raise InvalidConfigException(msg)
spoofcheck = SriovVF.get_on_off(json.get('spoofcheck'))
trust = SriovVF.get_on_off(json.get('trust'))
promisc = SriovVF.get_on_off(json.get('promisc'))
@ -1482,7 +1501,8 @@ class SriovVF(_BaseOpts):
macaddr = json.get('macaddr')
return SriovVF(device, vfid, *opts, vlan_id=vlan_id, qos=qos,
spoofcheck=spoofcheck, trust=trust, state=state,
macaddr=macaddr, promisc=promisc)
macaddr=macaddr, promisc=promisc,
min_tx_rate=min_tx_rate, max_tx_rate=max_tx_rate)
class SriovPF(_BaseOpts):

View File

@ -384,6 +384,10 @@ definitions:
$ref: "#/definitions/int_or_param"
qos:
$ref: "#/definitions/int_or_param"
min_tx_rate:
$ref: "#/definitions/int_or_param"
max_tx_rate:
$ref: "#/definitions/int_or_param"
hotplug:
$ref: "#/definitions/bool_or_param"
spoofcheck:

View File

@ -520,6 +520,12 @@ def configure_sriov_vf():
if 'qos' in item:
vlan_cmd = vlan_cmd + ('qos', str(item['qos']))
run_ip_config_cmd(*vlan_cmd)
if 'max_tx_rate' in item:
cmd = base_cmd + ('max_tx_rate', str(item['max_tx_rate']))
run_ip_config_cmd(*cmd)
if 'min_tx_rate' in item:
cmd = base_cmd + ('min_tx_rate', str(item['min_tx_rate']))
run_ip_config_cmd(*cmd)
if 'spoofcheck' in item:
cmd = base_cmd + ('spoofchk', item['spoofcheck'])
run_ip_config_cmd(*cmd)

View File

@ -1415,11 +1415,14 @@ DOMAIN="openstack.local subdomain.openstack.local"
def test_update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=None,
qos=None, spoofcheck=None, trust=None,
state=None, macaddr=None, promisc=None,
pci_address=None):
pci_address=None,
min_tx_rate=0, max_tx_rate=0):
self.assertEqual(pf_name, 'eth2')
self.assertEqual(vfid, 7)
self.assertEqual(vlan_id, 0)
self.assertEqual(qos, 0)
self.assertEqual(min_tx_rate, 0)
self.assertEqual(max_tx_rate, 0)
self.assertEqual(spoofcheck, None)
self.assertEqual(trust, None)
self.assertEqual(state, None)
@ -1462,12 +1465,15 @@ NETMASK=255.255.255.0
def test_update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=None,
qos=None, spoofcheck=None, trust=None,
state=None, macaddr=None, promisc=None,
pci_address=None):
pci_address=None,
min_tx_rate=0, max_tx_rate=0):
self.assertEqual(pf_name, 'eth2')
self.assertEqual(vf_name, 'eth2_7')
self.assertEqual(vfid, 7)
self.assertEqual(vlan_id, 100)
self.assertEqual(qos, 10)
self.assertEqual(min_tx_rate, 0)
self.assertEqual(max_tx_rate, 0)
self.assertTrue(spoofcheck)
self.assertTrue(trust)
self.assertEqual(state, "auto")
@ -1515,12 +1521,15 @@ NETMASK=255.255.255.0
def test_update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=None,
qos=None, spoofcheck=None, trust=None,
state=None, macaddr=None, promisc=None,
pci_address=None):
pci_address=None,
min_tx_rate=0, max_tx_rate=0):
self.assertEqual(pf_name, 'eth2')
self.assertEqual(vf_name, 'eth2_7')
self.assertEqual(vfid, 7)
self.assertEqual(vlan_id, 100)
self.assertEqual(qos, 10)
self.assertEqual(min_tx_rate, 0)
self.assertEqual(max_tx_rate, 0)
self.assertFalse(spoofcheck)
self.assertFalse(trust)
self.assertEqual(state, "enable")

View File

@ -462,6 +462,7 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'off', 'trust': 'on',
'promisc': 'on', 'pci_address': '0000:79:10.2'}]
@ -518,11 +519,13 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'off', 'trust': 'on',
'promisc': 'on'},
{'device_type': 'vf', 'name': 'em2_1',
'device': {'name': 'em2', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'off', 'trust': 'on',
'promisc': 'on'}]
@ -587,11 +590,13 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'on', 'trust': 'off',
'promisc': 'off'},
{'device_type': 'vf', 'name': 'em2_1',
'device': {'name': 'em2', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'on', 'trust': 'off',
'promisc': 'off'}]
@ -632,6 +637,7 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'pci_address': '0000:79:10.2',
'spoofcheck': 'off', 'trust': 'off',
'promisc': 'off'}]
@ -681,6 +687,7 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'spoofcheck': 'off', 'trust': 'on',
'pci_address': '0000:79:10.2'
}]
@ -723,6 +730,8 @@ class TestBridge(base.TestCase):
"vfid": 1,
"vlan_id": 111,
"qos": 1,
"min_tx_rate": 100,
"max_tx_rate": 500,
"spoofcheck": false,
"trust": false,
"promisc": false
@ -734,6 +743,7 @@ class TestBridge(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 100, 'max_tx_rate': 500,
'spoofcheck': 'off', 'trust': 'off',
'pci_address': '0000:79:10.2'
}]
@ -1229,6 +1239,7 @@ class TestLinuxBond(base.TestCase):
"vfid": 1,
"vlan_id": 111,
"qos": 1,
"max_tx_rate": 10,
"primary": true
},
{
@ -1236,19 +1247,22 @@ class TestLinuxBond(base.TestCase):
"device": "em2",
"vfid": 1,
"vlan_id": 111,
"qos": 1
"qos": 1,
"max_tx_rate": 10
}]
}
"""
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 10,
'pci_address': '0000:79:10.1',
'spoofcheck': 'on', 'trust': 'on',
'promisc': 'off'},
{'device_type': 'vf', 'name': 'em2_1',
'device': {'name': 'em2', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 10,
'pci_address': '0000:79:10.2',
'spoofcheck': 'on', 'trust': 'on',
'promisc': 'off'}]
@ -1310,12 +1324,14 @@ class TestLinuxBond(base.TestCase):
vf_final = [{'device_type': 'vf', 'name': 'em1_1',
'device': {'name': 'em1', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'pci_address': '0000:79:10.1',
'spoofcheck': 'off', 'trust': 'off',
'promisc': 'off'},
{'device_type': 'vf', 'name': 'em2_1',
'device': {'name': 'em2', 'vfid': 1},
'vlan_id': 111, 'qos': 1,
'min_tx_rate': 0, 'max_tx_rate': 0,
'pci_address': '0000:79:10.2',
'spoofcheck': 'off', 'trust': 'off',
'promisc': 'off'}]

View File

@ -254,9 +254,12 @@ class TestSriovConfig(base.TestCase):
"vfid": 1}, "promisc": "on", "vlan_id": 101,
"qos": 5, "macaddr": "AA:BB:CC:DD:EE:FF",
"spoofcheck": "on", "state": "auto", "trust": "on",
"min_tx_rate": 0, "max_tx_rate": 100,
"name": "p2p1_1"}]
exp_cmds = ["ip link set dev p2p1 vf 1 mac AA:BB:CC:DD:EE:FF",
"ip link set dev p2p1 vf 1 vlan 101 qos 5",
"ip link set dev p2p1 vf 1 min_tx_rate 0",
"ip link set dev p2p1 vf 1 max_tx_rate 100",
"ip link set dev p2p1_1 promisc on",
"ip link set dev p2p1 vf 1 spoofchk on",
"ip link set dev p2p1 vf 1 state auto",

View File

@ -200,6 +200,7 @@ class TestUtils(base.TestCase):
sriov_vf_map = yaml.safe_load(contents) if contents else []
self.assertEqual(1, len(sriov_vf_map))
test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
'min_tx_rate': 0, 'max_tx_rate': 0,
'device': {"name": "eth1", "vfid": 2}}]
self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
@ -207,13 +208,14 @@ class TestUtils(base.TestCase):
utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=10, qos=5,
spoofcheck="on", trust="on", state="enable",
macaddr="AA:BB:CC:DD:EE:FF", promisc="off",
pci_address="0000:80:00.1")
pci_address="0000:80:00.1", max_tx_rate=10)
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
sriov_vf_map = yaml.safe_load(contents) if contents else []
self.assertEqual(1, len(sriov_vf_map))
test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
'device': {'name': 'eth1', 'vfid': 2},
'vlan_id': 10, 'qos': 5,
'min_tx_rate': 0, 'max_tx_rate': 10,
'spoofcheck': 'on', 'trust': 'on',
'state': 'enable',
'macaddr': 'AA:BB:CC:DD:EE:FF',
@ -229,10 +231,11 @@ class TestUtils(base.TestCase):
utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=10, qos=5,
spoofcheck="on", trust="on", state="enable",
macaddr="AA:BB:CC:DD:EE:FF", promisc="off",
pci_address="0000:80:00.1")
pci_address="0000:80:00.1", max_tx_rate=10)
vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
'device': {'name': 'eth1', 'vfid': 2},
'vlan_id': 10, 'qos': 5,
'min_tx_rate': 0, 'max_tx_rate': 10,
'spoofcheck': 'on', 'trust': 'on',
'state': 'enable',
'macaddr': 'AA:BB:CC:DD:EE:FF',
@ -248,6 +251,7 @@ class TestUtils(base.TestCase):
vf_initial = [{'device_type': 'vf', 'name': 'eth1_2',
'device': {'name': 'eth1', 'vfid': 2},
'vlan_id': 10, 'qos': 5,
'min_tx_rate': 0, 'max_tx_rate': 00,
'spoofcheck': 'on', 'trust': 'on',
'state': 'enable',
'macaddr': 'AA:BB:CC:DD:EE:FF',
@ -258,10 +262,11 @@ class TestUtils(base.TestCase):
utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=100, qos=15,
spoofcheck="off", trust="off", state="auto",
macaddr="BB:BB:CC:DD:EE:FF", promisc="on",
pci_address="0000:80:00.1")
pci_address="0000:80:00.1", max_tx_rate=40)
vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
'device': {'name': 'eth1', 'vfid': 2},
'vlan_id': 100, 'qos': 15,
'min_tx_rate': 0, 'max_tx_rate': 40,
'spoofcheck': 'off', 'trust': 'off',
'state': 'auto',
'macaddr': 'BB:BB:CC:DD:EE:FF',

View File

@ -478,7 +478,7 @@ def _get_sriov_map():
def _set_vf_fields(vf_name, vlan_id, qos, spoofcheck, trust, state, macaddr,
promisc, pci_address):
promisc, pci_address, min_tx_rate, max_tx_rate):
vf_configs = {}
vf_configs['name'] = vf_name
if vlan_id != 0:
@ -489,6 +489,8 @@ def _set_vf_fields(vf_name, vlan_id, qos, spoofcheck, trust, state, macaddr,
vf_configs['qos'] = qos
else:
vf_configs['qos'] = None
vf_configs['min_tx_rate'] = min_tx_rate
vf_configs['max_tx_rate'] = max_tx_rate
vf_configs['spoofcheck'] = spoofcheck
vf_configs['trust'] = trust
vf_configs['state'] = state
@ -506,7 +508,8 @@ def _clear_empty_values(vf_config):
def update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=0, qos=0,
spoofcheck=None, trust=None, state=None, macaddr=None,
promisc=None, pci_address=None):
promisc=None, pci_address=None,
min_tx_rate=0, max_tx_rate=0):
sriov_map = _get_sriov_map()
for item in sriov_map:
if (item['device_type'] == 'vf' and
@ -514,7 +517,7 @@ def update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=0, qos=0,
item['device'].get('vfid') == vfid):
item.update(_set_vf_fields(vf_name, vlan_id, qos, spoofcheck,
trust, state, macaddr, promisc,
pci_address))
pci_address, min_tx_rate, max_tx_rate))
_clear_empty_values(item)
break
else:
@ -523,7 +526,7 @@ def update_sriov_vf_map(pf_name, vfid, vf_name, vlan_id=0, qos=0,
new_item['device'] = {"name": pf_name, "vfid": vfid}
new_item.update(_set_vf_fields(vf_name, vlan_id, qos, spoofcheck,
trust, state, macaddr, promisc,
pci_address))
pci_address, min_tx_rate, max_tx_rate))
_clear_empty_values(new_item)
sriov_map.append(new_item)