]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: allow to enable/disable fast-start and set delay
authorVincent Bernat <bernat@luffy.cx>
Wed, 8 May 2013 11:34:06 +0000 (13:34 +0200)
committerVincent Bernat <bernat@luffy.cx>
Wed, 8 May 2013 11:34:06 +0000 (13:34 +0200)
src/client/client.h
src/client/conf-med.c
src/client/conf.c
src/client/display.c
src/client/lldpcli.8
src/daemon/client.c
src/daemon/lldpd.c
src/lib/atom-private.c
src/lib/lldpctl.h

index c58db51e911cd497020775e397a3e19957e46b41..1b460d358ca588ca29bfa41c2146f38687a0db90 100644 (file)
@@ -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 *);
index daede1ccd423e80b53d04898f0d6bb5571e316d4..43149968545a43f2017979c6ef5af1a67882e574 100644 (file)
@@ -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);
 }
index cc6e81200b5cdf4139d9646fae2c037943779bf8..27274c678220580588a8a2c5bb766c471ab56487 100644 (file)
@@ -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);
 }
index 4a29435a716f2a98efd9e6243fe9aada8bdad4a5..748169eea99c94c1529c742e5797ef3b739a299c 100644 (file)
@@ -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);
index 2ec680a263893b8049f1d4ddc9e36e4b74a3f2d2..a915bc550ea384a2bba9d64e519dc93c43dad448 100644 (file)
@@ -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
index dbf504c401729937e0d3e15ce74bbe9e530cbaa4..c986467a2500a7edd4409e50f36cb394d7528187 100644 (file)
@@ -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;
index a04897bbe4a74ddab4251a991cd5bc7ce5ce7dd8..c7b8ecf10aa5d5370bfa59bb827cd08cbd761b5d 100644 (file)
@@ -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
index b732ce83f4bb66e410fa80024a65ed076924f66f..2624ad2e168f4df0510312be0abcae8c8b2de72f 100644 (file)
@@ -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;
index e9eba63a6ef2bb60127069752c7693d15d933185..3e8ef2049fb2d899311da1b874fdf15e85dfb7ed 100644 (file)
@@ -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. */