diff --git a/helpers/labgrid-raw-interface b/helpers/labgrid-raw-interface index 1d75b449a..dc78d4ca4 100755 --- a/helpers/labgrid-raw-interface +++ b/helpers/labgrid-raw-interface @@ -108,6 +108,15 @@ def main(program, options): args.append(options.ifname) args.extend(options.ethtool_set_eee_args) + if options.subcommand == "pause": + for arg in options.ethtool_pause_args: + if arg.startswith("-") or not allowed_chars.issuperset(arg): + raise ValueError(f"ethtool --pause arg '{arg}' contains invalid characters") + + args.append("--pause") + args.append(options.ifname) + args.extend(options.ethtool_pause_args) + try: os.execvp(args[0], args) except FileNotFoundError as e: @@ -154,6 +163,13 @@ if __name__ == "__main__": "ethtool_set_eee_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --set-eee args" ) + # ethtool: pause + ethtool_change_parser = ethtool_subparsers.add_parser("pause") + ethtool_change_parser.add_argument("ifname", type=str, help="interface name") + ethtool_change_parser.add_argument( + "ethtool_pause_args", metavar="ARG", nargs=argparse.REMAINDER, help="ethtool --pause args" + ) + args = parser.parse_args() try: main(args.program, args) diff --git a/labgrid/driver/rawnetworkinterfacedriver.py b/labgrid/driver/rawnetworkinterfacedriver.py index 93939c7b4..593d53bde 100644 --- a/labgrid/driver/rawnetworkinterfacedriver.py +++ b/labgrid/driver/rawnetworkinterfacedriver.py @@ -143,6 +143,28 @@ def configure_eee(self, **settings): cmd = self._wrap_command(cmd) subprocess.check_call(cmd) + @Driver.check_active + def get_pause_settings(self): + """ + Returns pause parameters via ethtool of the bound network interface resource. + """ + cmd = self.iface.command_prefix + ["ethtool", "--json", "--show-pause", self.iface.ifname] + output = subprocess.check_output(cmd, encoding="utf-8") + return json.loads(output)[0] + + @Driver.check_active + @step(args=["settings"]) + def configure_pause(self, **settings): + """ + Change pause parameters via ethtool of the bound network interface resource. + + Supported settings are described in ethtool(8) --pause + """ + cmd = ["ethtool", "pause", self.iface.ifname] + cmd += [item for pair in settings.items() for item in pair] + cmd = self._wrap_command(cmd) + subprocess.check_call(cmd) + def _stop(self, proc, *, timeout=None): assert proc is not None