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; if not, write to the Free Software Foundation, Inc.,
21
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include <net/ethernet.h>
36
#include "isisd/dict.h"
37
#include "isisd/isis_constants.h"
38
#include "isisd/isis_common.h"
39
#include "isisd/isis_misc.h"
40
#include "isisd/isis_flags.h"
41
#include "isisd/isis_circuit.h"
42
#include "isisd/isisd.h"
43
#include "isisd/isis_adjacency.h"
44
#include "isisd/isis_constants.h"
45
#include "isisd/isis_pdu.h"
46
#include "isisd/isis_tlv.h"
47
#include "isisd/isis_lsp.h"
48
#include "isisd/isis_dr.h"
49
#include "isisd/isis_events.h"
51
extern struct isis *isis;
52
extern struct thread_master *master;
55
isis_disflag2string (int disflag) {
65
return "unknown DIS state";
67
return NULL; /* not reached */
73
isis_run_dr_l1 (struct thread *thread)
75
struct isis_circuit *circuit;
77
circuit = THREAD_ARG (thread);
80
if (circuit->u.bc.run_dr_elect[0])
81
zlog_warn ("isis_run_dr(): run_dr_elect already set for l1");
83
circuit->u.bc.t_run_dr[0] = NULL;
84
circuit->u.bc.run_dr_elect[0] = 1;
90
isis_run_dr_l2 (struct thread *thread)
92
struct isis_circuit *circuit;
94
circuit = THREAD_ARG (thread);
97
if (circuit->u.bc.run_dr_elect[1])
98
zlog_warn ("isis_run_dr(): run_dr_elect already set for l2");
101
circuit->u.bc.t_run_dr[1] = NULL;
102
circuit->u.bc.run_dr_elect[1] = 1;
108
isis_check_dr_change (struct isis_adjacency *adj, int level)
112
if ( adj->dis_record[level-1].dis !=
113
adj->dis_record[(1*ISIS_LEVELS) + level - 1].dis)
114
/* was there a DIS state transition ? */
116
adj->dischanges[level-1]++;
117
/* ok rotate the history list through */
118
for (i = DIS_RECORDS - 1; i > 0; i--)
120
adj->dis_record[(i * ISIS_LEVELS) + level - 1].dis =
121
adj->dis_record[((i-1) * ISIS_LEVELS) + level - 1].dis;
122
adj->dis_record[(i * ISIS_LEVELS) + level - 1].last_dis_change =
123
adj->dis_record[((i-1) * ISIS_LEVELS) + level - 1].last_dis_change;
130
isis_dr_elect (struct isis_circuit *circuit, int level)
133
struct listnode *node;
134
struct isis_adjacency *adj, *adj_dr = NULL;
135
struct list *list = list_new ();
137
int biggest_prio = -1;
138
int cmp_res, retval = ISIS_OK;
140
own_prio = circuit->u.bc.priority[level - 1];
141
adjdb = circuit->u.bc.adjdb[level - 1];
144
zlog_warn ("isis_dr_elect() adjdb == NULL");
145
retval = ISIS_WARNING;
149
isis_adj_build_up_list (adjdb, list);
152
* Loop the adjacencies and find the one with the biggest priority
154
for (node = listhead (list); node; nextnode (node)) {
155
adj = getdata (node);
156
/* clear flag for show output */
157
adj->dis_record[level-1].dis = ISIS_IS_NOT_DIS;
158
adj->dis_record[level-1].last_dis_change = time (NULL);
160
if (adj->prio[level-1] > biggest_prio) {
161
biggest_prio = adj->prio[level-1];
163
} else if (adj->prio[level-1] == biggest_prio) {
165
* Comparison of MACs breaks a tie
168
cmp_res = memcmp (adj_dr->snpa, adj->snpa, ETH_ALEN);
173
zlog_warn ("isis_dr_elect(): multiple adjacencies with same SNPA");
182
* Could not find the DR - means we are alone and thus the DR
184
if ( !circuit->u.bc.is_dr[level - 1]) {
187
return isis_dr_commence (circuit, level);
193
* Now we have the DR adjacency, compare it to self
195
if (adj_dr->prio[level-1] < own_prio || (adj_dr->prio[level-1] == own_prio &&
196
memcmp (adj_dr->snpa, circuit->u.bc.snpa,
198
if (!circuit->u.bc.is_dr[level - 1]) {
200
* We are the DR -> commence
203
return isis_dr_commence (circuit, level);
207
/* ok we have found the DIS - lets mark the adjacency */
208
/* set flag for show output */
209
adj_dr->dis_record[level - 1].dis = ISIS_IS_DIS;
210
adj_dr->dis_record[level - 1].last_dis_change = time(NULL);
212
/* now loop through a second time to check if there has been a DIS change
213
* if yes rotate the history log
216
for (node = listhead (list); node; nextnode (node)) {
217
adj = getdata (node);
218
isis_check_dr_change(adj, level);
222
* We are not DR - if we were -> resign
225
if (circuit->u.bc.is_dr[level - 1]) {
227
return isis_dr_resign (circuit, level);
237
isis_dr_resign (struct isis_circuit *circuit, int level)
239
u_char id[ISIS_SYS_ID_LEN + 2];
241
zlog_info ("isis_dr_resign l%d", level);
243
circuit->u.bc.is_dr[level - 1] = 0;
244
circuit->u.bc.run_dr_elect[level - 1] = 0;
245
THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[level - 1]);
246
THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
248
memcpy (id, isis->sysid, ISIS_SYS_ID_LEN);
249
LSP_PSEUDO_ID(id) = circuit->circuit_id;
250
LSP_FRAGMENT(id) = 0;
251
lsp_purge_dr (id, circuit, level);
254
memset (circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
256
THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
258
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
259
circuit, 2 * circuit->hello_interval[1]);
261
THREAD_TIMER_ON(master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
262
isis_jitter (circuit->psnp_interval[level - 1], PSNP_JITTER));
264
memset (circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
266
THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
268
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
269
circuit, 2 * circuit->hello_interval[1]);
271
THREAD_TIMER_ON(master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
272
isis_jitter (circuit->psnp_interval[level - 1], PSNP_JITTER));
275
thread_add_event (master, isis_event_dis_status_change, circuit, 0);
281
isis_dr_commence (struct isis_circuit *circuit, int level)
283
u_char old_dr[ISIS_SYS_ID_LEN + 2];
285
zlog_info ("isis_dr_commence l%d", level);
287
/* Lets keep a pause in DR election */
288
circuit->u.bc.run_dr_elect[level - 1] = 0;
290
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
291
circuit, 2 * circuit->hello_multiplier[0] *
292
circuit->hello_interval[0]);
294
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
295
circuit, 2 * circuit->hello_multiplier[1] *
296
circuit->hello_interval[1]);
297
circuit->u.bc.is_dr[level - 1] = 1;
300
memcpy (old_dr, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
301
LSP_FRAGMENT (old_dr) = 0;
302
if (LSP_PSEUDO_ID(old_dr)) {
303
/* there was a dr elected, purge its LSPs from the db */
304
lsp_purge_dr (old_dr, circuit, level);
306
memcpy (circuit->u.bc.l1_desig_is, isis->sysid, ISIS_SYS_ID_LEN);
307
*(circuit->u.bc.l1_desig_is + ISIS_SYS_ID_LEN) = circuit->circuit_id;
309
assert (circuit->circuit_id); /* must be non-zero */
310
/* if (circuit->t_send_l1_psnp)
311
thread_cancel (circuit->t_send_l1_psnp); */
312
lsp_l1_pseudo_generate (circuit);
314
THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
315
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
316
circuit, 2 * circuit->hello_interval[0]);
318
THREAD_TIMER_ON(master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
319
isis_jitter(circuit->csnp_interval[level-1], CSNP_JITTER));
322
memcpy (old_dr, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
323
LSP_FRAGMENT (old_dr) = 0;
324
if (LSP_PSEUDO_ID(old_dr)) {
325
/* there was a dr elected, purge its LSPs from the db */
326
lsp_purge_dr (old_dr, circuit, level);
328
memcpy (circuit->u.bc.l2_desig_is, isis->sysid, ISIS_SYS_ID_LEN);
329
*(circuit->u.bc.l2_desig_is + ISIS_SYS_ID_LEN) = circuit->circuit_id;
331
assert (circuit->circuit_id); /* must be non-zero */
332
/* if (circuit->t_send_l1_psnp)
333
thread_cancel (circuit->t_send_l1_psnp); */
334
lsp_l2_pseudo_generate (circuit);
336
THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
337
THREAD_TIMER_ON(master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
338
circuit, 2 * circuit->hello_interval[1]);
340
THREAD_TIMER_ON(master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
341
isis_jitter (circuit->csnp_interval[level-1], CSNP_JITTER));
344
thread_add_event (master, isis_event_dis_status_change, circuit, 0);