Skip to content

native: provide socket-based ZEP device#6121

Merged
smlng merged 3 commits intoRIOT-OS:masterfrom
miri64:native/feat/zep_socket
Jan 18, 2018
Merged

native: provide socket-based ZEP device#6121
smlng merged 3 commits intoRIOT-OS:masterfrom
miri64:native/feat/zep_socket

Conversation

@miri64
Copy link
Copy Markdown
Member

@miri64 miri64 commented Nov 15, 2016

This is aiming to replace GNRC ZEP and allow platform independent IEEE 802.15.4 traffic on native (as opposed to #5582).

I tested it already with zep_mesh, a very simple network simulator I specifically wrote for ZEP (and RIOT, though I tried to keep it generalized):

zep_showcase

This is more or less done, but there are still some minor stuff I might add/change on a later point:

Depends on #6112 (merged).

@miri64 miri64 added 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 State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Nov 15, 2016
@miri64 miri64 added this to the Release 2017.01 milestone Nov 15, 2016
@miri64 miri64 added Platform: native Platform: This PR/issue effects the native platform Area: network Area: Networking labels Nov 15, 2016
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 15, 2016

(Just in case you are wondering why the EUI-64 is gradually growing with the nodes: it's generated from the sockets sockaddr. I took great care that the local port part is in the region were the last two bytes of the EUI-64 are and also used those two bytes for the short address).

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 15, 2016

I implemented this primarily to test my new NDP implementation I'm going to finally start in a few days.


ifneq (,$(filter netdev2_tap,$(USEMODULE)))
DIRS += netdev2_tap
DIRS += netdev2_tap
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.

there seem to spaces instead of tabs now ..

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.

Yes, this is the quasi convention for a while now. Since I touched this file anyway I allowed myself to change that ;-).

*/
void socket_zep_setup(socket_zep_t *dev, const socket_zep_params_t *params);

void socket_zep_cleanup(socket_zep_t *dev);
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.

Doxygen missing?

{
struct timeval tv;

gettimeofday(&tv, NULL);
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 the feeling gettimeofday should be added to syscalls...

return (memcmp(dst_addr, ieee802154_addr_bcast, dst_len) != 0) &&
(memcmp(dst_addr, dev->netdev.short_addr, dst_len) != 0);
default:
return false; /* better save than sorry ;-) */
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.

s/save/safe/ I guess

if (max_len != sizeof(uint16_t)) {
return -EOVERFLOW;
}
*v = SOCKET_ZEP_FRAME_PAYLOAD_LEN;
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.

you might want to check for v != NULL before...

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.

I think we don't do that anywhere else, but will do.

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.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 16, 2016

Addressed comments

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 16, 2016

I found the following patch useful for testing BTW ;-)

diff --git a/boards/native/Makefile.dep b/boards/native/Makefile.dep
index 88151e9..0991015 100644
--- a/boards/native/Makefile.dep
+++ b/boards/native/Makefile.dep
@@ -1,5 +1,5 @@
 ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
-  USEMODULE += netdev2_tap
+  USEMODULE += socket_zep
 endif

 ifneq (,$(filter socket_zep,$(USEMODULE)))
diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include
index 01fc119..232dc26 100644
--- a/boards/native/Makefile.include
+++ b/boards/native/Makefile.include
@@ -88,11 +88,11 @@ endif
 export LINKFLAGS += -ffunction-sections

 # set the tap interface for term/valgrind
-ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
-       export PORT ?= tap0
-else
-       export PORT =
-endif
+# ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
+#      export PORT ?= tap0
+# else
+#      export PORT =
+# endif

 export TERMFLAGS := $(PORT) $(TERMFLAGS)

(will provide a proper test application ASAP)

@kaspar030
Copy link
Copy Markdown
Contributor

Very nice! I won't find time to test, though...


if (getpeername(dev->sock_fd, (struct sockaddr *)&ss_array, &ss_len) < 0) {
perror("ZEP: Unable to retrieve remote address");
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here and below: the socket is connected at this point, should it be closed?

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.

I think that's a remnant from when I played around with unbound/unconnected sockets. Will do.

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.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Nov 22, 2016

Provided tests.

miri64 added a commit to miri64/RIOT that referenced this pull request Nov 22, 2016
When working on RIOT-OS#6121 I noticed that the documentation of the `netdev2`
driver part is not really precise. This fixes that.
@cgundogan
Copy link
Copy Markdown
Member

cgundogan commented Dec 15, 2016

this looks like a neat feature. Will try to find time on the weekend to give it a shot

@miri64 miri64 force-pushed the native/feat/zep_socket branch from ec2f8fb to 3af0d87 Compare December 27, 2016 10:20
@miri64 miri64 removed State: waiting for other PR State: The PR requires another PR to be merged first State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Dec 27, 2016
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Dec 27, 2016

Rebased to current master, since #6112 got merged => Removed Waiting for other PR label. Also removed WIP label. Those missing features can well be done in a follow-up.

@PeterKietzmann
Copy link
Copy Markdown
Member

@miri64 can you give a hint about how to use this, e.g. with gnrc_networking? I applied your patch and indeed, a gnrc_socket_zep thread appeared but unfortunately the gnrc_netdev2_tap interface is still predominant. Or am I mistaken in using gnrc_networking for testing this PR?

> ps  
ps
	pid | name                 | state    Q | pri | stack ( used) | base       | current    
	  - | isr_stack            | -        - |   - |  8192 (   -1) |  0x808a480 |  0x808a480
	  1 | idle                 | pending  Q |  15 |  8192 (  420) |  0x8088200 |  0x808a074 
	  2 | main                 | running  Q |   7 | 12288 ( 3124) |  0x8085200 |  0x8088074 
	  3 | pktdump              | bl rx    _ |   6 | 12288 (  976) |  0x8092500 |  0x8095374 
	  4 | 6lo                  | bl rx    _ |   3 |  8192 (  976) |  0x80a0ac0 |  0x80a2934 
	  5 | ipv6                 | bl rx    _ |   4 |  8192 ( 1424) |  0x809be40 |  0x809dcb4 
	  6 | udp                  | bl rx    _ |   5 |  8192 (  976) |  0x8095540 |  0x80973b4 
	  7 | gnrc_netdev2_tap     | bl rx    _ |   2 |  8192 ( 2356) |  0x8097c40 |  0x8099ab4 
	  8 | gnrc_socket_zep      | bl rx    _ |   2 |  8192 (  992) |  0x8099dc0 |  0x809bc34 
	  9 | RPL                  | bl rx    _ |   5 |  8192 ( 1080) |  0x809e7c0 |  0x80a0634 
	    | SUM                  |            |     | 90112 (12324)
> ifconfig
ifconfig
Iface  7   HWaddr: 3e:90:48:a8:59:e6 
           
           MTU:1500  HL:64  
           Source address length: 6
           Link type: wired
           inet6 addr: ff02::1/128  scope: local [multicast]
           inet6 addr: fe80::3c90:48ff:fea8:59e6/64  scope: local
           inet6 addr: ff02::1:ffa8:59e6/128  scope: local [multicast]
           inet6 addr: ff02::1a/128  scope: local [multicast]
           
           Statistics for Layer 2
            RX packets 0  bytes 0
            TX packets 1 (Multicast: 1)  bytes 64
            TX succeeded 1 errors 0
           Statistics for IPv6
            RX packets 0  bytes 0
            TX packets 1 (Multicast: 1)  bytes 50
            TX succeeded 1 errors 0

It would be great to have this for the release!

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 14, 2017

Have you cleaned between builds?

@PeterKietzmann
Copy link
Copy Markdown
Member

PeterKietzmann commented Jan 14, 2017

Sorry, my bad. I didn't apply your patch but just added USEMODULE += socket_zep to the Makefile.dep and forget to take out netdev2_tap. However, it seems there are some parameters needed to run a networking application with sock_zep, right? Could you provide a hint about how to run it? Would make testing easier for others.

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 12, 2018
@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 12, 2018

murdock isn't all that happy, can you have look?

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 16, 2018

@smlng Murdock should now be happy.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 16, 2018

Nope

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 16, 2018

That's a new one :D

@miri64 miri64 force-pushed the native/feat/zep_socket branch from ca1a23f to 4704c81 Compare January 16, 2018 14:56
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 16, 2018

Rebased (to include gnrc_netif to merge-base) and fixed.

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 17, 2018

@smlng now finally both Travis and Murdock are happy (except for squashing notice). Do you think we can include this into the release? Would be awesome for testing and debugging to have IEEE 802.15.4 for native.

BTW, @aabadie @kaspar030 @smlng Murdock doesn't seem to have flake8 to be installed.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 17, 2018

BTW, @aabadie @kaspar030 @smlng Murdock doesn't seem to have flake8 to be installed.

yep, workers need an update but not before release testing is done.

Otherwise, yes this should go into the release.

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

some minor comments on documentation (non blocking). But I also tried the test app which failed with an assertion as follows:

Socket ZEP device driver test
Initializing socket ZEP with (local: [::]:17754, remote: [::1]:17754)
(Hwaddrs: 455b, 005a45501c1e455b)
Send zero-length packet
Send 'Hello\0World\0'
Waiting for an incoming message (use `make test`)
tests/socket_zep/main.c:126 => 0x4d5c
*** RIOT kernel panic:
FAILED ASSERTION.

*** halted.


native: exiting

* @{
*
* @file
* @brief Configuration parameters for the @ref netdev_socket_zep driver
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.

indention off? One tab too much?

/**
* @defgroup netdev_socket_zep ZEP-based IEEE 802.15.4 device for native
* @ingroup netdev
* @brief
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.

mhm, a bit sad this is empty 😢 Maybe put the (rather long) defgroup title here, and shorten the above?

#include "debug.h"

/**
* @brief Define stack parameters for the MAC layer 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.

/brief/name/ for group

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.

Isn't generated anyways and the other devices use the same notation (also the brace doesn't seem to be closed... I just remove the brace, because this just refers to the stack, not the prio.

/**
* @defgroup net_zep ZEP header definitions
* @ingroup net
* @brief
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.

group description empty again 😢

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 17, 2018

while the error above was with make term the following comes from make test:

Socket ZEP device driver test
Initializing socket ZEP with (local: [::]:12345, remote: [::1]:17754)
(Hwaddrs: 3038, 005a45501c1e3038)
Send zero-length packet
Send 'Hello\0World\0'
Waiting for an incoming message (use `make test`)
Received invalid packet
Timeout in expect script at "child.expect(r"RSSI: \d+, LQI: \d+, Data:")" (tests/socket_zep/tests/01-run.py:50)
  File "/RIOT/dist/tools/testrunner/testrunner.py", line 55, in run
    testfunc(child)
  File "./tests/01-run.py", line 50, in testfunc
    child.expect(r"RSSI: \d+, LQI: \d+, Data:")
  File "/usr/local/lib/python3.6/site-packages/pexpect/spawnbase.py", line 321, in expect
    timeout, searchwindowsize, async)
  File "/usr/local/lib/python3.6/site-packages/pexpect/spawnbase.py", line 345, in expect_list
    return exp.expect_loop(timeout)
  File "/usr/local/lib/python3.6/site-packages/pexpect/expect.py", line 107, in expect_loop
    return self.timeout(e)
  File "/usr/local/lib/python3.6/site-packages/pexpect/expect.py", line 70, in timeout
    raise TIMEOUT(msg)

Run tests failed
make: *** [test] Error 1

@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 17, 2018

Did you used the most current version? I literally just fixed that in the latest batch and at least on my machine it was working with that.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 17, 2018

Did you used the most current version

okay, I'll quickly test again

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 17, 2018

I'll verified and I'm on the latest commit, but still get the errors as reported above. Though, I've to admit I test on macOS ...

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 17, 2018

retested on linux: works! So issues reported are likely macOS specific, still would be great to have it compatible in the future, if possible.

@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 18, 2018

please squash in a timely manner, the feature freeze is approaching slowly 😉

@miri64 miri64 force-pushed the native/feat/zep_socket branch from db4ac82 to 585e9a2 Compare January 18, 2018 08:15
@smlng
Copy link
Copy Markdown
Member

smlng commented Jan 18, 2018

ACK and GO!

@smlng smlng merged commit 5c0b058 into RIOT-OS:master Jan 18, 2018
@miri64 miri64 deleted the native/feat/zep_socket branch January 18, 2018 09:22
@miri64
Copy link
Copy Markdown
Member Author

miri64 commented Jan 18, 2018

Awesome! 🎉

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 Platform: native Platform: This PR/issue effects the native platform 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.

10 participants