File: isis_events.c

package info (click to toggle)
quagga 0.99.5-5etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 12,140 kB
  • ctags: 12,172
  • sloc: ansic: 170,694; sh: 10,447; perl: 639; makefile: 547; awk: 129; lisp: 62
file content (323 lines) | stat: -rw-r--r-- 8,491 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 * IS-IS Rout(e)ing protocol - isis_events.h   
 *
 * Copyright (C) 2001,2002   Sampo Saaristo
 *                           Tampere University of Technology      
 *                           Institute of Communications Engineering
 *
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public Licenseas published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) 
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
 * more details.

 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#include <zebra.h>

#include "log.h"
#include "memory.h"
#include "if.h"
#include "linklist.h"
#include "command.h"
#include "thread.h"
#include "hash.h"
#include "prefix.h"
#include "stream.h"

#include "isisd/dict.h"
#include "isisd/include-netbsd/iso.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_tlv.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_dr.h"
#include "isisd/isis_flags.h"
#include "isisd/isisd.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_spf.h"

extern struct thread_master *master;
extern struct isis *isis;

/* debug isis-spf spf-events 
 4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
 4w4d: ISIS-Spf (tlt): L2, 0000.0000.0042.01-00 TLV contents changed, code 0x2
 4w4d: ISIS-Spf (tlt): L2, new LSP 0 DEAD.BEEF.0043.00-00
 4w5d: ISIS-Spf (tlt): L1 SPF needed, periodic SPF, from 0x6091C844
 4w5d: ISIS-Spf (tlt): L2 SPF needed, periodic SPF, from 0x6091C844
*/

void
isis_event_circuit_state_change (struct isis_circuit *circuit, int up)
{
  struct isis_area *area;

  area = circuit->area;
  assert (area);
  area->circuit_state_changes++;

  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) circuit %s", circuit->area->area_tag,
	       up ? "up" : "down");

  /*
   * Regenerate LSPs this affects
   */
  lsp_regenerate_schedule (area);

  return;
}

void
isis_event_system_type_change (struct isis_area *area, int newtype)
{
  struct listnode *node;
  struct isis_circuit *circuit;

  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) system type change %s -> %s", area->area_tag,
	       circuit_t2string (area->is_type), circuit_t2string (newtype));

  if (area->is_type == newtype)
    return;			/* No change */

  switch (area->is_type)
    {
    case IS_LEVEL_1:
      if (area->lspdb[1] == NULL)
	area->lspdb[1] = lsp_db_init ();
      lsp_l2_generate (area);
      break;
    case IS_LEVEL_1_AND_2:
      if (newtype == IS_LEVEL_1)
	{
	  lsp_db_destroy (area->lspdb[1]);
	}
      else
	{
	  lsp_db_destroy (area->lspdb[0]);
	}
      break;
    case IS_LEVEL_2:
      if (area->lspdb[0] == NULL)
	area->lspdb[0] = lsp_db_init ();
      lsp_l1_generate (area);
      break;
    default:
      break;
    }

  area->is_type = newtype;
  for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit))
    isis_event_circuit_type_change (circuit, newtype);

  spftree_area_init (area);
  lsp_regenerate_schedule (area);

  return;
}

void
isis_event_area_addr_change (struct isis_area *area)
{

}

static void
circuit_commence_level (struct isis_circuit *circuit, int level)
{
  if (level == 1)
    {
      THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit,
		       isis_jitter (circuit->psnp_interval[0], PSNP_JITTER));

      if (circuit->circ_type == CIRCUIT_T_BROADCAST)
	{
	  THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[0], isis_run_dr_l1,
			   circuit, 2 * circuit->hello_interval[1]);

	  THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
			   send_lan_l1_hello, circuit,
			   isis_jitter (circuit->hello_interval[0],
					IIH_JITTER));

	  circuit->u.bc.lan_neighs[0] = list_new ();
	}
    }
  else
    {
      THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit,
		       isis_jitter (circuit->psnp_interval[1], PSNP_JITTER));

      if (circuit->circ_type == CIRCUIT_T_BROADCAST)
	{
	  THREAD_TIMER_ON (master, circuit->u.bc.t_run_dr[1], isis_run_dr_l2,
			   circuit, 2 * circuit->hello_interval[1]);

	  THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
			   send_lan_l2_hello, circuit,
			   isis_jitter (circuit->hello_interval[1],
					IIH_JITTER));

	  circuit->u.bc.lan_neighs[1] = list_new ();
	}
    }

  return;
}

static void
circuit_resign_level (struct isis_circuit *circuit, int level)
{
  int idx = level - 1;

  THREAD_TIMER_OFF (circuit->t_send_csnp[idx]);
  THREAD_TIMER_OFF (circuit->t_send_psnp[idx]);

  if (circuit->circ_type == CIRCUIT_T_BROADCAST)
    {
      THREAD_TIMER_OFF (circuit->u.bc.t_send_lan_hello[idx]);
      THREAD_TIMER_OFF (circuit->u.bc.t_run_dr[idx]);
      THREAD_TIMER_OFF (circuit->u.bc.t_refresh_pseudo_lsp[idx]);
      circuit->u.bc.run_dr_elect[idx] = 0;
    }

  return;
}

void
isis_event_circuit_type_change (struct isis_circuit *circuit, int newtype)
{

  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) circuit type change %s -> %s",
	       circuit->area->area_tag,
	       circuit_t2string (circuit->circuit_is_type),
	       circuit_t2string (newtype));

  if (circuit->circuit_is_type == newtype)
    return;			/* No change */

  if (!(newtype & circuit->area->is_type))
    {
      zlog_err ("ISIS-Evt (%s) circuit type change - invalid level %s because"
		" area is %s", circuit->area->area_tag,
		circuit_t2string (newtype),
		circuit_t2string (circuit->area->is_type));
      return;
    }

  switch (circuit->circuit_is_type)
    {
    case IS_LEVEL_1:
      if (newtype == IS_LEVEL_2)
	circuit_resign_level (circuit, 1);
      circuit_commence_level (circuit, 2);
      break;
    case IS_LEVEL_1_AND_2:
      if (newtype == IS_LEVEL_1)
	circuit_resign_level (circuit, 2);
      else
	circuit_resign_level (circuit, 1);
      break;
    case IS_LEVEL_2:
      if (newtype == IS_LEVEL_1)
	circuit_resign_level (circuit, 2);
      circuit_commence_level (circuit, 1);
      break;
    default:
      break;
    }

  circuit->circuit_is_type = newtype;
  lsp_regenerate_schedule (circuit->area);

  return;
}

 /* 04/18/2002 by Gwak. */
 /**************************************************************************
  *
  * EVENTS for LSP generation
  *
  * 1) an Adajacency or Circuit Up/Down event
  * 2) a chnage in Circuit metric
  * 3) a change in Reachable Address metric
  * 4) a change in manualAreaAddresses
  * 5) a change in systemID
  * 6) a change in DIS status
  * 7) a chnage in the waiting status
  *
  * ***********************************************************************
  *
  * current support event
  *
  * 1) Adjacency Up/Down event
  * 6) a change in DIS status
  *
  * ***********************************************************************/

void
isis_event_adjacency_state_change (struct isis_adjacency *adj, int newstate)
{
  /* adjacency state change event. 
   * - the only proto-type was supported */

  /* invalid arguments */
  if (!adj || !adj->circuit || !adj->circuit->area)
    return;

  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) Adjacency State change",
		adj->circuit->area->area_tag);

  /* LSP generation again */
  lsp_regenerate_schedule (adj->circuit->area);

  return;
}

/* events supporting code */

int
isis_event_dis_status_change (struct thread *thread)
{
  struct isis_circuit *circuit;

  circuit = THREAD_ARG (thread);

  /* invalid arguments */
  if (!circuit || !circuit->area)
    return 0;
  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) DIS status change", circuit->area->area_tag);

  /* LSP generation again */
  lsp_regenerate_schedule (circuit->area);

  return 0;
}

void
isis_event_auth_failure (char *area_tag, const char *error_string, u_char *sysid)
{
  if (isis->debugs & DEBUG_EVENTS)
    zlog_debug ("ISIS-Evt (%s) Authentication failure %s from %s",
		area_tag, error_string, sysid_print (sysid));

  return;
}