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; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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"
51 static const char *const csm_statestr
[] = {"C_STATE_NA", "C_STATE_INIT",
52 "C_STATE_CONF", "C_STATE_UP"};
54 #define STATE2STR(S) csm_statestr[S]
56 static const char *const csm_eventstr
[] = {
57 "NO_STATE", "ISIS_ENABLE", "IF_UP_FROM_Z",
58 "ISIS_DISABLE", "IF_DOWN_FROM_Z",
61 #define EVENT2STR(E) csm_eventstr[E]
63 struct isis_circuit
*isis_csm_state_change(enum isis_circuit_event event
,
64 struct isis_circuit
*circuit
,
67 enum isis_circuit_state old_state
;
68 struct isis_area
*area
= NULL
;
69 struct interface
*ifp
;
73 old_state
= circuit
->state
;
75 zlog_debug("CSM_EVENT for %s: %s", circuit
->interface
->name
,
84 isis_circuit_configure(circuit
, area
);
85 circuit
->state
= C_STATE_CONF
;
90 isis_circuit_if_add(circuit
, ifp
);
91 circuit
->state
= C_STATE_INIT
;
95 zlog_debug("circuit %s already disabled",
96 circuit
->interface
->name
);
100 zlog_debug("circuit %s already disconnected",
101 circuit
->interface
->name
);
110 isis_circuit_configure(circuit
, area
);
111 if (isis_circuit_up(circuit
) != ISIS_OK
) {
112 isis_circuit_deconfigure(circuit
, area
);
115 circuit
->state
= C_STATE_UP
;
116 isis_event_circuit_state_change(circuit
, circuit
->area
,
121 zlog_debug("circuit %s already connected",
122 circuit
->interface
->name
);
126 zlog_debug("circuit %s already disabled",
127 circuit
->interface
->name
);
132 isis_circuit_if_del(circuit
, ifp
);
133 circuit
->state
= C_STATE_NA
;
141 zlog_debug("circuit %s is already enabled",
142 circuit
->interface
->name
);
147 isis_circuit_if_add(circuit
, ifp
);
148 if (isis_circuit_up(circuit
) != ISIS_OK
) {
149 isis_circuit_if_del(circuit
, ifp
);
152 "Could not bring up %s because of invalid config.",
153 circuit
->interface
->name
);
156 circuit
->state
= C_STATE_UP
;
157 isis_event_circuit_state_change(circuit
, circuit
->area
,
163 isis_circuit_deconfigure(circuit
, area
);
164 circuit
->state
= C_STATE_NA
;
168 zlog_debug("circuit %s already disconnected",
169 circuit
->interface
->name
);
177 zlog_debug("circuit %s already enabled",
178 circuit
->interface
->name
);
182 zlog_debug("circuit %s already connected",
183 circuit
->interface
->name
);
188 isis_circuit_down(circuit
);
189 isis_circuit_deconfigure(circuit
, area
);
190 circuit
->state
= C_STATE_INIT
;
191 isis_event_circuit_state_change(circuit
, area
, 0);
196 isis_circuit_down(circuit
);
197 isis_circuit_if_del(circuit
, ifp
);
198 circuit
->state
= C_STATE_CONF
;
199 isis_event_circuit_state_change(circuit
, circuit
->area
,
207 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state
),
208 STATE2STR(circuit
->state
));