ospf6_asbr_status_update(ospf6, ospf6->redistribute);
}
-DEFUN (ospf6_redistribute,
+DEFPY (ospf6_redistribute,
ospf6_redistribute_cmd,
- "redistribute " FRR_REDIST_STR_OSPF6D,
- "Redistribute\n"
- FRR_REDIST_HELP_STR_OSPF6D)
-{
- int type;
- struct ospf6_redist *red;
-
- VTY_DECLVAR_CONTEXT(ospf6, ospf6);
-
- char *proto = argv[argc - 1]->text;
-
- type = proto_redistnum(AFI_IP6, proto);
- if (type < 0)
- return CMD_WARNING_CONFIG_FAILED;
-
- red = ospf6_redist_lookup(ospf6, type, 0);
- if (!red) {
- ospf6_redist_add(ospf6, type, 0);
- } else {
- /* To check, if user is providing same config */
- if (ROUTEMAP_NAME(red) == NULL)
- return CMD_SUCCESS;
-
- ospf6_asbr_redistribute_unset(ospf6, red, type);
- }
-
- ospf6_asbr_redistribute_set(ospf6, type);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (ospf6_redistribute_routemap,
- ospf6_redistribute_routemap_cmd,
- "redistribute " FRR_REDIST_STR_OSPF6D " route-map WORD",
+ "redistribute " FRR_REDIST_STR_OSPF6D "[{metric (0-16777214)|metric-type (1-2)$metric_type|route-map WORD$rmap_str}]",
"Redistribute\n"
FRR_REDIST_HELP_STR_OSPF6D
+ "Metric for redistributed routes\n"
+ "OSPF default metric\n"
+ "OSPF exterior metric type for redistributed routes\n"
+ "Set OSPF External Type 1/2 metrics\n"
"Route map reference\n"
"Route map name\n")
{
- int idx_protocol = 1;
- int idx_word = 3;
int type;
struct ospf6_redist *red;
+ int idx_protocol = 1;
+ char *proto = argv[idx_protocol]->text;
VTY_DECLVAR_CONTEXT(ospf6, ospf6);
- char *proto = argv[idx_protocol]->text;
type = proto_redistnum(AFI_IP6, proto);
if (type < 0)
return CMD_WARNING_CONFIG_FAILED;
+ if (!metric_str)
+ metric = -1;
+ if (!metric_type_str)
+ metric_type = -1;
+
red = ospf6_redist_lookup(ospf6, type, 0);
if (!red) {
red = ospf6_redist_add(ospf6, type, 0);
} else {
- /* To check, if user is providing same route map */
- if ((ROUTEMAP_NAME(red) != NULL)
- && (strcmp(argv[idx_word]->arg, ROUTEMAP_NAME(red)) == 0))
+ /* Check if nothing has changed. */
+ if (red->dmetric.value == metric
+ && red->dmetric.type == metric_type
+ && ((!ROUTEMAP_NAME(red) && !rmap_str)
+ || (ROUTEMAP_NAME(red) && rmap_str
+ && strmatch(ROUTEMAP_NAME(red), rmap_str))))
return CMD_SUCCESS;
ospf6_asbr_redistribute_unset(ospf6, red, type);
}
- ospf6_asbr_routemap_set(red, argv[idx_word]->arg);
+ red->dmetric.value = metric;
+ red->dmetric.type = metric_type;
+ if (rmap_str)
+ ospf6_asbr_routemap_set(red, rmap_str);
+ else
+ ospf6_asbr_routemap_unset(red);
ospf6_asbr_redistribute_set(ospf6, type);
return CMD_SUCCESS;
DEFUN (no_ospf6_redistribute,
no_ospf6_redistribute_cmd,
- "no redistribute " FRR_REDIST_STR_OSPF6D " [route-map WORD]",
+ "no redistribute " FRR_REDIST_STR_OSPF6D "[{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
NO_STR
"Redistribute\n"
FRR_REDIST_HELP_STR_OSPF6D
+ "Metric for redistributed routes\n"
+ "OSPF default metric\n"
+ "OSPF exterior metric type for redistributed routes\n"
+ "Set OSPF External Type 1/2 metrics\n"
"Route map reference\n"
"Route map name\n")
{
- int idx_protocol = 2;
int type;
struct ospf6_redist *red;
+ int idx_protocol = 2;
+ char *proto = argv[idx_protocol]->text;
VTY_DECLVAR_CONTEXT(ospf6, ospf6);
- char *proto = argv[idx_protocol]->text;
type = proto_redistnum(AFI_IP6, proto);
if (type < 0)
return CMD_WARNING_CONFIG_FAILED;
if (type == ZEBRA_ROUTE_OSPF6)
continue;
+ vty_out(vty, " redistribute %s", ZROUTE_NAME(type));
+ if (red->dmetric.value >= 0)
+ vty_out(vty, " metric %d", red->dmetric.value);
+ if (red->dmetric.type != DEFAULT_METRIC_TYPE)
+ vty_out(vty, " metric-type 1");
if (ROUTEMAP_NAME(red))
- vty_out(vty, " redistribute %s route-map %s\n",
- ZROUTE_NAME(type), ROUTEMAP_NAME(red));
- else
- vty_out(vty, " redistribute %s\n", ZROUTE_NAME(type));
+ vty_out(vty, " route-map %s", ROUTEMAP_NAME(red));
+ vty_out(vty, "\n");
}
return 0;
install_element(OSPF6_NODE,
&no_ospf6_default_information_originate_cmd);
install_element(OSPF6_NODE, &ospf6_redistribute_cmd);
- install_element(OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
install_element(OSPF6_NODE, &no_ospf6_redistribute_cmd);
}
assert result is None, assertmsg
-def expect_ospfv3_routes(router, routes, wait=5):
+def expect_ospfv3_routes(router, routes, wait=5, detail=False):
"Run command `ipv6 ospf6 route` and expect route with type."
tgen = get_topogen()
+ if detail == False:
+ cmd = "show ipv6 ospf6 route json"
+ else:
+ cmd = "show ipv6 ospf6 route detail json"
+
logger.info("waiting OSPFv3 router '{}' route".format(router))
test_func = partial(
topotest.router_json_cmp,
tgen.gears[router],
- "show ipv6 ospf6 route json",
+ cmd,
{"routes": routes}
)
_, result = topotest.run_and_expect(test_func, None, count=wait, wait=1)
expect_route("r1", "::/0", metric + 10)
+def test_redistribute_metrics():
+ """
+ Test that the configured metrics are honored when a static route is
+ redistributed.
+ """
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ # Add new static route on r3.
+ config = """
+ configure terminal
+ ipv6 route 2001:db8:500::/64 Null0
+ """
+ tgen.gears["r3"].vtysh_cmd(config)
+
+ route = {
+ "2001:db8:500::/64": {
+ "metricType":2,
+ "metricCost":10,
+ }
+ }
+ logger.info("Expecting AS-external route 2001:db8:500::/64 to show up with default metrics")
+ expect_ospfv3_routes("r2", route, wait=30, detail=True)
+
+ # Change the metric of redistributed routes of the static type on r3.
+ config = """
+ configure terminal
+ router ospf6
+ redistribute static metric 50 metric-type 1
+ """
+ tgen.gears["r3"].vtysh_cmd(config)
+
+ # Check if r3 reinstalled 2001:db8:500::/64 using the new metric type and value.
+ route = {
+ "2001:db8:500::/64": {
+ "metricType":1,
+ "metricCost":60,
+ }
+ }
+ logger.info("Expecting AS-external route 2001:db8:500::/64 to show up with updated metric type and value")
+ expect_ospfv3_routes("r2", route, wait=30, detail=True)
+
+
+
def test_nssa_lsa_type7():
"""
Test that static route gets announced as external route when redistributed