Skip to content

pkg/openthread: update for thread release 20180926#11204

Closed
Hyungsin wants to merge 2 commits into
RIOT-OS:masterfrom
Hyungsin:forupstream_openthread_2018_09_26
Closed

pkg/openthread: update for thread release 20180926#11204
Hyungsin wants to merge 2 commits into
RIOT-OS:masterfrom
Hyungsin:forupstream_openthread_2018_09_26

Conversation

@Hyungsin

@Hyungsin Hyungsin commented Mar 18, 2019

Copy link
Copy Markdown

Contribution description

This PR brings OpenThread version released on 20180926 to RIOT-OS.

  1. Miscellaneous fixes to match formats.
  2. Add MicroTimer function for the future use (CSMA/CA at the OpenThread code).
  3. Support data polling for sleepy end devices.
    @jia200x / @biboc, please review and test this.

Testing procedure

I checked that two samr21-xpro boards can be connected and ping to each other.

Issues/PRs references

@Hyungsin Hyungsin force-pushed the forupstream_openthread_2018_09_26 branch 3 times, most recently from a59746d to 74a3cb9 Compare March 18, 2019 23:02
@jia200x

jia200x commented Mar 19, 2019

Copy link
Copy Markdown
Member

awesome!

@Hyungsin

Copy link
Copy Markdown
Author

Just tested on two IoT-LAB-M3 nodes :)

@miri64

miri64 commented Jul 30, 2019

Copy link
Copy Markdown
Member

@Hyungsin needs rebase. @jia200x can you give this another look?

@miri64 miri64 requested a review from jia200x July 30, 2019 17:11
@miri64 miri64 added Area: network Area: Networking Area: pkg Area: External package ports Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Jul 30, 2019
@jia200x

jia200x commented Oct 18, 2019

Copy link
Copy Markdown
Member

@Hyungsin my biggest apologies.

I just noticed I personally merged #11540 which also updates OpenThread to the same version.

However, this PR still covers some points that were not included in #11540 (e.g ACK packet handling)
Do you plan to continue working on this? If so, does it work for you if we add the implementation details of this PR in the current master?

Again, sorry for not checking the version :/

@Hyungsin

Hyungsin commented Nov 15, 2019

Copy link
Copy Markdown
Author

@jia200x, @miri64, it is frustrating to rebase this PR because another PR #11540, which handles the same (actually smaller) issue but posted 2 months after this, was reviewed and merged first. Surprisingly, it took only two days for the PR #11540 to be merged, but this PR got zero review for the last 8 months.

@jia200x, I can rebase this but it would be good if you can test. Does it work for you?

@miri64

miri64 commented Nov 15, 2019

Copy link
Copy Markdown
Member

@jia200x, @miri64, it is frustrating to rebase this PR because another PR #11540, which handles the same issue but posted after this, was reviewed and merged first. This PR got zero reviews meanwhile.

Sorry, I wasn't aware about this happening. We are aware of this problem and try to be more careful in the future (see #12543). I hand the review to @jia200x.

@Hyungsin

Copy link
Copy Markdown
Author

@jia200x @miri64 I rebased it. Hope that it is tested soon.

@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 15, 2019

@maribu maribu left a comment

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.

I sadly do not have the background to properly review this. But I checked everything that does not need knowledge with openthread to be reviewed like code style and general concepts. This might speed up thinks a bit when a reviewer with the correct background takes a look.


static kernel_pid_t _pid;
static otInstance *sInstance;
static bool otTaskPending = false;

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.

Unless external packages enforce some code style for compatibility, we should try to stick to the RIOT coding convention for a consistency. See https://github.com/RIOT-OS/RIOT/blob/master/CODING_CONVENTIONS.md#naming

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.

we should update this in the file as well.
I would be ok to leave it as is in this PR and immediately after open another one for fixing this. What do you think?

* @param[in] aT0 The reference time.
* @param[in] aDt The time delay in microseconds from @p aT0.
*/
void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)

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.

I have never worked with openthread so far, so please forgive if I'm asking nonsense.

The implementation in this PR would allow one timer in total to be set with otPlatAlamMicroStartAt() and one with the milliseconds version. (And the version in master would allow one in total.) This seems to be strange to me.

If I had to guess, I would say one timer per otInstance would make most sense. And one timer in total would make second-most sense to. Can someone with the required knowledge comment on this?

I think it should be possible to only provide one common internal implementation and offer otPlatAlarmMicroStartAt() and otPlatAlarmMilliStartAt() as static inline wrappers on top if this in order to safe some ROM.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We need to call otPlatAlarmMilliFired(sInstance) when a millitimer is fired and otPlatAlarmMicroFired(sInstance) when a microtimer is fired. Without separation, I think it is hard to know what timer is fired. FYI, https://github.com/openthread/openthread/blob/master/src/core/common/timer.cpp

}

/* OpenThread will call this to stop alarms */
void otPlatAlarmMicroStop(otInstance *aInstance)

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.

This should also be possible to combine with the milli version (e.g. by one being a static inline wrapper for the other). Of course only if not two timers in total is actually what openthread expects.

}

/* OpenThread will call this for getting running time in microsecs */
uint32_t otPlatAlarmMicroGetNow(void)

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.

Providing this as static inline wrapper should safe some ROM.

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.

This is called by OpenThread, the symbol has to be exposed. So I guess it couldn't be static inline :/


static otRadioFrame sTransmitFrame;
static otRadioFrame sReceiveFrame;
static otRadioFrame sAckFrame;

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.

Again this is in misalignment with RIOT's coding convention. (As are the one above, that are not related to this PR.) If there is not technical reason for this, this should be renamed in order to comply with the coding convention.

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.

We have to adapt this file anyway in a further PR (lots of Camel Case here). Is it OK for you to leave it as is and we open a follow up right after we merge this?


/* Called upon TX event */
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
void sent_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)

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.

Why this change in name?
Please see comment in declaration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Checked

case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING:
DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n");
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
_create_fake_ack_frame(true);

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.

This seems odd to me. Maybe it is only because of the naming and me not being familiar with openthread. But I would expect ACKs to be created upon receiving a frame, not after sending one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, this "fake" ack is created to report the result of a sent frame to the upper layer. This is not for responding to a received frame.

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.

This same technique is used in some of the official platform implementations of Openthread.

uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) {
reversed_addr[i] = (uint8_t) ((uint8_t *)aExtAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
reversed_addr[i] = aExtAddress->m8[IEEE802154_LONG_ADDRESS_LEN - 1 - i];

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.

This is network vs host byte order, right? If so, reversed_addr is a misleading name. (You could also take a look at the eui64_t type and see if it would be handy here.)

If the host byte order happens to be network byte order, this would not work. Maybe _set_long_addr() could be changed to always expect network byte order? (Or even eui64_t?)

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.

OpenThread uses IEEE addresses in little endian (see OpenThread radio API)

So we need to reverse in order to write it in the hardware. Maybe we could choose a better name for this variable or add comments?

* @param[in] event just occurred netdev event
*/
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event);
void sent_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event);

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.

OK. Now (in context of the API doc I get the rename). Maybe even changing it to pkt_sent()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes. This is called after a packet transmission finishes. So may be pkt_sent is more appropriate.

* @param[in] dev pointer to a netdev interface
* @param[in] tb pointer to the TX buffer designed for OpenThread
* @param[in] rb pointer to the RX buffer designed for Open_Thread
* @param[in] ab pointer to the ACK buffer designed for Open_Thread

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.

Shouldn't it be "designated" instead of "designed"? If so, would you mind to sneak in a fix of the doc of tb and rb (as separate commit) into this PR?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Either one makes sense to me. So I can change as you want.

@jia200x

jia200x commented Nov 18, 2019

Copy link
Copy Markdown
Member

@jia200x, @miri64, it is frustrating to rebase this PR because another PR #11540, which handles the same (actually smaller) issue but posted 2 months after this, was reviewed and merged first. Surprisingly, it took only two days for the PR #11540 to be merged, but this PR got zero review for the last 8 months.

Hi @Hyungsin.
I totally get your frustration. My apologies, I was the one who merged #11540. There were not bad intentions, it was my mistake for not (re)checking existing solutions without approving and merging.

As @miri64 pointed out, we are aware of this situation and trying to fix it asap.

Thanks anyway that besides this, you rebased it to the current master. I will run the tests ASAP and we would be ready to go.

@Hyungsin

Copy link
Copy Markdown
Author

I will run the tests ASAP and we would be ready to go.

It is OK and Thanks for testing!

@Hyungsin

Copy link
Copy Markdown
Author

@jia200x ping?

@jia200x

jia200x commented Nov 29, 2019

Copy link
Copy Markdown
Member

@jia200x ping?

I will now. I was busy with #11022

@jia200x jia200x left a comment

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.

Some stuff I found while reviewing

Comment thread pkg/openthread/contrib/platform_alarm.c Outdated
/* Interupt handler for OpenThread milli-timer event */
static void _millitimer_cb(void* arg) {
(void)arg;
msg_t millitimer_msg;

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.

This structure should be globally allocated. Otherwise the message will be lost.

Comment thread pkg/openthread/contrib/platform_alarm.c Outdated
xtimer_set_msg(&ot_timer, dt, &ot_alarm_msg, thread_getpid());
}
uint32_t dt = aDt * US_PER_MS;
xtimer_set(&ot_millitimer, dt);

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.

I would say it's better to use xtimer_set_msg here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

resolved!

Comment thread pkg/openthread/contrib/platform_alarm.c Outdated
}

/* Interupt handler for OpenThread micro-timer event */
static void _microtimer_cb(void* arg) {

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.

same as above. This can be replaced by xtimer_set_msg

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

resolved!

case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING:
DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n");
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
_create_fake_ack_frame(true);

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.

This same technique is used in some of the official platform implementations of Openthread.

@Hyungsin

Copy link
Copy Markdown
Author

@jia200x just resolved your comments. Thanks!

@aabadie

aabadie commented Jan 15, 2020

Copy link
Copy Markdown
Contributor

@jia200x, maybe you'll find some time to have another look here ?

@jia200x

jia200x commented Feb 6, 2020

Copy link
Copy Markdown
Member

I'm back into this, I'm running some tests now.

DEBUG("otPlatRadioAddSrcMatchShortEntry\n");
(void)aInstance;
(void)aShortAddress;
bool pending = true;

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.

This "fake" SrcAddressMatch table should do the trick (if a SED receives an ACK with FP, if there was no data for that address it will just timeout).

However, in order to be compliant with the OpenThread API, the otPlatRadioEnableSrcMatch should be implemented.
(see OpenThread radio API). Otherwise SED won't have a chance of receive a packet if SrcMatch is disabled

uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) {
reversed_addr[i] = (uint8_t) ((uint8_t *)aExtAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
reversed_addr[i] = aExtAddress->m8[IEEE802154_LONG_ADDRESS_LEN - 1 - i];

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.

OpenThread uses IEEE addresses in little endian (see OpenThread radio API)

So we need to reverse in order to write it in the hardware. Maybe we could choose a better name for this variable or add comments?


static otRadioFrame sTransmitFrame;
static otRadioFrame sReceiveFrame;
static otRadioFrame sAckFrame;

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.

We have to adapt this file anyway in a further PR (lots of Camel Case here). Is it OK for you to leave it as is and we open a follow up right after we merge this?

}

/* OpenThread will call this for getting running time in microsecs */
uint32_t otPlatAlarmMicroGetNow(void)

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.

This is called by OpenThread, the symbol has to be exposed. So I guess it couldn't be static inline :/

@miri64

miri64 commented Jun 25, 2020

Copy link
Copy Markdown
Member

@Hyungsin @jia200x any progress?

@jia200x

jia200x commented Sep 16, 2020

Copy link
Copy Markdown
Member

ping @Hyungsin

@benpicco

benpicco commented Oct 2, 2020

Copy link
Copy Markdown
Contributor

Should probably be updated to thread-reference-20191113 and the new Radio HAL.

@jia200x

jia200x commented Oct 2, 2020

Copy link
Copy Markdown
Member

Should probably be updated to thread-reference-20191113 and the new Radio HAL.

Ideally.
OpenThread can run on top of the SubMAC (see #14979), so then we don't have to take care of some "high level" stuff (getting ACK frames and handing it in to the stack, etc).

@stale

stale Bot commented Jun 3, 2021

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale Bot added the State: stale State: The issue / PR has no activity for >185 days label Jun 3, 2021
@stale stale Bot closed this Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days 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