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
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)
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
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include "isisd/dict.h"
36 #include "isisd/include-netbsd/iso.h"
37 #include "isisd/isis_constants.h"
38 #include "isisd/isis_common.h"
39 #include "isisd/isis_flags.h"
40 #include "isisd/isis_circuit.h"
41 #include "isisd/isis_tlv.h"
42 #include "isisd/isis_lsp.h"
43 #include "isisd/isis_pdu.h"
44 #include "isisd/isis_network.h"
45 #include "isisd/isis_misc.h"
46 #include "isisd/isis_constants.h"
47 #include "isisd/isis_adjacency.h"
48 #include "isisd/isis_dr.h"
49 #include "isisd/isisd.h"
50 #include "isisd/isis_csm.h"
51 #include "isisd/isis_events.h"
53 extern struct isis *isis;
55 static const char *csm_statestr[] = {
62 #define STATE2STR(S) csm_statestr[S]
64 static const char *csm_eventstr[] = {
72 #define EVENT2STR(E) csm_eventstr[E]
75 isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg)
79 old_state = circuit ? circuit->state : C_STATE_NA;
80 if (isis->debugs & DEBUG_EVENTS)
81 zlog_debug ("CSM_EVENT: %s", EVENT2STR (event));
87 zlog_warn ("Non-null circuit while state C_STATE_NA");
88 assert (circuit == NULL);
92 circuit = isis_circuit_new ();
93 isis_circuit_configure (circuit, (struct isis_area *) arg);
94 circuit->state = C_STATE_CONF;
97 circuit = isis_circuit_new ();
98 isis_circuit_if_add (circuit, (struct interface *) arg);
99 listnode_add (isis->init_circ_list, circuit);
100 circuit->state = C_STATE_INIT;
103 zlog_warn ("circuit already disabled");
106 zlog_warn ("circuit already disconnected");
115 isis_circuit_configure (circuit, (struct isis_area *) arg);
116 if (isis_circuit_up (circuit) != ISIS_OK)
118 isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
121 circuit->state = C_STATE_UP;
122 isis_event_circuit_state_change (circuit, circuit->area, 1);
123 listnode_delete (isis->init_circ_list, circuit);
127 zlog_warn ("circuit already connected");
130 zlog_warn ("circuit already disabled");
133 isis_circuit_if_del (circuit, (struct interface *) arg);
134 listnode_delete (isis->init_circ_list, circuit);
135 isis_circuit_del (circuit);
145 zlog_warn ("circuit already enabled");
148 isis_circuit_if_add (circuit, (struct interface *) arg);
149 if (isis_circuit_up (circuit) != ISIS_OK)
151 zlog_err("Could not bring up %s because of invalid config.",
152 circuit->interface->name);
153 zlog_err("Clearing config for %s. Please re-examine it.",
154 circuit->interface->name);
155 if (circuit->ip_router)
157 circuit->ip_router = 0;
158 circuit->area->ip_circuits--;
160 if (circuit->ipv6_router)
162 circuit->ipv6_router = 0;
163 circuit->area->ipv6_circuits--;
165 circuit_update_nlpids(circuit);
166 isis_circuit_deconfigure(circuit, circuit->area);
167 listnode_add (isis->init_circ_list, circuit);
168 circuit->state = C_STATE_INIT;
171 circuit->state = C_STATE_UP;
172 isis_event_circuit_state_change (circuit, circuit->area, 1);
175 isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
176 isis_circuit_del (circuit);
180 zlog_warn ("circuit already disconnected");
189 zlog_warn ("circuit already configured");
192 zlog_warn ("circuit already connected");
195 isis_circuit_down (circuit);
196 isis_circuit_deconfigure (circuit, (struct isis_area *) arg);
197 circuit->state = C_STATE_INIT;
198 isis_event_circuit_state_change (circuit,
199 (struct isis_area *)arg, 0);
200 listnode_add (isis->init_circ_list, circuit);
203 isis_circuit_down (circuit);
204 isis_circuit_if_del (circuit, (struct interface *) arg);
205 circuit->state = C_STATE_CONF;
206 isis_event_circuit_state_change (circuit, circuit->area, 0);
212 zlog_warn ("Invalid circuit state %d", old_state);
215 if (isis->debugs & DEBUG_EVENTS)
216 zlog_debug ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state),
217 circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA));