Browse Source

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.
Paul Jakma 5 years ago
parent
commit
b6eef003e1
7 changed files with 64 additions and 70 deletions
  1. 1 2
      ospfd/ospf_abr.c
  2. 1 2
      ospfd/ospf_asbr.c
  3. 1 1
      ospfd/ospf_ase.c
  4. 5 14
      ospfd/ospf_lsa.c
  5. 40 33
      ospfd/ospf_spf.c
  6. 13 15
      ospfd/ospf_spf.h
  7. 3 3
      ospfd/ospf_vty.c

+ 1 - 2
ospfd/ospf_abr.c

@@ -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;

+ 1 - 2
ospfd/ospf_asbr.c

@@ -264,8 +264,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);
 }
 

+ 1 - 1
ospfd/ospf_ase.c

@@ -679,7 +679,7 @@ ospf_ase_calculate_timer (struct thread *t)
 
       quagga_gettime(QUAGGA_CLK_MONOTONIC, &stop_time);
 
-      zlog_info ("SPF Processing Time(usecs): External Routes: %d\n",
+      zlog_info ("SPF Processing Time(usecs): External Routes: %ld\n",
 		 (stop_time.tv_sec - start_time.tv_sec)*1000000L+
 		 (stop_time.tv_usec - start_time.tv_usec));
     }

+ 5 - 14
ospfd/ospf_lsa.c

@@ -2409,10 +2409,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;
 }
 
@@ -2446,10 +2443,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;
 }
@@ -2472,8 +2466,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 */
  
     }
@@ -2504,8 +2497,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 */
     }
 
@@ -3027,8 +3019,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);

+ 40 - 33
ospfd/ospf_spf.c

@@ -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 ()
+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 @@ 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)");
 
@@ -1405,12 +1404,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 ();
 
@@ -1420,7 +1425,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;
@@ -1432,6 +1437,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)
     {

+ 13 - 15
ospfd/ospf_spf.h

@@ -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 */

+ 3 - 3
ospfd/ospf_vty.c

@@ -771,7 +771,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;
@@ -2172,7 +2172,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;
 }
@@ -2189,7 +2189,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;
 }