libcoap icon indicating copy to clipboard operation
libcoap copied to clipboard

Multicast message

Open dfonovic opened this issue 1 year ago • 2 comments

According to the RFC, COAP multicast messages should be of type NON (non-confirmable). However, when using the RIOT OS COAP client, as shown in the screenshot, it sends CON (confirmable) messages. Screenshot 2024-02-20 140329

dfonovic avatar Feb 20 '24 13:02 dfonovic

@dfonovic Thanks for raising this. You are correct in that in any multicast request, NON must be used.

I am assuming that you are using the client example as provided in examples/riot/examples_libcoap_client. I will have a look at this.

mrdeep1 avatar Feb 20 '24 15:02 mrdeep1

@dfonovic Sorry that took so long to come back to you, but I found a general issue with handling multicast traffic - which is fixed in PR #1333. Please check this out and confirm or otherwise that things are now working for you.

mrdeep1 avatar Feb 29 '24 13:02 mrdeep1

It seems the problem with non ack messages and multicasti is working now. However, I have one more question; according to the RFC, when responding to a multicast request, a node should wait for a certain random time before responding to the request (known as leisure time) - Section 8.2 of [RFC7252]. Is it possible to consider implementing this mechanism in libcoap for RIOT OS? Eclipse Californium has this mechanism implemented in the configuration file so that the lower bound time parameter can be modified in the configuration file (Californium3.properties -> COAP.LEISURE=5[s]). Currently, I see a lot of lost packets (screenshot) when everyone responds to the get request at the same time. Thank you very much. Screenshot 2024-03-05 093640

dfonovic avatar Mar 05 '24 08:03 dfonovic

Thanks for doing the investigative work here.

As it happens, the various RIOT OS version coap servers are backing off a random time before responding. The request is at 18.054, the first response is at 18.293 with the last (eighth) one being at 22.825. Each server backs off for a random time between 0 and DEFAULT_LEISURE time (5 seconds).

The server does log 'delay' this information, you just need to increase the libcoap logging level to see this (using Kconfig (make menuconfig), or setting CONFIG_LIBCOAP_LOG_DEBUG=y in app.config).

[It is possible for a server to change the default_leisure time - see coap_session_set_default_leisure().]

The real issue here is that the coap client finishes on receipt of the first response (hence ICMPv6 responses to sever responses 2 to 8). I have just taken the appropriate code from the libcoap examples/coap-client.c and updated examples/libcoap-client/client-coap.c so that is waits for up to DEFAULT_LEISURE for other server responses. Changes have been pushed to #1333.

mrdeep1 avatar Mar 05 '24 10:03 mrdeep1

@dfonovic Can this be closed now?

mrdeep1 avatar Apr 25 '24 14:04 mrdeep1

It seems that everything is now in order and we can close it.

However, I have one more question. I am wondering if it is possible to set the "leisure time" parameter through the app.config file, without having to set the parameter in the source code.

dfonovic avatar Apr 26 '24 07:04 dfonovic

However, I have one more question. I am wondering if it is possible to set the "leisure time" parameter through the app.config file, without having to set the parameter in the source code.

There is no reason as to why you cant define something like CONFIG_LIBCOAP_LEISURE_TIME_MS=nnnn in app.config and then in your application do something like (after session is set up)

...
#ifdef CONFIG_LIBCOAP_LEISURE_TIME_MS
    coap_fixed_point_t value;
    value.integer_part = CONFIG_LIBCOAP_LEISURE_TIME_MS/1000;
    value.fractional_part = CONFIG_LIBCOAP_LEISURE_TIME_MS%1000;
    coap_session_set_default_leisure(session, value);
#endif /* CONFIG_LIBCOAP_LEISURE_TIME_MS */
...

mrdeep1 avatar Apr 26 '24 09:04 mrdeep1