Skip to content

examples/cord_epsim: change default RD server addr handling#10464

Merged
miri64 merged 5 commits intoRIOT-OS:masterfrom
haukepetersen:opt_cordepsim_addrhandling
Mar 27, 2019
Merged

examples/cord_epsim: change default RD server addr handling#10464
miri64 merged 5 commits intoRIOT-OS:masterfrom
haukepetersen:opt_cordepsim_addrhandling

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Contribution description

The cord_epsim example was per default using the all-nodes multicast address for contacting the RD server. Now the problem is, that currently our coap implementations (gcoap+nanocoap) do not support any multicast addressing (group communication). So the default configuration does actually not make much sense.

This PR changes the default RD address definition to the loopback address, so it will compile correctly in our compile tests. At the same time, it will print a warning and tell the user to specify a valid address using the RD_ADDR variable.

The doc and Makefile are adapted accordingly. Also I removed the default CORD_SERVER_ADDR define from the cord/config.h file and put a check for the define in the cord_epsim.c source.

Testing procedure

Run a RD server (e.g. aiocoap-rd), get its address, and compile and run the cord_epsim example with RD_ADDR set to that address.

Issues/PRs references

This issue was pointed out in #9857 initially.

@haukepetersen haukepetersen added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Area: CoAP Area: Constrained Application Protocol implementations labels Nov 26, 2018
Copy link
Copy Markdown
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

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

Overall, these changes accomplish the goal, and it's definitely better than failing on the multicast address. I tested, and the success case still works. I also tested changing RD_LT. See the few minor suggestions in the code. Barely worth blocking, but easy fixes.

@kb2ma kb2ma added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Nov 28, 2018
@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from 81f789f to e7c6fbf Compare December 6, 2018 11:17
@haukepetersen
Copy link
Copy Markdown
Contributor Author

Alright, here is a more radical rework of this PR:

  • I removed the epsim_standalone sub-module all together -> when aiming for a minimal setup, no one would ever want a dedicated thread for this simple task anyhow...
  • made the RD address configurable during runtime (as function param). This makes (i) the implemenation simpler and removes the need for ipv6_addr_from_str() inside of epsim, and (ii) this allows at least in theory, to run multiple simplified registrations in parallel...
  • removed the default values for CORD_SERVER_ADDR and CORD_SERVER_PORT -> for the former there is just no good value, and for the latter it is simpler to just use COAP_PORT directly
  • added a guard around the address warning in the application Makefile in case of make clean

Overall, this leads to a slimmer and more efficient implementation and hopefully makes epsim also easier to use.

@kb2ma kb2ma removed the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Dec 12, 2018
@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Dec 12, 2018

I like the simpler rework! I removed the testing label because I'm retesting now. I plan to post a review in the next day or so.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

good to hear, thanks!

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Dec 14, 2018

[edited for clearer explanation of error]

I like the simple main loop rather than a separate thread. Overall this version uses around 15K less flash and 600 bytes less RAM on a samr21-xpro. I agree it was a little odd to include ipv6_addr_from_str() internally. It's also nice not to have the separate CORD_SERVER_ definitions.

I tested this quite a bit, and I'm worried that the cord_epsim module is a little too simple. For example, suppose the app is built with default setttings and the RD server is unreachable. In this case, cord_epsim returns an error code some of the time. The error occurs when gcoap tries to send a registration confirmably before the previous confirmable send has timed out. By default, gcoap supports a single open confirmable message (GCOAP_RESEND_BUFS_MAX). On average a CoAP confirmable message will timeout after 77s, but cord_epsim resends after 45s. If the user sets a longer, more realistic timeout, they will not see any error feedback in a terminal.

I propose adding a response handler to cord_epsim to maintain a state variable. The response handler maintains the variable simply based on reception of an ACK from the server. Then the main module can query it as desired. Something like this for cord_epsim:

static unsigned _state = CORD_EPSIM_OK;

static void _reg_handler(unsigned req_state, coap_pkt_t* pdu,
                          sock_udp_ep_t *remote)
{
    (void)remote;
    (void)pdu;

    if (req_state == GCOAP_MEMO_RESP) {
        _state = CORD_EPSIM_OK;
    }
    else {
        _state = CORD_EPSIM_ERROR;
    }
}

unsigned cord_epsim_state(void)
{
    return _state;
}

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Thats a very good point and I fully agree. Will include those proposed changes.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

addressed comments and added the internal state tracking. This should indeed be far more failure tolerant now.

_state = (req_state == GCOAP_MEMO_RESP) ? CORD_EPSIM_OK : CORD_EPSIM_ERROR;
}

int cord_epsim_register(const sock_udp_ep_t *rd_ep)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Presently this function just returns a state value. However, before returning it must first set the _state variable.

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.

fixed

@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from df19382 to c19df21 Compare March 26, 2019 15:16
@haukepetersen
Copy link
Copy Markdown
Contributor Author

Fixed setting _state to BUSY after sending the registration request and included some minor doc and style fixes. I hope all comments are addressed.

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Mar 26, 2019

ACK! Tests fine. Please squash.

@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from c19df21 to 87f584a Compare March 26, 2019 21:09
@haukepetersen
Copy link
Copy Markdown
Contributor Author

done

@haukepetersen haukepetersen added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 26, 2019
@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Mar 27, 2019

@haukepetersen, please review the Murdock failure. It looks spurious to me. Should we just trigger a rebuild? How to do that?

@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from 87f584a to 96d6339 Compare March 27, 2019 09:08
@haukepetersen
Copy link
Copy Markdown
Contributor Author

I rebased. lets see what Murdock says now.

# user.
ifeq (\"::1\", $(RD_ADDR))
ifneq (clean, $(MAKECMDGOALS))
$(info WARNING: the RD server address is set to the loopback device!)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks to me like it is this line that is causing problems on Murdock with its weird way to parse output, since RD_ADDR is set to ::1 above.

@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from 96d6339 to 01a58da Compare March 27, 2019 13:30
@haukepetersen
Copy link
Copy Markdown
Contributor Author

I took the warning part on the localhost address out of the Makefile. Thinking about this, I think it should be sufficient to have the warning in the readme file. Also the RD address is printed when the application starts, so that users at least have a good chance in seeing the ::1 when configured as RD address.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

@kb2ma would you mind to have one final look if my latest changes are ok with you? Thanks!

@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Mar 27, 2019

Looks good to me. Tests still pass. The user will see the address in the CLI. Thanks to @miri64 for finding the problem.

Please squash. Let's try this again.

This commit rewrites the example so that the registration loop is
run inside the main() function instead of running the standalone
submodule of epsim. It also adapts the example application to
parse the RD UDP endpoint locally and provide this to epsim's
register() function.
@haukepetersen haukepetersen force-pushed the opt_cordepsim_addrhandling branch from 0ca842f to 840c8ae Compare March 27, 2019 17:26
@haukepetersen
Copy link
Copy Markdown
Contributor Author

squashed. lets hope for the best :-)

@miri64 miri64 merged commit 78247d9 into RIOT-OS:master Mar 27, 2019
@danpetry danpetry added this to the Release 2019.04 milestone Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: CoAP Area: Constrained Application Protocol implementations CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants