-
Notifications
You must be signed in to change notification settings - Fork 3k
[ONME-2927] Socket adaptation layer for nanostack #3517
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
Conversation
@c1728p9 @sg- @bridadan @geky Please review. Will not pass tests as we need to update Nanostack binaries first. @kjbracey-arm @SeppoTakalo |
@hasnainvirk Please have following line in the message: |
@SeppoTakalo @hasnainvirk went ahead and marked this as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good aside from some minor changes. I saw that TCP accept was added. Does this bring in support for TCP server sockets? That would be awesome.
const char * NanostackInterface::get_ip_address() | ||
{ | ||
static char text_address[40]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_address should probably be a part of the NanostackInterface class rather than static. You should also probably be holding nanostack's lock during this call.
return NSAPI_ERROR_UNSUPPORTED; | ||
nsapi_size_or_error_t ret; | ||
|
||
if (socket->closed() || (!address && !socket->is_connected())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be protected with nanostack_lock
ns_address_t ns_address; | ||
convert_mbed_addr_to_ns(&ns_address, &address); | ||
|
||
return do_sendto(handle, &ns_address, data, size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might add a comment that no locking is needed in socket_sendto since do_sendto is thread safe.
|
||
nsapi_size_or_error_t ret; | ||
|
||
if (socket->closed()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Socket could change state so the check should be done when nanostack_lock is held
goto out; | ||
} | ||
|
||
if (socket->closed()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to lock before checking state that could change
MBED_ASSERT(false); | ||
return NSAPI_ERROR_NO_SOCKET; | ||
} | ||
|
||
nanostack_lock(); | ||
if (!socket->is_listening()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to lock before checking state that could change
3b96ae4
to
aa87036
Compare
@c1728p9 Hi Russ, yes we have introduced TCP server sockets. Thanks for the review. |
Another notable benefit is that both client and server TCP sockets now have reliable delivery of incoming data. The queuing system used previously couldn't totally achieve that - there was no way to provide flow-control back-pressure to the sender, and if we ended up running out of queue memory and dropping an incoming chunk of data, it would be silently lost. (So far it has worked quite well in practice, but it has relied on apps reading data fast enough.) Nanostack's new queuing allows a per-socket limit to be imposed for both UDP and TCP rather than just queuing until memory exhaustion as NanostackInterface did. |
@VeliMattiLahtela the |
@bridadan It is supposed to fail. There is a API change in Nanostack so the build cannot pass until we provide new binaries. |
@SeppoTakalo My mistake, should have read the discussion! Thanks for pointing that out. |
aa87036
to
d6a60ac
Compare
Rebased the branch and imported new Nanostack binaries with coap-service update. |
Tested with mbed-os-cliapp network testsuite.
This is not ready to be merged. NOTE: Should not go into 5.3.x patch releases. Target is 5.4 |
From Cam-CI I can see:
Is this CI error? |
retest uvisor |
@mazimkhan I appear not to be able to restart uvisor... |
retest uvisor |
/morph test-nightly |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
As a result of major overhaul in Nanostack generally for socket API and especially for TCP, the adaptation layer for mbed-OS is being upgraded. Previously, as nanostack was not able to provide receive queue, adaptation layer had been faking it. Now with Stream Socket by default Nanostack provides 2K receive queue and 2K send queue. Receive queue size can be changed using setsockopt(). Batre metal nanostack would not provide with any receive queues with Datagram Socket, however in this adaptation layer we introduce a 2K receive queue size for the Datagram Socket as well. Layer state machine handling is polished to ensure robustness. ::socket_connect() will can return 2 new error codes now. NSAPI_ERROR_ALREADY (like posix EALREADY) in case if the connection is in progress or NSAPI_ERROR_IS_CONNECTED (like posix EISCONN) if already connected. NSAPI_ERROR_WOULDBLOCK is now mapped directly to nanostack NS_WOULDBLOCK. NanostackLockGaurd class is introduced which enables us to claim and release mutex using RAII style.
… from a1982c1..e125164 e125164 Check secure session pointer in timer callback (ARMmbed#61) f49e596 Update unit tests (ARMmbed#59) 6a5634a Support for multiple virtual services (ARMmbed#58) 7fe6b98 Remove yotta files (ARMmbed#57) 5c5c8fe Fix socket send return value overflow (ARMmbed#56) 0870d05 Update unit test stubs to match latest socket api (ARMmbed#55) e687be8 Merge pull request ARMmbed#54 from ARMmbed/warn_fixes b8fe613 updated unittests 8640d05 Compilation warnings fixed eea83e5 Flag out entropy source addition (ARMmbed#53) 7d72eb4 Fix unittests (ARMmbed#52) 4a6991e Avoid referencing ns_msghdr_t::flags git-subtree-dir: features/nanostack/FEATURE_NANOSTACK/coap-service git-subtree-split: e125164
d6a60ac
to
67ffdc4
Compare
@c1728p9 @kjbracey-arm @SeppoTakalo , I have amended some stuff pointed out by Russ. This should be okay now. Please proceed with the tests and merge once again. |
@bridadan Can you please run nightly tests on it ? We need to move forward here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some remaining nanostack_locks, and actually some apparently erroneous nanostack_unlocks after LockGuard.
@@ -381,7 +382,9 @@ void NanostackSocket::event_connect_fail(socket_callback_t *sock_cb) | |||
} | |||
|
|||
void NanostackSocket::event_incoming_connection(socket_callback_t *sock_cb) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Editing error
5e65978
to
b464ed0
Compare
NanostackLockGuard usage is now consistent throughout. Missing Lock assertion added at a few locations in the code
b464ed0
to
1f24533
Compare
In sendto(), memory allocation failures were mistakenly being treated as would blocks (assumption was that the device might be able to recover). However, that put the blocking socket into deep sleep and there was no mechanism to wake it up ever again. Somehow that got slipped through testing. Fixed in this amenment
/morph test-nightly |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
retest uvisor |
I restarted uvisor and jenkins CI, lets wait for results |
That
Is it not capable of setting the status here? |
@SeppoTakalo Usually this is due to an issue with the CI GitHub account running into the API query limit (there doesn't seem to be a way to increase the limit). I've talked with @tommikas and @mazimkhan multiple times about this, I think the plan is each CI will get a separate account. |
@SeppoTakalo I have restarted the job to update CI status. As it shows now. |
STATUS: ready
As a result of major overhaul in Nanostack generally for socket API and especially
for TCP, the adaptation layer for mbed-OS is being upgraded.
Previously, as nanostack was not able to provide receive queue, adaptation layer had been
faking it. Now with Stream Socket by default Nanostack provides 2K receive queue and 2K send queue.
Receive queue size can be changed using setsockopt(). Batre metal nanostack would not provide with any
receive queues with Datagram Socket, however in this adaptation layer we introduce a 2K receive queue size
for the Datagram Socket as well.
Layer state machine handling is polished to ensure robustness.
::socket_connect() will can return 2 new error codes now. NSAPI_ERROR_ALREADY (like posix EALREADY) in case
if the connection is in progress or NSAPI_ERROR_IS_CONNECTED (like posix EISCONN) if already connected.
NSAPI_ERROR_WOULDBLOCK is now mapped directly to nanostack NS_WOULDBLOCK.
NOTE: Target is 5.4 release. Should not go into 5.3.x patch releases.