From e923d5dbd8791cc9ff8f225f3160402eac053c5b Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Mon, 6 Jul 2020 09:01:28 +0200 Subject: [PATCH 1/3] sc_gnrc_netif: fix whitespaces in output Originally, the options and flags in the `netif` shell output were separated by two spaces. For later added flags this is not the case, making the parsing of those flags and options hard to impossible. This change adds those missing spaces + comments so it might not happen again in the future. --- sys/shell/commands/sc_gnrc_netif.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sys/shell/commands/sc_gnrc_netif.c b/sys/shell/commands/sc_gnrc_netif.c index 01be524b98..a42c24eb63 100644 --- a/sys/shell/commands/sc_gnrc_netif.c +++ b/sys/shell/commands/sc_gnrc_netif.c @@ -540,6 +540,7 @@ static void _netif_list(netif_t *iface) _print_iface_name(iface); printf(" "); + /* XXX divide options and flags by at least two spaces! */ res = netif_get_opt(iface, NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); if (res >= 0) { char hwaddr_str[res * 3]; @@ -678,6 +679,7 @@ static void _netif_list(netif_t *iface) line_thresh++; } #endif + /* XXX divide options and flags by at least two spaces! */ line_thresh = _newline(0U, line_thresh); line_thresh = _netif_list_flag(iface, NETOPT_PROMISCUOUSMODE, "PROMISC ", line_thresh); @@ -694,19 +696,20 @@ static void _netif_list(netif_t *iface) line_thresh = _netif_list_flag(iface, NETOPT_CSMA, "CSMA ", line_thresh); line_thresh += _LINE_THRESHOLD + 1; /* enforce linebreak after this option */ - line_thresh = _netif_list_flag(iface, NETOPT_AUTOCCA, "AUTOCCA ", + line_thresh = _netif_list_flag(iface, NETOPT_AUTOCCA, "AUTOCCA ", line_thresh); - line_thresh = _netif_list_flag(iface, NETOPT_IQ_INVERT, "IQ_INVERT ", + line_thresh = _netif_list_flag(iface, NETOPT_IQ_INVERT, "IQ_INVERT ", line_thresh); - line_thresh = _netif_list_flag(iface, NETOPT_SINGLE_RECEIVE, "RX_SINGLE ", + line_thresh = _netif_list_flag(iface, NETOPT_SINGLE_RECEIVE, "RX_SINGLE ", line_thresh); - line_thresh = _netif_list_flag(iface, NETOPT_CHANNEL_HOP, "CHAN_HOP ", + line_thresh = _netif_list_flag(iface, NETOPT_CHANNEL_HOP, "CHAN_HOP ", line_thresh); - line_thresh = _netif_list_flag(iface, NETOPT_OTAA, "OTAA ", + line_thresh = _netif_list_flag(iface, NETOPT_OTAA, "OTAA ", line_thresh); + /* XXX divide options and flags by at least two spaces! */ res = netif_get_opt(iface, NETOPT_MAX_PDU_SIZE, 0, &u16, sizeof(u16)); if (res > 0) { - printf("L2-PDU:%" PRIu16 " ", u16); + printf("L2-PDU:%" PRIu16 " ", u16); line_thresh++; } #ifdef MODULE_GNRC_IPV6 @@ -737,6 +740,7 @@ static void _netif_list(netif_t *iface) #endif #endif res = netif_get_opt(iface, NETOPT_SRC_LEN, 0, &u16, sizeof(u16)); + /* XXX divide options and flags by at least two spaces before this line! */ if (res >= 0) { printf("Source address length: %" PRIu16, u16); line_thresh++; From 1182f24b2537e1e6295163e373cfc352d58e7b48 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Mon, 6 Jul 2020 09:37:19 +0200 Subject: [PATCH 2/3] riotctrl_shell: provide netif interactions and parsers --- dist/pythonlibs/riotctrl_shell/netif.py | 382 ++++++++++++++++++ .../pythonlibs/riotctrl_shell/tests/common.py | 18 +- .../riotctrl_shell/tests/test_netif.py | 287 +++++++++++++ .../tests/test_netif_list_parse.py | 366 +++++++++++++++++ 4 files changed, 1049 insertions(+), 4 deletions(-) create mode 100644 dist/pythonlibs/riotctrl_shell/netif.py create mode 100644 dist/pythonlibs/riotctrl_shell/tests/test_netif.py create mode 100644 dist/pythonlibs/riotctrl_shell/tests/test_netif_list_parse.py diff --git a/dist/pythonlibs/riotctrl_shell/netif.py b/dist/pythonlibs/riotctrl_shell/netif.py new file mode 100644 index 0000000000..deb11f01fd --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/netif.py @@ -0,0 +1,382 @@ +# Copyright (C) 2020 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +""" +Shell interactions related to network interfaces + +Defines shell command interactions related to network interfaces +""" + +import re + +from riotctrl.shell import ShellInteraction, ShellInteractionParser + + +# ==== Parsers ==== + +class IfconfigListParser(ShellInteractionParser): + def __init__(self): + self.iface_c = re.compile(r"Iface\s+(?P\S+)\s") + # option values are repetitions of at least one non white space + # separated by at most one whitespace + # e.g. for MCS: 1 (BPSK, rate 1/2, 2x frequency repetition) MTU :1280 + # "1 (BPSK, rate 1/2, 2x frequency repetition)" belongs to the option + # value, "MTU" does not + self.option_c = re.compile(r"^(?P