1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
6 * This file is part of RSTP library.
8 * RSTP library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; version 2.1
12 * RSTP library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with RSTP library; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 **********************************************************************/
23 /* Path Cost monitoring state machine */
27 #include "stp_to.h" /* for STP_OUT_get_port_oper_speed */
35 #define GET_STATE_NAME STP_pcost_get_state_name
39 computeAutoPCost (STATE_MACH_T
*this)
42 register PORT_T
* port
= this->owner
.port
;
44 if (port
->usedSpeed
< 10L) { /* < 10Mb/s */
46 } else if (port
->usedSpeed
<= 10L) { /* 10 Mb/s */
48 } else if (port
->usedSpeed
<= 100L) { /* 100 Mb/s */
50 } else if (port
->usedSpeed
<= 1000L) { /* 1 Gb/s */
52 } else if (port
->usedSpeed
<= 10000L) { /* 10 Gb/s */
54 } else if (port
->usedSpeed
<= 100000L) { /* 100 Gb/s */
56 } else if (port
->usedSpeed
<= 1000000L) { /* 1 GTb/s */
58 } else if (port
->usedSpeed
<= 10000000L) { /* 10 Tb/s */
60 } else /* ??? */ { /* > Tb/s */
64 if (port
->pcost
->debug
) {
65 stp_trace ("usedSpeed=%lu lret=%ld", port
->usedSpeed
, lret
);
73 updPortPathCost (PORT_T
*port
)
75 port
->reselect
= True
;
76 port
->selected
= False
;
80 STP_pcost_enter_state (STATE_MACH_T
*this)
82 register PORT_T
* port
= this->owner
.port
;
84 switch (this->State
) {
88 port
->operSpeed
= STP_OUT_get_port_oper_speed (port
->port_index
);
90 if (port
->pcost
->debug
) {
91 stp_trace ("AUTO:operSpeed=%lu", port
->operSpeed
);
94 port
->usedSpeed
= port
->operSpeed
;
95 port
->operPCost
= computeAutoPCost (this);
98 port
->operPCost
= port
->adminPCost
;
102 updPortPathCost (port
);
108 STP_pcost_check_conditions (STATE_MACH_T
* this)
110 register PORT_T
* port
= this->owner
.port
;
112 switch (this->State
) {
114 return STP_hop_2_state (this, AUTO
);
116 return STP_hop_2_state (this, STABLE
);
118 return STP_hop_2_state (this, STABLE
);
120 if (ADMIN_PORT_PATH_COST_AUTO
== port
->adminPCost
&&
121 port
->operSpeed
!= port
->usedSpeed
) {
122 return STP_hop_2_state (this, AUTO
);
125 if (ADMIN_PORT_PATH_COST_AUTO
!= port
->adminPCost
&&
126 port
->operPCost
!= port
->adminPCost
) {
127 return STP_hop_2_state (this, FORSE
);