From 9302fbb69303b47fbb6f8d3f8ad624494ab2cfed Mon Sep 17 00:00:00 2001 From: Emanuele Di Pascale Date: Thu, 15 Nov 2018 12:11:19 +0100 Subject: [PATCH] isisd: retrofit the 'isis circuit-type' command Signed-off-by: Emanuele Di Pascale --- isisd/isis_cli.c | 98 +++++++++++++++++++++++++++++++++++++++++ isisd/isis_cli.h | 2 + isisd/isis_northbound.c | 1 + isisd/isis_vty_isisd.c | 63 -------------------------- 4 files changed, 101 insertions(+), 63 deletions(-) diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c index 809e17d477..1102005d8c 100644 --- a/isisd/isis_cli.c +++ b/isisd/isis_cli.c @@ -1704,6 +1704,101 @@ void cli_show_ip_isis_mt_ipv6_dstsrc(struct vty *vty, struct lyd_node *dnode, vty_out(vty, " isis topology ipv6-dstsrc\n"); } +/* + * XPath: /frr-interface:lib/interface/frr-isisd:isis/circuit-type + */ +DEFPY(isis_circuit_type, isis_circuit_type_cmd, + "isis circuit-type $type", + "IS-IS routing protocol\n" + "Configure circuit type for interface\n" + "Level-1 only adjacencies are formed\n" + "Level-1-2 adjacencies are formed\n" + "Level-2 only adjacencies are formed\n") +{ + nb_cli_enqueue_change( + vty, "./frr-isisd:isis/circuit-type", NB_OP_MODIFY, + strmatch(type, "level-2-only") ? "level-2" : type); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY(no_isis_circuit_type, no_isis_circuit_type_cmd, + "no isis circuit-type [level-1|level-1-2|level-2-only]", + NO_STR + "IS-IS routing protocol\n" + "Configure circuit type for interface\n" + "Level-1 only adjacencies are formed\n" + "Level-1-2 adjacencies are formed\n" + "Level-2 only adjacencies are formed\n") +{ + const struct lyd_node *dnode; + struct interface *ifp; + struct isis_circuit *circuit; + int is_type; + const char *circ_type; + + /* + * Default value depends on whether the circuit is part of an area, + * and the is-type of the area if there is one. So we need to do this + * here. + */ + dnode = yang_dnode_get(running_config->dnode, VTY_CURR_XPATH); + ifp = yang_dnode_get_entry(dnode, false); + if (!ifp) + goto def_val; + + circuit = circuit_scan_by_ifp(ifp); + if (!circuit) + goto def_val; + + if (circuit->state == C_STATE_UP) + is_type = circuit->area->is_type; + else + goto def_val; + + switch (is_type) { + case IS_LEVEL_1: + circ_type = "level-1"; + break; + case IS_LEVEL_2: + circ_type = "level-2"; + break; + case IS_LEVEL_1_AND_2: + circ_type = "level-1-2"; + break; + default: + return CMD_ERR_NO_MATCH; + } + nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type", + NB_OP_MODIFY, circ_type); + + return nb_cli_apply_changes(vty, NULL); + +def_val: + nb_cli_enqueue_change(vty, "./frr-isisd:isis/circuit-type", + NB_OP_MODIFY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_ip_isis_circ_type(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + int level = yang_dnode_get_enum(dnode, NULL); + + switch (level) { + case IS_LEVEL_1: + vty_out(vty, " isis circuit-type level-1\n"); + break; + case IS_LEVEL_2: + vty_out(vty, " isis circuit-type level-2-only\n"); + break; + case IS_LEVEL_1_AND_2: + vty_out(vty, " isis circuit-type level-1-2\n"); + break; + } +} + void isis_cli_init(void) { install_element(CONFIG_NODE, &router_isis_cmd); @@ -1781,6 +1876,9 @@ void isis_cli_init(void) install_element(INTERFACE_NODE, &no_psnp_interval_cmd); install_element(INTERFACE_NODE, &circuit_topology_cmd); + + install_element(INTERFACE_NODE, &isis_circuit_type_cmd); + install_element(INTERFACE_NODE, &no_isis_circuit_type_cmd); } #endif /* ifndef FABRICD */ diff --git a/isisd/isis_cli.h b/isisd/isis_cli.h index 6b529e71cb..6001f8bcae 100644 --- a/isisd/isis_cli.h +++ b/isisd/isis_cli.h @@ -113,5 +113,7 @@ void cli_show_ip_isis_mt_ipv6_mgmt(struct vty *vty, struct lyd_node *dnode, bool show_defaults); void cli_show_ip_isis_mt_ipv6_dstsrc(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +void cli_show_ip_isis_circ_type(struct vty *vty, struct lyd_node *dnode, + bool show_defaults); #endif /* ISISD_ISIS_CLI_H_ */ diff --git a/isisd/isis_northbound.c b/isisd/isis_northbound.c index 150b5755a5..562c77b9d0 100644 --- a/isisd/isis_northbound.c +++ b/isisd/isis_northbound.c @@ -2722,6 +2722,7 @@ const struct frr_yang_module_info frr_isisd_info = { { .xpath = "/frr-interface:lib/interface/frr-isisd:isis/circuit-type", .cbs.modify = lib_interface_isis_circuit_type_modify, + .cbs.cli_show = cli_show_ip_isis_circ_type, }, { .xpath = "/frr-interface:lib/interface/frr-isisd:isis/ipv4-routing", diff --git a/isisd/isis_vty_isisd.c b/isisd/isis_vty_isisd.c index 198e72964e..d114085f88 100644 --- a/isisd/isis_vty_isisd.c +++ b/isisd/isis_vty_isisd.c @@ -43,66 +43,6 @@ static int level_for_arg(const char *arg) return IS_LEVEL_2; } -DEFUN (isis_circuit_type, - isis_circuit_type_cmd, - "isis circuit-type ", - "IS-IS routing protocol\n" - "Configure circuit type for interface\n" - "Level-1 only adjacencies are formed\n" - "Level-1-2 adjacencies are formed\n" - "Level-2 only adjacencies are formed\n") -{ - int idx_level = 2; - int is_type; - struct isis_circuit *circuit = isis_circuit_lookup(vty); - if (!circuit) - return CMD_ERR_NO_MATCH; - - is_type = string2circuit_t(argv[idx_level]->arg); - if (!is_type) { - vty_out(vty, "Unknown circuit-type \n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (circuit->state == C_STATE_UP - && circuit->area->is_type != IS_LEVEL_1_AND_2 - && circuit->area->is_type != is_type) { - vty_out(vty, "Invalid circuit level for area %s.\n", - circuit->area->area_tag); - return CMD_WARNING_CONFIG_FAILED; - } - isis_circuit_is_type_set(circuit, is_type); - - return CMD_SUCCESS; -} - -DEFUN (no_isis_circuit_type, - no_isis_circuit_type_cmd, - "no isis circuit-type ", - NO_STR - "IS-IS routing protocol\n" - "Configure circuit type for interface\n" - "Level-1 only adjacencies are formed\n" - "Level-1-2 adjacencies are formed\n" - "Level-2 only adjacencies are formed\n") -{ - int is_type; - struct isis_circuit *circuit = isis_circuit_lookup(vty); - if (!circuit) - return CMD_ERR_NO_MATCH; - - /* - * Set the circuits level to its default value - */ - if (circuit->state == C_STATE_UP) - is_type = circuit->area->is_type; - else - is_type = IS_LEVEL_1_AND_2; - isis_circuit_is_type_set(circuit, is_type); - - return CMD_SUCCESS; -} - DEFUN (isis_network, isis_network_cmd, "isis network point-to-point", @@ -221,9 +161,6 @@ DEFUN (no_isis_priority_level, void isis_vty_daemon_init(void) { - install_element(INTERFACE_NODE, &isis_circuit_type_cmd); - install_element(INTERFACE_NODE, &no_isis_circuit_type_cmd); - install_element(INTERFACE_NODE, &isis_network_cmd); install_element(INTERFACE_NODE, &no_isis_network_cmd); -- 2.39.5