Skip to content

examples/lwip_ipv4: add example for LWIP IPv4 client/server #21519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krzysztof-cabaj
Copy link
Contributor

@krzysztof-cabaj krzysztof-cabaj commented May 31, 2025

Contribution description

This PR adds new example which shows how to implement LWIP IPv4 client and server.

Moreover, this example can be used in CI to check, if new code do not break LWIP IPv4.
In the previous few months at least two problems with LWIP IPv4 are detected manually,
and they should be detected by CI - see PR #21316 or PR #21342.

Testing procedure

Check client and server commands as described in the README.md.

Issues/PRs references

None

@krzysztof-cabaj krzysztof-cabaj requested a review from jia200x as a code owner May 31, 2025 16:45
@github-actions github-actions bot added Area: doc Area: Documentation Area: examples Area: Example Applications labels May 31, 2025
@crasbe crasbe added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 3, 2025
@riot-ci
Copy link

riot-ci commented Jun 3, 2025

Murdock results

✔️ PASSED

eeb5403 examples/lwip_ipv4: add makefile.ci

Success Failures Total Runtime
17 0 17 01m:40s

Artifacts

@krzysztof-cabaj
Copy link
Contributor Author

I try to generate makefile.ci automatically using sudo make -C ./examples/networking/misc/lwip_ipv4 generate-Makefile.ci
but after around 1h and occupied 5GB of disk it still stuck at acd52832 board.

@crasbe could you add label CI: no fast fail so I could generate makefile.ci manually.

@crasbe
Copy link
Contributor

crasbe commented Jun 3, 2025

I'll run it on my work computer tomorrow, then you can address the suggestions without triggering a full rebuild on every fixup.

@crasbe
Copy link
Contributor

crasbe commented Jun 4, 2025

This is the result for generate-Makefile.ci for your example:

BOARD_INSUFFICIENT_MEMORY := \
    bluepill-stm32f030c8 \
    i-nucleo-lrwan1 \
    nucleo-c031c6 \
    nucleo-f030r8 \
    nucleo-f031k6 \
    nucleo-f042k6 \
    nucleo-l011k4 \
    nucleo-l031k6 \
    nucleo-l053r8 \
    samd10-xmini \
    slstk3400a \
    stk3200 \
    stm32f030f4-demo \
    stm32f0discovery \
    stm32g0316-disco \
    stm32l0538-disco \
    weact-g030f6 \
    #

@krzysztof-cabaj
Copy link
Contributor Author

@crasbe Thanks for Makefile.ci generation.

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-lwip_ipv4 branch 3 times, most recently from 829cea9 to 867808b Compare June 7, 2025 16:00
Comment on lines +86 to +103
mutex_lock(&server_mutex);
server_running = 0;
mutex_unlock(&server_mutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you need that for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea is that if due to some errors this thread ends - we could start server once again.
I tested this situation with similar code after sock_udp_recv function (lines 98-105). When RIOT receives UDP datagram longer than 64 bytes (buffer size) it ends with error, but I could restart server and later everything works well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why the need for a mutex?

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-lwip_ipv4 branch 2 times, most recently from ea3ad62 to 9a20829 Compare June 13, 2025 10:24
@krzysztof-cabaj
Copy link
Contributor Author

All remarks from review fixed.
CI is green.

@krzysztof-cabaj
Copy link
Contributor Author

Can me move this PR a little forward?

}

if (data_len != (size_t)sock_udp_send(&sock, argv[3], data_len, NULL)) {
printf("Error sock_udp_send!\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You likely want to print the error.

Copy link
Contributor Author

@krzysztof-cabaj krzysztof-cabaj Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I want to print error.
Your comment concerns wrong condition? You suggest add only condition for <0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sock_udp_send() gives you an error code that can tell the user why the send failed.

Comment on lines +86 to +103
mutex_lock(&server_mutex);
server_running = 0;
mutex_unlock(&server_mutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why the need for a mutex?

return -1;
}

SHELL_COMMAND(server, "Starts server which receives UDP datagrams", _server_cmd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more convenient for testing if the server did auto-start.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer do not start server automatically.
This is (1) example, (2) user can from CLI start it on various port.

@krzysztof-cabaj krzysztof-cabaj force-pushed the examples-lwip_ipv4 branch 2 times, most recently from fbab430 to 85936e5 Compare June 20, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: examples Area: Example Applications CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants