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
);
74 updPortPathCost (STATE_MACH_T
*this)
79 STP_pcost_enter_state (STATE_MACH_T
*this)
81 register PORT_T
* port
= this->owner
.port
;
83 switch (this->State
) {
87 port
->operSpeed
= STP_OUT_get_port_oper_speed (port
->port_index
);
89 if (port
->pcost
->debug
) {
90 stp_trace ("AUTO:operSpeed=%lu", port
->operSpeed
);
93 port
->usedSpeed
= port
->operSpeed
;
94 port
->operPCost
= computeAutoPCost (this);
97 port
->operPCost
= port
->adminPCost
;
98 port
->usedSpeed
= (unsigned long)-1;
101 updPortPathCost (this);
107 STP_pcost_check_conditions (STATE_MACH_T
* this)
109 register PORT_T
* port
= this->owner
.port
;
111 switch (this->State
) {
113 return STP_hop_2_state (this, AUTO
);
115 return STP_hop_2_state (this, STABLE
);
117 return STP_hop_2_state (this, STABLE
);
119 if (ADMIN_PORT_PATH_COST_AUTO
== port
->adminPCost
&&
120 port
->operSpeed
!= port
->usedSpeed
) {
121 return STP_hop_2_state (this, AUTO
);
124 if (ADMIN_PORT_PATH_COST_AUTO
!= port
->adminPCost
&&
125 port
->operPCost
!= port
->adminPCost
) {
126 return STP_hop_2_state (this, FORSE
);