From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DAE8E4366A; Mon, 4 Dec 2023 11:07:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6928A40294; Mon, 4 Dec 2023 11:07:40 +0100 (CET) Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by mails.dpdk.org (Postfix) with ESMTP id BC10E4028C for ; Mon, 4 Dec 2023 11:07:38 +0100 (CET) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a1a0bc1e415so339319966b.0 for ; Mon, 04 Dec 2023 02:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1701684458; x=1702289258; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LRlgFWMF4lHHTUe2Fbt2wRHIHpYHi8hhEw3+yhRgU3I=; b=fR/YdTUmV/Ex5z2fknIxJwfqrPAh5xsr8iFqQFtY+yYMkosv1vLwZR16BUX7pNYOer +N7YPZ0ox6NQHmmbcEmZgjmwCHBNVDnFXNS6b6CWIPH/fdA025E2kjew2ZJoHSqF1Q7Z 9XB673p71rBHJhcJ0WCPC79gSLmnGf2qkXUFMmb/2kOTWS366g0mMFF4w/p3EC/HsLNo IZnZh51cYU7I9cmXFV9CK51lS906R2eZjQZsD7JLDWFO4iFYQoyV8BOcXcXlkjMe596f TEUoBi4aJO7pIGGBqsYTkkpEVFl13UUY85bGwKkYoVO/jWleqWSQXr0qG269eZ/Beopt Je9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701684458; x=1702289258; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LRlgFWMF4lHHTUe2Fbt2wRHIHpYHi8hhEw3+yhRgU3I=; b=h+ZAZ8Rb3nqokQHcLnM1CmT9uyoJfXdrBn/B6X+XjtLtg1F+qGLipohuBfpinlpE4S 4l18igUhqw20rCcLJA7LguyjpV0qNMr4+5NTbIC6ZtxlA6iinFPpXZ36A/Z4B19mfRHx dxvjT687V88m9oCm27VSovBACtkn27duBU/IihNyHMyGa8J+Kd04bsezmoFtpdjUEag/ wOoQFIFElAAOjIUHkyyNhfn7YaypiuMQkk6i5js/OHhm+sg4HZEkTg90zmPxFLBmKjUj 0v7hqUFO03Ph2PqBhbyJMnHKinukx6zJ9kqOe/VDES0wujMLDmkT1CwVthYVGZ6CC7Sz wMyA== X-Gm-Message-State: AOJu0YzuesUiigDdyHtUOIsM9MBjSTCbtOtDbCdc2YwSo/wzEzTDYF6D IUfJ+xSdabz9GsGiVvQyqCJsTfSagAnIZiK7VtOPWw== X-Google-Smtp-Source: AGHT+IFMM9g2LAvRHDfn4JgLdsvsAVhX5hiigfXyf0weReqIDm1ExvupzYiVKVeKBE3N37riG8GRgKY5QDY0HEmzMR8= X-Received: by 2002:a17:906:1dd:b0:a1a:678e:f7d0 with SMTP id 29-20020a17090601dd00b00a1a678ef7d0mr1648532ejj.109.1701684458258; Mon, 04 Dec 2023 02:07:38 -0800 (PST) MIME-Version: 1.0 References: <20231115130959.39420-1-juraj.linkes@pantheon.tech> <20231123151344.162812-1-juraj.linkes@pantheon.tech> <20231123151344.162812-21-juraj.linkes@pantheon.tech> In-Reply-To: From: =?UTF-8?Q?Juraj_Linke=C5=A1?= Date: Mon, 4 Dec 2023 11:07:27 +0100 Message-ID: Subject: Re: [PATCH v8 20/21] dts: scapy tg docstring update To: Jeremy Spewock Cc: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, paul.szczepanek@arm.com, yoan.picchi@foss.arm.com, Luca.Vizzarro@arm.com, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Dec 1, 2023 at 7:18=E2=80=AFPM Jeremy Spewock wrote: > > > > On Thu, Nov 23, 2023 at 10:14=E2=80=AFAM Juraj Linke=C5=A1 wrote: >> >> Format according to the Google format and PEP257, with slight >> deviations. >> >> Signed-off-by: Juraj Linke=C5=A1 >> --- >> .../testbed_model/traffic_generator/scapy.py | 91 +++++++++++-------- >> 1 file changed, 54 insertions(+), 37 deletions(-) >> >> diff --git a/dts/framework/testbed_model/traffic_generator/scapy.py b/dt= s/framework/testbed_model/traffic_generator/scapy.py >> index c88cf28369..30ea3914ee 100644 >> --- a/dts/framework/testbed_model/traffic_generator/scapy.py >> +++ b/dts/framework/testbed_model/traffic_generator/scapy.py >> @@ -2,14 +2,15 @@ >> # Copyright(c) 2022 University of New Hampshire >> # Copyright(c) 2023 PANTHEON.tech s.r.o. >> >> -"""Scapy traffic generator. >> +"""The Scapy traffic generator. >> >> -Traffic generator used for functional testing, implemented using the Sc= apy library. >> +A traffic generator used for functional testing, implemented with >> +`the Scapy library `_. >> The traffic generator uses an XML-RPC server to run Scapy on the remote= TG node. >> >> -The XML-RPC server runs in an interactive remote SSH session running Py= thon console, >> -where we start the server. The communication with the server is facilit= ated with >> -a local server proxy. >> +The traffic generator uses the :mod:`xmlrpc.server` module to run an XM= L-RPC server >> +in an interactive remote Python SSH session. The communication with the= server is facilitated >> +with a local server proxy from the :mod:`xmlrpc.client` module. >> """ >> >> import inspect >> @@ -69,20 +70,20 @@ def scapy_send_packets_and_capture( >> recv_iface: str, >> duration: float, >> ) -> list[bytes]: >> - """RPC function to send and capture packets. >> + """The RPC function to send and capture packets. >> >> - The function is meant to be executed on the remote TG node. >> + The function is meant to be executed on the remote TG node via the = server proxy. >> > > Should this maybe be "This function is meant" instead? I'm not completely= sure if it should be, I feel like it might be able to go either way. > There is something to this. It's a bit more explicit and as such less confusing which feels better, so I'll change it in all three instances. >> >> Args: >> xmlrpc_packets: The packets to send. These need to be converted= to >> - xmlrpc.client.Binary before sending to the remote server. >> + :class:`~xmlrpc.client.Binary` objects before sending to th= e remote server. >> send_iface: The logical name of the egress interface. >> recv_iface: The logical name of the ingress interface. >> duration: Capture for this amount of time, in seconds. >> >> Returns: >> A list of bytes. Each item in the list represents one packet, w= hich needs >> - to be converted back upon transfer from the remote node. >> + to be converted back upon transfer from the remote node. >> """ >> scapy_packets =3D [scapy.all.Packet(packet.data) for packet in xmlr= pc_packets] >> sniffer =3D scapy.all.AsyncSniffer( >> @@ -96,19 +97,15 @@ def scapy_send_packets_and_capture( >> >> >> def scapy_send_packets(xmlrpc_packets: list[xmlrpc.client.Binary], send= _iface: str) -> None: >> - """RPC function to send packets. >> + """The RPC function to send packets. >> >> - The function is meant to be executed on the remote TG node. >> - It doesn't return anything, only sends packets. >> + The function is meant to be executed on the remote TG node via the = server proxy. > > > Same thing here. I don't think it matters that much since you refer to it= as being "the RPC function" for sending packets, but it feels like you are= referring instead to this specific function on this line. > >> >> + It only sends `xmlrpc_packets`, without capturing them. >> >> Args: >> xmlrpc_packets: The packets to send. These need to be converted= to >> - xmlrpc.client.Binary before sending to the remote server. >> + :class:`~xmlrpc.client.Binary` objects before sending to th= e remote server. >> send_iface: The logical name of the egress interface. >> - >> - Returns: >> - A list of bytes. Each item in the list represents one packet, w= hich needs >> - to be converted back upon transfer from the remote node. >> """ >> scapy_packets =3D [scapy.all.Packet(packet.data) for packet in xmlr= pc_packets] >> scapy.all.sendp(scapy_packets, iface=3Dsend_iface, realtime=3DTrue,= verbose=3DTrue) >> @@ -128,11 +125,19 @@ def scapy_send_packets(xmlrpc_packets: list[xmlrpc= .client.Binary], send_iface: s >> >> >> class QuittableXMLRPCServer(SimpleXMLRPCServer): >> - """Basic XML-RPC server that may be extended >> - by functions serializable by the marshal module. >> + """Basic XML-RPC server. >> + >> + The server may be augmented by functions serializable by the :mod:`= marshal` module. >> """ >> >> def __init__(self, *args, **kwargs): >> + """Extend the XML-RPC server initialization. >> + >> + Args: >> + args: The positional arguments that will be passed to the s= uperclass's constructor. >> + kwargs: The keyword arguments that will be passed to the su= perclass's constructor. >> + The `allow_none` argument will be set to :data:`True`. >> + """ >> kwargs["allow_none"] =3D True >> super().__init__(*args, **kwargs) >> self.register_introspection_functions() >> @@ -140,13 +145,12 @@ def __init__(self, *args, **kwargs): >> self.register_function(self.add_rpc_function) >> >> def quit(self) -> None: >> + """Quit the server.""" >> self._BaseServer__shutdown_request =3D True >> return None >> >> def add_rpc_function(self, name: str, function_bytes: xmlrpc.client= .Binary) -> None: >> - """Add a function to the server. >> - >> - This is meant to be executed remotely. >> + """Add a function to the server from the local server proxy. >> >> Args: >> name: The name of the function. >> @@ -157,6 +161,11 @@ def add_rpc_function(self, name: str, function_byte= s: xmlrpc.client.Binary) -> N >> self.register_function(function) >> >> def serve_forever(self, poll_interval: float =3D 0.5) -> None: >> + """Extend the superclass method with an additional print. >> + >> + Once executed in the local server proxy, the print gives us a c= lear string to expect >> + when starting the server. The print means the function was exec= uted on the XML-RPC server. >> + """ >> print("XMLRPC OK") >> super().serve_forever(poll_interval) >> >> @@ -164,19 +173,12 @@ def serve_forever(self, poll_interval: float =3D 0= .5) -> None: >> class ScapyTrafficGenerator(CapturingTrafficGenerator): >> """Provides access to scapy functions via an RPC interface. >> >> - The traffic generator first starts an XML-RPC on the remote TG node= . >> - Then it populates the server with functions which use the Scapy lib= rary >> - to send/receive traffic. >> - >> - Any packets sent to the remote server are first converted to bytes. >> - They are received as xmlrpc.client.Binary objects on the server sid= e. >> - When the server sends the packets back, they are also received as >> - xmlrpc.client.Binary object on the client side, are converted back = to Scapy >> - packets and only then returned from the methods. >> + The class extends the base with remote execution of scapy functions= . > > > Same thing here if the above end up getting changed. > >> >> >> - Arguments: >> - tg_node: The node where the traffic generator resides. >> - config: The user configuration of the traffic generator. >> + Any packets sent to the remote server are first converted to bytes.= They are received as >> + :class:`~xmlrpc.client.Binary` objects on the server side. When the= server sends the packets >> + back, they are also received as :class:`~xmlrpc.client.Binary` obje= cts on the client side, are >> + converted back to :class:`~scapy.packet.Packet` objects and only th= en returned from the methods. >> >> Attributes: >> session: The exclusive interactive remote session created by th= e Scapy >> @@ -190,6 +192,22 @@ class ScapyTrafficGenerator(CapturingTrafficGenerat= or): >> _config: ScapyTrafficGeneratorConfig >> >> def __init__(self, tg_node: Node, config: ScapyTrafficGeneratorConf= ig): >> + """Extend the constructor with Scapy TG specifics. >> + >> + The traffic generator first starts an XML-RPC on the remote `tg= _node`. >> + Then it populates the server with functions which use the Scapy= library >> + to send/receive traffic: >> + >> + * :func:`scapy_send_packets_and_capture` >> + * :func:`scapy_send_packets` >> + >> + To enable verbose logging from the xmlrpc client, use the :opti= on:`--verbose` >> + command line argument or the :envvar:`DTS_VERBOSE` environment = variable. >> + >> + Args: >> + tg_node: The node where the traffic generator resides. >> + config: The traffic generator's test run configuration. >> + """ >> super().__init__(tg_node, config) >> >> assert ( >> @@ -231,10 +249,8 @@ def _start_xmlrpc_server_in_remote_python(self, lis= ten_port: int) -> None: >> # or class, so strip all lines containing only whitespace >> src =3D "\n".join([line for line in src.splitlines() if not lin= e.isspace() and line !=3D ""]) >> >> - spacing =3D "\n" * 4 >> - >> # execute it in the python terminal >> - self.session.send_command(spacing + src + spacing) >> + self.session.send_command(src + "\n") >> self.session.send_command( >> f"server =3D QuittableXMLRPCServer(('0.0.0.0', {listen_port= }));server.serve_forever()", >> "XMLRPC OK", >> @@ -267,6 +283,7 @@ def _send_packets_and_capture( >> return scapy_packets >> >> def close(self) -> None: >> + """Close the traffic generator.""" >> try: >> self.rpc_server_proxy.quit() >> except ConnectionRefusedError: >> -- >> 2.34.1 >>