Skip to content

Commit

Permalink
ospfd, ospf6d: introduce the "graceful-restart hello-delay" command
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rwestphal committed May 9, 2023
1 parent d8cf2fc commit 0c05cea
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 5 deletions.
13 changes: 13 additions & 0 deletions doc/user/ospf6d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions doc/user/ospfd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/libospf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions ospf6d/ospf6_gr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions ospf6d/ospf6_gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions ospf6d/ospf6_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -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))
Expand All @@ -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. */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions ospf6d/ospf6_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 4 additions & 0 deletions ospf6d/ospf6_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions ospf6d/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
39 changes: 34 additions & 5 deletions ospfd/ospf_gr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions ospfd/ospf_gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions ospfd/ospf_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions ospfd/ospf_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit 0c05cea

Please sign in to comment.