Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring 6top Implementation #1

Closed

Conversation

yatch
Copy link

@yatch yatch commented Nov 9, 2016

Overall, this work untangles 6P message manipulation code and the sample schedule function code which reside in a single file, sixtop.c. Two C-files are introduced: sixtop-6p.c and sixtop-sf-simple.c.

sixtop-6p.c is for 6P message manipulation, building and parsing. sixtop-sf-simple.c is for the sample schedule function which is used by the example application. sixtop.c is now recreated to implement external APIs and to manage protocol states.

There are also changes on variable names and constants to follow wordings in draft-ietf-6tisch-6top-protocol. For example, PAYLOAD_IE_SIXTOP is renamed to PAYLOAD_IE_IANA_IETF. Another example is using "cell" instead of "link".

Speaking of the internet-draft, there are some fixes to comply with the specification. The Metadata field of Add Request and Delete Request is now taken into account. The value for "Seqnum" is maintained per neighbor.

From the point of view of an application, its external behaviors are (hopefully) not changed. You'll see almost the same mote output as the original implementation with rpl-tsch-sixtop-z1.csc as shown below. Although, if you disable the filter of mote output, you'll see many differences in log messages.

mote-output

You may notice changes of spacing in core/net/mac/tsch/tsch.c. The intention here is to revert the changes considered to have been introduced accidentally at 6ac1dce.

@@ -60,7 +60,8 @@ enum ieee802154e_header_ie_id {
enum ieee802154e_payload_ie_id {
PAYLOAD_IE_ESDU = 0,
PAYLOAD_IE_MLME,
PAYLOAD_IE_SIXTOP,
PAYLOAD_IE_VENDOR,

Choose a reason for hiding this comment

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

what is that one for?

Copy link
Author

Choose a reason for hiding this comment

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

I put it so that PALYLOAD_IE_IANA_IETF (should be renamed to PAYLOAD_IE_IETF) doesn't have the Group ID value for another group, which is "Vendor Specific Nested IE". PAYLOAD_IE_VENDOR is not used effectively anywhere for now.

case PAYLOAD_IE_IANA_IETF:
/* Now expect 'len' bytes of Sixtop sub-IEs */
switch(*buf) {
case IANA_IETF_IE_6TOP:

Choose a reason for hiding this comment

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

code style: please indent case

Copy link
Author

Choose a reason for hiding this comment

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

Oops, OK!

switch(*buf) {
case IANA_IETF_IE_6TOP:
ies->sixtop_ie_content_ptr = buf + 1;
ies->sixtop_ie_content_len = len - 1;

Choose a reason for hiding this comment

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

the line above are not self-explanatory, please add a comment

Copy link
Author

Choose a reason for hiding this comment

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

Agree; put a commen like this: /* adjust buf and len by the size of the Sub-ID field, one octet. */

@@ -97,6 +97,9 @@ create_frame(int type, int do_create)
* source nor destination address, we have dest PAN ID iff compression is *set*. */
params.fcf.panid_compression = 0;

/* Set IE Present bit */
params.fcf.ie_list_present = packetbuf_attr(PACKETBUF_ATTR_MAC_METADATA);

Choose a reason for hiding this comment

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

Cool. Maybe we could even use the framer for EB and EACK generation now :)
(if so, definitely a different PR)

Copy link
Author

Choose a reason for hiding this comment

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

I agree with you; it should go with a different PR. I can do it later.

Copy link
Author

Choose a reason for hiding this comment

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

[off-topic] I've rewritten tsch_packet_create_eb() and tsch_packet_create_eack() with PACKETBUF_ATTR_MAC_METADATA in a different branch. It's ready for PR; but waiting for contiki-os#1914 to be merged since the test data depends on contiki-os#1914.

#include "sixtop.h"

int sixtop_6p_build_6top_request(uint8_t return_code, uint8_t sfid,
uint8_t seqno, const sixtop_msg_body_t *body);

Choose a reason for hiding this comment

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

naming for all functions in this file: I would remove _6top_ (already implied by the module name sixtop_6p)

Copy link
Author

Choose a reason for hiding this comment

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

Agree.

/**
* \file
* IEEE 802.15.4 TSCH MAC Sixtop.
* 6top Protocol (6P) - Core

Choose a reason for hiding this comment

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

I'm confused, is this 6top (as the file name suggests) or 6P?

Copy link
Author

Choose a reason for hiding this comment

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

Obviously more precise short explanation for the file is needed... Anyway, it's a part of 6P (6top Protocol).

sixtop_ie->version = buf[0] & 0x0f;
sixtop_ie->code = (buf[0] & 0xf0) >> 4;
sixtop_ie->sfid = buf[1];
sixtop_ie->seqno = buf[2] & 0x07;

Choose a reason for hiding this comment

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

shouldn't this be 0x0f?

Copy link
Author

Choose a reason for hiding this comment

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

This should be 0x0f!!

sixtop_ie->code = (buf[0] & 0xf0) >> 4;
sixtop_ie->sfid = buf[1];
sixtop_ie->seqno = buf[2] & 0x07;
sixtop_ie->gab = (buf[2] & 0x30) >> 0x04;

Choose a reason for hiding this comment

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

for clarity and consistency I would not use hex notation for the shift, i.e. >> 4

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I have no idea why I used hex notation here... Thanks for pointing it out.

sixtop_ie->sfid = buf[1];
sixtop_ie->seqno = buf[2] & 0x07;
sixtop_ie->gab = (buf[2] & 0x30) >> 0x04;
sixtop_ie->gba = (buf[2] & 0xc0) >> 0x04;

Choose a reason for hiding this comment

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

isn't this >> 6?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Should be >>6.

buf[0] = SIXTOP_6P_SUBIE_ID;
buf[1] = (sixtop_ie->code << 4) | SIXTOP_6P_VERSION;
buf[2] = sixtop_ie->sfid;
buf[3] = sixtop_ie->seqno & 0x0f;

Choose a reason for hiding this comment

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

looks like we do not handle gab and gba. Add a comment

Copy link
Author

Choose a reason for hiding this comment

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

Your eyes are correct. Better to put a comment. The gab/gba thing be added by a following patch..

Copy link
Author

@yatch yatch left a comment

Choose a reason for hiding this comment

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

I'll resolve all comments from @simonduq with a following patch.

@@ -60,7 +60,8 @@ enum ieee802154e_header_ie_id {
enum ieee802154e_payload_ie_id {
PAYLOAD_IE_ESDU = 0,
PAYLOAD_IE_MLME,
PAYLOAD_IE_SIXTOP,
PAYLOAD_IE_VENDOR,
Copy link
Author

Choose a reason for hiding this comment

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

I put it so that PALYLOAD_IE_IANA_IETF (should be renamed to PAYLOAD_IE_IETF) doesn't have the Group ID value for another group, which is "Vendor Specific Nested IE". PAYLOAD_IE_VENDOR is not used effectively anywhere for now.

case PAYLOAD_IE_IANA_IETF:
/* Now expect 'len' bytes of Sixtop sub-IEs */
switch(*buf) {
case IANA_IETF_IE_6TOP:
Copy link
Author

Choose a reason for hiding this comment

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

Oops, OK!

switch(*buf) {
case IANA_IETF_IE_6TOP:
ies->sixtop_ie_content_ptr = buf + 1;
ies->sixtop_ie_content_len = len - 1;
Copy link
Author

Choose a reason for hiding this comment

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

Agree; put a commen like this: /* adjust buf and len by the size of the Sub-ID field, one octet. */

@@ -97,6 +97,9 @@ create_frame(int type, int do_create)
* source nor destination address, we have dest PAN ID iff compression is *set*. */
params.fcf.panid_compression = 0;

/* Set IE Present bit */
params.fcf.ie_list_present = packetbuf_attr(PACKETBUF_ATTR_MAC_METADATA);
Copy link
Author

Choose a reason for hiding this comment

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

I agree with you; it should go with a different PR. I can do it later.

@@ -0,0 +1,284 @@
/*
* Copyright (c) 2014, Swedish Institute of Computer Science.
Copy link
Author

Choose a reason for hiding this comment

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

It's inherited from the original sixtop.c. I've asked @shalurajendran to handle this properly.

#include "sixtop.h"

int sixtop_6p_build_6top_request(uint8_t return_code, uint8_t sfid,
uint8_t seqno, const sixtop_msg_body_t *body);
Copy link
Author

Choose a reason for hiding this comment

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

Agree.

/**
* \file
* IEEE 802.15.4 TSCH MAC Sixtop.
* 6top Protocol (6P) - Core
Copy link
Author

Choose a reason for hiding this comment

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

Obviously more precise short explanation for the file is needed... Anyway, it's a part of 6P (6top Protocol).

/* send the message with TSCH MAC */
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, dest_addr);
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr);
tschmac_driver.send(NULL, NULL);
Copy link
Author

Choose a reason for hiding this comment

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

That's fine. It'd be nice to have a macro to check the definition of NETSTACK_MAC at the beginning of the file. If it's not the TSCH MAC, stop compiling the file with #error.

sixtop_ie->version = buf[0] & 0x0f;
sixtop_ie->code = (buf[0] & 0xf0) >> 4;
sixtop_ie->sfid = buf[1];
sixtop_ie->seqno = buf[2] & 0x07;
Copy link
Author

Choose a reason for hiding this comment

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

This should be 0x0f!!

sixtop_ie->code = (buf[0] & 0xf0) >> 4;
sixtop_ie->sfid = buf[1];
sixtop_ie->seqno = buf[2] & 0x07;
sixtop_ie->gab = (buf[2] & 0x30) >> 0x04;
Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I have no idea why I used hex notation here... Thanks for pointing it out.

- untangle 6P message manipulation and the sample schedule function
  - sixtop.c: 6P core part, newly introduced
  - sixtop-6p.c : 6P message manipulation code, based on the former sixtop.c
  - sixtop-sf-simple.c : Sample SF code,based on the former sixtop.c
- maintain a sequence number per neighbor to be used for request
- rename variables and constants
- comply more with draft-ietf-6tisch-6top-protocol-02
@yatch yatch force-pushed the pr/sixtop-refactoring branch 2 times, most recently from 7e363f6 to 4fff8a0 Compare December 1, 2016 20:56
@yatch
Copy link
Author

yatch commented Dec 1, 2016

I've pushed new changes to the branch. It becomes nicer and cleaner from my point of view, and supports draft-03.

@simonduq
Copy link

simonduq commented Dec 2, 2016

It's so much of a change to the original PR that I wonder if the best way to move forward isn't to simply have @yatch do a new independent PR to Contiki, rebased on @shalurajendran 's commits, and referring to @shalurajendran 's PR discussion. This will make code review a lot easier. @shalurajendran what do you think?

@yatch
Copy link
Author

yatch commented Dec 6, 2016

@shalurajendran What do you think of the suggestion from @simonduq ...? By the way, I made trivial changes and did force-push a while ago.

- support draft-ietf-6tisch-6top-protocol-03
- reconsider file structure and file names
- make sf-simple part of example
- update sixtop/README.md
- apply C-DAC copyright notice
- bugfix + cleanup
@simonduq
Copy link

simonduq commented Dec 7, 2016

IMO you should just go ahead: as long as the original commits are left in the history it will be clear you're not stealing the contribution. The PR is no more than a means to get the commits in after all :)

@shalurajendran
Copy link
Owner

Good work @yatch .

Proceed with the new PR as suggested by @simonduq . Happy that our effort will be referred :)

@yatch
Copy link
Author

yatch commented Dec 8, 2016

All right; close this PR and open another on on the Contiki repo. See you there :-)

@yatch yatch closed this Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants