Skip to content

nanocoap: introduce coap_opt_remove()#17881

Merged
chrysn merged 2 commits intoRIOT-OS:masterfrom
miri64:nanocoap/enh/opt_remove
Mar 31, 2022
Merged

nanocoap: introduce coap_opt_remove()#17881
chrysn merged 2 commits intoRIOT-OS:masterfrom
miri64:nanocoap/enh/opt_remove

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Mar 29, 2022

Contribution description

In some cases it might be necessary to remove an already added option. In fact, due to the delta-based construction of the CoAP option header, it oftentimes is easier to add a later-to-be-added option with slack and then remove it if it isn't used after all (e.g. the ETag option). This PR provides a function to remove an option from a completed packet.

Testing procedure

A unittest is provided with tests/unittests so run:

make -C tests/unittests/ tests-nanocoap flash-only test

for a board of your choice (preferably something else than native which I tested for)

Issues/PRs references

None.

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: CoAP Area: Constrained Application Protocol implementations labels Mar 29, 2022
@github-actions github-actions bot added Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework labels Mar 29, 2022
@miri64 miri64 requested a review from chrysn March 29, 2022 16:05
Copy link
Copy Markdown
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

(Didn't look at the test yet, that's a bit hard to process.)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 29, 2022

(Didn't look at the test yet, that's a bit hard to process.)

Anything I can do to make it better processable?

@chrysn
Copy link
Copy Markdown
Member

chrysn commented Mar 29, 2022

Anything I can do to make it better processable?

I think not, I just had to bite through setup.

What I think is worth covering is the removal of options with different deltas. An easy way to do this based on the existing code is to run test_nanocoap__option_remove several times with a "stride" parameter, where option n * stride is set with a value of n. Good values for stride would be 1 (as is now), 8 (as that makes a 1+data option fall into a 2+data case), 32 (staying at 2+data) and 200 (making 2+data fall into 3+data).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 30, 2022

and 200 (making 2+data fall into 3+data).

That seems to remain at 2+data. From RFC 7252, section 3.1 I assume you meant 269?

@chrysn
Copy link
Copy Markdown
Member

chrysn commented Mar 30, 2022

If of two delta=200 options the first is removed, the delta starts exceeding the 1+1+data range, and goes into the 1+2+data range. (Can also test with strides of 300 to test 1+2+data -> 1+2+data, but I expect that test to be less insightful).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 30, 2022

If of two delta=200 options the first is removed, the delta starts exceeding the 1+1+data range, and goes into the 1+2+data range. (Can also test with strides of 300 to test 1+2+data -> 1+2+data, but I expect that test to be less insightful).

Ahh yeah, got it. Just got confused with the initial option length.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 30, 2022

Mh... not sure if this is right now. The returned lengths coap_opt_remove() should be different, especially in the delta change range. But it somehow isn't. Will debug!

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 30, 2022

Mh... not sure if this is right now. The returned lengths coap_opt_remove() should be different, especially in the delta change range. But it somehow isn't. Will debug!

Done!

Comment on lines +1272 to +1273
* @brief Removes an option previously added with another function in this
* [group](@ref net_nanocoap_opt_add)
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.

Suggested change
* @brief Removes an option previously added with another function in this
* [group](@ref net_nanocoap_opt_add)
* @brief Removes an option previously added with another function in [the
* coap_opt_add_group](@ref net_nanocoap_opt_add)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in 3f74a33

@chrysn
Copy link
Copy Markdown
Member

chrysn commented Mar 30, 2022

For the public record (and especially implementers looking for that in this context): If an option is added where it is not known in advance how long it will be (i.e. when adding an option with some worst-case length for possible later removal), one might need a function, maybe called coap_opt_shorten, coap_opt_truncate or coap_opt_trim, that is similar to this one.

That function would share some properties with this one, but is generally easier to implement as the following option just needs to be moved (and not reencoded, possibly with a differently sized delta).

The present function could be generalized, or a shortening function could be added -- but that is out of scope here. (miri64 might have pointers to a simplified special-case / limited length version she might have around later).

@chrysn chrysn added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Mar 30, 2022
Copy link
Copy Markdown
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

Fine with the code so far, now going through the test.

@chrysn
Copy link
Copy Markdown
Member

chrysn commented Mar 30, 2022

Test looks good and covers enough that I don't feel the need to give this any additional local testing.

Please squash after addressing the comments.

@miri64 miri64 force-pushed the nanocoap/enh/opt_remove branch from 16e9d38 to 68f5514 Compare March 31, 2022 07:48
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 31, 2022

Please squash after addressing the comments.

Done

Copy link
Copy Markdown
Member

@chrysn chrysn left a comment

Choose a reason for hiding this comment

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

All looking good; the only review step I did not do is testing, but the provided test is thorough enough that I wouldn't know what else to test anyway, and it will be run by CI before merging.

Thanks, and ACK.

@miri64 miri64 added the Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines label Mar 31, 2022
@miri64 miri64 added Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by 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 labels Mar 31, 2022
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 31, 2022

[…] the only review step I did not do is testing, […]

I set the appropriate labels ;-)

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Mar 31, 2022

Failing test is unrelated.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Mar 31, 2022
@chrysn chrysn merged commit d6115e3 into RIOT-OS:master Mar 31, 2022
@miri64 miri64 deleted the nanocoap/enh/opt_remove branch March 31, 2022 20:07
@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 8, 2022
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 Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework 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: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by 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: 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.

3 participants