Skip to content

Commit a93f147

Browse files
driver/rawnetworkinterfacedriver: ethtool get/change pause settings
Add interface pause configuration (`ethtool --pause`) support to the RawNetworkInterfaceDriver. This allows configuring the pause parameters autoneg, rx and tx on the bound interface. Also add a `get_pause_settings()` method to query those settings. Signed-off-by: Bastian Krause <[email protected]>
1 parent 63b38ce commit a93f147

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

helpers/labgrid-raw-interface

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ def main(program, options):
108108
args.append(options.ifname)
109109
args.extend(options.ethtool_set_eee_args)
110110

111+
elif options.subcommand == "pause":
112+
for arg in options.ethtool_pause_args:
113+
if arg.startswith("-") or not allowed_chars.issuperset(arg):
114+
raise ValueError(f"ethtool --pause arg '{arg}' contains invalid characters")
115+
116+
args.append("--pause")
117+
args.append(options.ifname)
118+
args.extend(options.ethtool_pause_args)
119+
111120
try:
112121
os.execvp(args[0], args)
113122
except FileNotFoundError as e:
@@ -154,6 +163,13 @@ if __name__ == "__main__":
154163
"ethtool_set_eee_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --set-eee args"
155164
)
156165

166+
# ethtool: pause
167+
ethtool_change_parser = ethtool_subparsers.add_parser("pause")
168+
ethtool_change_parser.add_argument("ifname", type=str, help="interface name")
169+
ethtool_change_parser.add_argument(
170+
"ethtool_pause_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --pause args"
171+
)
172+
157173
args = parser.parse_args()
158174
try:
159175
main(args.program, args)

labgrid/driver/rawnetworkinterfacedriver.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,28 @@ def ethtool_configure_eee(self, **settings):
143143
cmd = self._wrap_command(cmd)
144144
subprocess.check_call(cmd)
145145

146+
@Driver.check_active
147+
def get_ethtool_pause_settings(self):
148+
"""
149+
Returns pause parameters via ethtool of the bound network interface resource.
150+
"""
151+
cmd = self.iface.command_prefix + ["ethtool", "--json", "--show-pause", self.iface.ifname]
152+
output = subprocess.check_output(cmd, encoding="utf-8")
153+
return json.loads(output)[0]
154+
155+
@Driver.check_active
156+
@step(args=["settings"])
157+
def ethtool_configure_pause(self, **settings):
158+
"""
159+
Change pause parameters via ethtool of the bound network interface resource.
160+
161+
Supported settings are described in ethtool(8) --pause
162+
"""
163+
cmd = ["ethtool", "pause", self.iface.ifname]
164+
cmd += [item for pair in settings.items() for item in pair]
165+
cmd = self._wrap_command(cmd)
166+
subprocess.check_call(cmd)
167+
146168
def _stop(self, proc, *, timeout=None):
147169
assert proc is not None
148170

0 commit comments

Comments
 (0)