Skip to content

Commit 63b38ce

Browse files
driver/rawnetworkinterfacedriver: ethtool get/change EEE settings
Add interface Energy Efficient Ethernet (EEE) configuration (`ethtool --set-eee`) support to the RawNetworkInterfaceDriver. This allows configuring the EEE parameters eee, tx-lpi, tx-timer and advertise on the bound interface. Also add a `get_eee_settings()` method to query those settings. Note that ethtool gained the required --json support for this sub command in v6.10. Signed-off-by: Bastian Krause <[email protected]>
1 parent f63dde9 commit 63b38ce

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

helpers/labgrid-raw-interface

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ def main(program, options):
9999
args.append(options.ifname)
100100
args.extend(options.ethtool_change_args)
101101

102+
elif options.subcommand == "set-eee":
103+
for arg in options.ethtool_set_eee_args:
104+
if arg.startswith("-") or not allowed_chars.issuperset(arg):
105+
raise ValueError(f"ethtool --set-eee arg '{arg}' contains invalid characters")
106+
107+
args.append("--set-eee")
108+
args.append(options.ifname)
109+
args.extend(options.ethtool_set_eee_args)
110+
102111
try:
103112
os.execvp(args[0], args)
104113
except FileNotFoundError as e:
@@ -138,6 +147,13 @@ if __name__ == "__main__":
138147
"ethtool_change_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --change args"
139148
)
140149

150+
# ethtool: set-eee
151+
ethtool_change_parser = ethtool_subparsers.add_parser("set-eee")
152+
ethtool_change_parser.add_argument("ifname", type=str, help="interface name")
153+
ethtool_change_parser.add_argument(
154+
"ethtool_set_eee_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --set-eee args"
155+
)
156+
141157
args = parser.parse_args()
142158
try:
143159
main(args.program, args)

labgrid/driver/rawnetworkinterfacedriver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ def ethtool_configure(self, **settings):
119119
cmd = self._wrap_command(cmd)
120120
subprocess.check_call(cmd)
121121

122+
@Driver.check_active
123+
def get_ethtool_eee_settings(self):
124+
"""
125+
Returns Energy-Efficient Ethernet settings via ethtool of the bound network interface
126+
resource.
127+
"""
128+
cmd = self.iface.command_prefix + ["ethtool", "--show-eee", "--json", self.iface.ifname]
129+
output = subprocess.check_output(cmd, encoding="utf-8")
130+
return json.loads(output)[0]
131+
132+
@Driver.check_active
133+
@step(args=["settings"])
134+
def ethtool_configure_eee(self, **settings):
135+
"""
136+
Change Energy-Efficient Ethernet settings via ethtool of the bound network interface
137+
resource.
138+
139+
Supported settings are described in ethtool(8) --set-eee (use "_" instead of "-").
140+
"""
141+
cmd = ["ethtool", "set-eee", self.iface.ifname]
142+
cmd += [item.replace("_", "-") for pair in settings.items() for item in pair]
143+
cmd = self._wrap_command(cmd)
144+
subprocess.check_call(cmd)
145+
122146
def _stop(self, proc, *, timeout=None):
123147
assert proc is not None
124148

0 commit comments

Comments
 (0)