-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Conversation
subsys/net/ip/net_shell.c
Outdated
|
||
SHELL_CREATE_STATIC_SUBCMD_SET(net_cmd_nbr) | ||
{ | ||
SHELL_CMD(rm, NULL, "Remove neighbor from cache.", |
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.
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; }
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.
In that case I would recommend using shell_cmd_precheck() function:
Prints help if request and prints error message on wrong argument count.
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.
Ok, I was wondering how the subcommand help was suppose to be done but missed this one in the sample app.
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.
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); |
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 is too uninformative to me. Maybe something more decriptive (e.g. SHELL_PRINT)?
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.
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.
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.
ok
if (ret) { | ||
printk("not supported\n"); | ||
PR("not supported\n"); |
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 is dedicated coloring for errors (SHELL_ERROR) and warnings (SHELL_WARNING) in shell. You should use those in error scenarios.
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.
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.", |
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.
You could solve 'stats' command in more handy way by utilizing dynamic autocompletion. It could have syntax like:
- net stats prints stats for all interfaces
- net_stats - prints stats for all named interfaces
Very similar approach is taken in log disable command (https://github.com/zephyrproject-rtos/zephyr/blob/f2596952599df87d9dafaa8d692f7f737a0fb3f6/subsys/logging/log_cmds.c#L390)
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.
That would be cool, there are also other commands that could benefit from this.
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.
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.
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.
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?
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.
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.
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.
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.
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.
To be honest I do not see easy solution for now to prompt command syntax + command help but to autocompleate only command name. :(
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.
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.
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.
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.
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.
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.
subsys/net/ip/net_shell.c
Outdated
|
||
SHELL_CMD_REGISTER(net, &net_commands, "Networking commands", NULL); | ||
|
||
SHELL_UART_DEFINE(shell_transport_uart); |
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.
you should leave shell definition to the application. Here only commands should be specified.
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.
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?
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.
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.
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.
@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.
subsys/net/ip/net_shell.c
Outdated
|
||
SHELL_CREATE_STATIC_SUBCMD_SET(net_cmd_nbr) | ||
{ | ||
SHELL_CMD(rm, NULL, "Remove neighbor from cache.", |
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.
if it is possible you could try to provide dynamic subcommand to be able to use tab to help pick a neighbor.
@jukkar, i'm very happy to see this. I've left few comments in the review. |
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 Report
@@ 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
Continue to review full report at Codecov.
|
Fixed merge conflict. |
Rebased against jarz-nordic:shell_rework |
@jukkar : Currently @nordic-krch is working on jarz-nordic:shell_rework branch to solve all conflicts. I hope it will be ready later today. |
Fixed sanity |
9745ea6
to
f292c9a
Compare
Updated because of changes in shell APIs. |
@jukkar : What about |
I hope @Vudentz will look into these. Are you otherwise ok with the PR? |
@Vudentz : Please update |
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>
Fixed merge conflict. @nordic-krch does this look now ok for you? |
Fixes #8875