]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_csm.c
Merge pull request #1204 from donaldsharp/static_uptime
[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/dict.h"
36 #include "isisd/isis_constants.h"
37 #include "isisd/isis_common.h"
38 #include "isisd/isis_flags.h"
39 #include "isisd/isis_circuit.h"
40 #include "isisd/isis_lsp.h"
41 #include "isisd/isis_pdu.h"
42 #include "isisd/isis_network.h"
43 #include "isisd/isis_misc.h"
44 #include "isisd/isis_constants.h"
45 #include "isisd/isis_adjacency.h"
46 #include "isisd/isis_dr.h"
47 #include "isisd/isisd.h"
48 #include "isisd/isis_csm.h"
49 #include "isisd/isis_events.h"
50
51 extern struct isis *isis;
52
53 static const char *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 *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 (isis->debugs & 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 if (!circuit->circuit_id) {
90 isis_circuit_if_del(circuit,
91 (struct interface *)arg);
92 isis_circuit_del(circuit);
93 circuit = NULL;
94 break;
95 }
96 listnode_add(isis->init_circ_list, circuit);
97 circuit->state = C_STATE_INIT;
98 break;
99 case ISIS_DISABLE:
100 zlog_warn("circuit already disabled");
101 break;
102 case IF_DOWN_FROM_Z:
103 zlog_warn("circuit already disconnected");
104 break;
105 }
106 break;
107 case C_STATE_INIT:
108 assert(circuit);
109 switch (event) {
110 case ISIS_ENABLE:
111 isis_circuit_configure(circuit,
112 (struct isis_area *)arg);
113 if (isis_circuit_up(circuit) != ISIS_OK) {
114 isis_circuit_deconfigure(
115 circuit, (struct isis_area *)arg);
116 break;
117 }
118 circuit->state = C_STATE_UP;
119 isis_event_circuit_state_change(circuit, circuit->area,
120 1);
121 listnode_delete(isis->init_circ_list, circuit);
122 break;
123 case IF_UP_FROM_Z:
124 assert(circuit);
125 zlog_warn("circuit already connected");
126 break;
127 case ISIS_DISABLE:
128 zlog_warn("circuit already disabled");
129 break;
130 case IF_DOWN_FROM_Z:
131 isis_circuit_if_del(circuit, (struct interface *)arg);
132 listnode_delete(isis->init_circ_list, circuit);
133 isis_circuit_del(circuit);
134 circuit = NULL;
135 break;
136 }
137 break;
138 case C_STATE_CONF:
139 assert(circuit);
140 switch (event) {
141 case ISIS_ENABLE:
142 zlog_warn("circuit already enabled");
143 break;
144 case IF_UP_FROM_Z:
145 isis_circuit_if_add(circuit, (struct interface *)arg);
146 if (!circuit->circuit_id)
147 break;
148 if (isis_circuit_up(circuit) != ISIS_OK) {
149 zlog_err(
150 "Could not bring up %s because of invalid config.",
151 circuit->interface->name);
152 zlog_err(
153 "Clearing config for %s. Please re-examine it.",
154 circuit->interface->name);
155 if (circuit->ip_router) {
156 circuit->ip_router = 0;
157 circuit->area->ip_circuits--;
158 }
159 if (circuit->ipv6_router) {
160 circuit->ipv6_router = 0;
161 circuit->area->ipv6_circuits--;
162 }
163 circuit_update_nlpids(circuit);
164 isis_circuit_deconfigure(circuit,
165 circuit->area);
166 listnode_add(isis->init_circ_list, circuit);
167 circuit->state = C_STATE_INIT;
168 break;
169 }
170 circuit->state = C_STATE_UP;
171 isis_event_circuit_state_change(circuit, circuit->area,
172 1);
173 break;
174 case ISIS_DISABLE:
175 isis_circuit_deconfigure(circuit,
176 (struct isis_area *)arg);
177 isis_circuit_del(circuit);
178 circuit = NULL;
179 break;
180 case IF_DOWN_FROM_Z:
181 zlog_warn("circuit already disconnected");
182 break;
183 }
184 break;
185 case C_STATE_UP:
186 assert(circuit);
187 switch (event) {
188 case ISIS_ENABLE:
189 zlog_warn("circuit already configured");
190 break;
191 case IF_UP_FROM_Z:
192 zlog_warn("circuit already connected");
193 break;
194 case ISIS_DISABLE:
195 isis_circuit_down(circuit);
196 isis_circuit_deconfigure(circuit,
197 (struct isis_area *)arg);
198 circuit->state = C_STATE_INIT;
199 isis_event_circuit_state_change(
200 circuit, (struct isis_area *)arg, 0);
201 listnode_add(isis->init_circ_list, circuit);
202 break;
203 case IF_DOWN_FROM_Z:
204 isis_circuit_down(circuit);
205 isis_circuit_if_del(circuit, (struct interface *)arg);
206 circuit->state = C_STATE_CONF;
207 isis_event_circuit_state_change(circuit, circuit->area,
208 0);
209 break;
210 }
211 break;
212
213 default:
214 zlog_warn("Invalid circuit state %d", old_state);
215 }
216
217 if (isis->debugs & DEBUG_EVENTS)
218 zlog_debug("CSM_STATE_CHANGE: %s -> %s ", STATE2STR(old_state),
219 circuit ? STATE2STR(circuit->state)
220 : STATE2STR(C_STATE_NA));
221
222 return circuit;
223 }