From 486a613301465ead527f54e095b4895fa0310016 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 8 May 2013 13:34:06 +0200 Subject: [PATCH] lldpcli: allow to enable/disable fast-start and set delay --- src/client/client.h | 2 +- src/client/conf-med.c | 86 +++++++++++++++++++++++++++++++++++++++++- src/client/conf.c | 8 +++- src/client/display.c | 5 +++ src/client/lldpcli.8 | 20 ++++++++++ src/daemon/client.c | 12 ++++++ src/daemon/lldpd.c | 2 +- src/lib/atom-private.c | 13 +++++++ src/lib/lldpctl.h | 4 +- 9 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index c58db51e..1b460d35 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -124,7 +124,7 @@ void register_commands_watch(struct cmd_node *); /* conf*.c */ void register_commands_configure(struct cmd_node *); -void register_commands_configure_med(struct cmd_node *); +void register_commands_configure_med(struct cmd_node *, struct cmd_node *); void register_commands_configure_dot3(struct cmd_node *); void register_commands_medpow(struct cmd_node *); void register_commands_dot3pow(struct cmd_node *); diff --git a/src/client/conf-med.c b/src/client/conf-med.c index daede1cc..43149968 100644 --- a/src/client/conf-med.c +++ b/src/client/conf-med.c @@ -456,11 +456,90 @@ register_commands_medpol(struct cmd_node *configure_med) } } +static int +cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "configure fast interval support"); + + 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; + } + + char *action = arg; + if ((!strcmp(action, "enable") && + (lldpctl_atom_set_int(config, + lldpctl_k_config_fast_start_enabled, 1) == NULL)) || + (!strcmp(action, "disable") && + (lldpctl_atom_set_int(config, + lldpctl_k_config_fast_start_enabled, 0) == NULL)) || + (!strcmp(action, "delay") && + (lldpctl_atom_set_str(config, + lldpctl_k_config_fast_start_interval, + cmdenv_get(env, "tx-interval")) == NULL))) { + log_warnx("lldpctl", "unable to setup fast start. %s", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "configruation for fast start applied"); + lldpctl_atom_dec_ref(config); + return 1; +} + +/** + * Register "configure med fast-start *" + */ +static void +register_commands_medfast(struct cmd_node *med, struct cmd_node *nomed) +{ + struct cmd_node *configure_fast = commands_new( + med, + "fast-start", "Fast start configuration", + cmd_check_no_env, NULL, "ports"); + struct cmd_node *unconfigure_fast = commands_new( + nomed, + "fast-start", "Fast start configuration", + cmd_check_no_env, NULL, "ports"); + + /* Enable */ + commands_new( + commands_new( + configure_fast, + "enable", "Enable fast start", + NULL, NULL, NULL), + NEWLINE, "Enable fast start", + NULL, cmd_faststart, "enable"); + + /* Set TX delay */ + commands_new( + commands_new( + commands_new(configure_fast, + "tx-interval", "Set LLDP fast transmit delay", + NULL, NULL, NULL), + NULL, "LLDP fast transmit delay in seconds", + NULL, cmd_store_env_value, "tx-interval"), + NEWLINE, "Set LLDP fast transmit delay", + NULL, cmd_faststart, "delay"); + + /* Disable */ + commands_new( + commands_new( + unconfigure_fast, + NEWLINE, "Disable fast start", + NULL, cmd_faststart, "disable"), + NEWLINE, "Disable fast start", + NULL, cmd_faststart, "disable"); +} + /** * Register "configure med *" */ void -register_commands_configure_med(struct cmd_node *configure) +register_commands_configure_med(struct cmd_node *configure, struct cmd_node *unconfigure) { if (lldpctl_key_get_map( lldpctl_k_med_policy_type)[0].string == NULL) @@ -470,8 +549,13 @@ register_commands_configure_med(struct cmd_node *configure) configure, "med", "MED configuration", NULL, NULL, NULL); + struct cmd_node *unconfigure_med = commands_new( + unconfigure, + "med", "MED configuration", + NULL, NULL, NULL); register_commands_medloc(configure_med); register_commands_medpol(configure_med); register_commands_medpow(configure_med); + register_commands_medfast(configure_med, unconfigure_med); } diff --git a/src/client/conf.c b/src/client/conf.c index cc6e8120..27274c67 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -78,9 +78,15 @@ register_commands_configure(struct cmd_node *root) "configure", "Change system settings", NULL, NULL, NULL); + struct cmd_node *unconfigure = commands_new( + root, + "unconfigure", + "Unconfigure system settings", + NULL, NULL, NULL); cmd_restrict_ports(configure); + cmd_restrict_ports(unconfigure); register_commands_configure_lldp(configure); - register_commands_configure_med(configure); + register_commands_configure_med(configure, unconfigure); register_commands_configure_dot3(configure); } diff --git a/src/client/display.c b/src/client/display.c index 4a29435a..748169ee 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -728,6 +728,11 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w) tag_datatag(w, "lldpmed-no-inventory", "Disable LLDP-MED inventory", (lldpctl_atom_get_int(configuration, lldpctl_k_config_lldpmed_noinventory) == 0)? "no":"yes"); + tag_datatag(w, "lldpmed-faststart", "LLDP-MED fast start mechanism", + (lldpctl_atom_get_int(configuration, lldpctl_k_config_fast_start_enabled) == 0)? + "no":"yes"); + tag_datatag(w, "lldpmed-faststart-interval", "LLDP-MED fast start interval", + N(lldpctl_atom_get_str(configuration, lldpctl_k_config_fast_start_interval))); tag_end(w); tag_end(w); diff --git a/src/client/lldpcli.8 b/src/client/lldpcli.8 index 2ec680a2..a915bc55 100644 --- a/src/client/lldpcli.8 +++ b/src/client/lldpcli.8 @@ -175,6 +175,26 @@ delay is the delay between two transmissions of LLDP PDU. The default value is 30 seconds. .Ed +.Cd configure med fast-start +.Cd enable | tx-interval Ar interval +.Bd -ragged -offset XXXXXX +Configure LLDP-MED fast start mechanism. When a new LLDP-MED-enabled +neighbor is detected, fast start allows +.Nm lldpd +to shorten the interval between two LLDPDU. +.Cd enable +should enable LLDP-MED fast start while +.Cd tx-interval +specifies the interval between two LLDPDU in seconds. The default +interval is 1 second. Once 4 LLDPDU have been sent, the fast start +mechanism is disabled until a new neighbor is detected. +.Ed + +.Cd unconfigure med fast-start +.Bd -ragged -offset XXXXXX +Disable LLDP-MED fast start mechanism. +.Ed + .Cd configure .Op ports Ar ethX Op ,... .Cd med location coordinate diff --git a/src/daemon/client.c b/src/daemon/client.c index dbf504c4..c986467a 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -75,6 +75,18 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, levent_send_now(cfg); } +#ifdef ENABLE_LLDPMED + if (config->c_enable_fast_start) { + cfg->g_config.c_enable_fast_start = (config->c_enable_fast_start == 1); + log_debug("rpc", "client asked to %s fast start", + cfg->g_config.c_enable_fast_start?"enable":"disable"); + } + if (config->c_tx_fast_interval) { + log_debug("rpc", "change fast interval to %d", config->c_tx_fast_interval); + cfg->g_config.c_tx_fast_interval = config->c_tx_fast_interval; + } +#endif + lldpd_config_cleanup(config); return 0; diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index a04897bb..c7b8ecf1 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1428,8 +1428,8 @@ lldpd_main(int argc, char *argv[]) cfg->g_config.c_receiveonly = receiveonly; cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL; cfg->g_config.c_max_neighbors = LLDPD_MAX_NEIGHBORS; - cfg->g_config.c_enable_fast_start = enable_fast_start; #ifdef ENABLE_LLDPMED + cfg->g_config.c_enable_fast_start = enable_fast_start; cfg->g_config.c_tx_fast_init = LLDPD_FAST_INIT; cfg->g_config.c_tx_fast_interval = LLDPD_FAST_TX_INTERVAL; #endif diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index b732ce83..2624ad2e 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -384,6 +384,10 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key) #ifdef ENABLE_LLDPMED case lldpctl_k_config_lldpmed_noinventory: return c->config->c_noinventory; + case lldpctl_k_config_fast_start_enabled: + return c->config->c_enable_fast_start; + case lldpctl_k_config_fast_start_interval: + return c->config->c_tx_fast_interval; #endif default: return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -408,6 +412,15 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, config.c_tx_interval = value; if (value > 0) c->config->c_tx_interval = value; break; +#ifdef ENABLE_LLDPMED + case lldpctl_k_config_fast_start_enabled: + config.c_enable_fast_start = value?1:2; + c->config->c_enable_fast_start = value; + break; + case lldpctl_k_config_fast_start_interval: + config.c_tx_fast_interval = c->config->c_tx_fast_interval = value; + break; +#endif default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index e9eba63a..3e8ef204 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -583,7 +583,7 @@ lldpctl_atom_t *lldpctl_get_port(lldpctl_atom_t *port); */ typedef enum { lldpctl_k_config_tx_interval, /**< `(I,WO)` Transmit interval. When set to -1, it is meant to transmit now. */ - lldpctl_k_config_receiveonly, /**< `(I)` Receive only mode */ + lldpctl_k_config_receiveonly, /**< `(I,WO)` Receive only mode */ lldpctl_k_config_mgmt_pattern, /**< `(S)` Pattern to choose the management address */ lldpctl_k_config_iface_pattern, /**< `(S)` Pattern of enabled interfaces */ lldpctl_k_config_cid_pattern, /**< `(S)` Interface pattern to choose the chassis ID */ @@ -592,6 +592,8 @@ typedef enum { lldpctl_k_config_advertise_version, /**< `(I)` Advertise version */ lldpctl_k_config_lldpmed_noinventory, /**< `(I)` Disable LLDP-MED inventory */ lldpctl_k_config_paused, /**< `(I)` lldpd is paused */ + lldpctl_k_config_fast_start_enabled, /**< `(I,WO)` Is fast start enabled */ + lldpctl_k_config_fast_start_interval, /**< `(I,WO)` Start fast transmit interval */ lldpctl_k_interface_name, /**< `(S)` The interface name. */ -- 2.39.5