Commit graph

65 commits

Author SHA1 Message Date
Robert Lubos abc91227b2 net: lib: zperf: Fix socket leak during asynchronous TCP upload
In case of TCP upload error, zperf would leak a socket when running in
asynchronous mode. The upload work have to release the socket it
allocated in any case, regardless of the session result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 11:38:11 -04:00
Robert Lubos 5cea38021e net: lib: zperf: Fix socket leak during socket setup
During socket setup, if one of the setsockopt() calls failed, the
function would return an error w/o closing the socket. That's wrong, as
in case of errors the function should clean up any resources it
allocated, the socket file descriptor is lost otherwise and resources
are leaked.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 11:38:11 -04:00
Ayush Singh 56882e2d91 net: zperf: Fix upload ping timeout error
Fixes remote address for ping before upload. This caused the ping in zperf
upload to timeout as shown in the following output:

```
uart:~$ zperf udp upload 2001:db8::2 5001 10 50 1M
Remote port is 5001
Connecting to 2001:db8::2
Duration:       10.00 s
Packet size:    50 bytes
Rate:           1000 kbps
Starting...
ping 2001:db8::2 timeout
Rate:           1.00 Mbps
Packet duration 390 us
```

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/68674

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-05-15 17:07:58 +02:00
Adam Matus 684a28656e net: zperf: Add periodic reporting for upload
Add option for zperf tcp upload that will enable periodic result reporting.
This is useful for monitoring performance swings during a longer session.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Adam Matus a6ededcc9f net: zperf: Move TCP nodelay socket option
TCP nodelay option is part of zperf upload params, but was not being
set in common zperf_prepare_upload_sock function. Move it there
to align with how other options are set.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Adam Matus 869d4fc041 net: zperf: Improve shell upload cmd
Minor improvements to usage of zperf_shell upload.
Added common defaults for the upload commands arguments.
Print defaults in cmd help.
Throw warning when user sets baud rate for TCP upload.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-04-12 11:54:49 +02:00
Declan Snyder 69e0b03ca9 net: zperf_shell: Fix IPv6 invalid warning
Fix the ipv6 invalid warning always appearing when
a valid ipv4 address is provided.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2024-04-05 18:46:58 +03:00
Fengming Ye 10670b7515 net: zperf: multicast support on multi interfaces
Zperf upload multicast always use default interface.
Zperf download multicast cannot receive packets from other than
224.0.0.1 which is default multicast group.

Add zperf upload/download option -I <interface name> for multicast.
So that user can select interface for multicast.
Add join multicast group for zperf download.

Use the "device list" command to get the interface name as
follows:
 "- ua (READY)"  #uAP interface name
 "- ml (READY)"  #STA interface name

Multicast traffic commands:
zperf udp upload -a -I ua 224.0.0.2 5001 10 1470 1M
zperf udp download -I ua 5001 224.0.0.3

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-03-15 13:07:14 +01:00
Fengming Ye c5b2a16dd2 net: zperf: fix download ipv6 bind fail on specific ip address
For command zperf udp download 5001 192.168.10.1,
zperf will bind both ipv4 and ipv6 sockets on ipv4 address.
But bind ipv6 socket will fail, thus command return fail.

Fix it by check ip address when zperf download.
For ipv4 address only bind ipv4 socket.
For ipv6 address only bind ipv6 socket.
For unspecific address bind both ipv4 and ipv6 sockets.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-03-14 09:47:03 +00:00
Gang Li 03fce7dd3c net: zperf: Fix multicast data failure to receive server's AckFIN packet
In iperf2, for multicast data, if it is a client, it will not wait for
the server's AckFIN packet. Because the iperf2 server will not send an
AckFIN packet.
So in zperf_upload_fin(), an error will occur when the zperf client
waits for the server's AckFIN packet.
Multicast only send the negative sequence number packet and doesn't
wait for a server ack can fix this issue.

Signed-off-by: Gang Li <gang.li_1@nxp.com>
2024-03-07 16:17:18 -06:00
Maochen Wang eda7dd1460 net: zperf: Fix wrong throughput in long-duration traffic test
The zperf received or sent bytes length and duration are in 32bits,
if running long-duration zperf test more than 20min, the value will
overflow, and the test result is wrong. Change it to 64bits can fix
this issue.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-02-29 11:54:07 +00:00
Maochen Wang e7444dcf42 net: zperf: Fix TOS option not working in zperf
When the zperf command is called with '-S' option which means IP_TOS
for IPv4 and IPV6_TCLASS for IPv6, an error is printed and the
setting does not work. The socket option handling was changed by
commit 77e522a5a243('net: context: Refactor option setters'), but the
callers of option setters were not changed. This causes the IP_TOS
or IPV6_TCLASS option failed to set. The fix is to use uint8_t to
store the value of the -S option.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-02-29 11:53:57 +00:00
Jukka Rissanen 4b82b108c8 net: zperf: Select also sockets API in Kconfig
We select sockets service API in Kconfig but should select also
sockets API so that user does not need to set the sockets API separately.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-02-28 09:40:41 +01:00
Robert Lubos 68bc981c52 net: zperf: Fix session leak
In case zperf session was aborted by the user (by for instance stopping
it from shell), or practically in case of any other
communication-related error, the zperf session could end up in a state
other than NULL or COMPLETED, with no way to recover. This made the
session no longer usable and eventually could lead to zperf being not
able to start a new session anymore.

Fix this by introducing zperf_session_reset() function, which resets the
session state back to defaults. The function is called when the zperf
receiver service is stopped.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
Robert Lubos 4ce0352026 net: zperf: Fix TCP receiver start/stop operation
The issues found for UDP receiver were also identified for TCP receiver,
this commit applies practically the same set of changes as in case of
UDP.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
Robert Lubos 139bc4e87e net: zperf: Fix UDP receiver start/stop operation
This commit fixes restarting of UDP receiver service, along with some
other minor cleanups:

* The core issue was udp_server_running flag not being cleared when
  service was stopped. Fix this by introducing udp_receiver_cleanup()
  which does all of the required cleanups when receiver service is
  stopped. The function is called either when the application stopped
  the service with zperf_udp_download_stop(), or when the service was
  stopped due to error.
* net_socket_service_unregister() was not called on
  zperf_udp_download_stop(), but only from the service callback - that
  would not work in case there's no active communication.
* at the same time, net_socket_service_unregister() would be called from
  the service callback in case of errors. Fix this, by making
  udp_recv_data() only return an error, and let the service callback to
  do the cleanup.
* Remove no longer used udp_server_run semaphore
* Remove udp_server_stop - with socket services it seems no longer
  needed.
* zperf_udp_receiver_init() now returns an error, so that we don't
  mark the service as running in case of socket/services error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-02-02 10:31:53 -06:00
Fengming Ye f61a0cb1fa net: zperf: fix the calculation ratio between mbps, kbps and bps
The ratio between mbps and kbps, kbps and bps should be 1000, instead of
1024, as common sense.
The wrong ratio will decrease the Zperf throughput result.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-01-29 10:05:35 +01:00
Jukka Rissanen 1e8cbd5d43 net: zperf: Convert UDP receiver to use socket services
Use socket services API for UDP receiver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Jukka Rissanen 07823f7710 net: zperf: Convert TCP receiver to use socket services
Use socket services API for TCP receiver.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-01-18 20:13:31 +01:00
Robert Lubos aa6f698d31 net: zperf: Fix TCP packet counting
Make sure we send the entire packet buffer before bumping the packet
counter, send() does not guarantee that all of the requested data will
be sent at once with STREAM socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-11-21 08:46:45 +00:00
Chaitanya Tata d4d96b3df2 net: zperf: Fix the check for IPv6
It was typo.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-11-03 11:21:16 +01:00
Chaitanya Tata a1024f6aeb net: zperf: By default bind to any IP address
Default behaviour should only bind to port independent of IP, this
allows even multicast/broadcast L4 traffic to be received.

User can always specify a specific address to bind using shell or
Kconfig or API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Chaitanya Tata dee1f2deaa net: zperf: Set default IP addresses only if configured
If the user has not configured then we see the error prints for the
defaults always.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Chaitanya Tata 6bd47ffb10 net: zperf: Distinguish between IPv4 and IPv6 address set failures
Using a generic IP for address set failures is confusing, esp. two same
prints (one for v4 and the other for v6), so, use explicit version.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-10-27 10:52:19 +02:00
Florian Grandel 630bfff65f net: lib: zperf: fix compiler warning
The compiler emits a "null where non-null expected" warning unless the
argument of strlen is non-null at compile time.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-10-03 15:21:34 +01:00
Rahul Singh 6ef75a26ea net: zperf: Add support for bind to host option for tcp/udp download
The current zperf tcp/udp download command doesn't provide the option
to bind the server to a specific host address. If there is more than
one interface, it will not be possible to test each interface with zperf
tcp/udp download command without building the Zpehyr.

This patch will add support for zperf tcp/udp download command to bind
server to host interface address.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
2023-09-29 16:25:26 +02:00
Jukka Rissanen fa4e978fba net: zperf: Fix the IPv6 ping done in shell
The zperf shell sends a IPv6 ping at the start when working
with IPv6. Convert the sending of the ping to use the new API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2023-09-28 09:34:20 +02:00
Chaitanya Tata 79158a777b zperf: Add support to configure context priority
This is handy in setting a custom priority for the context either
through shell or API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Chaitanya Tata 3b4c529d7e net: Add priority to ping
This is handy in testing of setting priority directly rather than
deriving from DSCP. Please note ICMP doesn't use net context.

This is applicable for both shell and API.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2023-09-12 21:26:28 -04:00
Gerard Marull-Paretas 8cf63ff367 net: lib: zperf: add missing init.h
File was using SYS_INIT without including init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-29 12:17:15 +01:00
Daniel Leung 2b09426fca net: zperf: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Nicolas Pitre bd3ed97230 subsys/net: zperf_udp_uploader: Remove sys_clock_timeout_end_calc() usage
The initial goal was to remove sys_clock_timeout_end_calc(). However,
several related issues have been fixed as well.

First this:

    int64_t print_interval = sys_clock_timeout_end_calc(K_SECONDS(1));
    /* Print log every seconds */
    int64_t print_info = print_interval - k_uptime_ticks();

    if (print_info <= 0) {
        [...]
    }

The above condition will simply never be true.

Then there is lots of back-and-forth time conversions using expensive
base-10 divisions for each loop iterations which is likely to impact
performance.

Let's do the time conversion only once outside the loop and track
everything in terms of ticks within the loop. Also the various timeouts
are open-coded based on the absolute uptime tick so to sample it only
once per round. Using sys_timepoint_calc() and sys_timepoint_timeout()
would have introduced additional uptime tick sampling which implies the
overhead of a downstream lock each time for no gain. For those reasons,
open coding those timeouts bears more benefits in this particular case
compared to using the timepoint API.

Then this:

    secs = k_ticks_to_ms_ceil32(loop_time) / 1000U;
    usecs = k_ticks_to_us_ceil32(loop_time) - secs * USEC_PER_SEC;

The above should round down not up to work accurately. And the usecs
value will become garbage past 1.2 hour of runtime due to overflows.

And no need to clamp the wait period which is on the microsec scale
using the total duration argument being on the millisec scale. That's
yet more loop overhead that can be omitted. The actual duration is
recorded at the end anyway.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Nicolas Pitre 7238b48182 subsys/net: zperf_tcp_uploader: move to timepoint API
Remove sys_clock_timeout_end_calc() usage.
While at it, remove dead last_print_time variable.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Florian Grandel 378f0dd29d net: lib: zperf: fix kernel panic due to invalid thread prio
Compiling an application with CONFIG_NET_ZPERF=y leaving
CONFIG_ZPERF_WORK_Q_THREAD_PRIORITY at its default value would
systematically cause a kernel panic during thread initialization.

The Kconfig variable is NUM_PREEMPT_PRIORITIES by default. Application
threads may not define a priority lower than NUM_PREEMPT_PRIORITIES - 1,
though.

This change limits zperf's thread priority to a valid range. It does not
change the default value as it makes sense to default the thread
priority to the lowest possible value (which is NUM_PREEMPT_PRIORITIES)
but Kconfig does not allow for arithmentic. So the combination of
CLAMP() plus the Kconfig default will ensure min priority plus limit the
range to valid values no matter what has been defined as priority in
Kconfig.

Fixes: #59141

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-13 06:58:15 -04:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Keith Packard 3f3224d880 subsys/net: Labels cannot be applied to declarations
C only permits labels on statements, not declarations.  Separate the
declarations from the assignments so that the labels can target
statements instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-05 10:38:34 +02:00
Krishna T 36c46afbb9 net: zperf: Make Zperf worker thread stack size configurable
All stack sizes should be configurable for memory adjustements.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 10:20:00 +00:00
Krishna T d6e54a417a net: zperf: Make Zperf worker thread priority configurable
This helps us test impact of scheduling on traffic.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-03-20 10:20:00 +00:00
Luca Fancellu 6748d588ab net: zperf: allow TCP receiver to handle multiple connections
Currently the zperf_tcp_receiver can handle only one TCP connection
each time, modify the code to poll and handle multiple connections.

Take the occasion to unify the bind and listen part of the code
between ipv4 and ipv6 part using a structure introduced to handle
the multiple connections.

Now in case the zsock_recv fails, we can't stop every connection
and fail through the error label, so just print the error message
and report the failure through the callback.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-03-16 12:56:10 +01:00
Luca Fancellu d485ef0231 net: zperf: Reduce the scope of input address variables
Reduce the scope of in4_addr_my and in6_addr_my pointer variables
that are currently global, but they are used only inside
tcp_receiver_thread.

Take the occasion to fix a typo in one error message.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-03-16 12:56:10 +01:00
Luca Fancellu d61dcf2f1d net: zperf: improve code quality for tcp_received function
Currently, in tcp_received function defined in zperf_tcp_receiver
module, the assignment of session->state to STATE_COMPLETED is
overwritten on the same path to STATE_NULL and a session is
considered free for both STATE_COMPLETED and STATE_NULL, so remove
the assignment to STATE_NULL.
Remove the break from the STATE_COMPLETED case handling so that it
can fallthrough, in case the same session is used after finish.
Remove also the STATE_LAST_PACKET_RECEIVED case because this state
is never reached.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu 7c4ea08db8 net: zperf: fix typo in error messages
Fix typo in error messages from the zperf_tcp_receiver where UDP
is written instead of TCP.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu 910de7f83d net: zperf: unify get_session among TCP and UDP
The modules zperf_udp_receiver and zperf_tcp_receiver use two
different functions to get a zperf session to store the
statistics, there is a TODO comment in the zperf_session module
suggesting to unify that part.
So delete the get_tcp_session function and use get_session for
both TCP and UDP receiver module.
Delete sock field from struct session because it's not used
anymore.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Luca Fancellu 1a12a070eb net: zperf: add configurable for the zperf sessions number
Currently the maximum number of zperf sessions handled is hardcoded
to 4, create a Kconfig parameter, with default value 4, to make the
maximum number of sessions configurable.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
2023-02-28 18:12:52 +01:00
Krishna T b136676772 net: lib: zperf: Add support to disable Nagle's algorithm
This helps in benchmarking smaller packets, esp. as this is the default
behaviour of iperf.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-02-20 09:53:43 +01:00
Robert Lubos 76dd77df7e net: zperf: Fix potential build warning
A variable was defined directly after a label in two case statements,
resulting in build warning with certain compilers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2023-01-10 14:07:21 +00:00
Krishna T 59842531d1 net: zperf: Make shell dependency optional
Now that we a proper API, shell is just optional, so, make the
dependency optional by refactoring the code.

Also, add a build test combination in twister.

Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
2023-01-03 11:02:01 +01:00
Robert Lubos d27ace4012 net: zperf: Simplify shell initialization
Instead of calling zperf shell initialization routine on the first
command execution, initialize it during system boot, along with other
zperf submodules.

Remove redundant IP address configuration on an interface. The default
configuration relies on NET_CONFIG module, so there's no need to set the
address manually in zperf.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos 7a2c8d2ab8 net: zperf: Shell cleanup
Zperf shell functionality is now encapsuled within a single file,
therefore it no longer makes sense to have a separate shell_utils
file.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00
Robert Lubos dd3fb692fe net: zperf: Add shell command to stop TCP/UDP server
Add zperf shell command to stop TCP/UDP server.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-12-22 11:05:11 +01:00