blob: 2282bbc85c5ec051c4fe1bf85975999f8e29faf0 [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>
24#include <net/ethernet.h>
25
26#include "log.h"
27#include "memory.h"
28#include "if.h"
29#include "linklist.h"
30#include "command.h"
31#include "thread.h"
32#include "hash.h"
33#include "prefix.h"
34#include "stream.h"
35
36#include "isisd/dict.h"
37#include "isisd/include-netbsd/iso.h"
38#include "isisd/isis_constants.h"
39#include "isisd/isis_common.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/isis_flags.h"
50#include "isisd/isisd.h"
51#include "isisd/isis_csm.h"
52#include "isisd/isis_events.h"
53
54extern struct isis *isis;
55
56static char *csm_statestr[] =
57{
58 "C_STATE_NA",
59 "C_STATE_INIT",
60 "C_STATE_CONF",
61 "C_STATE_UP"
62};
63
64#define STATE2STR(S) csm_statestr[S]
65
66static char *csm_eventstr[] =
67{
68 "NO_STATE",
69 "ISIS_ENABLE",
70 "IF_UP_FROM_Z",
71 "ISIS_DISABLE",
72 "IF_DOWN_FROM_Z",
73};
74
75#define EVENT2STR(E) csm_eventstr[E]
76
77
78struct isis_circuit*
79isis_csm_state_change (int event, struct isis_circuit *circuit,
80 void *arg)
81{
82 int old_state;
83
84 old_state = circuit ? circuit->state : C_STATE_NA;
85
86 zlog_info ("CSM_EVENT: %s", EVENT2STR(event));
87
88 switch (old_state) {
89 case C_STATE_NA:
90 if (circuit)
91 zlog_warn ("Non-null circuit while state C_STATE_NA");
92 switch (event) {
93 case ISIS_ENABLE:
94 circuit = isis_circuit_new ();
95 isis_circuit_configure (circuit, (struct isis_area *)arg);
96 circuit->state = C_STATE_CONF;
97 break;
98 case IF_UP_FROM_Z:
99 circuit = isis_circuit_new ();
100 isis_circuit_if_add (circuit, (struct interface *)arg);
101 listnode_add (isis->init_circ_list, circuit);
102 circuit->state = C_STATE_INIT;
103 break;
104 case ISIS_DISABLE:
105 zlog_warn ("circuit already disabled");
106 case IF_DOWN_FROM_Z:
107 zlog_warn ("circuit already disconnected");
108 break;
109 }
110 break;
111 case C_STATE_INIT:
112 switch (event) {
113 case ISIS_ENABLE:
114 isis_circuit_configure (circuit, (struct isis_area *)arg);
115 isis_circuit_up (circuit);
116 circuit->state = C_STATE_UP;
117 isis_event_circuit_state_change (circuit, 1);
118 listnode_delete (isis->init_circ_list, circuit);
119 break;
120 case IF_UP_FROM_Z:
121 zlog_warn ("circuit already connected");
122 break;
123 case ISIS_DISABLE:
124 zlog_warn ("circuit already disabled");
125 break;
126 case IF_DOWN_FROM_Z:
127 isis_circuit_if_del (circuit);
128 listnode_delete (isis->init_circ_list, circuit);
129 isis_circuit_del (circuit);
130 break;
131 }
132 break;
133 case C_STATE_CONF:
134 switch (event) {
135 case ISIS_ENABLE:
136 zlog_warn ("circuit already enabled");
137 break;
138 case IF_UP_FROM_Z:
139 isis_circuit_if_add (circuit, (struct interface *)arg);
140 isis_circuit_up (circuit);
141 circuit->state = C_STATE_UP;
142 isis_event_circuit_state_change (circuit, 1);
143 break;
144 case ISIS_DISABLE:
145 isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
146 isis_circuit_del (circuit);
147 break;
148 case IF_DOWN_FROM_Z:
149 zlog_warn ("circuit already disconnected");
150 break;
151 }
152 break;
153 case C_STATE_UP:
154 switch (event) {
155 case ISIS_ENABLE:
156 zlog_warn ("circuit already configured");
157 break;
158 case IF_UP_FROM_Z:
159 zlog_warn ("circuit already connected");
160 break;
161 case ISIS_DISABLE:
162 isis_circuit_deconfigure (circuit, (struct isis_area *)arg);
163 listnode_add (isis->init_circ_list, circuit);
164 circuit->state = C_STATE_INIT;
165 isis_event_circuit_state_change (circuit, 0);
166 break;
167 case IF_DOWN_FROM_Z:
168 isis_circuit_if_del (circuit);
169 circuit->state = C_STATE_CONF;
170 isis_event_circuit_state_change (circuit, 0);
171 break;
172 }
173 break;
174
175 default:
176 zlog_warn ("Invalid circuit state %d", old_state);
177 }
178
179 zlog_info ("CSM_STATE_CHANGE: %s -> %s ", STATE2STR (old_state),
180 circuit ? STATE2STR (circuit->state) : STATE2STR (C_STATE_NA));
181
182 return circuit;
183}
184
185
186