blob: 16c69910c0f2bb4b3edb80f2ec91c7dc9fd4cddd [file] [log] [blame]
jardineb5d44e2003-12-23 08:09:43 +00001/*
2 * IS-IS Rout(e)ing protocol - isis_events.h
3 *
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#include <stdlib.h>
23#include <stdio.h>
24#include <ctype.h>
25#include <zebra.h>
jardineb5d44e2003-12-23 08:09:43 +000026
27#include "log.h"
28#include "memory.h"
29#include "if.h"
30#include "linklist.h"
31#include "command.h"
32#include "thread.h"
33#include "hash.h"
34#include "prefix.h"
35#include "stream.h"
36
37#include "isisd/dict.h"
38#include "isisd/include-netbsd/iso.h"
39#include "isisd/isis_constants.h"
40#include "isisd/isis_common.h"
41#include "isisd/isis_circuit.h"
42#include "isisd/isis_tlv.h"
43#include "isisd/isis_lsp.h"
44#include "isisd/isis_pdu.h"
45#include "isisd/isis_network.h"
46#include "isisd/isis_misc.h"
47#include "isisd/isis_constants.h"
48#include "isisd/isis_adjacency.h"
49#include "isisd/isis_dr.h"
50#include "isisd/isis_flags.h"
51#include "isisd/isisd.h"
52#include "isisd/isis_csm.h"
53#include "isisd/isis_events.h"
54#include "isisd/isis_spf.h"
55
56extern struct thread_master *master;
57extern struct isis *isis;
58
59/* debug isis-spf spf-events
60 4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
61 4w4d: ISIS-Spf (tlt): L2, 0000.0000.0042.01-00 TLV contents changed, code 0x2
62 4w4d: ISIS-Spf (tlt): L2, new LSP 0 DEAD.BEEF.0043.00-00
63 4w5d: ISIS-Spf (tlt): L1 SPF needed, periodic SPF, from 0x6091C844
64 4w5d: ISIS-Spf (tlt): L2 SPF needed, periodic SPF, from 0x6091C844
65*/
66
hassof390d2c2004-09-10 20:48:21 +000067void
jardineb5d44e2003-12-23 08:09:43 +000068isis_event_circuit_state_change (struct isis_circuit *circuit, int up)
69{
70 struct isis_area *area;
hassof390d2c2004-09-10 20:48:21 +000071
jardineb5d44e2003-12-23 08:09:43 +000072 area = circuit->area;
73 assert (area);
74 area->circuit_state_changes++;
hassof390d2c2004-09-10 20:48:21 +000075
76 if (isis->debugs & DEBUG_EVENTS)
77 zlog_info ("ISIS-Evt (%s) circuit %s", circuit->area->area_tag,
jardineb5d44e2003-12-23 08:09:43 +000078 up ? "up" : "down");
hassof390d2c2004-09-10 20:48:21 +000079
jardineb5d44e2003-12-23 08:09:43 +000080 /*
81 * Regenerate LSPs this affects
82 */
83 lsp_regenerate_schedule (area);
84
85 return;
86}
87
hassof390d2c2004-09-10 20:48:21 +000088void
jardineb5d44e2003-12-23 08:09:43 +000089isis_event_system_type_change (struct isis_area *area, int newtype)
90{
91 struct listnode *node;
92 struct isis_circuit *circuit;
93
hassof390d2c2004-09-10 20:48:21 +000094 if (isis->debugs & DEBUG_EVENTS)
95 zlog_info ("ISIS-Evt (%s) system type change %s -> %s", area->area_tag,
jardineb5d44e2003-12-23 08:09:43 +000096 circuit_t2string (area->is_type), circuit_t2string (newtype));
hassof390d2c2004-09-10 20:48:21 +000097
jardineb5d44e2003-12-23 08:09:43 +000098 if (area->is_type == newtype)
hassof390d2c2004-09-10 20:48:21 +000099 return; /* No change */
100
101 switch (area->is_type)
102 {
103 case IS_LEVEL_1:
104 if (area->lspdb[1] == NULL)
105 area->lspdb[1] = lsp_db_init ();
106 lsp_l2_generate (area);
107 break;
108 case IS_LEVEL_1_AND_2:
109 if (newtype == IS_LEVEL_1)
110 {
111 lsp_db_destroy (area->lspdb[1]);
112 }
113 else
114 {
115 lsp_db_destroy (area->lspdb[0]);
116 }
117 break;
118 case IS_LEVEL_2:
119 if (area->lspdb[0] == NULL)
120 area->lspdb[0] = lsp_db_init ();
121 lsp_l1_generate (area);
122 break;
123 default:
124 break;
125 }
126
jardineb5d44e2003-12-23 08:09:43 +0000127 area->is_type = newtype;
hassof390d2c2004-09-10 20:48:21 +0000128 for (node = listhead (area->circuit_list); node; nextnode (node))
129 {
130 circuit = getdata (node);
131 isis_event_circuit_type_change (circuit, newtype);
132 }
jardineb5d44e2003-12-23 08:09:43 +0000133
134 spftree_area_init (area);
135 lsp_regenerate_schedule (area);
136
137 return;
138}
139
hassof390d2c2004-09-10 20:48:21 +0000140void
jardineb5d44e2003-12-23 08:09:43 +0000141isis_event_area_addr_change (struct isis_area *area)
142{
143
144}
145
146void
147circuit_commence_level (struct isis_circuit *circuit, int level)
148{
149 uint32_t interval;
150
hassof390d2c2004-09-10 20:48:21 +0000151 if (level == 1)
152 {
153 THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
154 isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));
hassod70f99e2004-02-11 20:26:31 +0000155
hassof390d2c2004-09-10 20:48:21 +0000156 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
157 {
158 interval =
159 circuit->hello_multiplier[0] * (circuit->hello_interval[0]);
hassod70f99e2004-02-11 20:26:31 +0000160
hassof390d2c2004-09-10 20:48:21 +0000161 THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
162 circuit, interval);
163
164 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
165 send_lan_l1_hello, circuit,
166 isis_jitter (circuit->hello_interval[0],
167 IIH_JITTER));
168
169 circuit->u.bc.lan_neighs[0] = list_new ();
170 }
jardineb5d44e2003-12-23 08:09:43 +0000171 }
hassof390d2c2004-09-10 20:48:21 +0000172 else
173 {
174 THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
175 isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));
176
177 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
178 {
179 interval =
180 circuit->hello_multiplier[1] * (circuit->hello_interval[1]);
181
182 THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
183 circuit, interval);
184
185 THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
186 send_lan_l2_hello, circuit,
187 isis_jitter (circuit->hello_interval[1],
188 IIH_JITTER));
189
190 circuit->u.bc.lan_neighs[1] = list_new ();
191 }
192 }
193
jardineb5d44e2003-12-23 08:09:43 +0000194 return;
195}
196
197void
198circuit_resign_level (struct isis_circuit *circuit, int level)
199{
200 int idx = level - 1;
jardineb5d44e2003-12-23 08:09:43 +0000201
hassof390d2c2004-09-10 20:48:21 +0000202 THREAD_TIMER_OFF (circuit->t_send_csnp[idx]);
203 THREAD_TIMER_OFF (circuit->t_send_psnp[idx]);
204
205 if (circuit->circ_type == CIRCUIT_T_BROADCAST)
206 {
207 THREAD_TIMER_OFF (circuit->u.bc.t_send_lan_hello[idx]);
208 THREAD_TIMER_OFF (circuit->u.bc.t_run_dr[idx]);
209 circuit->u.bc.run_dr_elect[idx] = 0;
210 }
211
jardineb5d44e2003-12-23 08:09:43 +0000212 return;
213}
214
hassof390d2c2004-09-10 20:48:21 +0000215void
216isis_event_circuit_type_change (struct isis_circuit *circuit, int newtype)
jardineb5d44e2003-12-23 08:09:43 +0000217{
hassof390d2c2004-09-10 20:48:21 +0000218
219 if (isis->debugs & DEBUG_EVENTS)
220 zlog_info ("ISIS-Evt (%s) circuit type change %s -> %s",
221 circuit->area->area_tag,
222 circuit_t2string (circuit->circuit_is_type),
jardineb5d44e2003-12-23 08:09:43 +0000223 circuit_t2string (newtype));
224
225 if (circuit->circuit_is_type == newtype)
hassof390d2c2004-09-10 20:48:21 +0000226 return; /* No change */
jardineb5d44e2003-12-23 08:09:43 +0000227
hassof390d2c2004-09-10 20:48:21 +0000228 if (!(newtype & circuit->area->is_type))
229 {
230 zlog_err ("ISIS-Evt (%s) circuit type change - invalid level %s because"
231 " area is %s", circuit->area->area_tag,
232 circuit_t2string (newtype),
233 circuit_t2string (circuit->area->is_type));
234 return;
235 }
236
237 switch (circuit->circuit_is_type)
238 {
239 case IS_LEVEL_1:
240 if (newtype == IS_LEVEL_2)
241 circuit_resign_level (circuit, 1);
242 circuit_commence_level (circuit, 2);
243 break;
244 case IS_LEVEL_1_AND_2:
245 if (newtype == IS_LEVEL_1)
246 circuit_resign_level (circuit, 2);
247 else
248 circuit_resign_level (circuit, 1);
249 break;
250 case IS_LEVEL_2:
251 if (newtype == IS_LEVEL_1)
252 circuit_resign_level (circuit, 2);
253 circuit_commence_level (circuit, 1);
254 break;
255 default:
256 break;
257 }
258
jardineb5d44e2003-12-23 08:09:43 +0000259 circuit->circuit_is_type = newtype;
260 lsp_regenerate_schedule (circuit->area);
261
262 return;
263}
264
265 /* 04/18/2002 by Gwak. */
266 /**************************************************************************
267 *
268 * EVENTS for LSP generation
269 *
270 * 1) an Adajacency or Circuit Up/Down event
271 * 2) a chnage in Circuit metric
272 * 3) a change in Reachable Address metric
273 * 4) a change in manualAreaAddresses
274 * 5) a change in systemID
275 * 6) a change in DIS status
276 * 7) a chnage in the waiting status
277 *
278 * ***********************************************************************
279 *
280 * current support event
281 *
282 * 1) Adjacency Up/Down event
283 * 6) a change in DIS status
284 *
285 * ***********************************************************************/
286
hassof390d2c2004-09-10 20:48:21 +0000287void
jardineb5d44e2003-12-23 08:09:43 +0000288isis_event_adjacency_state_change (struct isis_adjacency *adj, int newstate)
289{
290 /* adjacency state change event.
291 * - the only proto-type was supported */
hassof390d2c2004-09-10 20:48:21 +0000292
293 /* invalid arguments */
294 if (!adj || !adj->circuit || !adj->circuit->area)
295 return;
296
297 zlog_info ("ISIS-Evt (%s) Adjacency State change",
298 adj->circuit->area->area_tag);
299
jardineb5d44e2003-12-23 08:09:43 +0000300 /* LSP generation again */
301 lsp_regenerate_schedule (adj->circuit->area);
302
303 return;
304}
305
hassof891f442004-09-14 13:54:30 +0000306void
307isis_event_int_reach_change (struct isis_circuit *circuit)
308{
309 if (!circuit || !circuit->area)
310 return;
311
312 zlog_info ("ISIS-Evt (%s) Internal reachability change",
313 circuit->area->area_tag);
314
315 lsp_regenerate_schedule (circuit->area);
316
317 return;
318}
319
jardineb5d44e2003-12-23 08:09:43 +0000320/* events supporting code */
321
322int
323isis_event_dis_status_change (struct thread *thread)
324{
325 struct isis_circuit *circuit;
hassof390d2c2004-09-10 20:48:21 +0000326
jardineb5d44e2003-12-23 08:09:43 +0000327 circuit = THREAD_ARG (thread);
hassof390d2c2004-09-10 20:48:21 +0000328
jardineb5d44e2003-12-23 08:09:43 +0000329 /* invalid arguments */
hassof390d2c2004-09-10 20:48:21 +0000330 if (!circuit || !circuit->area)
331 return 0;
332
jardineb5d44e2003-12-23 08:09:43 +0000333 zlog_info ("ISIS-Evt (%s) DIS status change", circuit->area->area_tag);
334
335 /* LSP generation again */
336 lsp_regenerate_schedule (circuit->area);
hassof390d2c2004-09-10 20:48:21 +0000337
jardineb5d44e2003-12-23 08:09:43 +0000338 return 0;
339}
340
hassof390d2c2004-09-10 20:48:21 +0000341void
342isis_event_auth_failure (char *area_tag, char *error_string, char *sysid)
jardineb5d44e2003-12-23 08:09:43 +0000343{
344 zlog_info ("ISIS-Evt (%s) Authentication failure %s from %s",
345 area_tag, error_string, sysid_print (sysid));
hassof390d2c2004-09-10 20:48:21 +0000346
jardineb5d44e2003-12-23 08:09:43 +0000347 return;
348}