Skip to content

net/unicoap: basic CoAP group communication support - #22484

Draft
elenaf9 wants to merge 2 commits into
RIOT-OS:pr/unicoap-clientfrom
elenaf9:unicoap-03-client-group-communication
Draft

net/unicoap: basic CoAP group communication support#22484
elenaf9 wants to merge 2 commits into
RIOT-OS:pr/unicoap-clientfrom
elenaf9:unicoap-03-client-group-communication

Conversation

@elenaf9

@elenaf9 elenaf9 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Contribution description

WIP group communication support for unicoap.
Group communication is based on IP multicast, with non-confirmable messages. Most of it works already out-of-the-box using the gnrc IP multicast support. Two main changes required:

  • If a request was multicast, we can expect multiple replies. So only clear the memo after a timeout or if the user manually aborted the request.
  • Add the timeout for multicast requests, until which replies are acceptable.

Testing procedure

Tested successfully with one client and two servers using the unicoap_{client,server} example 1 with adafruit express boards:

  • add multicast addrs to servers: ifconfig 8 add ff02::fd
  • send request from client to multicast addr: unicoap get coap://[ff02::fd]/greeting?name=RIOTer
  • => should get two replies in return and eventually an (expected) timeout

Issues/PRs references

Small addition to #22266.

Tracking issue: #21389

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • none

Footnotes

  1. + added shell for the server

@github-actions github-actions Bot added Area: network Area: Networking Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System labels Jul 19, 2026
Comment thread sys/net/application_layer/unicoap/state.c Outdated
Comment thread sys/include/net/unicoap/client.h Outdated
@elenaf9 elenaf9 changed the title unicoap: basic group communication support unicoap: basic CoAP group communication support Jul 19, 2026
@AnnsAnns AnnsAnns added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR AI: Not Used AI was stated to not be used in this PR/Issue labels Jul 19, 2026
@riot-ci

riot-ci commented Jul 19, 2026

Copy link
Copy Markdown

Murdock results

FAILED

48cdf27 fixup! unicoap: basic group communication support

Artifacts

@crasbe crasbe added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary labels Jul 19, 2026
@carl-tud carl-tud changed the title unicoap: basic CoAP group communication support net/unicoap: basic CoAP group communication support Jul 20, 2026

@carl-tud carl-tud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of small things; would it be possible to cancel a multicast request using unicoap_cancel?

Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
Comment thread sys/net/application_layer/unicoap/state.c Outdated
Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/include/net/unicoap/config.h
@mguetschow

Copy link
Copy Markdown
Contributor

I assume this is an implementation of https://datatracker.ietf.org/doc/html/rfc7390? I was yesterday pointed to https://datatracker.ietf.org/doc/draft-ietf-core-groupcomm-bis/ which obsoletes RFC7390 with many more features. Might be worth to have a look. It is about to be published as RFC: https://queue.rfc-editor.org/#draft-ietf-core-groupcomm-bis

Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/net/application_layer/unicoap/include/private/state.h Outdated
Comment thread sys/net/application_layer/unicoap/include/private/state.h Outdated
Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
@github-actions github-actions Bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: build system Area: Build system Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration labels Jul 20, 2026
@elenaf9
elenaf9 force-pushed the unicoap-03-client-group-communication branch from 7d52f88 to 993cf29 Compare July 21, 2026 09:18
@github-actions github-actions Bot removed the Area: tests Area: tests and testing framework label Jul 21, 2026
@carl-tud
carl-tud deleted the branch RIOT-OS:pr/unicoap-client August 16, 2026 18:58
@carl-tud carl-tud closed this Aug 16, 2026
@carl-tud carl-tud reopened this Aug 16, 2026
@elenaf9
elenaf9 force-pushed the unicoap-03-client-group-communication branch from 993cf29 to d53226e Compare September 4, 2026 12:50
@github-actions github-actions Bot removed Area: doc Area: Documentation Area: build system Area: Build system labels Sep 4, 2026
@github-actions github-actions Bot removed Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration labels Sep 4, 2026
@elenaf9

elenaf9 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Basic testing of this PR was successful:

Tested successfully with one client and two servers using the unicoap_{client,server} example 1 with adafruit express boards:

  • add multicast addrs to servers: ifconfig 8 add ff02::fd
  • send request from client to multicast addr: unicoap get coap://[ff02::fd]/greeting?name=RIOTer
  • => should get two replies in return and eventually an (expected) timeout

Open TODOs

Open Questions:

  • Right now we still return the eventual request timeout as failure to the user. It's not really an error because it's simply the time at which we stop accepting responses. Should we just not inform the user of the timeout in the multicast scenario?

Footnotes

  1. + added shell for the server

@crasbe crasbe removed the State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary label Sep 4, 2026

@mguetschow mguetschow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for coding and testing! Some comments below.

  • Right now we still return the eventual request timeout as failure to the user. It's not really an error because it's simply the time at which we stop accepting responses. Should we just not inform the user of the timeout in the multicast scenario?

Agree that we should definitely not return it to the user as an error. But we probably want to inform the user about the finished wait time in case it has some resources alloced that it can free afterwards.

Also a prerequisite for the client sync APIs to continue working, I guess. See unicoap_send_request_sync and unicoap_send_request_sync_copy

Comment thread sys/include/net/unicoap/config.h Outdated
Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
Comment on lines 148 to +164

unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms : CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS,
"client.resp-timeout");
if (!multicast) {
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms :
CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS,
"client.resp-timeout");
}
else if (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0) {
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms :
CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS,
"client.resp-timeout");
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms : CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS,
"client.resp-timeout");
if (!multicast) {
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms :
CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS,
"client.resp-timeout");
}
else if (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0) {
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
(parameters && parameters->timeout_ms > 0) ?
parameters->timeout_ms :
CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS,
"client.resp-timeout");
}
}
uint32_t timeout_ms =
(parameters && parameters->timeout_ms > 0) ? parameters->timeout_ms :
(multicast) ? CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS :
CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS;
if (timeout_ms > 0) {
unicoap_event_schedule(&memo->super.exchange.timeout, _on_response_timeout,
timeout_ms, "client.resp-timeout");
}
}

is timeout_ms == 0 even a sensible value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

timeout == 0 is used to disable the timeout, see #22484 (comment).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see. That's missing in the documentation of the config value right now. Also what does it mean to be disabled? Wouldn't the client then be unable to free up any resources it may have used for the transmission forever? Or does it not need transmissions for multicast anyways?

I could think of DTLS sessions e.g.. But anyways, how about interplay with DTLS for multicast? Probably just not supported? Is is caught somewhere right now?

@elenaf9 elenaf9 Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's missing in the documentation of the config value right now

https://github.com/elenaf9/RIOT/blob/48cdf27bbacef19b4cd22323af5f04e29a9b9954/sys/include/net/unicoap/config.h#L286

Wouldn't the client then be unable to free up any resources it may have used for the transmission forever?

The user can still free up the resource by manually calling unicoap_cancel_request. This was discussed with @carl-tud out-of-band before.

But anyways, how about interplay with DTLS for multicast? Probably just not supported? Is is caught somewhere right now?

Per RFC 7390, the DTLS- based approach for CoAP is only for unicast and does not support group security features. Draft draft-ietf-core-groupcomm-bis specifies Group OSCORE as the default.
For this PR I think it's out of scope, but I'll add a check to catch the DTLS case.

Comment thread sys/net/application_layer/unicoap/state.c Outdated
Comment on lines +188 to 196

if (endpoint && !unicoap_endpoint_is_equal(&memo->super.endpoint,
endpoint) && !_is_multicast(memo)) {
continue;
}

if (token_length == sizeof(memo->token) && memcmp(memo->token, token, token_length) == 0) {
return memo;
}

@mguetschow mguetschow Sep 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure I understand that reasoning on the first glance. Could you elaborate?

I would expect: if multicast, just match on token. otherwise check endpoint and token. or does endpoint_is_equal does some special handling of multicast adresses?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would expect: if multicast, just match on token. otherwise check endpoint. or does endpoint_is_equal does some special handling of multicast adresses?

Yes, that's what this implements: if the endpoint doesn't match and it's not multicast =>continue. But will move the is_multicast check to the beginning so that we check that before comparing the endpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

then i would propose:

if ((multicast || (endpoint && is_equal)) && token-comparison)

in a single if-clause to avoid the continue?

@elenaf9 elenaf9 Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's how it was before. I personally find these very long multi-line if-clauses harder to read and understand. But I don't feel strongly about it. Will change it back.

Comment on lines +661 to +662
if (!_is_multicast(memo)) {
unicoap_event_cancel(&memo->super.exchange.timeout);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe add a comment why we don't cancel for multicast.

Apply suggestions from code review

Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
@crasbe crasbe added the State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Not Used AI was stated to not be used in this PR/Issue Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary 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.

6 participants