Re: [ovs-dev] [PATCH v6 17/18] lib/rstp: Eliminate ports_count.

2014-09-09 Thread Daniele Venturino
Acked-by: Daniele Venturino 

2014-08-21 1:57 GMT+02:00 Jarno Rajahalme :

> It was only used to guard against unintialized list.
>
> Signed-off-by: Jarno Rajahalme 
> ---
>  lib/rstp-common.h |1 -
>  lib/rstp-state-machines.c |  273
> -
>  lib/rstp.c|   89 +++
>  3 files changed, 164 insertions(+), 199 deletions(-)
>
> diff --git a/lib/rstp-common.h b/lib/rstp-common.h
> index d798ba2..2be5861 100644
> --- a/lib/rstp-common.h
> +++ b/lib/rstp-common.h
> @@ -867,7 +867,6 @@ struct rstp {
>
>  /* Ports */
>  struct list ports OVS_GUARDED_BY(rstp_mutex);
> -uint16_t ports_count OVS_GUARDED_BY(rstp_mutex);
>
>  struct ovs_refcount ref_cnt;
>
> diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
> index 5ae7124..c40449d 100644
> --- a/lib/rstp-state-machines.c
> +++ b/lib/rstp-state-machines.c
> @@ -190,18 +190,16 @@ move_rstp__(struct rstp *rstp)
>
>  rstp->changes = false;
>  port_role_selection_sm(rstp);
> -if (rstp->ports_count > 0) {
> -LIST_FOR_EACH (p, node, &rstp->ports) {
> -if (p->rstp_state != RSTP_DISABLED) {
> -port_receive_sm(p);
> -bridge_detection_sm(p);
> -port_information_sm(p);
> -port_role_transition_sm(p);
> -port_state_transition_sm(p);
> -topology_change_sm(p);
> -port_transmit_sm(p);
> -port_protocol_migration_sm(p);
> -}
> +LIST_FOR_EACH (p, node, &rstp->ports) {
> +if (p->rstp_state != RSTP_DISABLED) {
> +port_receive_sm(p);
> +bridge_detection_sm(p);
> +port_information_sm(p);
> +port_role_transition_sm(p);
> +port_state_transition_sm(p);
> +topology_change_sm(p);
> +port_transmit_sm(p);
> +port_protocol_migration_sm(p);
>  }
>  }
>  num_iterations++;
> @@ -219,19 +217,17 @@ void decrease_rstp_port_timers__(struct rstp *r)
>  {
>  struct rstp_port *p;
>
> -if (r->ports_count > 0) {
> -LIST_FOR_EACH (p, node, &r->ports) {
> -decrement_timer(&p->hello_when);
> -decrement_timer(&p->tc_while);
> -decrement_timer(&p->fd_while);
> -decrement_timer(&p->rcvd_info_while);
> -decrement_timer(&p->rr_while);
> -decrement_timer(&p->rb_while);
> -decrement_timer(&p->mdelay_while);
> -decrement_timer(&p->edge_delay_while);
> -decrement_timer(&p->tx_count);
> -p->uptime += 1;
> -}
> +LIST_FOR_EACH (p, node, &r->ports) {
> +decrement_timer(&p->hello_when);
> +decrement_timer(&p->tc_while);
> +decrement_timer(&p->fd_while);
> +decrement_timer(&p->rcvd_info_while);
> +decrement_timer(&p->rr_while);
> +decrement_timer(&p->rb_while);
> +decrement_timer(&p->mdelay_while);
> +decrement_timer(&p->edge_delay_while);
> +decrement_timer(&p->tx_count);
> +p->uptime += 1;
>  }
>  r->changes = true;
>  move_rstp__(r);
> @@ -254,10 +250,8 @@ updt_role_disabled_tree(struct rstp *r)
>  {
>  struct rstp_port *p;
>
> -if (r->ports_count > 0) {
> -LIST_FOR_EACH (p, node, &r->ports) {
> -p->selected_role = ROLE_DISABLED;
> -}
> +LIST_FOR_EACH (p, node, &r->ports) {
> +p->selected_role = ROLE_DISABLED;
>  }
>  }
>
> @@ -267,10 +261,8 @@ clear_reselect_tree(struct rstp *r)
>  {
>  struct rstp_port *p;
>
> -if (r->ports_count > 0) {
> -LIST_FOR_EACH (p, node, &r->ports) {
> -p->reselect = false;
> -}
> +LIST_FOR_EACH (p, node, &r->ports) {
> +p->reselect = false;
>  }
>  }
>
> @@ -287,32 +279,30 @@ updt_roles_tree__(struct rstp *r)
>  /* Letter c1) */
>  r->root_times = r->bridge_times;
>  /* Letters a) b) c) */
> -if (r->ports_count > 0) {
> -LIST_FOR_EACH (p, node, &r->ports) {
> -uint32_t old_root_path_cost;
> -uint32_t root_path_cost;
> +LIST_FOR_EACH (p, node, &r->ports) {
> +uint32_t old_root_path_cost;
> +uint32_t root_path_cost;
>
> -if (p->info_is != INFO_IS_RECEIVED) {
> -continue;
> -}
> -/* [17.6] */
> -candidate_vector = p->port_priority;
> -candidate_vector.bridge_port_id = p->port_id;
> -old_root_path_cost = candidate_vector.root_path_cost;
> -root_path_cost = old_root_path_cost + p->port_path_cost;
> -candidate_vector.root_path_cost = root_path_cost;
> -
> -if ((candidate_vector.designated_bridge_id &
> 0xULL) ==
> -(r->bridge_priority.designate

[ovs-dev] [PATCH v6 17/18] lib/rstp: Eliminate ports_count.

2014-08-20 Thread Jarno Rajahalme
It was only used to guard against unintialized list.

Signed-off-by: Jarno Rajahalme 
---
 lib/rstp-common.h |1 -
 lib/rstp-state-machines.c |  273 -
 lib/rstp.c|   89 +++
 3 files changed, 164 insertions(+), 199 deletions(-)

diff --git a/lib/rstp-common.h b/lib/rstp-common.h
index d798ba2..2be5861 100644
--- a/lib/rstp-common.h
+++ b/lib/rstp-common.h
@@ -867,7 +867,6 @@ struct rstp {
 
 /* Ports */
 struct list ports OVS_GUARDED_BY(rstp_mutex);
-uint16_t ports_count OVS_GUARDED_BY(rstp_mutex);
 
 struct ovs_refcount ref_cnt;
 
diff --git a/lib/rstp-state-machines.c b/lib/rstp-state-machines.c
index 5ae7124..c40449d 100644
--- a/lib/rstp-state-machines.c
+++ b/lib/rstp-state-machines.c
@@ -190,18 +190,16 @@ move_rstp__(struct rstp *rstp)
 
 rstp->changes = false;
 port_role_selection_sm(rstp);
-if (rstp->ports_count > 0) {
-LIST_FOR_EACH (p, node, &rstp->ports) {
-if (p->rstp_state != RSTP_DISABLED) {
-port_receive_sm(p);
-bridge_detection_sm(p);
-port_information_sm(p);
-port_role_transition_sm(p);
-port_state_transition_sm(p);
-topology_change_sm(p);
-port_transmit_sm(p);
-port_protocol_migration_sm(p);
-}
+LIST_FOR_EACH (p, node, &rstp->ports) {
+if (p->rstp_state != RSTP_DISABLED) {
+port_receive_sm(p);
+bridge_detection_sm(p);
+port_information_sm(p);
+port_role_transition_sm(p);
+port_state_transition_sm(p);
+topology_change_sm(p);
+port_transmit_sm(p);
+port_protocol_migration_sm(p);
 }
 }
 num_iterations++;
@@ -219,19 +217,17 @@ void decrease_rstp_port_timers__(struct rstp *r)
 {
 struct rstp_port *p;
 
-if (r->ports_count > 0) {
-LIST_FOR_EACH (p, node, &r->ports) {
-decrement_timer(&p->hello_when);
-decrement_timer(&p->tc_while);
-decrement_timer(&p->fd_while);
-decrement_timer(&p->rcvd_info_while);
-decrement_timer(&p->rr_while);
-decrement_timer(&p->rb_while);
-decrement_timer(&p->mdelay_while);
-decrement_timer(&p->edge_delay_while);
-decrement_timer(&p->tx_count);
-p->uptime += 1;
-}
+LIST_FOR_EACH (p, node, &r->ports) {
+decrement_timer(&p->hello_when);
+decrement_timer(&p->tc_while);
+decrement_timer(&p->fd_while);
+decrement_timer(&p->rcvd_info_while);
+decrement_timer(&p->rr_while);
+decrement_timer(&p->rb_while);
+decrement_timer(&p->mdelay_while);
+decrement_timer(&p->edge_delay_while);
+decrement_timer(&p->tx_count);
+p->uptime += 1;
 }
 r->changes = true;
 move_rstp__(r);
@@ -254,10 +250,8 @@ updt_role_disabled_tree(struct rstp *r)
 {
 struct rstp_port *p;
 
-if (r->ports_count > 0) {
-LIST_FOR_EACH (p, node, &r->ports) {
-p->selected_role = ROLE_DISABLED;
-}
+LIST_FOR_EACH (p, node, &r->ports) {
+p->selected_role = ROLE_DISABLED;
 }
 }
 
@@ -267,10 +261,8 @@ clear_reselect_tree(struct rstp *r)
 {
 struct rstp_port *p;
 
-if (r->ports_count > 0) {
-LIST_FOR_EACH (p, node, &r->ports) {
-p->reselect = false;
-}
+LIST_FOR_EACH (p, node, &r->ports) {
+p->reselect = false;
 }
 }
 
@@ -287,32 +279,30 @@ updt_roles_tree__(struct rstp *r)
 /* Letter c1) */
 r->root_times = r->bridge_times;
 /* Letters a) b) c) */
-if (r->ports_count > 0) {
-LIST_FOR_EACH (p, node, &r->ports) {
-uint32_t old_root_path_cost;
-uint32_t root_path_cost;
+LIST_FOR_EACH (p, node, &r->ports) {
+uint32_t old_root_path_cost;
+uint32_t root_path_cost;
 
-if (p->info_is != INFO_IS_RECEIVED) {
-continue;
-}
-/* [17.6] */
-candidate_vector = p->port_priority;
-candidate_vector.bridge_port_id = p->port_id;
-old_root_path_cost = candidate_vector.root_path_cost;
-root_path_cost = old_root_path_cost + p->port_path_cost;
-candidate_vector.root_path_cost = root_path_cost;
-
-if ((candidate_vector.designated_bridge_id & 0xULL) ==
-(r->bridge_priority.designated_bridge_id & 0xULL)) 
{
-break;
-}
-if (compare_rstp_priority_vector(&candidate_vector, &best_vector)
-== SUPERIOR) {
-best_vector = candidate_vector;
-r->root_times = p->port_times;
-r->root_times.message_age+