]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #6736 from NaveenThanikachalam/rmap_noop
[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 extern struct isis *isis;
52
53 static const char *const csm_statestr[] = {"C_STATE_NA", "C_STATE_INIT",
54 "C_STATE_CONF", "C_STATE_UP"};
55
56 #define STATE2STR(S) csm_statestr[S]
57
58 static const char *const csm_eventstr[] = {
59 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
60 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
61 };
62
63 #define EVENT2STR(E) csm_eventstr[E]
64
65 struct isis_circuit *
66 isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
67 {
68 int old_state;
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 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) {
140 flog_err(
141 EC_ISIS_CONFIG,
142 "Could not bring up %s because of invalid config.",
143 circuit->interface->name);
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;
188
189 default:
190 zlog_warn("Invalid circuit state %d", old_state);
191 }
192
193 if (IS_DEBUG_EVENTS)
194 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
195 circuit ? STATE2STR(circuit->state)
196 : STATE2STR(C_STATE_NA));
197
198 return circuit;
199 }