This module provides functions that are related to Offloads.
The function parse_offloads in the module is intended to be use for parsing
offloads alias. The function parse all used offloads, in each set all offloads
are on, except the ones specified as off.
It takes argument offloads string and returns tuple of used offloads and its
combinations.
It returns list of tuple, containing summary of all used offloads, and list
of all offloads settings.
Expected input: "tso on gso on tx off; tso off tx off ;rx off".
Signed-off-by: Kamil Jerabek <kjerabek(a)redhat.com>
---
v3 * parse_offloads modified to accept also offload "on" and offload name
containing "-"
v4 * parse_offloads now return offloads set in order as it is specified on
input
---
lnst/RecipeCommon/Offloads.py | 56 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
create mode 100644 lnst/RecipeCommon/Offloads.py
diff --git a/lnst/RecipeCommon/Offloads.py b/lnst/RecipeCommon/Offloads.py
new file mode 100644
index 0000000..a109a06
--- /dev/null
+++ b/lnst/RecipeCommon/Offloads.py
@@ -0,0 +1,56 @@
+"""
+This module defines the functions for Offloads tuning that can be imported
+directly into LNST Python tasks.
+
+Copyright 2016 Red Hat, Inc.
+Licensed under the GNU General Public License, version 2 as
+published by the Free Software Foundation; see COPYING for details.
+"""
+
+__author__ = """
+kjerabek(a)redhat.com (Kamil Jerabek)
+"""
+
+import re
+
+def parse_offloads(offloads):
+ """Parse offloads combination in string to tuple, containing list of
+ summary of all used offloads, and list of all offloads settings.
+ The function parse all used offloads, in each set all offloads are on,
+ except the ones specified as off.
+
+ Keyword arguments:
+ offloads -- string of offloads combination separated with ';'
+ Expected input: "tso on gso on tx off; tso off tx off ;rx off".
+ """
+
+ if offloads is None:
+ return None
+
+ is_valid = re.compile(r"^([a-z\-]+\s+(off|on)(\s*[;]\s*|\s*))+$")
+ opts_split = re.compile(r".*?(?=;)|.+$")
+ opts_offloads_split = re.compile(r"([a-z]+(?=\s+(off|on)))+")
+ offloads_split = re.compile(r"([a-z\-]+)(?=\s+off|\s+on)")
+
+ if re.match(is_valid, offloads) is None:
+ raise Exception('Invalid offloads format')
+
+ offload_set = ([], [])
+ sequence = re.findall(offloads_split, offloads)
+ [offload_set[0].append(i) for i in sequence if not offload_set[0].count(i)]
+
+ opts_match = filter(None, re.findall(opts_split, offloads))
+
+ for opts in opts_match:
+ sett = []
+ match = re.findall(opts_offloads_split, opts)
+
+ for offload in offload_set[0]:
+ if (offload, 'off') in match:
+ sett.append((offload, 'off'))
+ else:
+ sett.append((offload, 'on'))
+
+ offload_set[1].append(sett)
+
+ return offload_set
--
2.5.5