ospfd, ospf6d: introduce the "graceful-restart hello-delay" command

This command makes unplanned GR more reliable by manipulating the
sending of Grace-LSAs and Hello packets for a certain amount of time,
increasing the chance that the neighboring routers are aware of
the ongoing graceful restart before resuming normal OSPF operation.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2023-03-03 13:09:20 -03:00
parent d8cf2fc52f
commit 0c05ceae00
15 changed files with 266 additions and 5 deletions

View File

@ -287,6 +287,19 @@ OSPF6 interface
Sets interface's Router Dead Interval. Default value is 40.
.. clicmd:: ipv6 ospf6 graceful-restart hello-delay HELLODELAYINTERVAL
Set the length of time during which Grace-LSAs are sent at 1-second intervals
while coming back up after an unplanned outage. During this time, no hello
packets are sent.
A higher hello delay will increase the chance that all neighbors are notified
about the ongoing graceful restart before receiving a hello packet (which is
crucial for the graceful restart to succeed). The hello delay shouldn't be set
too high, however, otherwise the adjacencies might time out. As a best practice,
it's recommended to set the hello delay and hello interval with the same values.
The default value is 10 seconds.
.. clicmd:: ipv6 ospf6 retransmit-interval RETRANSMITINTERVAL
Sets interface's Rxmt Interval. Default value is 5.

View File

@ -635,6 +635,19 @@ Interfaces
:clicmd:`ip ospf dead-interval minimal hello-multiplier (2-20)` is also
specified for the interface.
.. clicmd:: ip ospf graceful-restart hello-delay (1-1800)
Set the length of time during which Grace-LSAs are sent at 1-second intervals
while coming back up after an unplanned outage. During this time, no hello
packets are sent.
A higher hello delay will increase the chance that all neighbors are notified
about the ongoing graceful restart before receiving a hello packet (which is
crucial for the graceful restart to succeed). The hello delay shouldn't be set
too high, however, otherwise the adjacencies might time out. As a best practice,
it's recommended to set the hello delay and hello interval with the same values.
The default value is 10 seconds.
.. clicmd:: ip ospf network (broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn])
When configuring a point-to-point network on an interface and the interface

View File

@ -55,6 +55,7 @@ extern "C" {
#define OSPF_ROUTER_DEAD_INTERVAL_DEFAULT 40
#define OSPF_ROUTER_DEAD_INTERVAL_MINIMAL 1
#define OSPF_HELLO_INTERVAL_DEFAULT 10
#define OSPF_HELLO_DELAY_DEFAULT 10
#define OSPF_ROUTER_PRIORITY_DEFAULT 1
#define OSPF_RETRANSMIT_INTERVAL_DEFAULT 5
#define OSPF_TRANSMIT_DELAY_DEFAULT 1

View File

@ -190,6 +190,14 @@ static void ospf6_gr_restart_exit(struct ospf6 *ospf6, const char *reason)
OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(area);
for (ALL_LIST_ELEMENTS_RO(area->if_list, anode, oi)) {
/* Disable hello delay. */
if (oi->gr.hello_delay.t_grace_send) {
oi->gr.hello_delay.elapsed_seconds = 0;
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
event_add_event(master, ospf6_hello_send, oi, 0,
&oi->thread_send_hello);
}
/* Reoriginate Link-LSA. */
if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
OSPF6_LINK_LSA_EXECUTE(oi);
@ -520,6 +528,21 @@ static void ospf6_gr_grace_period_expired(struct event *thread)
ospf6_gr_restart_exit(ospf6, "grace period has expired");
}
/* Send extra Grace-LSA out the interface (unplanned outages only). */
void ospf6_gr_iface_send_grace_lsa(struct event *thread)
{
struct ospf6_interface *oi = EVENT_ARG(thread);
ospf6_gr_lsa_originate(oi, oi->area->ospf6->gr_info.reason);
if (++oi->gr.hello_delay.elapsed_seconds < oi->gr.hello_delay.interval)
event_add_timer(master, ospf6_gr_iface_send_grace_lsa, oi, 1,
&oi->gr.hello_delay.t_grace_send);
else
event_add_event(master, ospf6_hello_send, oi, 0,
&oi->thread_send_hello);
}
/*
* Record in non-volatile memory that the given OSPF instance is attempting to
* perform a graceful restart.
@ -677,6 +700,11 @@ void ospf6_gr_unplanned_start_interface(struct ospf6_interface *oi)
/* Send Grace-LSA. */
ospf6_gr_lsa_originate(oi, oi->area->ospf6->gr_info.reason);
/* Start GR hello-delay interval. */
oi->gr.hello_delay.elapsed_seconds = 0;
event_add_timer(master, ospf6_gr_iface_send_grace_lsa, oi, 1,
&oi->gr.hello_delay.t_grace_send);
}
/* Prepare to start a Graceful Restart. */

View File

@ -155,6 +155,7 @@ extern int config_write_ospf6_gr(struct vty *vty, struct ospf6 *ospf6);
extern int config_write_ospf6_gr_helper(struct vty *vty, struct ospf6 *ospf6);
extern int config_write_ospf6_debug_gr_helper(struct vty *vty);
extern void ospf6_gr_iface_send_grace_lsa(struct event *thread);
extern void ospf6_gr_restart_enter(struct ospf6 *ospf6,
enum ospf6_gr_restart_reason reason,
int timestamp);

View File

@ -35,6 +35,7 @@
#include "ospf6_proto.h"
#include "lib/keychain.h"
#include "ospf6_auth_trailer.h"
#include "ospf6d/ospf6_interface_clippy.c"
DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_IF, "OSPF6 interface");
DEFINE_MTYPE(OSPF6D, OSPF6_AUTH_KEYCHAIN, "OSPF6 auth keychain");
@ -202,6 +203,7 @@ struct ospf6_interface *ospf6_interface_create(struct interface *ifp)
oi->priority = OSPF6_INTERFACE_PRIORITY;
oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
oi->gr.hello_delay.interval = OSPF_HELLO_DELAY_DEFAULT;
oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
oi->type = ospf6_default_iftype(ifp);
@ -324,6 +326,9 @@ void ospf6_interface_disable(struct ospf6_interface *oi)
EVENT_OFF(oi->thread_intra_prefix_lsa);
EVENT_OFF(oi->thread_as_extern_lsa);
EVENT_OFF(oi->thread_wait_timer);
oi->gr.hello_delay.elapsed_seconds = 0;
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
}
static struct in6_addr *
@ -1191,6 +1196,9 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
json_arr, json_object_new_string(lsa->name));
json_object_object_add(json_obj, "pendingLsaLsAck", json_arr);
if (oi->gr.hello_delay.interval != 0)
json_object_int_add(json_obj, "grHelloDelaySecs",
oi->gr.hello_delay.interval);
} else {
timerclear(&res);
if (event_is_scheduled(oi->thread_send_lsupdate))
@ -1216,6 +1224,10 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
: "off"));
for (ALL_LSDB(oi->lsack_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
if (oi->gr.hello_delay.interval != 0)
vty_out(vty, " Graceful Restart hello delay: %us\n",
oi->gr.hello_delay.interval);
}
/* BFD specific. */
@ -2168,6 +2180,50 @@ ALIAS (ipv6_ospf6_deadinterval,
"Interval time after which a neighbor is declared down\n"
SECONDS_STR)
DEFPY(ipv6_ospf6_gr_hdelay, ipv6_ospf6_gr_hdelay_cmd,
"ipv6 ospf6 graceful-restart hello-delay (1-1800)",
IP6_STR
OSPF6_STR
"Graceful Restart parameters\n"
"Delay the sending of the first hello packets.\n"
"Delay in seconds\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct ospf6_interface *oi;
oi = ifp->info;
if (oi == NULL)
oi = ospf6_interface_create(ifp);
/* Note: new or updated value won't affect ongoing graceful restart. */
oi->gr.hello_delay.interval = hello_delay;
return CMD_SUCCESS;
}
DEFPY(no_ipv6_ospf6_gr_hdelay, no_ipv6_ospf6_gr_hdelay_cmd,
"no ipv6 ospf6 graceful-restart hello-delay [(1-1800)]",
NO_STR
IP6_STR
OSPF6_STR
"Graceful Restart parameters\n"
"Delay the sending of the first hello packets.\n"
"Delay in seconds\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct ospf6_interface *oi;
oi = ifp->info;
if (oi == NULL)
oi = ospf6_interface_create(ifp);
oi->gr.hello_delay.interval = OSPF_HELLO_DELAY_DEFAULT;
oi->gr.hello_delay.elapsed_seconds = 0;
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
return CMD_SUCCESS;
}
/* interface variable set command */
DEFUN (ipv6_ospf6_transmitdelay,
ipv6_ospf6_transmitdelay_cmd,
@ -2635,6 +2691,11 @@ static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf)
else if (oi->type_cfg && oi->type == OSPF_IFTYPE_BROADCAST)
vty_out(vty, " ipv6 ospf6 network broadcast\n");
if (oi->gr.hello_delay.interval != OSPF_HELLO_DELAY_DEFAULT)
vty_out(vty,
" ipv6 ospf6 graceful-restart hello-delay %u\n",
oi->gr.hello_delay.interval);
ospf6_bfd_write_config(vty, oi);
ospf6_auth_write_config(vty, &oi->at_data);
@ -2733,12 +2794,14 @@ void ospf6_interface_init(void)
install_element(INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_gr_hdelay_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
install_element(INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_deadinterval_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_hellointerval_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_gr_hdelay_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_priority_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_retransmitinterval_cmd);
install_element(INTERFACE_NODE, &no_ipv6_ospf6_transmitdelay_cmd);

View File

@ -74,6 +74,15 @@ struct ospf6_interface {
uint16_t dead_interval;
uint32_t rxmt_interval;
/* Graceful-Restart data. */
struct {
struct {
uint16_t interval;
uint16_t elapsed_seconds;
struct event *t_grace_send;
} hello_delay;
} gr;
uint32_t state_change;
/* Cost */

View File

@ -2244,6 +2244,10 @@ void ospf6_hello_send(struct event *thread)
oi = (struct ospf6_interface *)EVENT_ARG(thread);
/* Check if the GR hello-delay is active. */
if (oi->gr.hello_delay.t_grace_send)
return;
if (oi->state <= OSPF6_INTERFACE_DOWN) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR))
zlog_debug("Unable to send Hello on down interface %s",

View File

@ -78,6 +78,7 @@ clippy_scan += \
ospf6d/ospf6_top.c \
ospf6d/ospf6_area.c \
ospf6d/ospf6_asbr.c \
ospf6d/ospf6_interface.c \
ospf6d/ospf6_lsa.c \
ospf6d/ospf6_gr_helper.c \
ospf6d/ospf6_gr.c \

View File

@ -237,13 +237,22 @@ static void ospf_gr_restart_exit(struct ospf *ospf, const char *reason)
*/
ospf_router_lsa_update_area(area);
/*
* 2) The router should reoriginate network-LSAs on all segments
* where it is the Designated Router.
*/
for (ALL_LIST_ELEMENTS_RO(area->oiflist, anode, oi))
for (ALL_LIST_ELEMENTS_RO(area->oiflist, anode, oi)) {
/* Disable hello delay. */
if (oi->gr.hello_delay.t_grace_send) {
oi->gr.hello_delay.elapsed_seconds = 0;
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
OSPF_ISM_TIMER_MSEC_ON(oi->t_hello,
ospf_hello_timer, 1);
}
/*
* 2) The router should reoriginate network-LSAs on all
* segments where it is the Designated Router.
*/
if (oi->state == ISM_DR)
ospf_network_lsa_update(oi);
}
}
/*
@ -561,6 +570,21 @@ static char *ospf_gr_nvm_filepath(struct ospf *ospf)
return filepath;
}
/* Send extra Grace-LSA out the interface (unplanned outages only). */
void ospf_gr_iface_send_grace_lsa(struct event *thread)
{
struct ospf_interface *oi = EVENT_ARG(thread);
struct ospf_if_params *params = IF_DEF_PARAMS(oi->ifp);
ospf_gr_lsa_originate(oi, oi->ospf->gr_info.reason, false);
if (++oi->gr.hello_delay.elapsed_seconds < params->v_gr_hello_delay)
event_add_timer(master, ospf_gr_iface_send_grace_lsa, oi, 1,
&oi->gr.hello_delay.t_grace_send);
else
OSPF_ISM_TIMER_MSEC_ON(oi->t_hello, ospf_hello_timer, 1);
}
/*
* Record in non-volatile memory that the given OSPF instance is attempting to
* perform a graceful restart.
@ -714,6 +738,11 @@ void ospf_gr_unplanned_start_interface(struct ospf_interface *oi)
{
/* Send Grace-LSA. */
ospf_gr_lsa_originate(oi, oi->ospf->gr_info.reason, false);
/* Start GR hello-delay interval. */
oi->gr.hello_delay.elapsed_seconds = 0;
event_add_timer(master, ospf_gr_iface_send_grace_lsa, oi, 1,
&oi->gr.hello_delay.t_grace_send);
}
/* Prepare to start a Graceful Restart. */

View File

@ -166,6 +166,7 @@ extern void ospf_gr_helper_supported_gracetime_set(struct ospf *ospf,
uint32_t interval);
extern void ospf_gr_helper_set_supported_planned_only_restart(struct ospf *ospf,
bool planned_only);
extern void ospf_gr_iface_send_grace_lsa(struct event *thread);
extern void ospf_gr_restart_enter(struct ospf *ospf,
enum ospf_gr_restart_reason reason,
int timestamp);

View File

@ -527,6 +527,7 @@ static struct ospf_if_params *ospf_new_if_params(void)
UNSET_IF_PARAM(oip, passive_interface);
UNSET_IF_PARAM(oip, v_hello);
UNSET_IF_PARAM(oip, fast_hello);
UNSET_IF_PARAM(oip, v_gr_hello_delay);
UNSET_IF_PARAM(oip, v_wait);
UNSET_IF_PARAM(oip, priority);
UNSET_IF_PARAM(oip, type);
@ -676,6 +677,9 @@ int ospf_if_new_hook(struct interface *ifp)
SET_IF_PARAM(IF_DEF_PARAMS(ifp), fast_hello);
IF_DEF_PARAMS(ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_gr_hello_delay);
IF_DEF_PARAMS(ifp)->v_gr_hello_delay = OSPF_HELLO_DELAY_DEFAULT;
SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
IF_DEF_PARAMS(ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;

View File

@ -72,6 +72,9 @@ struct ospf_if_params {
DECLARE_IF_PARAM(uint32_t, v_wait); /* Router Dead Interval */
bool is_v_wait_set; /* Check for Dead Interval set */
/* GR Hello Delay Interval */
DECLARE_IF_PARAM(uint16_t, v_gr_hello_delay);
/* MTU mismatch check (see RFC2328, chap 10.6) */
DECLARE_IF_PARAM(uint8_t, mtu_ignore);
@ -214,6 +217,14 @@ struct ospf_interface {
/* List of configured NBMA neighbor. */
struct list *nbr_nbma;
/* Graceful-Restart data. */
struct {
struct {
uint16_t elapsed_seconds;
struct event *t_grace_send;
} hello_delay;
} gr;
/* self-originated LSAs. */
struct ospf_lsa *network_lsa_self; /* network-LSA. */
struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */

View File

@ -244,6 +244,10 @@ void ospf_hello_timer(struct event *thread)
oi = EVENT_ARG(thread);
oi->t_hello = NULL;
/* Check if the GR hello-delay is active. */
if (oi->gr.hello_delay.t_grace_send)
return;
if (IS_DEBUG_OSPF(ism, ISM_TIMERS))
zlog_debug("ISM[%s]: Timer (Hello timer expire)", IF_NAME(oi));
@ -282,6 +286,7 @@ static void ism_timer_set(struct ospf_interface *oi)
EVENT_OFF(oi->t_hello);
EVENT_OFF(oi->t_wait);
EVENT_OFF(oi->t_ls_ack);
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
break;
case ISM_Loopback:
/* In this state, the interface may be looped back and will be
@ -289,6 +294,7 @@ static void ism_timer_set(struct ospf_interface *oi)
EVENT_OFF(oi->t_hello);
EVENT_OFF(oi->t_wait);
EVENT_OFF(oi->t_ls_ack);
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
break;
case ISM_Waiting:
/* The router is trying to determine the identity of DRouter and

View File

@ -3620,6 +3620,7 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
struct ospf_neighbor *nbr;
struct route_node *rn;
uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
struct ospf_if_params *params;
/* Is interface up? */
if (use_json) {
@ -3939,6 +3940,20 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
ospf_nbr_count(oi, 0),
ospf_nbr_count(oi, NSM_Full));
params = IF_DEF_PARAMS(ifp);
if (params &&
OSPF_IF_PARAM_CONFIGURED(params, v_gr_hello_delay)) {
if (use_json) {
json_object_int_add(json_interface_sub,
"grHelloDelaySecs",
params->v_gr_hello_delay);
} else
vty_out(vty,
" Graceful Restart hello delay: %us\n",
params->v_gr_hello_delay);
}
ospf_interface_bfd_show(vty, ifp, json_interface_sub);
/* OSPF Authentication information */
@ -8642,6 +8657,59 @@ DEFUN_HIDDEN (no_ospf_retransmit_interval,
return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
}
DEFPY (ip_ospf_gr_hdelay,
ip_ospf_gr_hdelay_cmd,
"ip ospf graceful-restart hello-delay (1-1800)",
IP_STR
"OSPF interface commands\n"
"Graceful Restart parameters\n"
"Delay the sending of the first hello packets.\n"
"Delay in seconds\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct ospf_if_params *params;
params = IF_DEF_PARAMS(ifp);
/* Note: new or updated value won't affect ongoing graceful restart. */
SET_IF_PARAM(params, v_gr_hello_delay);
params->v_gr_hello_delay = hello_delay;
return CMD_SUCCESS;
}
DEFPY (no_ip_ospf_gr_hdelay,
no_ip_ospf_gr_hdelay_cmd,
"no ip ospf graceful-restart hello-delay [(1-1800)]",
NO_STR
IP_STR
"OSPF interface commands\n"
"Graceful Restart parameters\n"
"Delay the sending of the first hello packets.\n"
"Delay in seconds\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct ospf_if_params *params;
struct route_node *rn;
params = IF_DEF_PARAMS(ifp);
UNSET_IF_PARAM(params, v_gr_hello_delay);
params->v_gr_hello_delay = OSPF_HELLO_DELAY_DEFAULT;
for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
struct ospf_interface *oi;
oi = rn->info;
if (!oi)
continue;
oi->gr.hello_delay.elapsed_seconds = 0;
EVENT_OFF(oi->gr.hello_delay.t_grace_send);
}
return CMD_SUCCESS;
}
DEFUN (ip_ospf_transmit_delay,
ip_ospf_transmit_delay_addr_cmd,
"ip ospf transmit-delay (1-65535) [A.B.C.D]",
@ -11834,6 +11902,15 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
vty_out(vty, "\n");
}
/* Hello Graceful-Restart Delay print. */
if (OSPF_IF_PARAM_CONFIGURED(params,
v_gr_hello_delay) &&
params->v_gr_hello_delay !=
OSPF_HELLO_DELAY_DEFAULT)
vty_out(vty,
" ip ospf graceful-restart hello-delay %u\n",
params->v_gr_hello_delay);
/* Router Priority print. */
if (OSPF_IF_PARAM_CONFIGURED(params, priority)
&& params->priority