forked from Mirror/frr
lib: fix the "set metric" route-map command
The "set metric" command wasn't processing metric additions and subtractions (using + and -) correctly. Fix those problems. Also, remove the "+metric" and "-metric" options since they don't work and don't make any sense (they could be interpreted as unitary increments/decrements but that was never supported). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
5ceb842f45
commit
add39cde9d
|
@ -719,15 +719,13 @@ DEFPY_YANG(
|
||||||
|
|
||||||
DEFPY_YANG(
|
DEFPY_YANG(
|
||||||
set_metric, set_metric_cmd,
|
set_metric, set_metric_cmd,
|
||||||
"set metric <(0-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt|+metric$ametric|-metric$smetric>",
|
"set metric <(-4294967295-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt>",
|
||||||
SET_STR
|
SET_STR
|
||||||
"Metric value for destination routing protocol\n"
|
"Metric value for destination routing protocol\n"
|
||||||
"Metric value\n"
|
"Metric value (use +/- for additions or subtractions)\n"
|
||||||
"Assign round trip time\n"
|
"Assign round trip time\n"
|
||||||
"Add round trip time\n"
|
"Add round trip time\n"
|
||||||
"Subtract round trip time\n"
|
"Subtract round trip time\n")
|
||||||
"Add metric\n"
|
|
||||||
"Subtract metric\n")
|
|
||||||
{
|
{
|
||||||
const char *xpath = "./set-action[action='metric']";
|
const char *xpath = "./set-action[action='metric']";
|
||||||
char xpath_value[XPATH_MAXLEN];
|
char xpath_value[XPATH_MAXLEN];
|
||||||
|
@ -746,17 +744,17 @@ DEFPY_YANG(
|
||||||
snprintf(xpath_value, sizeof(xpath_value),
|
snprintf(xpath_value, sizeof(xpath_value),
|
||||||
"%s/subtract-round-trip-time", xpath);
|
"%s/subtract-round-trip-time", xpath);
|
||||||
snprintf(value, sizeof(value), "true");
|
snprintf(value, sizeof(value), "true");
|
||||||
} else if (ametric) {
|
} else if (metric_str && metric_str[0] == '+') {
|
||||||
snprintf(xpath_value, sizeof(xpath_value), "%s/add-metric",
|
snprintf(xpath_value, sizeof(xpath_value), "%s/add-metric",
|
||||||
xpath);
|
xpath);
|
||||||
snprintf(value, sizeof(value), "true");
|
snprintf(value, sizeof(value), "%s", ++metric_str);
|
||||||
} else if (smetric) {
|
} else if (metric_str && metric_str[0] == '-') {
|
||||||
snprintf(xpath_value, sizeof(xpath_value), "%s/subtract-metric",
|
snprintf(xpath_value, sizeof(xpath_value), "%s/subtract-metric",
|
||||||
xpath);
|
xpath);
|
||||||
snprintf(value, sizeof(value), "true");
|
snprintf(value, sizeof(value), "%s", ++metric_str);
|
||||||
} else {
|
} else {
|
||||||
snprintf(xpath_value, sizeof(xpath_value), "%s/value", xpath);
|
snprintf(xpath_value, sizeof(xpath_value), "%s/value", xpath);
|
||||||
snprintf(value, sizeof(value), "%lu", metric);
|
snprintf(value, sizeof(value), "%s", metric_str);
|
||||||
}
|
}
|
||||||
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value);
|
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value);
|
||||||
|
|
||||||
|
@ -831,9 +829,12 @@ void route_map_action_show(struct vty *vty, struct lyd_node *dnode,
|
||||||
} else if (yang_dnode_get(dnode, "./subtract-round-trip-time")) {
|
} else if (yang_dnode_get(dnode, "./subtract-round-trip-time")) {
|
||||||
vty_out(vty, " set metric -rtt\n");
|
vty_out(vty, " set metric -rtt\n");
|
||||||
} else if (yang_dnode_get(dnode, "./add-metric")) {
|
} else if (yang_dnode_get(dnode, "./add-metric")) {
|
||||||
vty_out(vty, " set metric +metric\n");
|
vty_out(vty, " set metric +%s\n",
|
||||||
|
yang_dnode_get_string(dnode, "./add-metric"));
|
||||||
} else if (yang_dnode_get(dnode, "./subtract-metric")) {
|
} else if (yang_dnode_get(dnode, "./subtract-metric")) {
|
||||||
vty_out(vty, " set metric -metric\n");
|
vty_out(vty, " set metric -%s\n",
|
||||||
|
yang_dnode_get_string(dnode,
|
||||||
|
"./subtract-metric"));
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, " set metric %s\n",
|
vty_out(vty, " set metric %s\n",
|
||||||
yang_dnode_get_string(dnode, "./value"));
|
yang_dnode_get_string(dnode, "./value"));
|
||||||
|
|
|
@ -983,8 +983,19 @@ lib_route_map_entry_set_action_value_destroy(struct nb_cb_destroy_args *args)
|
||||||
static int
|
static int
|
||||||
lib_route_map_entry_set_action_add_metric_modify(struct nb_cb_modify_args *args)
|
lib_route_map_entry_set_action_add_metric_modify(struct nb_cb_modify_args *args)
|
||||||
{
|
{
|
||||||
|
char metric_str[16];
|
||||||
|
|
||||||
|
if (args->event == NB_EV_VALIDATE
|
||||||
|
&& yang_dnode_get_uint32(args->dnode, NULL) == 0) {
|
||||||
|
snprintf(args->errmsg, args->errmsg_len,
|
||||||
|
"Can't add zero to metric");
|
||||||
|
return NB_ERR_VALIDATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(metric_str, sizeof(metric_str), "+%s",
|
||||||
|
yang_dnode_get_string(args->dnode, NULL));
|
||||||
return set_action_modify(args->event, args->dnode, args->resource,
|
return set_action_modify(args->event, args->dnode, args->resource,
|
||||||
"+metric");
|
metric_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lib_route_map_entry_set_action_add_metric_destroy(
|
static int lib_route_map_entry_set_action_add_metric_destroy(
|
||||||
|
@ -999,8 +1010,19 @@ static int lib_route_map_entry_set_action_add_metric_destroy(
|
||||||
static int lib_route_map_entry_set_action_subtract_metric_modify(
|
static int lib_route_map_entry_set_action_subtract_metric_modify(
|
||||||
struct nb_cb_modify_args *args)
|
struct nb_cb_modify_args *args)
|
||||||
{
|
{
|
||||||
|
char metric_str[16];
|
||||||
|
|
||||||
|
if (args->event == NB_EV_VALIDATE
|
||||||
|
&& yang_dnode_get_uint32(args->dnode, NULL) == 0) {
|
||||||
|
snprintf(args->errmsg, args->errmsg_len,
|
||||||
|
"Can't subtract zero from metric");
|
||||||
|
return NB_ERR_VALIDATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(metric_str, sizeof(metric_str), "-%s",
|
||||||
|
yang_dnode_get_string(args->dnode, NULL));
|
||||||
return set_action_modify(args->event, args->dnode, args->resource,
|
return set_action_modify(args->event, args->dnode, args->resource,
|
||||||
"-metric");
|
metric_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lib_route_map_entry_set_action_subtract_metric_destroy(
|
static int lib_route_map_entry_set_action_subtract_metric_destroy(
|
||||||
|
|
|
@ -373,15 +373,19 @@ module frr-route-map {
|
||||||
|
|
||||||
case add-metric {
|
case add-metric {
|
||||||
leaf add-metric {
|
leaf add-metric {
|
||||||
description "Add unit to metric.";
|
description "Add value to metric.";
|
||||||
type boolean;
|
type uint32 {
|
||||||
|
range "0..4294967295";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case subtract-metric {
|
case subtract-metric {
|
||||||
leaf subtract-metric {
|
leaf subtract-metric {
|
||||||
description "Subtract unit from metric.";
|
description "Subtract value from metric.";
|
||||||
type boolean;
|
type uint32 {
|
||||||
|
range "0..4294967295";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue