blob: b20579037aee8c2f3bf735700deb70024fefc79c [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
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; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000024
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/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_circuit.h"
40#include "isisd/isis_tlv.h"
41#include "isisd/isis_lsp.h"
42#include "isisd/isis_pdu.h"
43#include "isisd/isis_network.h"
44#include "isisd/isis_misc.h"
45#include "isisd/isis_constants.h"
46#include "isisd/isis_adjacency.h"
47#include "isisd/isis_dr.h"
48#include "isisd/isis_flags.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_csm.h"
51#include "isisd/isis_events.h"
52
53extern struct isis *isis;
54
55static char *csm_statestr[] =
56{
57 "C_STATE_NA",
58 "C_STATE_INIT",
59 "C_STATE_CONF",
60 "C_STATE_UP"
61};
62
63#define STATE2STR(S) csm_statestr[S]
64
65static char *csm_eventstr[] =
66{
67 "NO_STATE",
68 "ISIS_ENABLE",
69 "IF_UP_FROM_Z",
70 "ISIS_DISABLE",
71 "IF_DOWN_FROM_Z",
72};
73
74#define EVENT2STR(E) csm_eventstr[E]
75
76
77struct isis_circuit*
78isis_csm_state_change (int event, struct isis_circuit *circuit,
79 void *arg)
80{
81 int old_state;
82
83 old_state = circuit ? circuit->state : C_STATE_NA;
84
85 zlog_info ("CSM_EVENT: %s", EVENT2STR(event));
86
87 switch (old_state) {
88 case C_STATE_NA:
89 if (circuit)
90 zlog_warn ("Non-null circuit while state C_STATE_NA");
91 switch (event) {
92 case ISIS_ENABLE:
93 circuit = isis_circuit_new ();
94 isis_circuit_configure (circuit, (struct isis_area *)arg);
95 circuit->state = C_STATE_CONF;
96 break;
97 case IF_UP_FROM_Z:
98 circuit = isis_circuit_new ();
99 isis_circuit_if_add (circuit, (struct interface *)arg);
100 listnode_add (isis->init_circ_list, circuit);
101 circuit->state = C_STATE_INIT;
102 break;
103 case ISIS_DISABLE:
104 zlog_warn ("circuit already disabled");
105 case IF_DOWN_FROM_Z:
106 zlog_warn ("circuit already disconnected");
107 break;
108 }
109 break;
110 case C_STATE_INIT:
111 switch (event) {
112 case ISIS_ENABLE:
113 isis_circuit_configure (circuit, (struct isis_area *)arg);
114 isis_circuit_up (circuit);
115 circuit->state = C_STATE_UP;
116 isis_event_circuit_state_change (circuit, 1);
117 listnode_delete (isis->init_circ_list, circuit);
118 break;
119 case IF_UP_FROM_Z:
120 zlog_warn ("circuit already connected");
121 break;
122 case ISIS_DISABLE:
123 zlog_warn ("circuit already disabled");
124 break;
125 case IF_DOWN_FROM_Z:
126 isis_circuit_if_del (circuit);
127 listnode_delete (isis->init_circ_list, circuit);
128 isis_circuit_del (circuit);
129 break;
130 }
131 break;
132 case C_STATE_CONF:
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 isis_circuit_up (circuit);
140 circuit->state = C_STATE_UP;
141 isis_event_circuit_state_change (circuit, 1);
142 break;
143 case ISIS_DISABLE:
144 isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
145 isis_circuit_del (circuit);
146 break;
147 case IF_DOWN_FROM_Z:
148 zlog_warn ("circuit already disconnected");
149 break;
150 }
151 break;
152 case C_STATE_UP:
153 switch (event) {
154 case ISIS_ENABLE:
155 zlog_warn ("circuit already configured");
156 break;
157 case IF_UP_FROM_Z:
158 zlog_warn ("circuit already connected");
159 break;
160 case ISIS_DISABLE:
161 isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
162 listnode_add (isis->init_circ_list, circuit);
163 circuit->state = C_STATE_INIT;
164 isis_event_circuit_state_change (circuit, 0);
165 break;
166 case IF_DOWN_FROM_Z:
167 isis_circuit_if_del (circuit);
168 circuit->state = C_STATE_CONF;
169 isis_event_circuit_state_change (circuit, 0);
170 break;
171 }
172 break;
173
174 default:
175 zlog_warn ("Invalid circuit state %d", old_state);
176 }
177
178 zlog_info ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state),
179 circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA));
180
181 return circuit;
182}
183
184
185