ospfd: Some small tweaks to the SPF execution reason patch

* ospf_spf.h: use an enum for the reason, and have it as a new argument to
  ospf_spf_calculate_schedule, no need for additional call, and let compiler
  do the checking.
* ospf_spf.c: format changes - Quagga coding style places function names
  at the start of a new line, for easy grepping for definition.
  (ospf_spf_calculate_timer) Change the log format of SPF execution time to
  avoid ginormous line, and make logging conditional, as is the norm.

(cherry picked from commit b6eef003e1a79471addea0b01853b08aed812cc8)

Conflicts:
	ospfd/ospf_spf.c
This commit is contained in:
Paul Jakma 2014-10-09 14:19:51 +01:00 committed by Daniel Walton
parent 7498d58d56
commit d3a9c76878
6 changed files with 63 additions and 69 deletions

View file

@ -556,8 +556,7 @@ ospf_check_abr_status (struct ospf *ospf)
if (new_flags != ospf->flags)
{
ospf_flag_spf_reason (SPF_FLAG_ABR_STATUS_CHANGE);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_ABR_STATUS_CHANGE);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
ospf->flags = new_flags;

View file

@ -291,8 +291,7 @@ ospf_asbr_status_update (struct ospf *ospf, u_char status)
}
/* Transition from/to status ASBR, schedule timer. */
ospf_flag_spf_reason (SPF_FLAG_ASBR_STATUS_CHANGE);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_ASBR_STATUS_CHANGE);
ospf_router_lsa_update (ospf);
}

View file

@ -2468,10 +2468,7 @@ ospf_router_lsa_install (struct ospf *ospf, struct ospf_lsa *new,
ospf_refresher_register_lsa (ospf, new);
}
if (rt_recalc)
{
ospf_flag_spf_reason (SPF_FLAG_ROUTER_LSA_INSTALL);
ospf_spf_calculate_schedule (ospf);
}
ospf_spf_calculate_schedule (ospf, SPF_FLAG_ROUTER_LSA_INSTALL);
return new;
}
@ -2505,10 +2502,7 @@ ospf_network_lsa_install (struct ospf *ospf,
ospf_refresher_register_lsa (ospf, new);
}
if (rt_recalc)
{
ospf_flag_spf_reason (SPF_FLAG_NETWORK_LSA_INSTALL);
ospf_spf_calculate_schedule (ospf);
}
ospf_spf_calculate_schedule (ospf, SPF_FLAG_NETWORK_LSA_INSTALL);
return new;
}
@ -2531,8 +2525,7 @@ ospf_summary_lsa_install (struct ospf *ospf, struct ospf_lsa *new,
/* This doesn't exist yet... */
ospf_summary_incremental_update(new); */
#else /* #if 0 */
ospf_flag_spf_reason (SPF_FLAG_SUMMARY_LSA_INSTALL);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_SUMMARY_LSA_INSTALL);
#endif /* #if 0 */
}
@ -2563,8 +2556,7 @@ ospf_summary_asbr_lsa_install (struct ospf *ospf, struct ospf_lsa *new,
- RFC 2328 Section 16.5 implies it should be */
/* ospf_ase_calculate_schedule(); */
#else /* #if 0 */
ospf_flag_spf_reason (SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL);
#endif /* #if 0 */
}
@ -3086,8 +3078,7 @@ ospf_lsa_maxage_walker_remover (struct ospf *ospf, struct ospf_lsa *lsa)
ospf_ase_incremental_update (ospf, lsa);
break;
default:
ospf_flag_spf_reason (SPF_FLAG_MAXAGE);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_MAXAGE);
break;
}
ospf_lsa_maxage (ospf, lsa);

View file

@ -50,42 +50,41 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
static unsigned int spf_reason_flags = 0;
static void ospf_clear_spf_reason_flags (void )
static void
ospf_clear_spf_reason_flags (void)
{
spf_reason_flags = 0;
}
void ospf_flag_spf_reason (unsigned int reason)
static void
ospf_spf_set_reason (ospf_spf_reason_t reason)
{
if (reason <= SPF_FLAG_MAX_VALUE)
spf_reason_flags |= reason;
else
spf_reason_flags |= SPF_FLAG_MISC;
spf_reason_flags |= 1 << reason;
}
static void
ospf_get_spf_reason_str (char *buf)
{
if (buf)
if (!buf)
return;
buf[0] = '\0';
if (spf_reason_flags)
{
buf[0] = '\0';
if (spf_reason_flags)
{
if (spf_reason_flags & SPF_FLAG_ROUTER_LSA_INSTALL)
strcat (buf, "R, ");
if (spf_reason_flags & SPF_FLAG_NETWORK_LSA_INSTALL)
strcat (buf, "N, ");
if (spf_reason_flags & SPF_FLAG_SUMMARY_LSA_INSTALL)
strcat (buf, "S, ");
if (spf_reason_flags & SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL)
strcat (buf, "AS, ");
if (spf_reason_flags & SPF_FLAG_ABR_STATUS_CHANGE)
strcat (buf, "ABR, ");
if (spf_reason_flags & SPF_FLAG_ASBR_STATUS_CHANGE)
strcat (buf, "ASBR, ");
if (spf_reason_flags & SPF_FLAG_MAXAGE)
strcat (buf, "M, ");
}
if (spf_reason_flags & SPF_FLAG_ROUTER_LSA_INSTALL)
strcat (buf, "R, ");
if (spf_reason_flags & SPF_FLAG_NETWORK_LSA_INSTALL)
strcat (buf, "N, ");
if (spf_reason_flags & SPF_FLAG_SUMMARY_LSA_INSTALL)
strcat (buf, "S, ");
if (spf_reason_flags & SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL)
strcat (buf, "AS, ");
if (spf_reason_flags & SPF_FLAG_ABR_STATUS_CHANGE)
strcat (buf, "ABR, ");
if (spf_reason_flags & SPF_FLAG_ASBR_STATUS_CHANGE)
strcat (buf, "ASBR, ");
if (spf_reason_flags & SPF_FLAG_MAXAGE)
strcat (buf, "M, ");
buf[strlen(buf)-2] = '\0'; /* skip the last ", " */
}
}
@ -1399,12 +1398,18 @@ ospf_spf_calculate_timer (struct thread *thread)
ospf_get_spf_reason_str (rbuf);
if (IS_OSPF_ABR (ospf))
zlog_info ("SPF Processing Time(usecs): # Areas: %d, SPF Time: %ld, InterArea: %ld, Prune: %ld, RouteInstall: %ld, ABR: %ld, Total: %ld, Reason: %s\n",
areas_processed, spf_time, ia_time, prune_time, rt_time, abr_time, total_spf_time, rbuf);
else
zlog_info ("SPF Processing Time(usecs): SPF Time: %ld, InterArea: %ld, Prune: %ld, RouteInstall: %ld, Total: %ld, Reason: %s\n",
spf_time, ia_time, prune_time, rt_time, total_spf_time, rbuf);
if (IS_DEBUG_OSPF_EVENT)
{
zlog_info ("SPF Processing Time(usecs): %ld", total_spf_time);
zlog_info ("\t SPF Time: %ld", spf_time);
zlog_info ("\t InterArea: %ld", ia_time);
zlog_info ("\t Prune: %ld", prune_time);
zlog_info ("\tRouteInstall: %ld", rt_time);
if (IS_OSPF_ABR (ospf))
zlog_info ("\t ABR: %ld (%d areas)",
abr_time, areas_processed);
zlog_info ("Reason(s) for SPF: %s", rbuf);
}
ospf_clear_spf_reason_flags ();
@ -1414,7 +1419,7 @@ ospf_spf_calculate_timer (struct thread *thread)
/* Add schedule for SPF calculation. To avoid frequenst SPF calc, we
set timer for SPF calc. */
void
ospf_spf_calculate_schedule (struct ospf *ospf)
ospf_spf_calculate_schedule (struct ospf *ospf, ospf_spf_reason_t reason)
{
unsigned long delay, elapsed, ht;
struct timeval result;
@ -1426,6 +1431,8 @@ ospf_spf_calculate_schedule (struct ospf *ospf)
if (ospf == NULL)
return;
ospf_spf_set_reason (reason);
/* SPF calculation timer is already scheduled. */
if (ospf->t_spf_calc)
{

View file

@ -59,22 +59,20 @@ struct vertex_parent
int backlink; /* index back to parent for router-lsa's */
};
extern void ospf_spf_calculate_schedule (struct ospf *);
/* What triggered the SPF ? */
typedef enum {
SPF_FLAG_ROUTER_LSA_INSTALL = 1,
SPF_FLAG_NETWORK_LSA_INSTALL,
SPF_FLAG_SUMMARY_LSA_INSTALL,
SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL,
SPF_FLAG_MAXAGE,
SPF_FLAG_ABR_STATUS_CHANGE,
SPF_FLAG_ASBR_STATUS_CHANGE,
SPF_FLAG_CONFIG_CHANGE,
} ospf_spf_reason_t;
extern void ospf_spf_calculate_schedule (struct ospf *, ospf_spf_reason_t);
extern void ospf_rtrs_free (struct route_table *);
/* void ospf_spf_calculate_timer_add (); */
/* What triggered the SPF ? Can have at most 32 reasons with this */
#define SPF_FLAG_ROUTER_LSA_INSTALL 0x1
#define SPF_FLAG_NETWORK_LSA_INSTALL 0x2
#define SPF_FLAG_SUMMARY_LSA_INSTALL 0x4
#define SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL 0x8
#define SPF_FLAG_MAXAGE 0x10
#define SPF_FLAG_ABR_STATUS_CHANGE 0x20
#define SPF_FLAG_ASBR_STATUS_CHANGE 0x40
#define SPF_FLAG_MAX_VALUE 0x40 /* Update this when adding flags */
#define SPF_FLAG_MISC 0x1000000 /* Keep this last */
extern void ospf_flag_spf_reason (unsigned int reason);
#endif /* _QUAGGA_OSPF_SPF_H */

View file

@ -900,7 +900,7 @@ ospf_find_vl_data (struct ospf *ospf, struct ospf_vl_config_data *vl_config)
{
vl_data->vl_oi = ospf_vl_new (ospf, vl_data);
ospf_vl_add (ospf, vl_data);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
}
}
return vl_data;
@ -2408,7 +2408,7 @@ DEFUN (ospf_compatible_rfc1583,
if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
{
SET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
}
return CMD_SUCCESS;
}
@ -2428,7 +2428,7 @@ DEFUN (no_ospf_compatible_rfc1583,
if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
{
UNSET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
ospf_spf_calculate_schedule (ospf);
ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
}
return CMD_SUCCESS;
}