]>
Commit | Line | Data |
---|---|---|
ad02a0eb SH |
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 | /* Topolgy Change state machine : 17.25 */ | |
24 | ||
25 | #include "base.h" | |
26 | #include "stpm.h" | |
27 | #include "stp_to.h" /* for STP_OUT_flush_lt */ | |
28 | ||
29 | #define STATES { \ | |
30 | CHOOSE(INIT), \ | |
31 | CHOOSE(INACTIVE), \ | |
32 | CHOOSE(TCACTIVE), \ | |
33 | CHOOSE(DETECTED), \ | |
34 | CHOOSE(NOTIFIED_TC), \ | |
35 | CHOOSE(PROPAGATING), \ | |
36 | CHOOSE(ACKNOWLEDGED), \ | |
37 | CHOOSE(NOTIFIED_TCN), \ | |
38 | } | |
39 | ||
40 | #define GET_STATE_NAME STP_topoch_get_state_name | |
41 | #include "choose.h" | |
42 | ||
43 | /* We can flush learned fdb by port, so set this in stpm.c and topoch.c */ | |
44 | /* This doesn't seem to solve the topology change problems. Don't use it yet */ | |
45 | //#define STRONGLY_SPEC_802_1W | |
46 | ||
47 | #ifndef STRONGLY_SPEC_802_1W | |
48 | /* | |
49 | * In many kinds of hardware the function | |
50 | * STP_OUT_flush_lt is a) is very hard and b) cannot | |
51 | * delete learning emtries per port. The alternate | |
52 | * method may be used: we don't care operEdge flag here, | |
53 | * but clean learning table once for TopologyChange | |
54 | * for all ports, except the received port. I am ready to discuss :( | |
55 | * See below word STRONGLY_SPEC_802_1W | |
56 | */ | |
57 | #else | |
58 | static Bool | |
59 | flush (STATE_MACH_T *this, char* reason) /* 17.19.9 */ | |
60 | { | |
61 | register PORT_T* port = this->owner.port; | |
62 | Bool bret; | |
63 | ||
64 | if (port->operEdge) return True; | |
65 | if (this->debug) { | |
66 | stp_trace("%s (%s, %s, %s, '%s')", | |
67 | "flush", port->port_name, port->owner->name, | |
68 | "this port", | |
69 | reason); | |
70 | } | |
71 | ||
72 | bret = STP_OUT_flush_lt (port->port_index, port->owner->vlan_id, | |
73 | LT_FLASH_ONLY_THE_PORT, reason); | |
74 | return bret; | |
75 | } | |
76 | #endif | |
77 | ||
78 | static void | |
79 | setTcPropBridge (STATE_MACH_T* this, char* reason) /* 17.19.14 */ | |
80 | { | |
81 | register PORT_T* port = this->owner.port; | |
82 | register PORT_T* tmp; | |
83 | ||
84 | for (tmp = port->owner->ports; tmp; tmp = tmp->next) { | |
85 | if (tmp->port_index != port->port_index) | |
86 | tmp->tcProp = True; | |
87 | } | |
88 | ||
89 | #ifndef STRONGLY_SPEC_802_1W | |
90 | #ifdef STP_DBG | |
91 | if (this->debug) { | |
92 | stp_trace("%s (%s, %s, %s, '%s')", | |
93 | "clearFDB", port->port_name, port->owner->name, | |
94 | "other ports", reason); | |
95 | } | |
96 | #endif | |
97 | ||
98 | STP_OUT_flush_lt (port->port_index, port->owner->vlan_id, | |
99 | LT_FLASH_ALL_PORTS_EXCLUDE_THIS, reason); | |
100 | #endif | |
101 | } | |
102 | ||
103 | static unsigned int | |
104 | newTcWhile (STATE_MACH_T* this) /* 17.19.7 */ | |
105 | { | |
106 | register PORT_T* port = this->owner.port; | |
107 | ||
108 | if (port->sendRSTP && port->operPointToPointMac) { | |
109 | return 2 * port->owner->rootTimes.HelloTime; | |
110 | } | |
111 | #ifdef ORIG | |
112 | return port->owner->rootTimes.MaxAge; | |
113 | #else | |
114 | return port->owner->rootTimes.MaxAge + port->owner->rootTimes.ForwardDelay; | |
115 | #endif | |
116 | } | |
117 | ||
118 | void | |
119 | STP_topoch_enter_state (STATE_MACH_T* this) | |
120 | { | |
121 | register PORT_T* port = this->owner.port; | |
122 | ||
123 | switch (this->State) { | |
124 | case BEGIN: | |
125 | case INIT: | |
126 | #ifdef STRONGLY_SPEC_802_1W | |
127 | flush (this, "topoch INIT"); | |
128 | #endif | |
129 | port->tcWhile = 0; | |
130 | port->tc = | |
131 | port->tcProp = | |
132 | port->tcAck = False; | |
133 | break; | |
134 | case INACTIVE: | |
135 | port->rcvdTc = | |
136 | port->rcvdTcn = | |
137 | port->rcvdTcAck = port->tc = port->tcProp = False; | |
138 | break; | |
139 | case TCACTIVE: | |
140 | break; | |
141 | case DETECTED: | |
142 | port->tcWhile = newTcWhile (this); | |
143 | #ifdef STP_DBG | |
144 | if (this->debug) | |
145 | stp_trace("DETECTED: tcWhile=%d on port %s", | |
146 | port->tcWhile, port->port_name); | |
147 | #endif | |
148 | setTcPropBridge (this, "DETECTED"); | |
149 | port->tc = False; | |
150 | break; | |
151 | case NOTIFIED_TC: | |
152 | port->rcvdTcn = port->rcvdTc = False; | |
153 | if (port->role == DesignatedPort) { | |
154 | port->tcAck = True; | |
155 | } | |
156 | setTcPropBridge (this, "NOTIFIED_TC"); | |
157 | break; | |
158 | case PROPAGATING: | |
159 | port->tcWhile = newTcWhile (this); | |
160 | #ifdef STP_DBG | |
161 | if (this->debug) | |
162 | stp_trace("PROPAGATING: tcWhile=%d on port %s", | |
163 | port->tcWhile, port->port_name); | |
164 | #endif | |
165 | #ifdef STRONGLY_SPEC_802_1W | |
166 | flush (this, "topoch PROPAGATING"); | |
167 | #endif | |
168 | port->tcProp = False; | |
169 | break; | |
170 | case ACKNOWLEDGED: | |
171 | port->tcWhile = 0; | |
172 | #ifdef STP_DBG | |
173 | if (this->debug) | |
174 | stp_trace("ACKNOWLEDGED: tcWhile=%d on port %s", | |
175 | port->tcWhile, port->port_name); | |
176 | #endif | |
177 | port->rcvdTcAck = False; | |
178 | break; | |
179 | case NOTIFIED_TCN: | |
180 | port->tcWhile = newTcWhile (this); | |
181 | #ifdef STP_DBG | |
182 | if (this->debug) | |
183 | stp_trace("NOTIFIED_TCN: tcWhile=%d on port %s", | |
184 | port->tcWhile, port->port_name); | |
185 | #endif | |
186 | break; | |
187 | }; | |
188 | } | |
189 | ||
190 | Bool | |
191 | STP_topoch_check_conditions (STATE_MACH_T* this) | |
192 | { | |
193 | register PORT_T* port = this->owner.port; | |
194 | ||
195 | if (BEGIN == this->State) { | |
196 | return STP_hop_2_state (this, INIT); | |
197 | } | |
198 | ||
199 | switch (this->State) { | |
200 | case INIT: | |
201 | return STP_hop_2_state (this, INACTIVE); | |
202 | case INACTIVE: | |
203 | if (port->role == RootPort || port->role == DesignatedPort) | |
204 | return STP_hop_2_state (this, TCACTIVE); | |
205 | if (port->rcvdTc || port->rcvdTcn || port->rcvdTcAck || | |
206 | port->tc || port->tcProp) | |
207 | return STP_hop_2_state (this, INACTIVE); | |
208 | break; | |
209 | case TCACTIVE: | |
210 | if (port->role != RootPort && (port->role != DesignatedPort)) | |
211 | return STP_hop_2_state (this, INIT); | |
212 | if (port->tc) | |
213 | return STP_hop_2_state (this, DETECTED); | |
214 | if (port->rcvdTcn) | |
215 | return STP_hop_2_state (this, NOTIFIED_TCN); | |
216 | if (port->rcvdTc) | |
217 | return STP_hop_2_state (this, NOTIFIED_TC); | |
218 | if (port->tcProp && !port->operEdge) | |
219 | return STP_hop_2_state (this, PROPAGATING); | |
220 | if (port->rcvdTcAck) | |
221 | return STP_hop_2_state (this, ACKNOWLEDGED); | |
222 | break; | |
223 | case DETECTED: | |
224 | return STP_hop_2_state (this, TCACTIVE); | |
225 | case NOTIFIED_TC: | |
226 | return STP_hop_2_state (this, TCACTIVE); | |
227 | case PROPAGATING: | |
228 | return STP_hop_2_state (this, TCACTIVE); | |
229 | case ACKNOWLEDGED: | |
230 | return STP_hop_2_state (this, TCACTIVE); | |
231 | case NOTIFIED_TCN: | |
232 | return STP_hop_2_state (this, NOTIFIED_TC); | |
233 | }; | |
234 | return False; | |
235 | } | |
236 |