Skip to content

Commit

Permalink
ospfd: update "show ip ospf" to include GR information (FRRouting#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
  • Loading branch information
rwestphal committed Nov 4, 2021
1 parent b6b7c17 commit 29b197c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
59 changes: 57 additions & 2 deletions ospfd/ospf_gr.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,22 @@ static void ospf_gr_restart_exit(struct ospf *ospf, const char *reason)
* should be removed.
*/
ospf->gr_info.finishing_restart = true;
XFREE(MTYPE_TMP, ospf->gr_info.exit_reason);
ospf->gr_info.exit_reason = XSTRDUP(MTYPE_TMP, reason);
ospf_spf_calculate_schedule(ospf, SPF_FLAG_GR_FINISH);

/* 6) Any grace-LSAs that the router originated should be flushed. */
ospf_gr_flush_grace_lsas(ospf);
}

/* Enter the Graceful Restart mode. */
void ospf_gr_restart_enter(struct ospf *ospf, int timestamp)
void ospf_gr_restart_enter(struct ospf *ospf,
enum ospf_gr_restart_reason reason, int timestamp)
{
unsigned long remaining_time;

ospf->gr_info.restart_in_progress = true;
ospf->gr_info.reason = reason;

/* Schedule grace period timeout. */
remaining_time = timestamp - time(NULL);
Expand Down Expand Up @@ -713,7 +717,8 @@ void ospf_gr_nvm_read(struct ospf *ospf)
ospf_gr_restart_exit(
ospf, "grace period has expired already");
} else
ospf_gr_restart_enter(ospf, timestamp);
ospf_gr_restart_enter(ospf, OSPF_GR_SW_RESTART,
timestamp);
}

json_object_object_del(json_instances, inst_name);
Expand Down Expand Up @@ -772,6 +777,56 @@ static void ospf_gr_prepare(void)
}
}

void ospf_gr_show(struct vty *vty, struct ospf *ospf, json_object *json)
{
const char *status;

status = (ospf->gr_info.prepare_in_progress
|| ospf->gr_info.restart_in_progress)
? "in progress"
: "not started";

if (json) {
json_object_boolean_add(json, "grEnabled",
ospf->gr_info.restart_support);
if (ospf->gr_info.restart_support) {
json_object_string_add(json, "grStatus", status);
if (ospf->gr_info.reason != OSPF_GR_UNKNOWN_RESTART)
json_object_string_add(
json, "grReason",
ospf_restart_reason2str(
ospf->gr_info.reason));
if (ospf->gr_info.t_grace_period)
json_object_int_add(
json, "grRemainingTimeSecs",
thread_timer_remain_second(
ospf->gr_info.t_grace_period));
if (ospf->gr_info.exit_reason)
json_object_string_add(
json, "grExitReason",
ospf->gr_info.exit_reason);
}
} else {
vty_out(vty, " Graceful Restart: %s\n",
ospf->gr_info.restart_support ? "enabled" : "disabled");
if (ospf->gr_info.restart_support) {
vty_out(vty, " Status: %s\n", status);
if (ospf->gr_info.reason != OSPF_GR_UNKNOWN_RESTART)
vty_out(vty, " Restart reason: %s\n",
ospf_restart_reason2str(
ospf->gr_info.reason));
if (ospf->gr_info.t_grace_period)
vty_out(vty,
" Restart remaining time: %lus\n",
thread_timer_remain_second(
ospf->gr_info.t_grace_period));
if (ospf->gr_info.exit_reason)
vty_out(vty, " Restart exit reason: %s\n",
ospf->gr_info.exit_reason);
}
}
}

DEFPY(graceful_restart_prepare, graceful_restart_prepare_cmd,
"graceful-restart prepare ip ospf",
"Graceful Restart commands\n"
Expand Down
7 changes: 6 additions & 1 deletion ospfd/ospf_gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef _ZEBRA_OSPF_GR_H
#define _ZEBRA_OSPF_GR_H

#include "lib/json.h"

#define OSPF_GR_NOT_HELPER 0
#define OSPF_GR_ACTIVE_HELPER 1

Expand Down Expand Up @@ -185,11 +187,14 @@ extern void ospf_gr_lsa_originate(struct ospf_interface *oi,
enum ospf_gr_restart_reason reason,
bool maxage);
extern int ospf_gr_iface_send_grace_lsa(struct thread *thread);
extern void ospf_gr_restart_enter(struct ospf *ospf, int timestamp);
extern void ospf_gr_restart_enter(struct ospf *ospf,
enum ospf_gr_restart_reason reason,
int timestamp);
extern void ospf_gr_check_lsdb_consistency(struct ospf *ospf,
struct ospf_area *area);
extern void ospf_gr_check_adjs(struct ospf *ospf);
extern void ospf_gr_nvm_read(struct ospf *ospf);
extern void ospf_gr_show(struct vty *vty, struct ospf *ospf, json_object *json);
extern void ospf_gr_init(void);

#endif /* _ZEBRA_OSPF_GR_H */
2 changes: 1 addition & 1 deletion ospfd/ospf_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static int ospf_instance_shutdown(struct nb_cb_modify_args *args)
}

/* Reenable routing instance in the GR mode. */
ospf_gr_restart_enter(ospf,
ospf_gr_restart_enter(ospf, OSPF_GR_SWITCH_CONTROL_PROCESSOR,
time(NULL) + OSPF_DFLT_GRACE_INTERVAL);
ospf_shutdown(ospf, false, false);
} else
Expand Down
4 changes: 3 additions & 1 deletion ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ DEFPY(ospf_instance_shutdown_graceful, ospf_instance_shutdown_graceful_cmd,
}

/* Reenable routing instance in the GR mode. */
ospf_gr_restart_enter(ospf,
ospf_gr_restart_enter(ospf, OSPF_GR_SWITCH_CONTROL_PROCESSOR,
time(NULL) + ospf->gr_info.grace_period);
ospf_shutdown(ospf, false, false);
} else
Expand Down Expand Up @@ -3482,6 +3482,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
}
}

ospf_gr_show(vty, ospf, json);

/* show LDP-Sync status */
ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0);

Expand Down
1 change: 1 addition & 0 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ static void ospf_finish_final(struct ospf *ospf)

if (!ospf->gr_info.prepare_in_progress)
ospf_flush_self_originated_lsas_now(ospf);
XFREE(MTYPE_TMP, ospf->gr_info.exit_reason);

/* Unregister redistribution */
for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
Expand Down
2 changes: 2 additions & 0 deletions ospfd/ospfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ struct ospf_gr_info {
bool prepare_in_progress;
bool finishing_restart;
uint32_t grace_period;
int reason;
char *exit_reason;
struct thread *t_grace_period;
};

Expand Down

0 comments on commit 29b197c

Please sign in to comment.