Skip to content

Commit

Permalink
ospfd: Some small tweaks to the SPF execution reason patch
Browse files Browse the repository at this point in the history
* 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 b6eef00)

Conflicts:
	ospfd/ospf_spf.c
  • Loading branch information
pjakma authored and Daniel Walton committed May 26, 2016
1 parent 7498d58 commit d3a9c76
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 69 deletions.
3 changes: 1 addition & 2 deletions ospfd/ospf_abr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions ospfd/ospf_asbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 5 additions & 14 deletions ospfd/ospf_lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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 */

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

Expand Down Expand Up @@ -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);
Expand Down
73 changes: 40 additions & 33 deletions ospfd/ospf_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ", " */
}
}
Expand Down Expand Up @@ -1307,7 +1306,7 @@ ospf_spf_calculate_timer (struct thread *thread)
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)");

Expand Down Expand Up @@ -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 ();

Expand All @@ -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;
Expand All @@ -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)
{
Expand Down
28 changes: 13 additions & 15 deletions ospfd/ospf_spf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
6 changes: 3 additions & 3 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit d3a9c76

Please sign in to comment.