Skip to content

net/link_layer: implement EUI provider#14634

Merged
fjmolinas merged 7 commits intoRIOT-OS:masterfrom
benpicco:eui_provider
Sep 1, 2020
Merged

net/link_layer: implement EUI provider#14634
fjmolinas merged 7 commits intoRIOT-OS:masterfrom
benpicco:eui_provider

Conversation

@benpicco
Copy link
Contributor

@benpicco benpicco commented Jul 28, 2020

Contribution description

This implements EUI providers that can be implemented by a board to provide EUIs (MAC addresses) to network interfaces.

Testing procedure

Flash examples/gnrc_networking on samr21-xpro.
You can observe that the Long HWaddr in ifconfig now matches the MAC address printed on the reverse of the board.

2020-07-24 15:34:14,163 # Iface  7  HWaddr: 48:C5  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK 
2020-07-24 15:34:14,164 #           
2020-07-24 15:34:14,168 #           Long HWaddr: 00:04:25:19:18:01:C8:C5 
2020-07-24 15:34:14,175 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4 
2020-07-24 15:34:14,182 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  MTU:1280  HL:64  RTR  
2020-07-24 15:34:14,184 #           6LO  IPHC  
2020-07-24 15:34:14,187 #           Source address length: 8
2020-07-24 15:34:14,190 #           Link type: wireless
2020-07-24 15:34:14,196 #           inet6 addr: fe80::204:2519:1801:c8c5  scope: link  VAL
2020-07-24 15:34:14,199 #           inet6 group: ff02::2
2020-07-24 15:34:14,202 #           inet6 group: ff02::1
2020-07-24 15:34:14,206 #           inet6 group: ff02::1:ff01:c8c5

samr21-xpro

Flash examples/gnrc_networking on avr-rss2.
You can observe that the Long HWaddr in ifconfig now matches the MAC address printed on the reverse of the board.

2020-07-28 13:07:45,898 # Iface  7  HWaddr: 0B:B1  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK 
2020-07-28 13:07:45,898 #           
2020-07-28 13:07:45,904 #           Long HWaddr: FC:C2:3D:00:00:00:0B:B1 
2020-07-28 13:07:45,910 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4 
2020-07-28 13:07:45,917 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  MTU:1280  HL:64  RTR  
2020-07-28 13:07:45,920 #           6LO  IPHC  
2020-07-28 13:07:45,923 #           Source address length: 8
2020-07-28 13:07:45,926 #           Link type: wireless
2020-07-28 13:07:45,932 #           inet6 addr: fe80::fec2:3d00:0:bb1  scope: link  VAL
2020-07-28 13:07:45,935 #           inet6 group: ff02::2
2020-07-28 13:07:45,938 #           inet6 group: ff02::1
2020-07-28 13:07:45,940 #           inet6 group: ff02::1:ff00:bb1

Iavr-rss2

Issues/PRs references

split off & waiting for #13746

@benpicco benpicco added Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first labels Jul 28, 2020
@miri64
Copy link
Member

miri64 commented Jul 28, 2020

Flash examples/gnrc_networking on samr21-xpro.

There are some more boards changed in this PR. What is the reasoning for not requiring to testing them?

@benpicco
Copy link
Contributor Author

I think @chudov is the only one who has a derfmega256

@chudov
Copy link
Contributor

chudov commented Jul 28, 2020

I can provide photo of derfmega256 with arrow to MAC address if needed.

@chudov
Copy link
Contributor

chudov commented Jul 28, 2020

Flash examples/gnrc_networking on derfmega256.
You can observe that the Long HWaddr in ifconfig now matches the MAC address printed on the module.

Iface  7  HWaddr: 35:59  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK

      Long HWaddr: 00:21:2E:FF:FF:03:B5:59 
       TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4 
      AUTOACK  ACK_REQ  CSMA  L2-PDU:102  MTU:1280  HL:64  RTR  
      6LO  IPHC  
      Source address length: 8
      Link type: wireless
      inet6 addr: fe80::221:2eff:ff03:b559  scope: link  VAL
      inet6 group: ff02::2
      inet6 group: ff02::1
      inet6 group: ff02::1:ff03:b559
      
      Statistics for Layer 2
        RX packets 0  bytes 0
        TX packets 3 (Multicast: 3)  bytes 129
        TX succeeded 3 errors 0
      Statistics for IPv6
        RX packets 0  bytes 0
        TX packets 3 (Multicast: 3)  bytes 192
        TX succeeded 3 errors 0

image

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Aug 17, 2020
@benpicco benpicco requested a review from maribu August 21, 2020 20:24
@benpicco
Copy link
Contributor Author

Rebased to make use of #14778

@benpicco
Copy link
Contributor Author

Rebased again as #12600 already includes some of the changes of this PR.

@benpicco
Copy link
Contributor Author

No impact if no eui_prvider is defined for the board:

openmote-b

master

   text	   data	    bss	    dec	    hex	filename
 100684	    184	  20668	 121536	  1dac0	/home/benpicco/dev/RIOT/examples/gnrc_networking/bin/openmote-b/gnrc_networking.elf

this PR

   text	   data	    bss	    dec	    hex	filename
 100676	    184	  20668	 121528	  1dab8	/home/benpicco/dev/RIOT/examples/gnrc_networking/bin/openmote-b/gnrc_networking.elf

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

I have some questions (to be clear I understand this api correctly):

  • radio provides a EUI: this might imply a dependency to the radio module, would we use ifndef MODULE_% for this? The provider type would make sure we don't mix them up.

  • multiple interfaces on same radio (at86rf215): there is a NETDEV_AT86RF215 type which interface would use the provided eui will there be two?

  • why use edbg for the radio mac address? what happens if ethos is used, or usb? We want it to be constant I guess, so which interface to choose? When the radio device provides the eui64 this is pretty straightforward, but I'm not clear when it relates to other providers. This point can probably be solved with some doc.

Otherwise I think this looks nice, i'll give it a test now.

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

Tested on samr21-xpro it matches the address on the board MAC: 000425191801CCA0

2020-08-25 11:21:35,647 # ifconfig
2020-08-25 11:21:35,654 # Iface  7  HWaddr: 4C:A0  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK 
2020-08-25 11:21:35,655 #           
2020-08-25 11:21:35,660 #           Long HWaddr: 00:04:25:19:18:01:CC:A0 
2020-08-25 11:21:35,667 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4 
2020-08-25 11:21:35,674 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  MTU:1280  HL:64  RTR  
2020-08-25 11:21:35,676 #           6LO  IPHC  
2020-08-25 11:21:35,679 #           Source address length: 8
2020-08-25 11:21:35,682 #           Link type: wireless
2020-08-25 11:21:35,690 #           inet6 addr: fe80::204:2519:1801:cca0  scope: link  VAL
2020-08-25 11:21:35,691 #           inet6 group: ff02::2
2020-08-25 11:21:35,693 #           inet6 group: ff02::1
2020-08-25 11:21:35,697 #           inet6 group: ff02::1:ff01:cca0
2020-08-25 11:21:35,698 #           
2020-08-25 11:21:35,701 #           Statistics for Layer 2
2020-08-25 11:21:35,704 #             RX packets 0  bytes 0
2020-08-25 11:21:35,708 #             TX packets 2 (Multicast: 2)  bytes 86
2020-08-25 11:21:35,712 #             TX succeeded 2 errors 0
2020-08-25 11:21:35,714 #           Statistics for IPv6
2020-08-25 11:21:35,717 #             RX packets 0  bytes 0
2020-08-25 11:21:35,722 #             TX packets 2 (Multicast: 2)  bytes 128
2020-08-25 11:21:35,725 #             TX succeeded 2 errors 0
2020-08-25 11:21:35,725 # 
ifconfig 7 set state reset
2020-08-25 11:21:56,659 #  ifconfig 7 set state reset
2020-08-25 11:21:56,664 # success: set state of interface 7 to RESET
> ifconfig
2020-08-25 11:21:58,561 #  ifconfig
2020-08-25 11:21:58,568 # Iface  7  HWaddr: 4C:A0  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK 
2020-08-25 11:21:58,569 #           
2020-08-25 11:21:58,573 #           Long HWaddr: 00:04:25:19:18:01:CC:A0 
2020-08-25 11:21:58,580 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4 
2020-08-25 11:21:58,587 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  MTU:1280  HL:64  RTR  
2020-08-25 11:21:58,589 #           6LO  IPHC  
2020-08-25 11:21:58,592 #           Source address length: 2
2020-08-25 11:21:58,595 #           Link type: wireless
2020-08-25 11:21:58,601 #           inet6 addr: fe80::204:2519:1801:cca0  scope: link  VAL
2020-08-25 11:21:58,604 #           inet6 group: ff02::2
2020-08-25 11:21:58,606 #           inet6 group: ff02::1
2020-08-25 11:21:58,610 #           inet6 group: ff02::1:ff01:cca0
2020-08-25 11:21:58,611 #           
2020-08-25 11:21:58,614 #           Statistics for Layer 2
2020-08-25 11:21:58,617 #             RX packets 0  bytes 0
2020-08-25 11:21:58,622 #             TX packets 4 (Multicast: 4)  bytes 172
2020-08-25 11:21:58,625 #             TX succeeded 4 errors 0
2020-08-25 11:21:58,628 #           Statistics for IPv6
2020-08-25 11:21:58,631 #             RX packets 0  bytes 0
2020-08-25 11:21:58,635 #             TX packets 4 (Multicast: 4)  bytes 256
2020-08-25 11:21:58,638 #             TX succeeded 4 errors 0
2020-08-25 11:21:58,639 # 

@fjmolinas
Copy link
Contributor

If the radio provides a EUI already there is no need for an external EUI provider. The driver can handle it internally - this is what cc2538_rf does.

perfect!

The MAC address provided by edbg is configured to only match NETDEV_AT86RF2XX, so it will only used by the at86rf2xx radio driver.

What I meant with this question is what was the reasoning behind this, I agree with this matching, I just think it would be nice to document, so that others adding this module will follow the same reasoning (at least for the default configuration that goes in master). e.g.:

  • if the radio provides a eui64 prefer that one
  • if a radio provides multiple interfaces, use the provided eui64 for one interface as default
  • if the board provides a eui64 use this one exclusively for the radio
  • if there are multiple eui64 assign them first to hardware interfaces (e.g: radios, usb, etc.)
  • software interfaces (ethos) should use luid
  • etc...

what do you think?

@fjmolinas fjmolinas self-assigned this Aug 25, 2020
@benpicco benpicco removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 25, 2020
@benpicco
Copy link
Contributor Author

I extended the documentation. I hope it's a bit more understandable now :)
Say if there is something missing.

@fjmolinas
Copy link
Contributor

I extended the documentation. I hope it's a bit more understandable now :)
Say if there is something missing.

Looks good!

@fjmolinas
Copy link
Contributor

Some more testing:

  • short address is not the same across platforms (below 2 samr21-xpro)
  • no issues communicating
2020-08-25 14:47:19,170 # ifconfig
2020-08-25 14:47:19,177 # Iface  4  HWaddr: 2B:07  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK
2020-08-25 14:47:19,178 #
2020-08-25 14:47:19,182 #           Long HWaddr: 00:04:25:19:18:01:AB:07
2020-08-25 14:47:19,189 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4
2020-08-25 14:47:19,196 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  Source address length: 2
2020-08-25 14:47:19,197 #
> 2020-08-25 14:49:00,775 #  PKTDUMP: data received:
2020-08-25 14:49:00,779 # ~~ SNIP  0 - size:   5 byte, type: NETTYPE_UNDEF (0)
2020-08-25 14:49:00,782 # 00000000  68  65  6C  6C  6F
2020-08-25 14:49:00,787 # ~~ SNIP  1 - size:  18 byte, type: NETTYPE_NETIF (-1)
2020-08-25 14:49:00,790 # if_pid: 4  rssi: -31  lqi: 255
2020-08-25 14:49:00,791 # flags: 0x0
2020-08-25 14:49:00,792 # src_l2addr: 4C:A0
2020-08-25 14:49:00,795 # dst_l2addr: 00:04:25:19:18:01:AB:07
2020-08-25 14:49:00,799 # ~~ PKT    -  2 snips, total size:  23 byte
txtsnd 4 00:04:25:19:18:01:CC:A0
2020-08-25 14:49:09,916 # txtsnd 4 00:04:25:19:18:01:CC:A0
2020-08-25 14:49:09,920 # usage: txtsnd <if> [<L2 addr>|bcast] <data>
> txtsnd 4 00:04:25:19:18:01:CC:A0 hello
2020-08-25 14:49:15,139 #  txtsnd 4 00:04:25:19:18:01:CC:A0 hello

2020-08-25 14:47:59,009 # ifconfig
2020-08-25 14:47:59,018 # Iface  4  HWaddr: 4C:A0  Channel: 26  Page: 0  NID: 0x23  PHY: O-QPSK
2020-08-25 14:47:59,021 #
2020-08-25 14:47:59,022 #           Long HWaddr: 00:04:25:19:18:01:CC:A0
2020-08-25 14:47:59,034 #            TX-Power: 0dBm  State: IDLE  max. Retrans.: 3  CSMA Retries: 4
2020-08-25 14:47:59,058 #           AUTOACK  ACK_REQ  CSMA  L2-PDU:102  Source address length: 2
2020-08-25 14:47:59,065 #
> txtsnd 4 00:04:25:19:18:01:AB:07 hello
2020-08-25 14:49:00,770 #  txtsnd 4 00:04:25:19:18:01:AB:07 hello
> 2020-08-25 14:49:15,144 #  PKTDUMP: data received:
2020-08-25 14:49:15,149 # ~~ SNIP  0 - size:   5 byte, type: NETTYPE_UNDEF (0)
2020-08-25 14:49:15,151 # 00000000  68  65  6C  6C  6F
2020-08-25 14:49:15,156 # ~~ SNIP  1 - size:  18 byte, type: NETTYPE_NETIF (-1)
2020-08-25 14:49:15,159 # if_pid: 4  rssi: -31  lqi: 255
2020-08-25 14:49:15,160 # flags: 0x0
2020-08-25 14:49:15,162 # src_l2addr: 2B:07
2020-08-25 14:49:15,165 # dst_l2addr: 00:04:25:19:18:01:CC:A0
2020-08-25 14:49:15,169 # ~~ PKT    -  2 snips, total size:  23 byte

@fjmolinas
Copy link
Contributor

So I took a look at #12641 where this PR comes from. I'm trying to figure out if it fulfills requirements expressed there.

From #12641 (comment), I think all points are achieved since the TYPE and INDEX allow for concrete mapping between interfaces.

@miri64 concern #12641 (review) seems to have been addressed with #13746.

Also should https://github.com/RIOT-OS/RIOT/pull/13232/files be adapted as well?

@maribu @miri64 can you confirm that this new attempt fits your expectations?

@benpicco
Copy link
Contributor Author

Also should https://github.com/RIOT-OS/RIOT/pull/13232/files be adapted as well?

Converting the remaining netdevs to register themselves and use the eui_get methods will be done in follow-up PRs.
So far only two drivers have been converted to the new method in this PR as a demonstrator.

But the old luid approach will keep working, so there is no urgency in the transition.

@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 Aug 30, 2020
@fjmolinas
Copy link
Contributor

@maribu @miri64 can you confirm that this new attempt fits your expectations?

ping @maribu @miri64? If there are no comments today, I'll go with "no answer = positive answer" and ACK this afternoon.

@miri64
Copy link
Member

miri64 commented Sep 1, 2020

no answer :P

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

@maribu @miri64 can you confirm that this new attempt fits your expectations?

ping @maribu @miri64? If there are no comments today, I'll go with "no answer = positive answer" and ACK this afternoon.

ACK!

@fjmolinas fjmolinas merged commit 6f84870 into RIOT-OS:master Sep 1, 2020
@benpicco benpicco deleted the eui_provider branch September 1, 2020 14:37
@benpicco
Copy link
Contributor Author

benpicco commented Sep 1, 2020

@herjulf will be happy about this too 😄

@herjulf
Copy link
Contributor

herjulf commented Sep 1, 2020

Oh yes. Thanks!
Happy to remove own hacks for this general solution.

Comment on lines +195 to +202
static inline void eui_short_from_eui64(eui64_t *addr_long,
network_uint16_t *addr_short)
{
/* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
* 0 for unicast addresses */
addr_short->u8[0] = addr_long->uint8[6] & 0x7F;
addr_short->u8[1] = addr_long->uint8[7];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm realizing just now that this is not implementing the same workaround to have unique short address that is done for luid_get_short().

    luid_base(addr, sizeof(*addr));
    addr->u8[1] ^= lastused++;

    /* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
     * 0 for unicast addresses */
    addr->u8[0] &= 0x7F;

Should this call luid_get_short instead? OR change it to:

static inline void eui_short_from_eui64(eui64_t *addr_long,
                                        network_uint16_t *addr_short)
{
    /* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
     * 0 for unicast addresses */
    addr_short->u8[0] = addr_long->uint8[0] & 0x7F;
    addr_short->u8[1] ^= addr_long->uint8[1];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh? Byte 7 will change if we got the EUI64 from luid and there are multiple interfaces

void luid_get_eui64(eui64_t *addr)
{
    luid_base(addr, sizeof(*addr));
    addr->uint8[7] ^= lastused++;

    eui64_set_local(addr);
    eui64_clear_group(addr);
}

void luid_netdev_get_eui64(const netdev_t *netdev, eui64_t *addr)
{
    luid_base(addr, sizeof(*addr));
#ifdef MODULE_NETDEV_REGISTER
    addr->uint8[6] ^= netdev->type;
    addr->uint8[7] ^= netdev->index;
#else
    /* we should only get here with gnrc_netif_single */
    (void)netdev;
#endif

    eui64_set_local(addr);
    eui64_clear_group(addr);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its the same issue described in #13358, on multiple iotl-lab-m3 they all get the same short-addres 13:15 .

Copy link
Contributor

@fjmolinas fjmolinas Sep 9, 2020

Choose a reason for hiding this comment

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

Huh? Byte 7 will change if we got the EUI64 from luid and there are multiple interfaces

I'm talking about uniqueness across platforms, not interfaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

@benpicco do you have an issue with the proposed change?

static inline void eui_short_from_eui64(eui64_t *addr_long,
                                        network_uint16_t *addr_short)
{
    /* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
     * 0 for unicast addresses */
    addr_short->u8[0] = addr_long->uint8[0] & 0x7F;
    addr_short->u8[1] ^= addr_long->uint8[1];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@aabadie do you have some input on the m3? Could we do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't followed all the discussion in detail here. What I see is that there's a regression introduced on iotlab-m3. Why is it not possible to compute the EUI-64 from cpuid and eventually the interface ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is it not possible to compute the EUI-64 from cpuid and eventually the interface ?

This is what happens, but it seems like the last bytes of the generated EUI-64 are not very rich in entropy.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is what happens, but it seems like the last bytes of the generated EUI-64 are not very rich in entropy.

Then why the logic from #13362 was changed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#13362 replaced the logic in the driver with a common helper function.
That it 'solved' this problem was by accident.

The root cause is that the CPU ID (especially the uniform parts) is reflected too directly in the generated ID.
How about we shuffle the bytes a bit?

@herjulf
Copy link
Contributor

herjulf commented Sep 24, 2020

Hmm
I guess we could provide Ethernet modules like enc28j60 without any native EUI48 using the same scheme? To harmonize the addresses.

@benpicco
Copy link
Contributor Author

Sure! See #15083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants