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.
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index a7155bc..1fe8ab4 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -50,42 +50,41 @@
static unsigned int spf_reason_flags = 0;
-static void ospf_clear_spf_reason_flags ()
+static void
+ospf_clear_spf_reason_flags ()
{
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 ", " */
}
}
@@ -1313,7 +1312,7 @@
unsigned long ia_time, prune_time, rt_time;
unsigned long abr_time, total_spf_time, spf_time;
char rbuf[32]; /* reason_buf */
-
+
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("SPF: Timer (SPF calculation expire)");
@@ -1405,12 +1404,18 @@
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 ();
@@ -1420,7 +1425,7 @@
/* 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;
@@ -1432,6 +1437,8 @@
if (ospf == NULL)
return;
+ ospf_spf_set_reason (reason);
+
/* SPF calculation timer is already scheduled. */
if (ospf->t_spf_calc)
{