]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #7258 from mjstapp/zebra_remove_slsp
[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 struct isis_area *area = NULL;
69
70 old_state = circuit ? circuit->state : C_STATE_NA;
71 if (IS_DEBUG_EVENTS)
72 zlog_debug("CSM_EVENT: %s", EVENT2STR(event));
73
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 area = arg;
82
83 circuit = isis_circuit_new(area->isis);
84 isis_circuit_configure(circuit, area);
85 circuit->state = C_STATE_CONF;
86 break;
87 case IF_UP_FROM_Z:
88 isis = isis_lookup_by_vrfid(((struct interface *)arg)->vrf_id);
89 if (isis == NULL) {
90 zlog_warn(
91 " %s : ISIS routing instance not found",
92 __func__);
93 break;
94 }
95 circuit = isis_circuit_new(isis);
96 isis_circuit_if_add(circuit, (struct interface *)arg);
97 listnode_add(isis->init_circ_list, circuit);
98 circuit->state = C_STATE_INIT;
99 break;
100 case ISIS_DISABLE:
101 zlog_warn("circuit already disabled");
102 break;
103 case IF_DOWN_FROM_Z:
104 zlog_warn("circuit already disconnected");
105 break;
106 }
107 break;
108 case C_STATE_INIT:
109 assert(circuit);
110 switch (event) {
111 case ISIS_ENABLE:
112 isis_circuit_configure(circuit,
113 (struct isis_area *)arg);
114 if (isis_circuit_up(circuit) != ISIS_OK) {
115 isis_circuit_deconfigure(
116 circuit, (struct isis_area *)arg);
117 break;
118 }
119 circuit->state = C_STATE_UP;
120 isis_event_circuit_state_change(circuit, circuit->area,
121 1);
122 listnode_delete(circuit->isis->init_circ_list,
123 circuit);
124 break;
125 case IF_UP_FROM_Z:
126 assert(circuit);
127 zlog_warn("circuit already connected");
128 break;
129 case ISIS_DISABLE:
130 zlog_warn("circuit already disabled");
131 break;
132 case IF_DOWN_FROM_Z:
133 isis_circuit_if_del(circuit, (struct interface *)arg);
134 listnode_delete(circuit->isis->init_circ_list,
135 circuit);
136 isis_circuit_del(circuit);
137 circuit = NULL;
138 break;
139 }
140 break;
141 case C_STATE_CONF:
142 assert(circuit);
143 switch (event) {
144 case ISIS_ENABLE:
145 zlog_warn("circuit already enabled");
146 break;
147 case IF_UP_FROM_Z:
148 isis_circuit_if_add(circuit, (struct interface *)arg);
149 if (isis_circuit_up(circuit) != ISIS_OK) {
150 isis_circuit_if_del(circuit, (struct interface *)arg);
151 flog_err(
152 EC_ISIS_CONFIG,
153 "Could not bring up %s because of invalid config.",
154 circuit->interface->name);
155 break;
156 }
157 circuit->state = C_STATE_UP;
158 isis_event_circuit_state_change(circuit, circuit->area,
159 1);
160 break;
161 case ISIS_DISABLE:
162 isis_circuit_deconfigure(circuit,
163 (struct isis_area *)arg);
164 isis_circuit_del(circuit);
165 circuit = NULL;
166 break;
167 case IF_DOWN_FROM_Z:
168 zlog_warn("circuit already disconnected");
169 break;
170 }
171 break;
172 case C_STATE_UP:
173 assert(circuit);
174 switch (event) {
175 case ISIS_ENABLE:
176 zlog_warn("circuit already configured");
177 break;
178 case IF_UP_FROM_Z:
179 zlog_warn("circuit already connected");
180 break;
181 case ISIS_DISABLE:
182 isis = circuit->isis;
183 isis_circuit_down(circuit);
184 isis_circuit_deconfigure(circuit,
185 (struct isis_area *)arg);
186 circuit->state = C_STATE_INIT;
187 isis_event_circuit_state_change(
188 circuit, (struct isis_area *)arg, 0);
189 listnode_add(isis->init_circ_list, circuit);
190 break;
191 case IF_DOWN_FROM_Z:
192 isis_circuit_down(circuit);
193 isis_circuit_if_del(circuit, (struct interface *)arg);
194 circuit->state = C_STATE_CONF;
195 isis_event_circuit_state_change(circuit, circuit->area,
196 0);
197 break;
198 }
199 break;
200
201 default:
202 zlog_warn("Invalid circuit state %d", old_state);
203 }
204
205 if (IS_DEBUG_EVENTS)
206 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
207 circuit ? STATE2STR(circuit->state)
208 : STATE2STR(C_STATE_NA));
209
210 return circuit;
211 }