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

Convert net-shell to use new shell #9825

Merged
merged 9 commits into from
Oct 15, 2018
Merged

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Sep 6, 2018

Fixes #8875

@jukkar jukkar added In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on area: Networking area: Shell Shell subsystem DNM This PR should not be merged (Do Not Merge) labels Sep 6, 2018
@nashif nashif added this to the v1.14.0 milestone Sep 6, 2018

SHELL_CREATE_STATIC_SUBCMD_SET(net_cmd_nbr)
{
SHELL_CMD(rm, NULL, "Remove neighbor from cache.",
Copy link
Contributor

@jakub-uC jakub-uC Sep 7, 2018

Choose a reason for hiding this comment

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

You are defining a help string for this command (and others):

SHELL_CMD(rm, NULL, "Remove neighbor from cache.",
		  cmd_net_nbr_rm),

However in the command handler: cmd_net_nbr_rm you are not calling a function resposible for printing help.
In current command implementation when user will call command:
net nbr rm -h or net nbr rm --help
help string "Remove neighbor from cache." will not be dispayed by shell.

To be able to see help string you need to add following code at the beginning of command halder:

if (shell_help_requested(shell)) { shell_help_print(shell, opt, opt_len); return; }

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case I would recommend using shell_cmd_precheck() function:

Prints help if request and prints error message on wrong argument count.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I was wondering how the subcommand help was suppose to be done but missed this one in the sample app.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hint: Function shell_help_print prints help for existing command and subcommands 1 level below.

I prefere to add this function to each command handler, for either root command or subcommands.

{
enum ethernet_hw_caps caps = net_eth_get_hw_capabilities(iface);
int i;

for (i = 0; i < ARRAY_SIZE(eth_hw_caps); i++) {
if (caps & eth_hw_caps[i].capability) {
printk("\t%s\n", eth_hw_caps[i].description);
PR("\t%s\n", eth_hw_caps[i].description);
Copy link
Contributor

Choose a reason for hiding this comment

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

PR is too uninformative to me. Maybe something more decriptive (e.g. SHELL_PRINT)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried to keep the macro name short, the lines are quite long already. I originally had the full shell_fprintf(shell, SHELL_NORMAL, ....); but that was just way too long.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

if (ret) {
printk("not supported\n");
PR("not supported\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

There is dedicated coloring for errors (SHELL_ERROR) and warnings (SHELL_WARNING) in shell. You should use those in error scenarios.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, makes sense.

SHELL_CMD(rpl, NULL, "Show RPL mesh routing status.", cmd_net_rpl),
SHELL_CMD(stacks, NULL, "Show network stacks information.",
cmd_net_stacks),
SHELL_CMD(stats, &net_cmd_stats, "Show network statistics.",
Copy link
Contributor

Choose a reason for hiding this comment

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

You could solve 'stats' command in more handy way by utilizing dynamic autocompletion. It could have syntax like:

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be cool, there are also other commands that could benefit from this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have been experimenting with the dynamic commands. I added dynamic completion for net iface up <idx> command. I got it working but it is not very user friendly atm.
In this example I have two network interfaces. When completing the command I see this:

net:~$ net iface up <tab>
  0  1

but it is not easy to understand what the values actually mean. For that one needs to add --help string in which case I get

net:~$ net iface up 1 --help
up - 'net iface up <iface index>' takes network interface up.
Options:
  -h, --help  :Show command help.
Subcommands:
  0  :Ethernet (0x00421860)
  1  :Ethernet (0x00421920)

For user this is quite cumbersome. Why not show the help during completion like this:

net:~$ net iface up <tab>
  0  :Ethernet (0x00421860)
  1  :Ethernet (0x00421920)

This would be much more user friendly and user could select the proper index immediately. If there is only one interface, then it is selected automatically currently and this is just fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

So you would like to have help string for promted dynamic commands or all commands?
Or maybe I could prepare special type of dynamic commands printing this help?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just setting entry->help = set_iface_index_help(idx); for dynamic command, and was expecting that it's value would be used in completion. Will send new version shortly so you can see how I did this.

Copy link
Member Author

@jukkar jukkar Sep 10, 2018

Choose a reason for hiding this comment

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

That is certainly expected but the output net iface up 0: Ethernet (0x12345678) after pressing the tab would be wrong for this command thus this approach cannot be used here.

Hmm, github does not seem to handle <tab> prints correctly in my comment, it does not print them without quotes.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest I do not see easy solution for now to prompt command syntax + command help but to autocompleate only command name. :(

Copy link
Member Author

Choose a reason for hiding this comment

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

I will probably remove the dynamic completion support from net-shell as the feature uses lot of memory. Especially the IPv6 neighbor completion uses 240 bytes memory by default. The network interface index completion is using smaller amount of memory but is currently not very user friendly.

Copy link
Collaborator

@pizi-nordic pizi-nordic Sep 17, 2018

Choose a reason for hiding this comment

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

Could we use interface names, like eth0, at shell level?
The prefix will depend on interface type (eth = Ethernet) and number for interface index.

I also think, that keeping features like neighbor completion is a good thing. SoC with plenty of RAM will see direct benefit and the smaller SoC will be still OK if we make this option configurable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could we use interface names, like eth0, at shell level?

Currently we do not have a concept for interface name in IP stack, if we introduce such a name it would be only for shell which complicates things. This needs to be pondered more, atm there are more important things to do so this is left for later (at least from my part). Patches are welcome of course.

if we make this option configurable.

Yes, I was planning to make the completion configurable and enable it by default.


SHELL_CMD_REGISTER(net, &net_commands, "Networking commands", NULL);

SHELL_UART_DEFINE(shell_transport_uart);
Copy link
Contributor

Choose a reason for hiding this comment

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

you should leave shell definition to the application. Here only commands should be specified.

Copy link
Member Author

@jukkar jukkar Sep 7, 2018

Choose a reason for hiding this comment

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

Hmm, with net-shell the idea is that the app only needs to set CONFIG_NET_SHELL=y and get a shell automatically. This worked with legacy shell but has things changed with the new shell?

Copy link
Contributor

Choose a reason for hiding this comment

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

note, that in future there might be multiple transports (net too) and even multiple shell instances available so that approach will not fly for long. We might approach that the other way: add UART as default transport to the shell module.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nordic-krch The SHELL_DEFINE() macro is a bit problematic as it requires the transport as a parameter. As a user I would just like to set CONFIG_NET_SHELL=y and expecting that net-shell is enabled without any configuration. Could the transport parameter left out or set to NULL? The shell subsystem would then just select the default backend in that case. Setting the backend here looks something that would be better done in some other part of the system.


SHELL_CREATE_STATIC_SUBCMD_SET(net_cmd_nbr)
{
SHELL_CMD(rm, NULL, "Remove neighbor from cache.",
Copy link
Contributor

Choose a reason for hiding this comment

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

if it is possible you could try to provide dynamic subcommand to be able to use tab to help pick a neighbor.

@nordic-krch
Copy link
Contributor

@jukkar, i'm very happy to see this. I've left few comments in the review.

@jukkar
Copy link
Member Author

jukkar commented Sep 7, 2018

Added dynamic command support for "net iface", "net stats" and "net nbr" commands. Also added color output if there is error/warning/info message printed.

@codecov-io
Copy link

codecov-io commented Sep 7, 2018

Codecov Report

Merging #9825 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9825      +/-   ##
==========================================
+ Coverage   53.18%   53.34%   +0.16%     
==========================================
  Files         210      211       +1     
  Lines       25825    25824       -1     
  Branches     5686     5684       -2     
==========================================
+ Hits        13735    13777      +42     
+ Misses       9781     9734      -47     
- Partials     2309     2313       +4
Impacted Files Coverage Δ
subsys/net/ip/net_private.h 83.33% <ø> (ø) ⬆️
include/net/net_if.h 58.97% <ø> (-1.03%) ⬇️
subsys/net/ip/net_core.c 73.48% <100%> (+0.2%) ⬆️
subsys/net/ip/net_shell.h 100% <100%> (ø)
lib/posix/pthread_sched.c 41.66% <0%> (-20.84%) ⬇️
subsys/net/ip/net_if.c 65.49% <0%> (+0.11%) ⬆️
lib/posix/pthread_mutex.c 77.77% <0%> (+1.38%) ⬆️
lib/posix/pthread.c 80.36% <0%> (+12.32%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b307be0...9c92690. Read the comment docs.

@jukkar jukkar removed DNM This PR should not be merged (Do Not Merge) In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on labels Sep 10, 2018
@nordic-krch nordic-krch mentioned this pull request Sep 12, 2018
@jukkar
Copy link
Member Author

jukkar commented Sep 14, 2018

Fixed merge conflict.

@jukkar
Copy link
Member Author

jukkar commented Sep 17, 2018

Rebased against jarz-nordic:shell_rework

@jakub-uC
Copy link
Contributor

jakub-uC commented Sep 17, 2018

@jukkar : Currently @nordic-krch is working on jarz-nordic:shell_rework branch to solve all conflicts. I hope it will be ready later today.

@jukkar
Copy link
Member Author

jukkar commented Oct 8, 2018

Fixed sanity

@jukkar
Copy link
Member Author

jukkar commented Oct 11, 2018

Updated because of changes in shell APIs.

@jakub-uC
Copy link
Contributor

jakub-uC commented Oct 11, 2018

@jukkar : What about *.conf files under this location: tests/bluetooth/shell ?
Maybe not with this PR but I guess they need to be updated

@jukkar
Copy link
Member Author

jukkar commented Oct 11, 2018

What about *.conf files under this location: tests/bluetooth/shell ?

I hope @Vudentz will look into these. Are you otherwise ok with the PR?

@jakub-uC
Copy link
Contributor

@Vudentz : Please update *.conf files under: tests/bluetooth/shell to get rid off old shell dependencies.

Convert net-shell to use the new shell API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
There were no shell commands implemented so remove the shell
support from this sample application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Use new shell instead of the legacy one. This commit also fixes
the configuration file mess and allows the program to be run on
more hardware.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
ROM consumption is higher with new shell which prevents
quark_se_c1000_devboard from building. Remove that board
from sanitychecker runs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
@jukkar
Copy link
Member Author

jukkar commented Oct 12, 2018

Fixed merge conflict.

@nordic-krch does this look now ok for you?

@nordic-krch nordic-krch self-requested a review October 15, 2018 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants