From f88442acdee831e1fb9baf67d9545efc705a054c Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 22 Jan 2013 23:14:53 +0100 Subject: [PATCH] lldpcli: possibility to configure tx-delay --- src/client/conf-dot3.c | 4 +++ src/client/conf-med.c | 4 +++ src/client/conf.c | 56 ++++++++++++++++++++++++++++++++++++------ src/client/lldpcli.8 | 9 +++++++ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/client/conf-dot3.c b/src/client/conf-dot3.c index 5588f757..a71aa7aa 100644 --- a/src/client/conf-dot3.c +++ b/src/client/conf-dot3.c @@ -27,6 +27,10 @@ void register_commands_configure_dot3(struct cmd_node *configure) { + if (lldpctl_key_get_map( + lldpctl_k_dot3_power_class)[0].string == NULL) + return; + struct cmd_node *configure_dot3 = commands_new( configure, "dot3", "Dot3 configuration", diff --git a/src/client/conf-med.c b/src/client/conf-med.c index 4aef70c9..daede1cc 100644 --- a/src/client/conf-med.c +++ b/src/client/conf-med.c @@ -462,6 +462,10 @@ register_commands_medpol(struct cmd_node *configure_med) void register_commands_configure_med(struct cmd_node *configure) { + if (lldpctl_key_get_map( + lldpctl_k_med_policy_type)[0].string == NULL) + return; + struct cmd_node *configure_med = commands_new( configure, "med", "MED configuration", diff --git a/src/client/conf.c b/src/client/conf.c index 3a9b8df8..cc6e8120 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -21,6 +21,51 @@ #include "client.h" #include "../log.h" +static int +cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "set transmit delay"); + + lldpctl_atom_t *config = lldpctl_get_configuration(conn); + if (config == NULL) { + log_warnx("lldpctl", "unable to get configuration from lldpd. %s", + lldpctl_last_strerror(conn)); + return 0; + } + if (lldpctl_atom_set_str(config, + lldpctl_k_config_tx_interval, cmdenv_get(env, "tx-interval")) == NULL) { + log_warnx("lldpctl", "unable to set transmit delay. %s", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "transmit delay set to new value"); + lldpctl_atom_dec_ref(config); + return 1; +} + +/** + * Register `configure lldp` commands. + */ +void +register_commands_configure_lldp(struct cmd_node *configure) +{ + struct cmd_node *configure_lldp = commands_new( + configure, + "lldp", "LLDP configuration", + NULL, NULL, NULL); + + commands_new( + commands_new( + commands_new(configure_lldp, + "tx-interval", "Set LLDP transmit delay", + cmd_check_no_env, NULL, "ports"), + NULL, "LLDP transmit delay in seconds", + NULL, cmd_store_env_value, "tx-interval"), + NEWLINE, "Set LLDP transmit delay", + NULL, cmd_txdelay, NULL); +} /** * Register `configure` and `no configure` commands. @@ -28,12 +73,6 @@ void register_commands_configure(struct cmd_node *root) { - int has_med = (lldpctl_key_get_map( - lldpctl_k_med_policy_type)[0].string != NULL); - int has_dot3 = (lldpctl_key_get_map( - lldpctl_k_dot3_power_class)[0].string != NULL); - if (!has_med && !has_dot3) return; - struct cmd_node *configure = commands_new( root, "configure", @@ -41,6 +80,7 @@ register_commands_configure(struct cmd_node *root) NULL, NULL, NULL); cmd_restrict_ports(configure); - if (has_med) register_commands_configure_med(configure); - if (has_dot3) register_commands_configure_dot3(configure); + register_commands_configure_lldp(configure); + register_commands_configure_med(configure); + register_commands_configure_dot3(configure); } diff --git a/src/client/lldpcli.8 b/src/client/lldpcli.8 index 1c726d76..dffa7a67 100644 --- a/src/client/lldpcli.8 +++ b/src/client/lldpcli.8 @@ -150,6 +150,15 @@ Make update its information and send new LLDP PDU on all interfaces. .Ed +.Cd configure +.Op ports Ar ethX Op ,... +.Cd lldp tx-interval Ar interval +.Bd -ragged -offset XXXXXX +Change transmit delay to the specified value in seconds. The transmit +delay is the delay between two transmissions of LLDP PDU. The default +value is 30 seconds. +.Ed + .Cd configure .Op ports Ar ethX Op ,... .Cd med location coordinate -- 2.39.5