]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #6912 from GalaxyGorilla/ospf_ti_lfa_prep
[mirror_frr.git] / isisd / isis_csm.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_csm.c
3 * IS-IS circuit state machine
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
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)
11 * any later version.
12 *
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
16 * more details.
17 *
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
21 */
22
23 #include <zebra.h>
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
35 #include "isisd/isis_constants.h"
36 #include "isisd/isis_common.h"
37 #include "isisd/isis_flags.h"
38 #include "isisd/isis_circuit.h"
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"
46 #include "isisd/isisd.h"
47 #include "isisd/isis_csm.h"
48 #include "isisd/isis_events.h"
49 #include "isisd/isis_errors.h"
50
51 static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
52 "C_STATE_CONF", "C_STATE_UP"};
53
54 #define STATE2STR(S) csm_statestr[S]
55
56 static const char *const csm_eventstr[] = {
57 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
58 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
59 };
60
61 #define EVENT2STR(E) csm_eventstr[E]
62
63 struct isis_circuit *
64 isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
65 {
66 int old_state;
67 struct isis *isis = NULL;
68
69 old_state = circuit ? circuit->state : C_STATE_NA;
70 if (IS_DEBUG_EVENTS)
71 zlog_debug("CSM_EVENT: %s", EVENT2STR(event));
72
73 switch (old_state) {
74 case C_STATE_NA:
75 if (circuit)
76 zlog_warn("Non-null circuit while state C_STATE_NA");
77 assert(circuit == NULL);
78 switch (event) {
79 case ISIS_ENABLE:
80 circuit = isis_circuit_new();
81 isis_circuit_configure(circuit,
82 (struct isis_area *)arg);
83 circuit->state = C_STATE_CONF;
84 break;
85 case IF_UP_FROM_Z:
86 circuit = isis_circuit_new();
87 isis_circuit_if_add(circuit, (struct interface *)arg);
88 isis = isis_lookup_by_vrfid(circuit->interface->vrf_id);
89 if (isis == NULL) {
90 zlog_warn(
91 " %s : ISIS routing instance not found",
92 __func__);
93 break;
94 }
95 listnode_add(isis->init_circ_list, circuit);
96 circuit->state = C_STATE_INIT;
97 break;
98 case ISIS_DISABLE:
99 zlog_warn("circuit already disabled");
100 break;
101 case IF_DOWN_FROM_Z:
102 zlog_warn("circuit already disconnected");
103 break;
104 }
105 break;
106 case C_STATE_INIT:
107 assert(circuit);
108 switch (event) {
109 case ISIS_ENABLE:
110 isis_circuit_configure(circuit,
111 (struct isis_area *)arg);
112 if (isis_circuit_up(circuit) != ISIS_OK) {
113 isis_circuit_deconfigure(
114 circuit, (struct isis_area *)arg);
115 break;
116 }
117 circuit->state = C_STATE_UP;
118 isis_event_circuit_state_change(circuit, circuit->area,
119 1);
120 listnode_delete(circuit->area->isis->init_circ_list,
121 circuit);
122 break;
123 case IF_UP_FROM_Z:
124 assert(circuit);
125 zlog_warn("circuit already connected");
126 break;
127 case ISIS_DISABLE:
128 zlog_warn("circuit already disabled");
129 break;
130 case IF_DOWN_FROM_Z:
131 isis_circuit_if_del(circuit, (struct interface *)arg);
132 isis = isis_lookup_by_vrfid(circuit->interface->vrf_id);
133 if (isis == NULL) {
134 zlog_warn(
135 "%s : ISIS routing instance not found",
136 __func__);
137 break;
138 }
139
140 listnode_delete(isis->init_circ_list, circuit);
141 isis_circuit_del(circuit);
142 circuit = NULL;
143 break;
144 }
145 break;
146 case C_STATE_CONF:
147 assert(circuit);
148 switch (event) {
149 case ISIS_ENABLE:
150 zlog_warn("circuit already enabled");
151 break;
152 case IF_UP_FROM_Z:
153 isis_circuit_if_add(circuit, (struct interface *)arg);
154 if (isis_circuit_up(circuit) != ISIS_OK) {
155 flog_err(
156 EC_ISIS_CONFIG,
157 "Could not bring up %s because of invalid config.",
158 circuit->interface->name);
159 break;
160 }
161 circuit->state = C_STATE_UP;
162 isis_event_circuit_state_change(circuit, circuit->area,
163 1);
164 break;
165 case ISIS_DISABLE:
166 isis_circuit_deconfigure(circuit,
167 (struct isis_area *)arg);
168 isis_circuit_del(circuit);
169 circuit = NULL;
170 break;
171 case IF_DOWN_FROM_Z:
172 zlog_warn("circuit already disconnected");
173 break;
174 }
175 break;
176 case C_STATE_UP:
177 assert(circuit);
178 switch (event) {
179 case ISIS_ENABLE:
180 zlog_warn("circuit already configured");
181 break;
182 case IF_UP_FROM_Z:
183 zlog_warn("circuit already connected");
184 break;
185 case ISIS_DISABLE:
186 isis_circuit_down(circuit);
187 isis_circuit_deconfigure(circuit,
188 (struct isis_area *)arg);
189 circuit->state = C_STATE_INIT;
190 isis_event_circuit_state_change(
191 circuit, (struct isis_area *)arg, 0);
192
193 isis = isis_lookup_by_vrfid(circuit->interface->vrf_id);
194 if (isis == NULL) {
195 zlog_warn(
196 "%s : ISIS routing instance not found",
197 __func__);
198 break;
199 }
200
201 listnode_add(isis->init_circ_list, circuit);
202 break;
203 case IF_DOWN_FROM_Z:
204 isis_circuit_down(circuit);
205 isis_circuit_if_del(circuit, (struct interface *)arg);
206 circuit->state = C_STATE_CONF;
207 isis_event_circuit_state_change(circuit, circuit->area,
208 0);
209 break;
210 }
211 break;
212
213 default:
214 zlog_warn("Invalid circuit state %d", old_state);
215 }
216
217 if (IS_DEBUG_EVENTS)
218 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
219 circuit ? STATE2STR(circuit->state)
220 : STATE2STR(C_STATE_NA));
221
222 return circuit;
223 }