Skip to content

Cellular: Preventing Socket ID assignment until actual socket creation at the modem #10431

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

Closed
wants to merge 6 commits into from

Conversation

hasnainvirk
Copy link
Contributor

@hasnainvirk hasnainvirk commented Apr 17, 2019

Description

Local modem ip stacks vary in their implementations and the way of
working. Some of the modems may not open a socket until an IP context is
assigned. That's why we came up with a container that stores addresses of
any CellularSocket instances created on-demand by the application. When
the application requests opening a socket we allocate and store the
primitive in the container however actual socket creation at the modem
may happen at a later stage, e.g., a call to send_to() may result in
actual opening of a socket.

That's why we must not assign socket ids in the CellularSocket object
during construction. It must happen when actual socket is opened and is
alive.

Another implication of the previous model is that we may have multiple
sockets created in our container but the actual socket ids are not
assigned yet, so we cannot directly map the socket id to the container
indices which has been happening previously.

To solve this issue we have promoted the AT_CellularStack::find_socket_index(...) method
to be a protected method rather than being private so that the children
can use the method to determine if the given index in the container
corresponds to the assigned socket id or not.

We have given up on the socket->created flag and the whole decision
making to actually open a socket on the modem happens on the basis of a
valid socket id being assigned or not.

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@AnttiKauppila @kjbracey-arm @AriParkkila @blind-owl @mirelachirica @jarvte

Release Notes

Hasnain Virk added 6 commits April 17, 2019 15:50
Local modem ip stacks vary in their implementations and the way of
working. Some of the modems may not open a socket until an IP context is
assigned. That's why we came up with a container that stores addresses of
any CellularSocket instances created on-demand by the application. When
the application requests opening a socket we store allocate and store the
premitive in the container however actual socket creation at the modem
may happen at a later stage, e.g., a call to send_to() may result in
actual opening of a socket.

That's why we must not assign socket ids in the CellularSocket object
during construction. It must happen when actual socket is opened and is
alive.

Another implication of the previous model is that we may have multiple
sockets created in our container but the actual socket ids are not
assigned yet, so we cannot directly map the socket id to the container
indices which has been happening previously.

To solve this issue we have promoted the AT_CellularStac::find_socket_index(...) method
to be a protected method rather than being private so that the children
can use the method to determine if the given index in the container
corrsponds to the assigned socket id or not.

We have given up on the socket->created flag and the whole decision
making to actually open a socket on the modem happens on the basis of a
valid socket being assigned or not.
Socket ids will be assigned in the create_socket_impl(...) method. This
is the point where an actual socket creation at the modem takes place.
Changes introduced to accomodate the socket id assignment upon actual
creation of the socket at the modem.
Changes to accomodate socket id assignment upon actual creation of the
socket at the modem.
This modem is a special case. It uses a given socket ID value rather
than providing one. A naive solution here would be to directly map the
index of a CellularSocket object in the CellularSocket container. But
considering the case where there are multiple sockets being opened (some
sockets being already created at the modem and some yet not created), direct mapping
to indices will not work. As it can happen that the CellularSocket
object is allocated but the socket id is not assigned yet as it is not
actually created on the modem.

In such a case, we check the container and assign the socket id from the
pool if an empty slot was found.
Changes to accomodate socket id assigment upon actual creation of the
socket at the modem.
@ciarmcom
Copy link
Member

@hasnainvirk, thank you for your changes.
@mirelachirica @blind-owl @jarvte @kjbracey-arm @AnttiKauppila @AriParkkila @ARMmbed/mbed-os-wan @ARMmbed/mbed-os-maintainers please review.

@hasnainvirk hasnainvirk changed the title Sock id debacle [Cellular] Preventing Socket ID assignment until actual socket creation at the modem Apr 17, 2019
@40Grit
Copy link

40Grit commented Apr 18, 2019

@trowbridgec

Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

(Probably too late, but looking at the existing code, I'd be strongly inclined to bin the _socket array and just have a linked list of CellularSocket objects - if you're using dynamic allocation anyway, then what does having a fixed-size array of pointers buy you? Just have a linked list, and make your nsapi_socket_t be the actual pointer to the CellularSocket.)

@hasnainvirk
Copy link
Contributor Author

Looks fine to me.

(Probably too late, but looking at the existing code, I'd be strongly inclined to bin the _socket array and just have a linked list of CellularSocket objects - if you're using dynamic allocation anyway, then what does having a fixed-size array of pointers buy you? Just have a linked list, and make your nsapi_socket_t be the actual pointer to the CellularSocket.)

Makes sense. Will mark the suggestion as a future item.

@adbridge
Copy link
Contributor

ci started

@mbed-ci
Copy link

mbed-ci commented Apr 26, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_exporter

@adbridge
Copy link
Contributor

Looks like a licence issue - restarted

@adbridge
Copy link
Contributor

Restarted

@hasnainvirk
Copy link
Contributor Author

Restarted

CI doesn't seem to be started.

@0xc0170 0xc0170 changed the title [Cellular] Preventing Socket ID assignment until actual socket creation at the modem Cellular: Preventing Socket ID assignment until actual socket creation at the modem Apr 29, 2019
@alekla01
Copy link
Contributor

Restarted

CI doesn't seem to be started.

it was restarted: PASS: 2019-04-29T10:51:03.000Z vs FAIL: 2019-04-26T00:36:37.000Z. However, the restarting process did not follow the current CI assumptions -> status not updated.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 30, 2019

it was restarted: PASS: 2019-04-29T10:51:03.000Z vs FAIL: 2019-04-26T00:36:37.000Z. However, the restarting process did not follow the current CI assumptions -> status not updated.

I restarted it again

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 30, 2019

@AnttiKauppila @kjbracey-arm @AriParkkila @blind-owl @mirelachirica @jarvte

Any more reviews for this PR? It looks ready

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2019

Reminder to move this PR forward!

@adbridge
Copy link
Contributor

@AnttiKauppila Code freeze for 5.13 is one week today. If you want this to go in could you please find someone to review ?

@AnttiKauppila
Copy link

@adbridge @AriParkkila Has already approved this, is that not enough?

@adbridge
Copy link
Contributor

@hasnainvirk could you please rebase to remove the conflict?
@AnttiKauppila it was more about having someone review the updates after the previous approval. Thanks for doing so.

@0xc0170
Copy link
Contributor

0xc0170 commented May 22, 2019

I would like to add this to CI, please rebase asap.

@AriParkkila
Copy link

@0xc0170 I moved this (for rebasing in my repo) to #10639. This PR can be closed.

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

Successfully merging this pull request may close these issues.

10 participants