2 * IS-IS Rout(e)ing protocol - isis_dr.c
3 * IS-IS designated router related routines
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "isisd/dict.h"
36 #include "isisd/isis_constants.h"
37 #include "isisd/isis_common.h"
38 #include "isisd/isis_misc.h"
39 #include "isisd/isis_flags.h"
40 #include "isisd/isis_circuit.h"
41 #include "isisd/isisd.h"
42 #include "isisd/isis_adjacency.h"
43 #include "isisd/isis_constants.h"
44 #include "isisd/isis_pdu.h"
45 #include "isisd/isis_tlv.h"
46 #include "isisd/isis_lsp.h"
47 #include "isisd/isis_dr.h"
48 #include "isisd/isis_events.h"
51 isis_disflag2string (int disflag
)
63 return "unknown DIS state";
65 return NULL
; /* not reached */
69 isis_run_dr_l1 (struct thread
*thread
)
71 struct isis_circuit
*circuit
;
73 circuit
= THREAD_ARG (thread
);
76 if (circuit
->u
.bc
.run_dr_elect
[0])
77 zlog_warn ("isis_run_dr(): run_dr_elect already set for l1");
79 circuit
->u
.bc
.t_run_dr
[0] = NULL
;
80 circuit
->u
.bc
.run_dr_elect
[0] = 1;
86 isis_run_dr_l2 (struct thread
*thread
)
88 struct isis_circuit
*circuit
;
90 circuit
= THREAD_ARG (thread
);
93 if (circuit
->u
.bc
.run_dr_elect
[1])
94 zlog_warn ("isis_run_dr(): run_dr_elect already set for l2");
97 circuit
->u
.bc
.t_run_dr
[1] = NULL
;
98 circuit
->u
.bc
.run_dr_elect
[1] = 1;
104 isis_check_dr_change (struct isis_adjacency
*adj
, int level
)
108 if (adj
->dis_record
[level
- 1].dis
!=
109 adj
->dis_record
[(1 * ISIS_LEVELS
) + level
- 1].dis
)
110 /* was there a DIS state transition ? */
112 adj
->dischanges
[level
- 1]++;
113 /* ok rotate the history list through */
114 for (i
= DIS_RECORDS
- 1; i
> 0; i
--)
116 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1].dis
=
117 adj
->dis_record
[((i
- 1) * ISIS_LEVELS
) + level
- 1].dis
;
118 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1].last_dis_change
=
119 adj
->dis_record
[((i
- 1) * ISIS_LEVELS
) + level
-
127 isis_dr_elect (struct isis_circuit
*circuit
, int level
)
130 struct listnode
*node
;
131 struct isis_adjacency
*adj
, *adj_dr
= NULL
;
132 struct list
*list
= list_new ();
134 int biggest_prio
= -1;
135 int cmp_res
, retval
= ISIS_OK
;
137 own_prio
= circuit
->priority
[level
- 1];
138 adjdb
= circuit
->u
.bc
.adjdb
[level
- 1];
142 zlog_warn ("isis_dr_elect() adjdb == NULL");
146 isis_adj_build_up_list (adjdb
, list
);
149 * Loop the adjacencies and find the one with the biggest priority
151 for (ALL_LIST_ELEMENTS_RO (list
, node
, adj
))
153 /* clear flag for show output */
154 adj
->dis_record
[level
- 1].dis
= ISIS_IS_NOT_DIS
;
155 adj
->dis_record
[level
- 1].last_dis_change
= time (NULL
);
157 if (adj
->prio
[level
- 1] > biggest_prio
)
159 biggest_prio
= adj
->prio
[level
- 1];
162 else if (adj
->prio
[level
- 1] == biggest_prio
)
165 * Comparison of MACs breaks a tie
169 cmp_res
= memcmp (adj_dr
->snpa
, adj
->snpa
, ETH_ALEN
);
176 ("isis_dr_elect(): multiple adjacencies with same SNPA");
188 * Could not find the DR - means we are alone. Resign if we were DR.
190 if (circuit
->u
.bc
.is_dr
[level
- 1])
191 retval
= isis_dr_resign (circuit
, level
);
197 * Now we have the DR adjacency, compare it to self
199 if (adj_dr
->prio
[level
- 1] < own_prio
||
200 (adj_dr
->prio
[level
- 1] == own_prio
&&
201 memcmp (adj_dr
->snpa
, circuit
->u
.bc
.snpa
, ETH_ALEN
) < 0))
203 adj_dr
->dis_record
[level
- 1].dis
= ISIS_IS_NOT_DIS
;
204 adj_dr
->dis_record
[level
- 1].last_dis_change
= time (NULL
);
206 /* rotate the history log */
207 for (ALL_LIST_ELEMENTS_RO (list
, node
, adj
))
208 isis_check_dr_change (adj
, level
);
210 /* We are the DR, commence DR */
211 if (circuit
->u
.bc
.is_dr
[level
- 1] == 0 && listcount (list
) > 0)
212 retval
= isis_dr_commence (circuit
, level
);
216 /* ok we have found the DIS - lets mark the adjacency */
217 /* set flag for show output */
218 adj_dr
->dis_record
[level
- 1].dis
= ISIS_IS_DIS
;
219 adj_dr
->dis_record
[level
- 1].last_dis_change
= time (NULL
);
221 /* now loop through a second time to check if there has been a DIS change
222 * if yes rotate the history log
225 for (ALL_LIST_ELEMENTS_RO (list
, node
, adj
))
226 isis_check_dr_change (adj
, level
);
229 * We are not DR - if we were -> resign
231 if (circuit
->u
.bc
.is_dr
[level
- 1])
232 retval
= isis_dr_resign (circuit
, level
);
239 isis_dr_resign (struct isis_circuit
*circuit
, int level
)
241 u_char id
[ISIS_SYS_ID_LEN
+ 2];
243 zlog_debug ("isis_dr_resign l%d", level
);
245 circuit
->u
.bc
.is_dr
[level
- 1] = 0;
246 circuit
->u
.bc
.run_dr_elect
[level
- 1] = 0;
247 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[level
- 1]);
248 THREAD_TIMER_OFF (circuit
->u
.bc
.t_refresh_pseudo_lsp
[level
- 1]);
249 circuit
->lsp_regenerate_pending
[level
- 1] = 0;
251 memcpy (id
, isis
->sysid
, ISIS_SYS_ID_LEN
);
252 LSP_PSEUDO_ID (id
) = circuit
->circuit_id
;
253 LSP_FRAGMENT (id
) = 0;
254 lsp_purge_pseudo (id
, circuit
, level
);
258 memset (circuit
->u
.bc
.l1_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
260 THREAD_TIMER_OFF (circuit
->t_send_csnp
[0]);
262 thread_add_timer(master
, isis_run_dr_l1
, circuit
,
263 2 * circuit
->hello_interval
[0],
264 &circuit
->u
.bc
.t_run_dr
[0]);
266 thread_add_timer(master
, send_l1_psnp
, circuit
,
267 isis_jitter(circuit
->psnp_interval
[level
- 1], PSNP_JITTER
),
268 &circuit
->t_send_psnp
[0]);
272 memset (circuit
->u
.bc
.l2_desig_is
, 0, ISIS_SYS_ID_LEN
+ 1);
274 THREAD_TIMER_OFF (circuit
->t_send_csnp
[1]);
276 thread_add_timer(master
, isis_run_dr_l2
, circuit
,
277 2 * circuit
->hello_interval
[1],
278 &circuit
->u
.bc
.t_run_dr
[1]);
280 thread_add_timer(master
, send_l2_psnp
, circuit
,
281 isis_jitter(circuit
->psnp_interval
[level
- 1], PSNP_JITTER
),
282 &circuit
->t_send_psnp
[1]);
285 thread_add_event(master
, isis_event_dis_status_change
, circuit
, 0, NULL
);
291 isis_dr_commence (struct isis_circuit
*circuit
, int level
)
293 u_char old_dr
[ISIS_SYS_ID_LEN
+ 2];
295 if (isis
->debugs
& DEBUG_EVENTS
)
296 zlog_debug ("isis_dr_commence l%d", level
);
298 /* Lets keep a pause in DR election */
299 circuit
->u
.bc
.run_dr_elect
[level
- 1] = 0;
301 thread_add_timer(master
, isis_run_dr_l1
, circuit
,
302 2 * circuit
->hello_interval
[0],
303 &circuit
->u
.bc
.t_run_dr
[0]);
305 thread_add_timer(master
, isis_run_dr_l2
, circuit
,
306 2 * circuit
->hello_interval
[1],
307 &circuit
->u
.bc
.t_run_dr
[1]);
308 circuit
->u
.bc
.is_dr
[level
- 1] = 1;
312 memcpy (old_dr
, circuit
->u
.bc
.l1_desig_is
, ISIS_SYS_ID_LEN
+ 1);
313 LSP_FRAGMENT (old_dr
) = 0;
314 if (LSP_PSEUDO_ID (old_dr
))
316 /* there was a dr elected, purge its LSPs from the db */
317 lsp_purge_pseudo (old_dr
, circuit
, level
);
319 memcpy (circuit
->u
.bc
.l1_desig_is
, isis
->sysid
, ISIS_SYS_ID_LEN
);
320 *(circuit
->u
.bc
.l1_desig_is
+ ISIS_SYS_ID_LEN
) = circuit
->circuit_id
;
322 assert (circuit
->circuit_id
); /* must be non-zero */
323 /* if (circuit->t_send_l1_psnp)
324 thread_cancel (circuit->t_send_l1_psnp); */
325 lsp_generate_pseudo (circuit
, 1);
327 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[0]);
328 thread_add_timer(master
, isis_run_dr_l1
, circuit
,
329 2 * circuit
->hello_interval
[0],
330 &circuit
->u
.bc
.t_run_dr
[0]);
332 thread_add_timer(master
, send_l1_csnp
, circuit
,
333 isis_jitter(circuit
->csnp_interval
[level
- 1], CSNP_JITTER
),
334 &circuit
->t_send_csnp
[0]);
339 memcpy (old_dr
, circuit
->u
.bc
.l2_desig_is
, ISIS_SYS_ID_LEN
+ 1);
340 LSP_FRAGMENT (old_dr
) = 0;
341 if (LSP_PSEUDO_ID (old_dr
))
343 /* there was a dr elected, purge its LSPs from the db */
344 lsp_purge_pseudo (old_dr
, circuit
, level
);
346 memcpy (circuit
->u
.bc
.l2_desig_is
, isis
->sysid
, ISIS_SYS_ID_LEN
);
347 *(circuit
->u
.bc
.l2_desig_is
+ ISIS_SYS_ID_LEN
) = circuit
->circuit_id
;
349 assert (circuit
->circuit_id
); /* must be non-zero */
350 /* if (circuit->t_send_l1_psnp)
351 thread_cancel (circuit->t_send_l1_psnp); */
352 lsp_generate_pseudo (circuit
, 2);
354 THREAD_TIMER_OFF (circuit
->u
.bc
.t_run_dr
[1]);
355 thread_add_timer(master
, isis_run_dr_l2
, circuit
,
356 2 * circuit
->hello_interval
[1],
357 &circuit
->u
.bc
.t_run_dr
[1]);
359 thread_add_timer(master
, send_l2_csnp
, circuit
,
360 isis_jitter(circuit
->csnp_interval
[level
- 1], CSNP_JITTER
),
361 &circuit
->t_send_csnp
[1]);
364 thread_add_event(master
, isis_event_dis_status_change
, circuit
, 0, NULL
);