]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_csm.c | |
3 | * IS-IS circuit state machine | |
4 | * Copyright (C) 2001,2002 Sampo Saaristo | |
d62a17ae | 5 | * Tampere University of Technology |
eb5d44eb | 6 | * Institute of Communications Engineering |
7 | * | |
d62a17ae | 8 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public Licenseas published by the Free | |
10 | * Software Foundation; either version 2 of the License, or (at your option) | |
eb5d44eb | 11 | * any later version. |
12 | * | |
d62a17ae | 13 | * This program is distributed in the hope that it will be useful,but WITHOUT |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
eb5d44eb | 16 | * more details. |
17 | * | |
896014f4 DL |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
eb5d44eb | 21 | */ |
22 | ||
23 | #include <zebra.h> | |
eb5d44eb | 24 | |
25 | #include "log.h" | |
26 | #include "memory.h" | |
27 | #include "if.h" | |
28 | #include "linklist.h" | |
29 | #include "command.h" | |
30 | #include "thread.h" | |
31 | #include "hash.h" | |
32 | #include "prefix.h" | |
33 | #include "stream.h" | |
34 | ||
eb5d44eb | 35 | #include "isisd/isis_constants.h" |
36 | #include "isisd/isis_common.h" | |
3f045a08 | 37 | #include "isisd/isis_flags.h" |
eb5d44eb | 38 | #include "isisd/isis_circuit.h" |
eb5d44eb | 39 | #include "isisd/isis_lsp.h" |
40 | #include "isisd/isis_pdu.h" | |
41 | #include "isisd/isis_network.h" | |
42 | #include "isisd/isis_misc.h" | |
43 | #include "isisd/isis_constants.h" | |
44 | #include "isisd/isis_adjacency.h" | |
45 | #include "isisd/isis_dr.h" | |
eb5d44eb | 46 | #include "isisd/isisd.h" |
47 | #include "isisd/isis_csm.h" | |
48 | #include "isisd/isis_events.h" | |
54ece698 | 49 | #include "isisd/isis_errors.h" |
eb5d44eb | 50 | |
2b64873d | 51 | static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT", |
d62a17ae | 52 | "C_STATE_CONF", "C_STATE_UP"}; |
eb5d44eb | 53 | |
54 | #define STATE2STR(S) csm_statestr[S] | |
55 | ||
2b64873d | 56 | static const char *const csm_eventstr[] = { |
d62a17ae | 57 | "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z", |
58 | "ISIS_DISABLE", "IF_DOWN_FROM_Z", | |
eb5d44eb | 59 | }; |
60 | ||
61 | #define EVENT2STR(E) csm_eventstr[E] | |
62 | ||
9d454ad2 DS |
63 | struct isis_circuit *isis_csm_state_change(enum isis_circuit_event event, |
64 | struct isis_circuit *circuit, | |
65 | void *arg) | |
eb5d44eb | 66 | { |
61cd5761 | 67 | enum isis_circuit_state old_state; |
eab88f36 | 68 | struct isis *isis = NULL; |
bfa51457 | 69 | struct isis_area *area = NULL; |
c5b8ce06 | 70 | struct interface *ifp; |
eb5d44eb | 71 | |
d62a17ae | 72 | old_state = circuit ? circuit->state : C_STATE_NA; |
e740f9c1 | 73 | if (IS_DEBUG_EVENTS) |
d62a17ae | 74 | zlog_debug("CSM_EVENT: %s", EVENT2STR(event)); |
f390d2c7 | 75 | |
d62a17ae | 76 | switch (old_state) { |
77 | case C_STATE_NA: | |
78 | if (circuit) | |
79 | zlog_warn("Non-null circuit while state C_STATE_NA"); | |
80 | assert(circuit == NULL); | |
81 | switch (event) { | |
82 | case ISIS_ENABLE: | |
bfa51457 DS |
83 | area = arg; |
84 | ||
85 | circuit = isis_circuit_new(area->isis); | |
86 | isis_circuit_configure(circuit, area); | |
d62a17ae | 87 | circuit->state = C_STATE_CONF; |
88 | break; | |
89 | case IF_UP_FROM_Z: | |
c5b8ce06 DS |
90 | ifp = arg; |
91 | isis = isis_lookup_by_vrfid(ifp->vrf_id); | |
eab88f36 | 92 | if (isis == NULL) { |
c5b8ce06 DS |
93 | if (IS_DEBUG_EVENTS) |
94 | zlog_debug( | |
95 | " %s : ISIS routing instance not found when attempting to apply against interface %s", | |
96 | __func__, ifp->name); | |
eab88f36 K |
97 | break; |
98 | } | |
bfa51457 | 99 | circuit = isis_circuit_new(isis); |
c5b8ce06 | 100 | isis_circuit_if_add(circuit, ifp); |
d62a17ae | 101 | listnode_add(isis->init_circ_list, circuit); |
102 | circuit->state = C_STATE_INIT; | |
103 | break; | |
104 | case ISIS_DISABLE: | |
c5b8ce06 DS |
105 | if (IS_DEBUG_EVENTS) |
106 | zlog_debug( | |
107 | "circuit disable event passed for a non existent circuit"); | |
d62a17ae | 108 | break; |
109 | case IF_DOWN_FROM_Z: | |
c5b8ce06 DS |
110 | if (IS_DEBUG_EVENTS) |
111 | zlog_debug( | |
112 | "circuit disconnect event passed for a non existent circuit"); | |
d62a17ae | 113 | break; |
114 | } | |
115 | break; | |
116 | case C_STATE_INIT: | |
117 | assert(circuit); | |
118 | switch (event) { | |
119 | case ISIS_ENABLE: | |
120 | isis_circuit_configure(circuit, | |
121 | (struct isis_area *)arg); | |
122 | if (isis_circuit_up(circuit) != ISIS_OK) { | |
123 | isis_circuit_deconfigure( | |
124 | circuit, (struct isis_area *)arg); | |
125 | break; | |
126 | } | |
127 | circuit->state = C_STATE_UP; | |
128 | isis_event_circuit_state_change(circuit, circuit->area, | |
129 | 1); | |
0bcdb96b | 130 | listnode_delete(circuit->isis->init_circ_list, |
eab88f36 | 131 | circuit); |
d62a17ae | 132 | break; |
133 | case IF_UP_FROM_Z: | |
c5b8ce06 DS |
134 | if (IS_DEBUG_EVENTS) |
135 | zlog_debug("circuit %s already connected", | |
136 | circuit->interface->name); | |
d62a17ae | 137 | break; |
138 | case ISIS_DISABLE: | |
c5b8ce06 DS |
139 | if (IS_DEBUG_EVENTS) |
140 | zlog_debug("circuit %s already disabled", | |
141 | circuit->interface->name); | |
d62a17ae | 142 | break; |
143 | case IF_DOWN_FROM_Z: | |
144 | isis_circuit_if_del(circuit, (struct interface *)arg); | |
0bcdb96b IR |
145 | listnode_delete(circuit->isis->init_circ_list, |
146 | circuit); | |
d62a17ae | 147 | isis_circuit_del(circuit); |
148 | circuit = NULL; | |
149 | break; | |
150 | } | |
151 | break; | |
152 | case C_STATE_CONF: | |
153 | assert(circuit); | |
154 | switch (event) { | |
155 | case ISIS_ENABLE: | |
c5b8ce06 DS |
156 | if (IS_DEBUG_EVENTS) |
157 | zlog_debug("circuit %p is already enabled", | |
158 | circuit); | |
d62a17ae | 159 | break; |
160 | case IF_UP_FROM_Z: | |
161 | isis_circuit_if_add(circuit, (struct interface *)arg); | |
162 | if (isis_circuit_up(circuit) != ISIS_OK) { | |
733c4db5 | 163 | isis_circuit_if_del(circuit, (struct interface *)arg); |
af4c2728 | 164 | flog_err( |
1a7ecb96 | 165 | EC_ISIS_CONFIG, |
d62a17ae | 166 | "Could not bring up %s because of invalid config.", |
167 | circuit->interface->name); | |
d62a17ae | 168 | break; |
169 | } | |
170 | circuit->state = C_STATE_UP; | |
171 | isis_event_circuit_state_change(circuit, circuit->area, | |
172 | 1); | |
173 | break; | |
174 | case ISIS_DISABLE: | |
175 | isis_circuit_deconfigure(circuit, | |
176 | (struct isis_area *)arg); | |
177 | isis_circuit_del(circuit); | |
178 | circuit = NULL; | |
179 | break; | |
180 | case IF_DOWN_FROM_Z: | |
c5b8ce06 DS |
181 | if (IS_DEBUG_EVENTS) |
182 | zlog_debug("circuit %p already disconnected", | |
183 | circuit); | |
d62a17ae | 184 | break; |
185 | } | |
186 | break; | |
187 | case C_STATE_UP: | |
188 | assert(circuit); | |
189 | switch (event) { | |
190 | case ISIS_ENABLE: | |
c5b8ce06 DS |
191 | if (IS_DEBUG_EVENTS) |
192 | zlog_debug("circuit %s already configured", | |
193 | circuit->interface->name); | |
d62a17ae | 194 | break; |
195 | case IF_UP_FROM_Z: | |
c5b8ce06 DS |
196 | if (IS_DEBUG_EVENTS) |
197 | zlog_debug("circuit %s already connected", | |
198 | circuit->interface->name); | |
d62a17ae | 199 | break; |
200 | case ISIS_DISABLE: | |
bfa51457 | 201 | isis = circuit->isis; |
d62a17ae | 202 | isis_circuit_down(circuit); |
203 | isis_circuit_deconfigure(circuit, | |
204 | (struct isis_area *)arg); | |
205 | circuit->state = C_STATE_INIT; | |
206 | isis_event_circuit_state_change( | |
207 | circuit, (struct isis_area *)arg, 0); | |
208 | listnode_add(isis->init_circ_list, circuit); | |
209 | break; | |
210 | case IF_DOWN_FROM_Z: | |
211 | isis_circuit_down(circuit); | |
212 | isis_circuit_if_del(circuit, (struct interface *)arg); | |
213 | circuit->state = C_STATE_CONF; | |
214 | isis_event_circuit_state_change(circuit, circuit->area, | |
215 | 0); | |
216 | break; | |
217 | } | |
218 | break; | |
d62a17ae | 219 | } |
f390d2c7 | 220 | |
e740f9c1 | 221 | if (IS_DEBUG_EVENTS) |
d62a17ae | 222 | zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state), |
223 | circuit ? STATE2STR(circuit->state) | |
224 | : STATE2STR(C_STATE_NA)); | |
eb5d44eb | 225 | |
d62a17ae | 226 | return circuit; |
eb5d44eb | 227 | } |