[bgpd] rearrange some structs for less padding, stats for table/attrs.

2006-03-12 Paul Jakma <paul.jakma@sun.com>

	* bgp_attr.h: (struct attr) rearrange fields to avoid
	  wasted padding between them as much as possible.
	  (attr_count,attr_unknown_count) export new functions to
	  return number of counts of cached attributes.
	* bgp_attr.c: (attr_count,attr_unknown_count) new functions to
	  return number of counts of cached attributes.
	* bgp_route.h: (struct bgp_info) rearrange fields to avoid
	  wasted padding.
	* bgp_table.h: (struct bgp_table) Add a count field, of number
	  of nodes in the table.
	  (struct bgp_node)  rearrange fields to avoid
	  wasted padding between them, though I don't think there
	  was any in this case.
	* bgp_table.c: (bgp_node_{delete,get}) Maintain the table node count.
	  (bgp_table_count) new function to access the table count.
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index 0c8c9d6..51f2e13 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -1,3 +1,21 @@
+2006-03-12 Paul Jakma <paul.jakma@sun.com>
+
+	* bgp_attr.h: (struct attr) rearrange fields to avoid
+	  wasted padding between them as much as possible.
+	  (attr_count,attr_unknown_count) export new functions to
+	  return number of counts of cached attributes.
+	* bgp_attr.c: (attr_count,attr_unknown_count) new functions to
+	  return number of counts of cached attributes.
+	* bgp_route.h: (struct bgp_info) rearrange fields to avoid
+	  wasted padding.
+	* bgp_table.h: (struct bgp_table) Add a count field, of number
+	  of nodes in the table.
+	  (struct bgp_node)  rearrange fields to avoid
+	  wasted padding between them, though I don't think there
+	  was any in this case. 
+	* bgp_table.c: (bgp_node_{delete,get}) Maintain the table node count.
+	  (bgp_table_count) new function to access the table count.
+
 2006-03-03 Paul Jakma <paul.jakma@sun.com>
 
 	* bgp_route.c: (bgp_clear_node_complete) Doh. When clearing
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 3b27517..27ddab1 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -274,6 +274,18 @@
 
 struct hash *attrhash;
 
+unsigned long int
+attr_count (void)
+{
+  return attrhash->count;
+}
+
+unsigned long int
+attr_unknown_count (void)
+{
+  return transit_hash->count;
+}
+
 unsigned int
 attrhash_key_make (struct attr *attr)
 {
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index ad0302d..a018256 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -48,30 +48,11 @@
 /* BGP attribute structure. */
 struct attr
 {
-  /* Reference count of this attribute. */
-  unsigned long refcnt;
-
-  /* Flag of attribute is set or not. */
-  u_int32_t flag;
-
   /* Attributes. */
-  u_char origin;
-  struct in_addr nexthop;
-  u_int32_t med;
-  u_int32_t local_pref;
-  as_t aggregator_as;
-  struct in_addr aggregator_addr;
-  u_int32_t weight;
-  struct in_addr originator_id;
-  struct cluster_list *cluster;
-
-  u_char mp_nexthop_len;
 #ifdef HAVE_IPV6
   struct in6_addr mp_nexthop_global;
   struct in6_addr mp_nexthop_local;
 #endif /* HAVE_IPV6 */
-  struct in_addr mp_nexthop_global_in;
-  struct in_addr mp_nexthop_local_in;
 
   /* AS Path structure */
   struct aspath *aspath;
@@ -81,9 +62,31 @@
 
   /* Extended Communities attribute. */
   struct ecommunity *ecommunity;
-
+  
+  /* Route-Reflector Cluster attribute */
+  struct cluster_list *cluster;
+  
   /* Unknown transitive attribute. */
   struct transit *transit;
+
+  /* Reference count of this attribute. */
+  unsigned long refcnt;
+
+  /* Flag of attribute is set or not. */
+  u_int32_t flag;
+  
+  /* Apart from in6_addr, the remaining static attributes */
+  struct in_addr nexthop;
+  u_int32_t med;
+  u_int32_t local_pref;
+  struct in_addr aggregator_addr;
+  struct in_addr originator_id;
+  struct in_addr mp_nexthop_global_in;
+  struct in_addr mp_nexthop_local_in;
+  u_int32_t weight;
+  as_t aggregator_as;
+  u_char origin;
+  u_char mp_nexthop_len;
 };
 
 /* Router Reflector related structure. */
@@ -129,6 +132,8 @@
 extern unsigned int attrhash_key_make (struct attr *);
 extern int attrhash_cmp (struct attr *, struct attr *);
 extern void attr_show_all (struct vty *);
+extern unsigned long int attr_count (void);
+extern unsigned long int attr_unknown_count (void);
 
 /* Cluster list prototypes. */
 extern int cluster_loop_check (struct cluster_list *, struct in_addr);
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index 24be30f..e5f3ae5 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -29,20 +29,27 @@
   struct bgp_info *next;
   struct bgp_info *prev;
   
+  /* Peer structure.  */
+  struct peer *peer;
+
+  /* Attribute structure.  */
+  struct attr *attr;
+
+  /* Pointer to dampening structure.  */
+  struct bgp_damp_info *damp_info;
+
+  /* Uptime.  */
+  time_t uptime;
+
+  /* This route is suppressed with aggregation.  */
+  int suppress;
+  
+  /* Nexthop reachability check.  */
+  u_int32_t igpmetric;
+
   /* reference count */
   unsigned int lock;
   
-  /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
-  u_char type;
-
-  /* When above type is BGP.  This sub type specify BGP sub type
-     information.  */
-  u_char sub_type;
-#define BGP_ROUTE_NORMAL       0
-#define BGP_ROUTE_STATIC       1
-#define BGP_ROUTE_AGGREGATE    2
-#define BGP_ROUTE_REDISTRIBUTE 3 
-
   /* BGP information status.  */
   u_int16_t flags;
 #define BGP_INFO_IGP_CHANGED    (1 << 0)
@@ -57,26 +64,19 @@
 #define BGP_INFO_REMOVED        (1 << 9)
 #define BGP_INFO_COUNTED	(1 << 10)
 
-  /* Peer structure.  */
-  struct peer *peer;
-
-  /* Attribute structure.  */
-  struct attr *attr;
-
-  /* This route is suppressed with aggregation.  */
-  int suppress;
-  
-  /* Nexthop reachability check.  */
-  u_int32_t igpmetric;
-
-  /* Uptime.  */
-  time_t uptime;
-
-  /* Pointer to dampening structure.  */
-  struct bgp_damp_info *damp_info;
-
   /* MPLS label.  */
   u_char tag[3];
+
+  /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
+  u_char type;
+
+  /* When above type is BGP.  This sub type specify BGP sub type
+     information.  */
+  u_char sub_type;
+#define BGP_ROUTE_NORMAL       0
+#define BGP_ROUTE_STATIC       1
+#define BGP_ROUTE_AGGREGATE    2
+#define BGP_ROUTE_REDISTRIBUTE 3 
 };
 
 /* BGP static route configuration. */
diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c
index a3b489d..810dab5 100644
--- a/bgpd/bgp_table.c
+++ b/bgpd/bgp_table.c
@@ -350,8 +350,10 @@
 	  match = new;
 	  new = bgp_node_set (table, p);
 	  set_link (match, new);
+	  table->count++;
 	}
     }
+  table->count++;
   bgp_lock_node (new);
   
   return new;
@@ -389,7 +391,9 @@
     }
   else
     node->table->top = child;
-
+  
+  node->table->count--;
+  
   bgp_node_free (node);
 
   /* If parent node is stub then delete it also. */
@@ -492,3 +496,9 @@
   bgp_unlock_node (start);
   return NULL;
 }
+
+unsigned long
+bgp_table_count (struct bgp_table *table)
+{
+  return table->count;
+}
diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h
index e13022b..62421e7 100644
--- a/bgpd/bgp_table.h
+++ b/bgpd/bgp_table.h
@@ -39,6 +39,8 @@
   void *owner;
 
   struct bgp_node *top;
+  
+  unsigned long count;
 };
 
 struct bgp_node
@@ -51,18 +53,16 @@
 #define l_left   link[0]
 #define l_right  link[1]
 
-  unsigned int lock;
-
   void *info;
 
   struct bgp_adj_out *adj_out;
 
   struct bgp_adj_in *adj_in;
 
-  void *aggregate;
-
   struct bgp_node *prn;
 
+  unsigned int lock;
+
   u_char flags;
 #define BGP_NODE_PROCESS_SCHEDULED	(1 << 0)
 };
@@ -84,5 +84,5 @@
 extern struct bgp_node *bgp_node_match_ipv6 (struct bgp_table *,
 					  struct in6_addr *);
 #endif /* HAVE_IPV6 */
-
+extern unsigned long bgp_table_count (struct bgp_table *);
 #endif /* _QUAGGA_BGP_TABLE_H */