From: Vincent Bernat Date: Sat, 11 Jul 2015 20:59:23 +0000 (+0200) Subject: lldpcli: add "show chassis" command X-Git-Tag: 0.7.16~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3407e638d4348013fc1339a9f9edd7aa92f9b5c9;p=thirdparty%2Flldpd.git lldpcli: add "show chassis" command This demonstrates the use of `lldpctl_get_local_chassis()` function. --- diff --git a/src/client/client.h b/src/client/client.h index cd737c22..9e7fa46d 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -113,6 +113,8 @@ void display_interfaces(lldpctl_conn_t *, struct writer *, struct cmd_env *, int, int); void display_interface(lldpctl_conn_t *, struct writer *, int, lldpctl_atom_t *, lldpctl_atom_t *, int, int); +void display_local_chassis(lldpctl_conn_t *, struct writer *, + struct cmd_env *, int); void display_configuration(lldpctl_conn_t *, struct writer *); void display_interfaces_stats(lldpctl_conn_t *, struct writer *, struct cmd_env *); diff --git a/src/client/display.c b/src/client/display.c index a44f94eb..053ad247 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -549,6 +549,22 @@ display_age(time_t lastchange) return sage; } +void +display_local_chassis(lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, int details) +{ + tag_start(w, "local-chassis", "Local chassis"); + + lldpctl_atom_t *chassis = lldpctl_get_local_chassis(conn); + display_chassis(w, chassis, details); + if (details == DISPLAY_DETAILS) { + display_med(w, NULL, chassis); + } + lldpctl_atom_dec_ref(chassis); + + tag_end(w); +} + void display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden, lldpctl_atom_t *iface, lldpctl_atom_t *neighbor, int details, int protocol) diff --git a/src/client/lldpcli.8.in b/src/client/lldpcli.8.in index 4e4c9d0c..1ccdab55 100644 --- a/src/client/lldpcli.8.in +++ b/src/client/lldpcli.8.in @@ -127,6 +127,17 @@ one or several ports, the information displayed is limited to the given list of ports. .Ed +.Cd show chassis +.Op Cd details | summary +.Bd -ragged -offset XXXXXX +Display information about local chassis. With +.Cd summary , +most details are skipped. On the other hand, with +.Cd details , +all available information will be displayed, giving a verbose +view. +.Ed + .Cd watch .Op ports Ar ethX Op ,... .Op Cd details | summary diff --git a/src/client/show.c b/src/client/show.c index 1e2a06d3..7922b3e2 100644 --- a/src/client/show.c +++ b/src/client/show.c @@ -47,6 +47,30 @@ cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +/** + * Show chassis. + * + * The environment will contain the following keys: + * - C{summary} if we want to show only a summary + * - C{detailed} for a detailed overview + */ +static int +cmd_show_chassis(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "show chassis data (%s)", + cmdenv_get(env, "summary")?"summary": + cmdenv_get(env, "detailed")?"detailed": + "normal"); + + display_local_chassis(conn, w, env, + cmdenv_get(env, "summary")?DISPLAY_BRIEF: + cmdenv_get(env, "detailed")?DISPLAY_DETAILS: + DISPLAY_NORMAL); + + return 1; +} + /** * Show stats. * @@ -182,17 +206,11 @@ cmd_watch_neighbors(struct lldpctl_conn_t *conn, struct writer *w, } /** - * Register common subcommands for `watch` and `show neighbors`. + * Register common subcommands for `watch` and `show neighbors` and `show chassis' */ void -register_common_commands(struct cmd_node *root) +register_common_commands(struct cmd_node *root, int neighbor) { - /* With hidden neighbors */ - commands_new(root, - "hidden", - "Include hidden neighbors", - cmd_check_no_env, cmd_store_env_and_pop, "hidden"); - /* With more details */ commands_new(root, "details", @@ -205,6 +223,14 @@ register_common_commands(struct cmd_node *root) "With less details", cmd_check_no_detailed_nor_summary, cmd_store_env_and_pop, "summary"); + if (!neighbor) return; + + /* With hidden neighbors */ + commands_new(root, + "hidden", + "Include hidden neighbors", + cmd_check_no_env, cmd_store_env_and_pop, "hidden"); + /* Some specific port */ cmd_restrict_ports(root); @@ -243,6 +269,12 @@ register_commands_show(struct cmd_node *root) "Show neighbors data", NULL, NULL, NULL); + struct cmd_node *chassis = commands_new( + show, + "chassis", + "Show local chassis data", + NULL, NULL, NULL); + struct cmd_node *stats = commands_new( show, "statistics", @@ -255,7 +287,15 @@ register_commands_show(struct cmd_node *root) "Show neighbors data", NULL, cmd_show_neighbors, NULL); - register_common_commands(neighbors); + register_common_commands(neighbors, 1); + + /* Chassis data */ + commands_new(chassis, + NEWLINE, + "Show local chassis data", + NULL, cmd_show_chassis, NULL); + + register_common_commands(chassis, 0); /* Stats data */ commands_new(stats, @@ -305,5 +345,5 @@ register_commands_watch(struct cmd_node *root) "Monitor neighbors change", NULL, cmd_watch_neighbors, NULL); - register_common_commands(watch); + register_common_commands(watch, 1); } diff --git a/tests/lldpcli.conf b/tests/lldpcli.conf index 94d2d41f..29c31731 100644 --- a/tests/lldpcli.conf +++ b/tests/lldpcli.conf @@ -5,6 +5,7 @@ show neighbors details hidden show neighbors summary show neighbors ports eth0 details show configuration +show chassis details show statistics show statistics summary show statistics ports eth0