]> git.ipfire.org Git - people/ms/rstp.git/blob - rstplib/pcost.c
remove ifdef'd code
[people/ms/rstp.git] / rstplib / pcost.c
1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
4 * Author: Alex Rozin
5 *
6 * This file is part of RSTP library.
7 *
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
11 *
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.
16 *
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
20 * 02111-1307, USA.
21 **********************************************************************/
22
23 /* Path Cost monitoring state machine */
24
25 #include "base.h"
26 #include "stpm.h"
27 #include "stp_to.h" /* for STP_OUT_get_port_oper_speed */
28
29 #define STATES { \
30 CHOOSE(AUTO), \
31 CHOOSE(FORSE), \
32 CHOOSE(STABLE), \
33 }
34
35 #define GET_STATE_NAME STP_pcost_get_state_name
36 #include "choose.h"
37
38 static long
39 computeAutoPCost (STATE_MACH_T *this)
40 {
41 long lret;
42 register PORT_T* port = this->owner.port;
43
44 if (port->usedSpeed < 10L) { /* < 10Mb/s */
45 lret = 20000000;
46 } else if (port->usedSpeed <= 10L) { /* 10 Mb/s */
47 lret = 2000000;
48 } else if (port->usedSpeed <= 100L) { /* 100 Mb/s */
49 lret = 200000;
50 } else if (port->usedSpeed <= 1000L) { /* 1 Gb/s */
51 lret = 20000;
52 } else if (port->usedSpeed <= 10000L) { /* 10 Gb/s */
53 lret = 2000;
54 } else if (port->usedSpeed <= 100000L) { /* 100 Gb/s */
55 lret = 200;
56 } else if (port->usedSpeed <= 1000000L) { /* 1 GTb/s */
57 lret = 20;
58 } else if (port->usedSpeed <= 10000000L) { /* 10 Tb/s */
59 lret = 2;
60 } else /* ??? */ { /* > Tb/s */
61 lret = 1;
62 }
63 #ifdef STP_DBG
64 if (port->pcost->debug) {
65 stp_trace ("usedSpeed=%lu lret=%ld", port->usedSpeed, lret);
66 }
67 #endif
68
69 return lret;
70 }
71
72 static void
73 updPortPathCost (PORT_T *port)
74 {
75 port->reselect = True;
76 port->selected = False;
77 }
78
79 void
80 STP_pcost_enter_state (STATE_MACH_T *this)
81 {
82 register PORT_T* port = this->owner.port;
83
84 switch (this->State) {
85 case BEGIN:
86 break;
87 case AUTO:
88 port->operSpeed = STP_OUT_get_port_oper_speed (port->port_index);
89 #ifdef STP_DBG
90 if (port->pcost->debug) {
91 stp_trace ("AUTO:operSpeed=%lu", port->operSpeed);
92 }
93 #endif
94 port->usedSpeed = port->operSpeed;
95 port->operPCost = computeAutoPCost (this);
96 break;
97 case FORSE:
98 port->operPCost = port->adminPCost;
99 port->usedSpeed = -1;
100 break;
101 case STABLE:
102 updPortPathCost (port);
103 break;
104 }
105 }
106
107 Bool
108 STP_pcost_check_conditions (STATE_MACH_T* this)
109 {
110 register PORT_T* port = this->owner.port;
111
112 switch (this->State) {
113 case BEGIN:
114 return STP_hop_2_state (this, AUTO);
115 case AUTO:
116 return STP_hop_2_state (this, STABLE);
117 case FORSE:
118 return STP_hop_2_state (this, STABLE);
119 case STABLE:
120 if (ADMIN_PORT_PATH_COST_AUTO == port->adminPCost &&
121 port->operSpeed != port->usedSpeed) {
122 return STP_hop_2_state (this, AUTO);
123 }
124
125 if (ADMIN_PORT_PATH_COST_AUTO != port->adminPCost &&
126 port->operPCost != port->adminPCost) {
127 return STP_hop_2_state (this, FORSE);
128 }
129 break;
130 }
131 return False;
132 }
133