]>
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 | |
51 | extern struct isis *isis; | |
52 | ||
2b64873d | 53 | static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT", |
d62a17ae | 54 | "C_STATE_CONF", "C_STATE_UP"}; |
eb5d44eb | 55 | |
56 | #define STATE2STR(S) csm_statestr[S] | |
57 | ||
2b64873d | 58 | static const char *const csm_eventstr[] = { |
d62a17ae | 59 | "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z", |
60 | "ISIS_DISABLE", "IF_DOWN_FROM_Z", | |
eb5d44eb | 61 | }; |
62 | ||
63 | #define EVENT2STR(E) csm_eventstr[E] | |
64 | ||
f390d2c7 | 65 | struct isis_circuit * |
d62a17ae | 66 | isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg) |
eb5d44eb | 67 | { |
d62a17ae | 68 | int old_state; |
eb5d44eb | 69 | |
d62a17ae | 70 | old_state = circuit ? circuit->state : C_STATE_NA; |
e740f9c1 | 71 | if (IS_DEBUG_EVENTS) |
d62a17ae | 72 | zlog_debug("CSM_EVENT: %s", EVENT2STR(event)); |
f390d2c7 | 73 | |
d62a17ae | 74 | switch (old_state) { |
75 | case C_STATE_NA: | |
76 | if (circuit) | |
77 | zlog_warn("Non-null circuit while state C_STATE_NA"); | |
78 | assert(circuit == NULL); | |
79 | switch (event) { | |
80 | case ISIS_ENABLE: | |
81 | circuit = isis_circuit_new(); | |
82 | isis_circuit_configure(circuit, | |
83 | (struct isis_area *)arg); | |
84 | circuit->state = C_STATE_CONF; | |
85 | break; | |
86 | case IF_UP_FROM_Z: | |
87 | circuit = isis_circuit_new(); | |
88 | isis_circuit_if_add(circuit, (struct interface *)arg); | |
89 | listnode_add(isis->init_circ_list, circuit); | |
90 | circuit->state = C_STATE_INIT; | |
91 | break; | |
92 | case ISIS_DISABLE: | |
93 | zlog_warn("circuit already disabled"); | |
94 | break; | |
95 | case IF_DOWN_FROM_Z: | |
96 | zlog_warn("circuit already disconnected"); | |
97 | break; | |
98 | } | |
99 | break; | |
100 | case C_STATE_INIT: | |
101 | assert(circuit); | |
102 | switch (event) { | |
103 | case ISIS_ENABLE: | |
104 | isis_circuit_configure(circuit, | |
105 | (struct isis_area *)arg); | |
106 | if (isis_circuit_up(circuit) != ISIS_OK) { | |
107 | isis_circuit_deconfigure( | |
108 | circuit, (struct isis_area *)arg); | |
109 | break; | |
110 | } | |
111 | circuit->state = C_STATE_UP; | |
112 | isis_event_circuit_state_change(circuit, circuit->area, | |
113 | 1); | |
114 | listnode_delete(isis->init_circ_list, circuit); | |
115 | break; | |
116 | case IF_UP_FROM_Z: | |
117 | assert(circuit); | |
118 | zlog_warn("circuit already connected"); | |
119 | break; | |
120 | case ISIS_DISABLE: | |
121 | zlog_warn("circuit already disabled"); | |
122 | break; | |
123 | case IF_DOWN_FROM_Z: | |
124 | isis_circuit_if_del(circuit, (struct interface *)arg); | |
125 | listnode_delete(isis->init_circ_list, circuit); | |
126 | isis_circuit_del(circuit); | |
127 | circuit = NULL; | |
128 | break; | |
129 | } | |
130 | break; | |
131 | case C_STATE_CONF: | |
132 | assert(circuit); | |
133 | switch (event) { | |
134 | case ISIS_ENABLE: | |
135 | zlog_warn("circuit already enabled"); | |
136 | break; | |
137 | case IF_UP_FROM_Z: | |
138 | isis_circuit_if_add(circuit, (struct interface *)arg); | |
139 | if (isis_circuit_up(circuit) != ISIS_OK) { | |
af4c2728 | 140 | flog_err( |
1a7ecb96 | 141 | EC_ISIS_CONFIG, |
d62a17ae | 142 | "Could not bring up %s because of invalid config.", |
143 | circuit->interface->name); | |
d62a17ae | 144 | break; |
145 | } | |
146 | circuit->state = C_STATE_UP; | |
147 | isis_event_circuit_state_change(circuit, circuit->area, | |
148 | 1); | |
149 | break; | |
150 | case ISIS_DISABLE: | |
151 | isis_circuit_deconfigure(circuit, | |
152 | (struct isis_area *)arg); | |
153 | isis_circuit_del(circuit); | |
154 | circuit = NULL; | |
155 | break; | |
156 | case IF_DOWN_FROM_Z: | |
157 | zlog_warn("circuit already disconnected"); | |
158 | break; | |
159 | } | |
160 | break; | |
161 | case C_STATE_UP: | |
162 | assert(circuit); | |
163 | switch (event) { | |
164 | case ISIS_ENABLE: | |
165 | zlog_warn("circuit already configured"); | |
166 | break; | |
167 | case IF_UP_FROM_Z: | |
168 | zlog_warn("circuit already connected"); | |
169 | break; | |
170 | case ISIS_DISABLE: | |
171 | isis_circuit_down(circuit); | |
172 | isis_circuit_deconfigure(circuit, | |
173 | (struct isis_area *)arg); | |
174 | circuit->state = C_STATE_INIT; | |
175 | isis_event_circuit_state_change( | |
176 | circuit, (struct isis_area *)arg, 0); | |
177 | listnode_add(isis->init_circ_list, circuit); | |
178 | break; | |
179 | case IF_DOWN_FROM_Z: | |
180 | isis_circuit_down(circuit); | |
181 | isis_circuit_if_del(circuit, (struct interface *)arg); | |
182 | circuit->state = C_STATE_CONF; | |
183 | isis_event_circuit_state_change(circuit, circuit->area, | |
184 | 0); | |
185 | break; | |
186 | } | |
187 | break; | |
f390d2c7 | 188 | |
d62a17ae | 189 | default: |
190 | zlog_warn("Invalid circuit state %d", old_state); | |
191 | } | |
f390d2c7 | 192 | |
e740f9c1 | 193 | if (IS_DEBUG_EVENTS) |
d62a17ae | 194 | zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state), |
195 | circuit ? STATE2STR(circuit->state) | |
196 | : STATE2STR(C_STATE_NA)); | |
eb5d44eb | 197 | |
d62a17ae | 198 | return circuit; |
eb5d44eb | 199 | } |