]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: retrofit the 'metric-style' command
authorEmanuele Di Pascale <emanuele@voltanet.io>
Tue, 13 Nov 2018 17:05:00 +0000 (18:05 +0100)
committerEmanuele Di Pascale <emanuele@voltanet.io>
Tue, 18 Dec 2018 14:21:52 +0000 (15:21 +0100)
Note that some of the validation checks that were previously
executed in the code have been moved to the YANG model.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
isisd/isis_cli.c
isisd/isis_cli.h
isisd/isis_northbound.c
isisd/isis_vty_isisd.c
isisd/isisd.c
isisd/isisd.h

index 36caae5703958f54616fa94b143adf8fc4707ee6..7f8b3d54f2a2443cac7104e0b5f024274c0d9590 100644 (file)
@@ -444,6 +444,52 @@ void cli_show_isis_attached(struct vty *vty, struct lyd_node *dnode,
        vty_out(vty, " set-attached-bit\n");
 }
 
+/*
+ * XPath: /frr-isisd:isis/instance/metric-style
+ */
+DEFPY(metric_style, metric_style_cmd,
+         "metric-style <narrow|transition|wide>$style",
+      "Use old-style (ISO 10589) or new-style packet formats\n"
+      "Use old style of TLVs with narrow metric\n"
+      "Send and accept both styles of TLVs during transition\n"
+      "Use new style of TLVs to carry wider metric\n")
+{
+       nb_cli_enqueue_change(vty, "./metric-style", NB_OP_MODIFY, style);
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
+DEFPY(no_metric_style, no_metric_style_cmd,
+         "no metric-style [narrow|transition|wide]",
+         NO_STR
+         "Use old-style (ISO 10589) or new-style packet formats\n"
+      "Use old style of TLVs with narrow metric\n"
+      "Send and accept both styles of TLVs during transition\n"
+      "Use new style of TLVs to carry wider metric\n")
+{
+       nb_cli_enqueue_change(vty, "./metric-style", NB_OP_MODIFY, "narrow");
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
+void cli_show_isis_metric_style(struct vty *vty, struct lyd_node *dnode,
+                               bool show_defaults)
+{
+       int metric = yang_dnode_get_enum(dnode, NULL);
+
+       switch (metric) {
+       case ISIS_NARROW_METRIC:
+               vty_out(vty, " metric-style narrow\n");
+               break;
+       case ISIS_WIDE_METRIC:
+               vty_out(vty, " metric-style wide\n");
+               break;
+       case ISIS_TRANSITION_METRIC:
+               vty_out(vty, " metric-style transition\n");
+               break;
+       }
+}
+
 void isis_cli_init(void)
 {
        install_element(CONFIG_NODE, &router_isis_cmd);
@@ -462,6 +508,9 @@ void isis_cli_init(void)
 
        install_element(ISIS_NODE, &set_overload_bit_cmd);
        install_element(ISIS_NODE, &set_attached_bit_cmd);
+
+       install_element(ISIS_NODE, &metric_style_cmd);
+       install_element(ISIS_NODE, &no_metric_style_cmd);
 }
 
 #endif /* ifndef FABRICD */
index cdf71f650b8e85f9c66ec0f9a97995ede1e0ac83..dbb0a1a256bb5df66865c0d470a97bfd71ac6b71 100644 (file)
@@ -37,5 +37,7 @@ void cli_show_isis_attached(struct vty *vty, struct lyd_node *dnode,
                            bool show_defaults);
 void cli_show_isis_overload(struct vty *vty, struct lyd_node *dnode,
                            bool show_defaults);
+void cli_show_isis_metric_style(struct vty *vty, struct lyd_node *dnode,
+                               bool show_defaults);
 
 #endif /* ISISD_ISIS_CLI_H_ */
index 454d94a39584d4b53ed88939bfdda9f6da2a5d0c..a9774d1a31de93b655a327d7e8a25c0213834dd2 100644 (file)
@@ -321,7 +321,18 @@ static int isis_instance_metric_style_modify(enum nb_event event,
                                             const struct lyd_node *dnode,
                                             union nb_resource *resource)
 {
-       /* TODO: implement me. */
+       struct isis_area *area;
+       bool old_metric, new_metric;
+       enum isis_metric_style metric_style = yang_dnode_get_enum(dnode, NULL);
+
+       if (event != NB_EV_APPLY)
+               return NB_OK;
+
+       area = yang_dnode_get_entry(dnode, true);
+       old_metric = (metric_style == ISIS_WIDE_METRIC) ? false : true;
+       new_metric = (metric_style == ISIS_NARROW_METRIC) ? false : true;
+       isis_area_metricstyle_set(area, old_metric, new_metric);
+
        return NB_OK;
 }
 
@@ -1771,6 +1782,7 @@ const struct frr_yang_module_info frr_isisd_info = {
                {
                        .xpath = "/frr-isisd:isis/instance/metric-style",
                        .cbs.modify = isis_instance_metric_style_modify,
+                       .cbs.cli_show = cli_show_isis_metric_style,
                },
                {
                        .xpath = "/frr-isisd:isis/instance/purge-originator",
index 567441f185c359ab9fc0c7f9115b94e6167badcd..ce5c1dfadf09863feea7e826e49160ec1a741bcd 100644 (file)
@@ -465,98 +465,6 @@ DEFUN (no_psnp_interval_level,
        return CMD_SUCCESS;
 }
 
-static int validate_metric_style_narrow(struct vty *vty, struct isis_area *area)
-{
-       struct isis_circuit *circuit;
-       struct listnode *node;
-
-       if (!vty)
-               return CMD_WARNING_CONFIG_FAILED;
-
-       if (!area) {
-               vty_out(vty, "ISIS area is invalid\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit)) {
-               if ((area->is_type & IS_LEVEL_1)
-                   && (circuit->is_type & IS_LEVEL_1)
-                   && (circuit->te_metric[0] > MAX_NARROW_LINK_METRIC)) {
-                       vty_out(vty, "ISIS circuit %s metric is invalid\n",
-                               circuit->interface->name);
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-               if ((area->is_type & IS_LEVEL_2)
-                   && (circuit->is_type & IS_LEVEL_2)
-                   && (circuit->te_metric[1] > MAX_NARROW_LINK_METRIC)) {
-                       vty_out(vty, "ISIS circuit %s metric is invalid\n",
-                               circuit->interface->name);
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-       }
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (metric_style,
-       metric_style_cmd,
-       "metric-style <narrow|transition|wide>",
-       "Use old-style (ISO 10589) or new-style packet formats\n"
-       "Use old style of TLVs with narrow metric\n"
-       "Send and accept both styles of TLVs during transition\n"
-       "Use new style of TLVs to carry wider metric\n")
-{
-       int idx_metric_style = 1;
-       VTY_DECLVAR_CONTEXT(isis_area, area);
-       int ret;
-
-       if (strncmp(argv[idx_metric_style]->arg, "w", 1) == 0) {
-               isis_area_metricstyle_set(area, false, true);
-               return CMD_SUCCESS;
-       }
-
-       if (area_is_mt(area)) {
-               vty_out(vty,
-                       "Narrow metrics cannot be used while multi topology IS-IS is active\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       ret = validate_metric_style_narrow(vty, area);
-       if (ret != CMD_SUCCESS)
-               return ret;
-
-       if (strncmp(argv[idx_metric_style]->arg, "t", 1) == 0)
-               isis_area_metricstyle_set(area, true, true);
-       else if (strncmp(argv[idx_metric_style]->arg, "n", 1) == 0)
-               isis_area_metricstyle_set(area, true, false);
-       return CMD_SUCCESS;
-
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_metric_style,
-       no_metric_style_cmd,
-       "no metric-style",
-       NO_STR
-       "Use old-style (ISO 10589) or new-style packet formats\n")
-{
-       VTY_DECLVAR_CONTEXT(isis_area, area);
-       int ret;
-
-       if (area_is_mt(area)) {
-               vty_out(vty,
-                       "Narrow metrics cannot be used while multi topology IS-IS is active\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       ret = validate_metric_style_narrow(vty, area);
-       if (ret != CMD_SUCCESS)
-               return ret;
-
-       isis_area_metricstyle_set(area, true, false);
-       return CMD_SUCCESS;
-}
-
 DEFUN (lsp_gen_interval_level,
        lsp_gen_interval_level_cmd,
        "lsp-gen-interval <level-1|level-2> (1-120)",
@@ -731,9 +639,6 @@ void isis_vty_daemon_init(void)
        install_element(INTERFACE_NODE, &psnp_interval_level_cmd);
        install_element(INTERFACE_NODE, &no_psnp_interval_level_cmd);
 
-       install_element(ROUTER_NODE, &metric_style_cmd);
-       install_element(ROUTER_NODE, &no_metric_style_cmd);
-
        install_element(ROUTER_NODE, &lsp_gen_interval_level_cmd);
        install_element(ROUTER_NODE, &no_lsp_gen_interval_level_cmd);
 
index 084cbf16c2520f903517a6c6d4a0cfd4b42d453b..ee4f7e664db41ddd1eb06268fe6f02f32cf7e2db 100644 (file)
@@ -1746,11 +1746,9 @@ void isis_area_is_type_set(struct isis_area *area, int is_type)
 void isis_area_metricstyle_set(struct isis_area *area, bool old_metric,
                               bool new_metric)
 {
-       if (area->oldmetric != old_metric || area->newmetric != new_metric) {
-               area->oldmetric = old_metric;
-               area->newmetric = new_metric;
-               lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
-       }
+       area->oldmetric = old_metric;
+       area->newmetric = new_metric;
+       lsp_regenerate_schedule(area, IS_LEVEL_1 | IS_LEVEL_2, 1);
 }
 
 void isis_area_overload_bit_set(struct isis_area *area, bool overload_bit)
index 8447a309b2a89ce58fdd80066acd6702f14c69c7..ff09db8ea243105fa5005dd52d240d828562959f 100644 (file)
@@ -98,6 +98,13 @@ struct lsp_refresh_arg {
        int level;
 };
 
+/* for yang configuration */
+enum isis_metric_style {
+       ISIS_NARROW_METRIC = 0,
+       ISIS_WIDE_METRIC,
+       ISIS_TRANSITION_METRIC,
+};
+
 struct isis_area {
        struct isis *isis;                             /* back pointer */
        dict_t *lspdb[ISIS_LEVELS];                    /* link-state dbs */