<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 19, 2023 at 11:45 AM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The subject could be improved. That these methods are required is<br>
kinda obvious. We should try to actually include some useful<br>
information in the subject, such as "add basic methods to testpmd<br>
shell", but even that is not saying much. Maybe "add startup<br>
verification and forwarding to testpmd shell" - I actually like<br>
something like this.<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">The subject on this commit was something that I was having trouble with for quite some time, I was trying to think of something that would be descriptive enough and not too long so I opted to go for the more vague subject and explain it in the body, but I like this subject much better and will change to using that in the next version.<br></div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On Mon, Dec 18, 2023 at 7:13 PM <<a href="mailto:jspewock@iol.unh.edu" target="_blank">jspewock@iol.unh.edu</a>> wrote:<br>
><br>
> From: Jeremy Spewock <<a href="mailto:jspewock@iol.unh.edu" target="_blank">jspewock@iol.unh.edu</a>><br>
><br>
> Added a method within the testpmd interactive shell that polls the<br>
> status of ports and verifies that the link status on a given port is<br>
> "up." Polling will continue until either the link comes up, or the<br>
> timeout is reached. Also added methods for starting and stopping packet<br>
> forwarding in testpmd and a method for setting the forwarding mode on<br>
> testpmd. The method for starting packet forwarding will also attempt to<br>
> verify that forwarding did indeed start by default.<br>
><br>
<br>
The body should not explain what we're adding, but why we're adding it.<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">Very good point and I'll keep this in mind in the future.<br></div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
><br>
> +    def start(self, verify: bool = True) -> None:<br>
> +        """Start packet forwarding with the current configuration.<br>
> +<br>
> +        Args:<br>
> +            verify: If :data:`True` , a second start command will be sent in an attempt to verify<br>
> +                packet forwarding started as expected.<br>
> +<br>
<br>
Isn't there a better way to verify this? Like with some show command?<br>
Or is this how it's supposed to be used?<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">I looked through documentation and the outputs of many of the show commands and I wasn't able to find one that indicated that forwarding had actually started.  Clearly testpmd holds this state somewhere but I couldn't find where. I agree that this method of verification doesn't seem perfect but I wasn't able to find a more automated method of doing so since the start command has no output otherwise.<br></div><div style="font-family:arial,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,sans-serif" class="gmail_default">One place that does seem to display if forwarding has started is using the command: `show port (port_id) rxq|txq (queue_id) desc (desc_id) status` (specifically the rxq variant) but this seems to take a few seconds to update its state between available and done when you stop forwarding so it seems like it could lead to inaccurate verification. This would also make assumptions on the number of rx and tx queues which I'm unsure if we would want to make.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +        Raises:<br>
> +            InteractiveCommandExecutionError: If `verify` is :data:`True` and forwarding fails to<br>
> +                start.<br>
> +        """<br>
> +        self.send_command("start")<br>
> +        if verify:<br>
> +            # If forwarding was already started, sending "start" again should tell us<br>
> +            if "Packet forwarding already started" not in self.send_command("start"):<br>
> +                raise InteractiveCommandExecutionError("Testpmd failed to start packet forwarding.")<br>
> +<br>
> +    def stop(self) -> None:<br>
> +        """Stop packet forwarding."""<br>
> +        self.send_command("stop")<br>
> +<br>
<br>
Do we want to do verification here as well? Is there a reason to do<br>
such verification?<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">I figured there wasn't much of a reason as your two options when you run this command are you aren't already forwarding in which case this command still gets you into the state you want to be in, or you are forwarding and it stops you which also puts you into the correct state.</div><div style="font-family:arial,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,sans-serif" class="gmail_default">I guess that assumes that there can't be an error when trying to stop forwarding, so I could add a verification step for that purpose, but I don't think it would commonly be the case that stopping fails. There isn't really harm in verifying this for safety though, so I'll add it.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
>      def get_devices(self) -> list[TestPmdDevice]:<br>
>          """Get a list of device names that are known to testpmd<br>
><br>
> @@ -43,3 +101,37 @@ def get_devices(self) -> list[TestPmdDevice]:<br>
>              if "device name:" in line.lower():<br>
>                  dev_list.append(TestPmdDevice(line))<br>
>          return dev_list<br>
> +<br>
> +    def wait_link_status_up(self, port_id: int, timeout=SETTINGS.timeout) -> bool:<br>
> +        """Wait until the link status on the given port is "up".<br>
> +<br>
> +        Arguments:<br>
> +            port_id: Port to check the link status on.<br>
> +            timeout: Time to wait for the link to come up. The default value for this<br>
> +                argument is set using the :option:`-t, --timeout` command-line argument<br>
> +                or the :envvar:`DTS_TIMEOUT` environment variable.<br>
> +<br>
> +        Returns:<br>
> +            If the link came up in time or not.<br>
<br>
This is a bit of a pet peeve of mine - Whether the link came up.<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">Definitely would sound better that way, I'll make the change.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +        """<br>
> +        time_to_stop = time.time() + timeout<br>
> +        while time.time() < time_to_stop:<br>
> +            port_info = self.send_command(f"show port info {port_id}")<br>
> +            if "Link status: up" in port_info:<br>
> +                break<br>
> +            time.sleep(0.5)<br>
<br>
How long does it usually take? If it's in the order of seconds, then<br>
0.5 seems fine, if it's faster, the sleep should probably be shorter.<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">Generally this is something that I've actually seen be up instantly when you open an interactive terminal in testpmd, so another option could be to just make this a single verification check. The reason it was left this way right now was just under the assumption that if a link was down for some reason it might be able to recover within the timeout, but whether that takes seconds or not would depend on why the link was down.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +        else:<br>
> +            self._logger.error(f"The link for port {port_id} did not come up in the given timeout.")<br>
> +        return "Link status: up" in port_info<br>
> +<br>
> +    def set_forward_mode(self, mode: TestPmdForwardingModes):<br>
> +        """Set packet forwarding mode.<br>
> +<br>
> +        Args:<br>
> +            mode: The forwarding mode to use.<br>
> +        """<br>
> +        self.send_command(f"set fwd {mode.value}")<br>
> +<br>
<br>
Again the verification - does it make sense to verify this as well?<br></blockquote><div><br></div><div style="font-family:arial,sans-serif" class="gmail_default">That's a good point and is something easy to verify, I'll add this as well.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +    def close(self) -> None:<br>
> +        self.send_command("exit", "")<br>
> +        return super().close()<br>
> --<br>
> 2.43.0<br>
><br>
</blockquote></div></div>