mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 07:48:07 +00:00
ospfd: refactor the "area nssa" command using DEFPY
Combine all variation of the "area nssa" command into a single DEFPY to improve code maintainability. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
44e90d5521
commit
e85194f572
204
ospfd/ospf_vty.c
204
ospfd/ospf_vty.c
@ -1433,15 +1433,29 @@ DEFUN (no_ospf_area_stub_no_summary,
|
|||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
|
DEFPY (ospf_area_nssa,
|
||||||
struct cmd_token **argv, int cfg_nosum,
|
ospf_area_nssa_cmd,
|
||||||
int nosum)
|
"area <A.B.C.D|(0-4294967295)>$area_str nssa\
|
||||||
|
[{\
|
||||||
|
<translate-candidate|translate-never|translate-always>$translator_role\
|
||||||
|
|no-summary$no_summary\
|
||||||
|
|suppress-fa$suppress_fa\
|
||||||
|
}]",
|
||||||
|
"OSPF area parameters\n"
|
||||||
|
"OSPF area ID in IP address format\n"
|
||||||
|
"OSPF area ID as a decimal value\n"
|
||||||
|
"Configure OSPF area as nssa\n"
|
||||||
|
"Configure NSSA-ABR for translate election (default)\n"
|
||||||
|
"Configure NSSA-ABR to never translate\n"
|
||||||
|
"Configure NSSA-ABR to always translate\n"
|
||||||
|
"Do not inject inter-area routes into nssa\n"
|
||||||
|
"Suppress forwarding address\n")
|
||||||
{
|
{
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
||||||
struct in_addr area_id;
|
struct in_addr area_id;
|
||||||
int ret, format;
|
int ret, format;
|
||||||
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg);
|
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
|
||||||
|
|
||||||
ret = ospf_area_nssa_set(ospf, area_id);
|
ret = ospf_area_nssa_set(ospf, area_id);
|
||||||
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
||||||
@ -1452,14 +1466,14 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
|
|||||||
return CMD_WARNING_CONFIG_FAILED;
|
return CMD_WARNING_CONFIG_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 3) {
|
if (translator_role) {
|
||||||
if (strncmp(argv[3]->text, "translate-c", 11) == 0)
|
if (strncmp(translator_role, "translate-c", 11) == 0)
|
||||||
ospf_area_nssa_translator_role_set(
|
ospf_area_nssa_translator_role_set(
|
||||||
ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
|
ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
|
||||||
else if (strncmp(argv[3]->text, "translate-n", 11) == 0)
|
else if (strncmp(translator_role, "translate-n", 11) == 0)
|
||||||
ospf_area_nssa_translator_role_set(
|
ospf_area_nssa_translator_role_set(
|
||||||
ospf, area_id, OSPF_NSSA_ROLE_NEVER);
|
ospf, area_id, OSPF_NSSA_ROLE_NEVER);
|
||||||
else if (strncmp(argv[3]->text, "translate-a", 11) == 0)
|
else if (strncmp(translator_role, "translate-a", 11) == 0)
|
||||||
ospf_area_nssa_translator_role_set(
|
ospf_area_nssa_translator_role_set(
|
||||||
ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
|
ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
|
||||||
} else {
|
} else {
|
||||||
@ -1467,12 +1481,15 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
|
|||||||
OSPF_NSSA_ROLE_CANDIDATE);
|
OSPF_NSSA_ROLE_CANDIDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg_nosum) {
|
if (no_summary)
|
||||||
if (nosum)
|
ospf_area_nssa_no_summary_set(ospf, area_id);
|
||||||
ospf_area_no_summary_set(ospf, area_id);
|
else
|
||||||
else
|
ospf_area_no_summary_unset(ospf, area_id);
|
||||||
ospf_area_no_summary_unset(ospf, area_id);
|
|
||||||
}
|
if (suppress_fa)
|
||||||
|
ospf_area_nssa_suppress_fa_set(ospf, area_id);
|
||||||
|
else
|
||||||
|
ospf_area_nssa_suppress_fa_unset(ospf, area_id);
|
||||||
|
|
||||||
/* Flush the external LSA for the specified area */
|
/* Flush the external LSA for the specified area */
|
||||||
ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
|
ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
|
||||||
@ -1482,141 +1499,14 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
|
|||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFPY (no_ospf_area_nssa,
|
||||||
DEFUN (ospf_area_nssa_translate,
|
|
||||||
ospf_area_nssa_translate_cmd,
|
|
||||||
"area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n"
|
|
||||||
"Configure NSSA-ABR for translate election (default)\n"
|
|
||||||
"Configure NSSA-ABR to never translate\n"
|
|
||||||
"Configure NSSA-ABR to always translate\n")
|
|
||||||
{
|
|
||||||
return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN (ospf_area_nssa,
|
|
||||||
ospf_area_nssa_cmd,
|
|
||||||
"area <A.B.C.D|(0-4294967295)> nssa",
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n")
|
|
||||||
{
|
|
||||||
return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd,
|
|
||||||
"area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n"
|
|
||||||
"Suppress forwarding address\n")
|
|
||||||
{
|
|
||||||
int idx_ipv4_number = 1;
|
|
||||||
struct in_addr area_id;
|
|
||||||
int format;
|
|
||||||
|
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
|
|
||||||
argv[idx_ipv4_number]->arg);
|
|
||||||
|
|
||||||
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
|
||||||
format);
|
|
||||||
ospf_area_nssa_suppress_fa_set(ospf, area_id);
|
|
||||||
|
|
||||||
ospf_schedule_abr_task(ospf);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd,
|
|
||||||
"no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
|
|
||||||
NO_STR
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n"
|
|
||||||
"Suppress forwarding address\n")
|
|
||||||
{
|
|
||||||
int idx_ipv4_number = 2;
|
|
||||||
struct in_addr area_id;
|
|
||||||
int format;
|
|
||||||
|
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
|
||||||
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
|
|
||||||
argv[idx_ipv4_number]->arg);
|
|
||||||
|
|
||||||
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
|
||||||
format);
|
|
||||||
ospf_area_nssa_suppress_fa_unset(ospf, area_id);
|
|
||||||
|
|
||||||
ospf_schedule_abr_task(ospf);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN (ospf_area_nssa_no_summary,
|
|
||||||
ospf_area_nssa_no_summary_cmd,
|
|
||||||
"area <A.B.C.D|(0-4294967295)> nssa no-summary",
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n"
|
|
||||||
"Do not inject inter-area routes into nssa\n")
|
|
||||||
{
|
|
||||||
int idx_ipv4_number = 1;
|
|
||||||
struct in_addr area_id;
|
|
||||||
int format;
|
|
||||||
|
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
|
|
||||||
argv[idx_ipv4_number]->arg);
|
|
||||||
|
|
||||||
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
|
||||||
format);
|
|
||||||
ospf_area_nssa_no_summary_set(ospf, area_id);
|
|
||||||
|
|
||||||
ospf_schedule_abr_task(ospf);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN (no_ospf_area_nssa_no_summary,
|
|
||||||
no_ospf_area_nssa_no_summary_cmd,
|
|
||||||
"no area <A.B.C.D|(0-4294967295)> nssa no-summary",
|
|
||||||
NO_STR
|
|
||||||
"OSPF area parameters\n"
|
|
||||||
"OSPF area ID in IP address format\n"
|
|
||||||
"OSPF area ID as a decimal value\n"
|
|
||||||
"Configure OSPF area as nssa\n"
|
|
||||||
"Do not inject inter-area routes into nssa\n")
|
|
||||||
{
|
|
||||||
int idx_ipv4_number = 2;
|
|
||||||
struct in_addr area_id;
|
|
||||||
int format;
|
|
||||||
|
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
|
||||||
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
|
|
||||||
argv[idx_ipv4_number]->arg);
|
|
||||||
|
|
||||||
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
|
|
||||||
format);
|
|
||||||
ospf_area_no_summary_unset(ospf, area_id);
|
|
||||||
|
|
||||||
ospf_schedule_abr_task(ospf);
|
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFUN (no_ospf_area_nssa,
|
|
||||||
no_ospf_area_nssa_cmd,
|
no_ospf_area_nssa_cmd,
|
||||||
"no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
|
"no area <A.B.C.D|(0-4294967295)>$area_str nssa\
|
||||||
|
[{\
|
||||||
|
<translate-candidate|translate-never|translate-always>\
|
||||||
|
|no-summary\
|
||||||
|
|suppress-fa\
|
||||||
|
}]",
|
||||||
NO_STR
|
NO_STR
|
||||||
"OSPF area parameters\n"
|
"OSPF area parameters\n"
|
||||||
"OSPF area ID in IP address format\n"
|
"OSPF area ID in IP address format\n"
|
||||||
@ -1624,26 +1514,27 @@ DEFUN (no_ospf_area_nssa,
|
|||||||
"Configure OSPF area as nssa\n"
|
"Configure OSPF area as nssa\n"
|
||||||
"Configure NSSA-ABR for translate election (default)\n"
|
"Configure NSSA-ABR for translate election (default)\n"
|
||||||
"Configure NSSA-ABR to never translate\n"
|
"Configure NSSA-ABR to never translate\n"
|
||||||
"Configure NSSA-ABR to always translate\n")
|
"Configure NSSA-ABR to always translate\n"
|
||||||
|
"Do not inject inter-area routes into nssa\n"
|
||||||
|
"Suppress forwarding address\n")
|
||||||
{
|
{
|
||||||
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
|
||||||
int idx_ipv4_number = 2;
|
|
||||||
struct in_addr area_id;
|
struct in_addr area_id;
|
||||||
int format;
|
int format;
|
||||||
|
|
||||||
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
|
VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
|
||||||
argv[idx_ipv4_number]->arg);
|
|
||||||
|
|
||||||
/* Flush the NSSA LSA for the specified area */
|
/* Flush the NSSA LSA for the specified area */
|
||||||
ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
|
ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
|
||||||
ospf_area_nssa_unset(ospf, area_id, argc);
|
ospf_area_no_summary_unset(ospf, area_id);
|
||||||
|
ospf_area_nssa_suppress_fa_unset(ospf, area_id);
|
||||||
|
ospf_area_nssa_unset(ospf, area_id);
|
||||||
|
|
||||||
ospf_schedule_abr_task(ospf);
|
ospf_schedule_abr_task(ospf);
|
||||||
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DEFUN (ospf_area_default_cost,
|
DEFUN (ospf_area_default_cost,
|
||||||
ospf_area_default_cost_cmd,
|
ospf_area_default_cost_cmd,
|
||||||
"area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
|
"area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
|
||||||
@ -13029,11 +12920,6 @@ void ospf_vty_init(void)
|
|||||||
|
|
||||||
/* "area nssa" commands. */
|
/* "area nssa" commands. */
|
||||||
install_element(OSPF_NODE, &ospf_area_nssa_cmd);
|
install_element(OSPF_NODE, &ospf_area_nssa_cmd);
|
||||||
install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
|
|
||||||
install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
|
|
||||||
install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
|
|
||||||
install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
|
|
||||||
install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
|
|
||||||
install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
|
install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
|
||||||
|
|
||||||
install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
|
install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
|
||||||
|
@ -1701,7 +1701,7 @@ int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id, int argc)
|
int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id)
|
||||||
{
|
{
|
||||||
struct ospf_area *area;
|
struct ospf_area *area;
|
||||||
|
|
||||||
@ -1709,22 +1709,14 @@ int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id, int argc)
|
|||||||
if (area == NULL)
|
if (area == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* argc < 5 -> 'no area x nssa' */
|
ospf->anyNSSA--;
|
||||||
if (argc < 5 && area->external_routing == OSPF_AREA_NSSA) {
|
/* set NSSA area defaults */
|
||||||
ospf->anyNSSA--;
|
area->no_summary = 0;
|
||||||
/* set NSSA area defaults */
|
area->suppress_fa = 0;
|
||||||
area->no_summary = 0;
|
area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
|
||||||
area->suppress_fa = 0;
|
area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
|
||||||
area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
|
area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
|
||||||
area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
|
ospf_area_type_set(area, OSPF_AREA_DEFAULT);
|
||||||
area->NSSATranslatorStabilityInterval =
|
|
||||||
OSPF_NSSA_TRANS_STABLE_DEFAULT;
|
|
||||||
ospf_area_type_set(area, OSPF_AREA_DEFAULT);
|
|
||||||
} else {
|
|
||||||
ospf_area_nssa_translator_role_set(ospf, area_id,
|
|
||||||
OSPF_NSSA_ROLE_CANDIDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ospf_area_check_free(ospf, area_id);
|
ospf_area_check_free(ospf, area_id);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -697,8 +697,7 @@ extern int ospf_area_no_summary_set(struct ospf *ospf, struct in_addr area_id);
|
|||||||
extern int ospf_area_no_summary_unset(struct ospf *ospf,
|
extern int ospf_area_no_summary_unset(struct ospf *ospf,
|
||||||
struct in_addr area_id);
|
struct in_addr area_id);
|
||||||
extern int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id);
|
extern int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id);
|
||||||
extern int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id,
|
extern int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id);
|
||||||
int argc);
|
|
||||||
extern int ospf_area_nssa_suppress_fa_set(struct ospf *ospf,
|
extern int ospf_area_nssa_suppress_fa_set(struct ospf *ospf,
|
||||||
struct in_addr area_id);
|
struct in_addr area_id);
|
||||||
extern int ospf_area_nssa_suppress_fa_unset(struct ospf *ospf,
|
extern int ospf_area_nssa_suppress_fa_unset(struct ospf *ospf,
|
||||||
|
@ -111,9 +111,7 @@ def ospf_unconfigure_suppress_fa(router_name, area):
|
|||||||
|
|
||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
router = tgen.gears[router_name]
|
router = tgen.gears[router_name]
|
||||||
router.vtysh_cmd(
|
router.vtysh_cmd("conf t\nrouter ospf\narea {} nssa\nexit\n".format(area))
|
||||||
"conf t\nrouter ospf\nno area {} nssa suppress-fa\nexit\n".format(area)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def ospf_get_lsa_type5(router_name):
|
def ospf_get_lsa_type5(router_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user