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