From 282ae30c4ae3aac7205b456efefbf4b374841a1b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 9 May 2018 01:34:59 -0300 Subject: [PATCH] ripd: retrofit the 'default-metric' command to the new northbound model Trivial conversion. rip->default_metric was converted to an uint8_t to match the way it's defined in the YANG module. Signed-off-by: Renato Westphal --- ripd/rip_cli.c | 47 +++++++++++++++++++++++++++++++++++++++++++ ripd/rip_cli.h | 2 ++ ripd/rip_northbound.c | 8 +++++++- ripd/ripd.c | 38 +--------------------------------- ripd/ripd.h | 5 +---- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c index 9193c089a8..d374ea64f0 100644 --- a/ripd/rip_cli.c +++ b/ripd/rip_cli.c @@ -145,6 +145,51 @@ void cli_show_rip_default_information_originate(struct vty *vty, vty_out(vty, " default-information originate\n"); } +/* + * XPath: /frr-ripd:ripd/instance/default-metric + */ +DEFPY (rip_default_metric, + rip_default_metric_cmd, + "default-metric (1-16)", + "Set a metric of redistribute routes\n" + "Default metric\n") +{ + struct cli_config_change changes[] = { + { + .xpath = "./default-metric", + .operation = NB_OP_MODIFY, + .value = default_metric_str, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); +} + +DEFPY (no_rip_default_metric, + no_rip_default_metric_cmd, + "no default-metric [(1-16)]", + NO_STR + "Set a metric of redistribute routes\n" + "Default metric\n") +{ + struct cli_config_change changes[] = { + { + .xpath = "./default-metric", + .operation = NB_OP_MODIFY, + .value = NULL, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); +} + +void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " default-metric %s\n", + yang_dnode_get_string(dnode, NULL)); +} + void rip_cli_init(void) { install_element(CONFIG_NODE, &router_rip_cmd); @@ -152,4 +197,6 @@ void rip_cli_init(void) install_element(RIP_NODE, &rip_allow_ecmp_cmd); install_element(RIP_NODE, &rip_default_information_originate_cmd); + install_element(RIP_NODE, &rip_default_metric_cmd); + install_element(RIP_NODE, &no_rip_default_metric_cmd); } diff --git a/ripd/rip_cli.h b/ripd/rip_cli.h index d63f02dd96..3e60ae8f93 100644 --- a/ripd/rip_cli.h +++ b/ripd/rip_cli.h @@ -28,5 +28,7 @@ extern void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode, extern void cli_show_rip_default_information_originate(struct vty *vty, struct lyd_node *dnode, bool show_defaults); +extern void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode, + bool show_defaults); #endif /* _FRR_RIP_CLI_H_ */ diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index 884e2a83d1..67719cb254 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -131,7 +131,12 @@ static int ripd_instance_default_metric_modify(enum nb_event event, const struct lyd_node *dnode, union nb_resource *resource) { - /* TODO: implement me. */ + if (event != NB_EV_APPLY) + return NB_OK; + + rip->default_metric = yang_dnode_get_uint8(dnode, NULL); + /* rip_update_default_metric (); */ + return NB_OK; } @@ -759,6 +764,7 @@ const struct frr_yang_module_info frr_ripd_info = { { .xpath = "/frr-ripd:ripd/instance/default-metric", .cbs.modify = ripd_instance_default_metric_modify, + .cbs.cli_show = cli_show_rip_default_metric, }, { .xpath = "/frr-ripd:ripd/instance/distance/default", diff --git a/ripd/ripd.c b/ripd/ripd.c index 7dfabc623d..1ae1d29eb4 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2926,35 +2926,6 @@ rip_update_default_metric (void) } #endif -DEFUN (rip_default_metric, - rip_default_metric_cmd, - "default-metric (1-16)", - "Set a metric of redistribute routes\n" - "Default metric\n") -{ - int idx_number = 1; - if (rip) { - rip->default_metric = atoi(argv[idx_number]->arg); - /* rip_update_default_metric (); */ - } - return CMD_SUCCESS; -} - -DEFUN (no_rip_default_metric, - no_rip_default_metric_cmd, - "no default-metric [(1-16)]", - NO_STR - "Set a metric of redistribute routes\n" - "Default metric\n") -{ - if (rip) { - rip->default_metric = RIP_DEFAULT_METRIC_DEFAULT; - /* rip_update_default_metric (); */ - } - return CMD_SUCCESS; -} - - DEFUN (rip_timers, rip_timers_cmd, "timers basic (5-2147483647) (5-2147483647) (5-2147483647)", @@ -3500,7 +3471,7 @@ DEFUN (show_ip_rip_status, config_show_distribute(vty); /* Default metric information. */ - vty_out(vty, " Default redistribution metric is %d\n", + vty_out(vty, " Default redistribution metric is %u\n", rip->default_metric); /* Redistribute information. */ @@ -3614,11 +3585,6 @@ static int config_write_rip(struct vty *vty) /* RIP enabled network and interface configuration. */ config_write_rip_network(vty, 1); - /* RIP default metric configuration */ - if (rip->default_metric != RIP_DEFAULT_METRIC_DEFAULT) - vty_out(vty, " default-metric %d\n", - rip->default_metric); - /* Distribute configuration. */ write += config_write_distribute(vty); @@ -3919,8 +3885,6 @@ void rip_init(void) install_default(RIP_NODE); install_element(RIP_NODE, &rip_version_cmd); install_element(RIP_NODE, &no_rip_version_cmd); - install_element(RIP_NODE, &rip_default_metric_cmd); - install_element(RIP_NODE, &no_rip_default_metric_cmd); install_element(RIP_NODE, &rip_timers_cmd); install_element(RIP_NODE, &no_rip_timers_cmd); install_element(RIP_NODE, &rip_route_cmd); diff --git a/ripd/ripd.h b/ripd/ripd.h index c2e39f1a71..1ecedf3680 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -140,7 +140,7 @@ struct rip { unsigned long garbage_time; /* RIP default metric. */ - int default_metric; + uint8_t default_metric; /* RIP default distance. */ uint8_t distance; @@ -346,9 +346,6 @@ struct rip_md5_data { /* N.B. stuff will break if (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ -/* Default value for "default-metric" command. */ -#define RIP_DEFAULT_METRIC_DEFAULT 1 - /* RIP event. */ enum rip_event { RIP_READ, -- 2.39.5