summaryrefslogtreecommitdiff
path: root/ospf6d/ospf6_damp.c
blob: 878c48f609c58693ace850adc88d8c8c51cd530e (plain)
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
/*
 * OSPF flap dampening by Manav Bhatia
 * Copyright (C) 2002 
 * 
 * This file is part of GNU Zebra.
 * 
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 * 
 * GNU Zebra 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 GNU Zebra; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.  
 */

#include <zebra.h>
#include <math.h>

#include "log.h"
#include "prefix.h"
#include "thread.h"
#include "table.h"
#include "command.h"
#include "vty.h"

extern struct thread_master *master;

#include "ospf6_damp.h"

#ifdef HAVE_OSPF6_DAMP

#define DELTA_REUSE         10 /* Time granularity for reuse lists */
#define DELTA_T              5 /* Time granularity for decay arrays */
#define DEFAULT_HALF_LIFE   60 /* (sec)     1 min */

#define DEFAULT_PENALTY   1000
#define DEFAULT_REUSE      750
#define DEFAULT_SUPPRESS  2000

#define REUSE_LIST_SIZE    256
#define REUSE_ARRAY_SIZE  1024

/* Global variable to access damping configuration */
struct ospf6_damp_config damp_config;
struct ospf6_damp_config *dc = &damp_config;
u_int reuse_array_offset = 0;
struct route_table *damp_info_table[OSPF6_DAMP_TYPE_MAX];
struct thread *ospf6_reuse_thread = NULL;

int ospf6_damp_debug = 0;
#define IS_OSPF6_DEBUG_DAMP (ospf6_damp_debug)

static struct ospf6_damp_info *
ospf6_damp_lookup (u_short type, struct prefix *name)
{
  struct route_node *node;

  node = route_node_lookup (damp_info_table[type], name);
  if (node && node->info)
    return (struct ospf6_damp_info *) node->info;
  return NULL;
}

static struct ospf6_damp_info *
ospf6_damp_create (u_short type, struct prefix *name)
{
  struct route_node *node;
  struct ospf6_damp_info *di;
  char namebuf[64];

  di = ospf6_damp_lookup (type, name);
  if (di)
    return di;

  if (IS_OSPF6_DEBUG_DAMP)
    {
      prefix2str (name, namebuf, sizeof (namebuf));
      zlog_info ("DAMP: create: type: %d, name: %s", type, namebuf);
    }

  di = (struct ospf6_damp_info *)
    malloc (sizeof (struct ospf6_damp_info));
  memset (di, 0, sizeof (struct ospf6_damp_info));
  di->type = type;
  prefix_copy (&di->name, name);

  node = route_node_get (damp_info_table[type], name);
  node->info = di;

  return di;
}

static void
ospf6_damp_delete (u_short type, struct prefix *name)
{
  struct route_node *node;
  struct ospf6_damp_info *di;
  char namebuf[64];

  node = route_node_lookup (damp_info_table[type], name);
  if (! node || ! node->info)
    return;

  di = node->info;

  if (IS_OSPF6_DEBUG_DAMP)
    {
      prefix2str (&di->name, namebuf, sizeof (namebuf));
      zlog_info ("DAMP: delete: type: %d, name: %s",
                 di->type, namebuf);
    }

  node->info = NULL;
  free (di);
}

/* compute and fill the configuration parameter */
void
ospf6_damp_init_config (u_int half_life, u_int reuse,
                        u_int suppress, u_int t_hold)
{
  int i;
  double max_ratio, max_ratio1, max_ratio2;

  dc->half_life = half_life ? half_life : DEFAULT_HALF_LIFE;
  dc->reuse     = reuse     ? reuse     : DEFAULT_REUSE;
  dc->suppress  = suppress  ? suppress  : DEFAULT_SUPPRESS;
  dc->t_hold    = t_hold    ? t_hold    : 4 * dc->half_life;

  /* Initialize system-wide params */
  dc->delta_t = DELTA_T;
  dc->delta_reuse = DELTA_REUSE;
  dc->default_penalty = DEFAULT_PENALTY;
  dc->reuse_index_array_size = REUSE_ARRAY_SIZE;

  /* ceiling is the maximum penalty a route may attain */
  /* ceiling = reuse * 2^(T-hold/half-life) */
  dc->ceiling = (int)
    (dc->reuse * (pow (2, (double) dc->t_hold / dc->half_life)));

  /* Decay-array computations */
  /* decay_array_size = decay memory/time granularity */
  dc->decay_array_size = ceil ((double) dc->t_hold / dc->delta_t);
  dc->decay_array = malloc (sizeof (double) * (dc->decay_array_size));

  /* Each i-th element is per tick delay raised to the i-th power */
  dc->decay_array[0] = 1.0;
  dc->decay_array[1] = exp ((1.0 / (dc->half_life / dc->delta_t)) * log (0.5));
  for (i = 2; i < dc->decay_array_size; i++)
    dc->decay_array[i] = dc->decay_array[i - 1] * dc->decay_array[1];

  /* Reuse-list computations (reuse queue head array ?) */
  dc->reuse_list_size = ceil ((double) dc->t_hold / dc->delta_reuse) + 1;
  if (dc->reuse_list_size == 0 || dc->reuse_list_size > REUSE_LIST_SIZE)
    dc->reuse_list_size = REUSE_LIST_SIZE;
  dc->reuse_list_array = (struct ospf6_damp_info **)
    malloc (dc->reuse_list_size * sizeof (struct ospf6_reuse_list *));
  memset (dc->reuse_list_array, 0x00,
          dc->reuse_list_size * sizeof (struct ospf6_reuse_list *));

  /* Reuse-array computations */
  dc->reuse_index_array = malloc (sizeof (int) * dc->reuse_index_array_size);

  /*
   * This is the maximum ratio between the current value of the penalty and
   * the reuse value which can be indexed by the reuse array. It will be 
   * limited by the ceiling or by the amount of time that the reuse list 
   * covers 
   */
  max_ratio1 = (double) dc->ceiling / dc->reuse;
  max_ratio2 = exp ((double) dc->t_hold / dc->half_life) * log10 (2.0);
  max_ratio = (max_ratio2 != 0 && max_ratio2 < max_ratio1 ?
               max_ratio2 : max_ratio1);

  /*
   * reuse array is just an estimator and we need something
   * to use the full array 
   */
  dc->scale_factor = (double) dc->reuse_index_array_size / (max_ratio - 1);

  for (i = 0; i < dc->reuse_index_array_size; i++)
    {
      dc->reuse_index_array[i] = (int)
        (((double) dc->half_life / dc->delta_reuse) *
         log10 (1.0 / (dc->reuse * (1.0 + ((double) i / dc->scale_factor))))
         / log10 (0.5));
    }

  dc->enabled = ON;
}

static double
ospf6_damp_decay (time_t tdiff)
{
  int index = tdiff / dc->delta_t;

  if (index >= dc->decay_array_size)
    return 0;

  return dc->decay_array[index];
}

static int
ospf6_damp_reuse_index (int penalty)
{
  int index;

  index = (int) (((double) penalty / dc->reuse - 1.0) * dc->scale_factor);

  if (index >= dc->reuse_index_array_size)
    index = dc->reuse_index_array_size - 1;

  return (dc->reuse_index_array[index] - dc->reuse_index_array[0]);
}

static int
ospf6_reuse_list_lookup (struct ospf6_damp_info *di)
{
  struct ospf6_damp_info *info;

  for (info = dc->reuse_list_array[di->index]; info; info = info->next)
    {
      if (info == di)
        return 1;
    }
  return 0;
}

static void
ospf6_reuse_list_remove (struct ospf6_damp_info *di)
{
  if (di->prev)
    di->prev->next = di->next;
  else
    dc->reuse_list_array[di->index] = di->next;
  if (di->next)
    di->next->prev = di->prev;

  di->index = -1;
  di->prev = NULL;
  di->next = NULL;
}

static void
ospf6_reuse_list_add (struct ospf6_damp_info *di)
{
  /* set the index of reuse-array */
  di->index = (reuse_array_offset + (ospf6_damp_reuse_index (di->penalty)))
              % dc->reuse_list_size;

  /* insert to the head of the reuse list */
  di->next = dc->reuse_list_array[di->index];
  if (di->next)
    di->next->prev = di;
  di->prev = NULL;
  dc->reuse_list_array[di->index] = di;
}

/* When we quit damping for a target, we should execute proper event
   which have been postponed during damping */
static void
ospf6_damp_stop (struct ospf6_damp_info *di)
{
  time_t t_now;
  char namebuf[64];
  struct timeval now;

  if (IS_OSPF6_DEBUG_DAMP)
    {
      t_now = time (NULL);
      prefix2str (&di->name, namebuf, sizeof (namebuf));
      gettimeofday (&now, NULL);
      zlog_info ("DAMP: %lu.%06lu stop damping: %ld: type: %d, name: %s",
                 now.tv_sec, now.tv_usec,
                 t_now, di->type, namebuf);
    }

  /* set flag indicates that we're damping this target */
  di->damping = OFF;

  /* if the target's current status differ from that it should be,
     execute the proper event to repair his status */
  if (di->target_status != di->event_type)
    {
      (*(di->event)) (di->target);
      di->target_status = di->event_type;

      di->event = NULL;
      di->event_type = event_none;
    }
}

/* ospf6_reuse_timer is called every DELTA_REUSE seconds.
   Each route in the current reuse-list is evaluated
   and is used or requeued */
int
ospf6_damp_reuse_timer (struct thread *t)
{
  struct ospf6_damp_info *di, *next;
  time_t t_now, t_diff;
  char namebuf[64];
  struct timeval now;

  /* Restart the reuse timer */
  ospf6_reuse_thread =
    thread_add_timer (master, ospf6_damp_reuse_timer, NULL, dc->delta_reuse);

  t_now = time (NULL);

  /* get the damp info list head */
  di = dc->reuse_list_array[reuse_array_offset];
  dc->reuse_list_array[reuse_array_offset] = NULL;

  /* rotate the circular reuse list head array */
  reuse_array_offset = (reuse_array_offset + 1) % dc->reuse_list_size;

  /* for each damp info */
  while (di)
    {
      next = di->next;
      di->next = NULL;

      /* Update penalty */
      t_diff = t_now - di->t_updated;
      di->t_updated = t_now;
      di->penalty = (int)
        ((double) di->penalty * ospf6_damp_decay (t_diff));
      /* configration of ceiling may be just changed */
      if (di->penalty > dc->ceiling)
        di->penalty = dc->ceiling;

      if (IS_OSPF6_DEBUG_DAMP)
        {
          prefix2str (&di->name, namebuf, sizeof (namebuf));
          gettimeofday (&now, NULL);
          zlog_info ("DAMP: %lu.%06lu update penalty: type: %d, name: %s, penalty: %d",
                     now.tv_sec, now.tv_usec,
                     di->type, namebuf, di->penalty);
        }

      /* If the penalty becomes under reuse,
         call real event that we have been postponed. */
      if (di->penalty < dc->reuse && di->damping == ON)
        ospf6_damp_stop (di);

      /* If the penalty becomes less than the half of the
         reuse value, this damp info will be freed from reuse-list,
         by assuming that it is considered to be stable enough already,
         and there's no need to maintain flapping history for this. */
      if (di->penalty <= dc->reuse / 2)
        {
          ospf6_damp_delete (di->type, &di->name);
          di = next;
          continue;
        }

      /* re-insert to the reuse-list */
      ospf6_reuse_list_add (di);

      di = next;
    }

  return 0;
}

static void
ospf6_damp_event (damp_event_t event_type,
                  u_short type, struct prefix *name,
                  int (*event) (void *), void *target)
{
  time_t t_now, t_diff;
  struct ospf6_damp_info *di;
  char namebuf[64];
  struct timeval now;

  if (dc->enabled == OFF)
    {
      (*event) (target);
      return;
    }

  di = ospf6_damp_lookup (type, name);
  if (! di)
    di = ospf6_damp_create (type, name);

  t_now = time (NULL);

  di->event = event;
  di->target = target;
  di->event_type = event_type;

  if (! ospf6_reuse_list_lookup (di))
    di->t_start = t_now;
  else
    {
      ospf6_reuse_list_remove (di);

      t_diff = t_now - di->t_updated;
      di->penalty = (int) (di->penalty * ospf6_damp_decay (t_diff));
    }

  /* penalty only on down event */
  if (event_type == event_down)
    {
      di->flap++;
      di->penalty += dc->default_penalty;
    }

  /* limit penalty up to ceiling */
  if (di->penalty > dc->ceiling)
    di->penalty = dc->ceiling;

  if (IS_OSPF6_DEBUG_DAMP)
    {
      prefix2str (&di->name, namebuf, sizeof (namebuf));
      gettimeofday (&now, NULL);
      zlog_info ("DAMP: %lu.%06lu update penalty: type: %d, name: %s, penalty: %d",
                 now.tv_sec, now.tv_usec,
                 di->type, namebuf, di->penalty);
    }

  /* if penalty < reuse, stop damping here */
  if (di->penalty < dc->reuse && di->damping == ON)
    {
      if (IS_OSPF6_DEBUG_DAMP)
        {
          prefix2str (&di->name, namebuf, sizeof (namebuf));
          gettimeofday (&now, NULL);
          zlog_info ("DAMP: %lu.%06lu stop damping: %ld: type: %d, name: %s",
                     now.tv_sec, now.tv_usec,
                     t_now, di->type, namebuf);
        }
      di->damping = OFF;
    }

  /* if event == up and if penalty >= suppress , start damping here */
  if (di->event_type == event_up && di->penalty >= dc->suppress &&
      di->damping == OFF)
    {
      if (IS_OSPF6_DEBUG_DAMP)
        {
          prefix2str (&di->name, namebuf, sizeof (namebuf));
          gettimeofday (&now, NULL);
          zlog_info ("DAMP: %lu.%06lu start damping: %ld: type: %d, name: %s",
                     now.tv_sec, now.tv_usec,
                     t_now, type, namebuf);
        }
      di->damping = ON;
    }

  /* execute event if we're not damping */
  if (di->damping == OFF)
    {
      (*(di->event)) (di->target);
      di->target_status = di->event_type;
    }

  /* if the penalty goes beyond suppress value, start damping */
  if (di->penalty >= dc->suppress && di->damping == OFF)
    {
      if (IS_OSPF6_DEBUG_DAMP)
        {
          prefix2str (name, namebuf, sizeof (namebuf));
          gettimeofday (&now, NULL);
          zlog_info ("DAMP: %lu.%06lu start damping: %ld: type: %d, name: %s",
                     now.tv_sec, now.tv_usec,
                     t_now, type, namebuf);
        }
      di->damping = ON;
    }

  /* update last-updated-time field */
  di->t_updated = t_now;

  /* Insert it into the reuse list */
  ospf6_reuse_list_add (di);
}

void
ospf6_damp_event_up (u_short type, struct prefix *name,
                     int (*event) (void *), void *target)
{
  struct timeval now;

  gettimeofday (&now, NULL);
  if (IS_OSPF6_DEBUG_DAMP)
    zlog_info ("DAMP: Up   Event at %lu.%06lu", now.tv_sec, now.tv_usec);

  ospf6_damp_event (event_up, type, name, event, target);
}

void
ospf6_damp_event_down (u_short type, struct prefix *name,
                       int (*event) (void *), void *target)
{
  struct timeval now;

  gettimeofday (&now, NULL);
  if (IS_OSPF6_DEBUG_DAMP)
    zlog_info ("DAMP: Down Event at %lu.%06lu", now.tv_sec, now.tv_usec);

  ospf6_damp_event (event_down, type, name, event, target);
}

int
ospf6_damp_debug_thread (struct thread *thread)
{
  int i;
  struct ospf6_damp_info *di;
  char buf[256];
  time_t t_now;
  struct timeval now;

  for (i = 0; i < dc->reuse_list_size; i++)
    {
      for (di = dc->reuse_list_array[i]; di; di = di->next)
        {
          t_now = time (NULL);
          gettimeofday (&now, NULL);
          prefix2str (&di->name, buf, sizeof (buf));
          zlog_info ("DAMP: %lu.%06lu %c %-32s penalty %7u",
                     now.tv_sec, now.tv_usec,
                     (di->damping == ON ? 'D' : 'A'), buf,
                     (u_int) (di->penalty *
                              ospf6_damp_decay (t_now - di->t_updated)));
        }
    }
  thread_add_timer (master, ospf6_damp_debug_thread, NULL, 1);
  return 0;
}

DEFUN (show_ipv6_ospf6_route_flapping,
       show_ipv6_ospf6_route_flapping_cmd,
       "show ipv6 ospf6 route flapping",
       SHOW_STR
       IP6_STR
       OSPF6_STR)
{
  int i;
  struct ospf6_damp_info *di;
  char buf[256];
  time_t t_now;

  t_now = time (NULL);
  vty_out (vty, "%c %-32s %7s%s", ' ', "Prefix", "penalty", VTY_NEWLINE);

  for (i = 0; i < dc->reuse_list_size; i++)
    {
      for (di = dc->reuse_list_array[i]; di; di = di->next)
        {
          prefix2str (&di->name, buf, sizeof (buf));
          vty_out (vty, "%c %-32s %7u%s",
                   (di->damping == ON ? 'D' : ' '), buf,
                   (u_int) (di->penalty *
                            ospf6_damp_decay (t_now - di->t_updated)),
                   VTY_NEWLINE);
        }
    }

  return CMD_SUCCESS;
}

DEFUN (ospf6_flap_damping_route,
       ospf6_flap_damping_route_cmd,
       "flap-damping route <0-4294967295> <0-4294967295> "
                          "<0-4294967295> <0-4294967295>",
       "enable flap dampening\n"
       "enable route flap dampening\n"
       "half-life in second\n"
       "reuse value\n"
       "suppress value\n"
       "t-hold in second (maximum time that the target can be damped)\n"
      )
{
  u_int half_life, reuse, suppress, t_hold;

  if (argc)
    {
      half_life = (u_int) strtoul (argv[0], NULL, 10);
      reuse     = (u_int) strtoul (argv[1], NULL, 10);
      suppress  = (u_int) strtoul (argv[2], NULL, 10);
      t_hold    = (u_int) strtoul (argv[3], NULL, 10);
    }
  else
    {
      half_life = (u_int) DEFAULT_HALF_LIFE;
      reuse     = (u_int) DEFAULT_REUSE;
      suppress  = (u_int) DEFAULT_SUPPRESS;
      t_hold    = (u_int) DEFAULT_HALF_LIFE * 4;
    }

  if (reuse && suppress && reuse >= suppress)
    {
      vty_out (vty, "reuse value exceeded suppress value, failed%s\n",
               VTY_NEWLINE);
      return CMD_SUCCESS;
    }

  if (half_life && t_hold && half_life >= t_hold)
    {
      vty_out (vty, "half-life exceeded t-hold, failed%s\n", VTY_NEWLINE);
      return CMD_SUCCESS;
    }

  ospf6_damp_init_config (half_life, reuse, suppress, t_hold);

  if (ospf6_reuse_thread == NULL)
    ospf6_reuse_thread =
      thread_add_timer (master, ospf6_damp_reuse_timer, NULL, dc->delta_reuse);

  return CMD_SUCCESS;
}

DEFUN (show_ipv6_ospf6_damp_config,
       show_ipv6_ospf6_camp_config_cmd,
       "show ipv6 ospf6 damp config",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       "Flap-dampening information\n"
       "shows dampening configuration\n"
      )
{
  int i;

  vty_out (vty, "%10s %10s %10s %10s%s",
           "Half life", "Suppress", "Reuse", "T-hold",
           VTY_NEWLINE);
  vty_out (vty, "%10u %10u %10u %10u%s",
           dc->half_life, dc->suppress, dc->reuse, dc->t_hold,
           VTY_NEWLINE);
  vty_out (vty, "%s", VTY_NEWLINE);

  vty_out (vty, "Delta-t = %u%s", dc->delta_t, VTY_NEWLINE);
  vty_out (vty, "Delta-Reuse = %u%s", dc->delta_reuse, VTY_NEWLINE);
  vty_out (vty, "Default-Penalty = %u%s", dc->default_penalty, VTY_NEWLINE);
  vty_out (vty, "Ceiling = %u%s", dc->ceiling, VTY_NEWLINE);
  vty_out (vty, "ScaleFactor = %f%s", dc->scale_factor, VTY_NEWLINE);

  vty_out (vty, "DecayArray(%d) =%s", dc->decay_array_size, VTY_NEWLINE);
  for (i = 0; i < dc->decay_array_size; i++)
    {
      if (i % 10 == 0)
        vty_out (vty, "  ");
      vty_out (vty, " %f", dc->decay_array[i]);
      if (i % 10 == 0)
        vty_out (vty, "%s", VTY_NEWLINE);
    }
  vty_out (vty, "%s", VTY_NEWLINE);

  vty_out (vty, "ReuseIndexArray(%d) =%s",
           dc->reuse_index_array_size, VTY_NEWLINE);
  for (i = 0; i < dc->reuse_index_array_size; i++)
    {
      if (i % 10 == 0)
        vty_out (vty, "  ");
      vty_out (vty, " %d", dc->reuse_index_array[i]);
      if (i % 10 == 0)
        vty_out (vty, "%s", VTY_NEWLINE);
    }
  vty_out (vty, "%s", VTY_NEWLINE);

  return CMD_SUCCESS;
}

void
ospf6_damp_config_write (struct vty *vty)
{
  if (dc->enabled == ON)
    {
      vty_out (vty, " flap-damping route %u %u %u %u%s",
               dc->half_life, dc->reuse, dc->suppress, dc->t_hold,
               VTY_NEWLINE);
    }
}

DEFUN (debug_ospf6_damp,
       debug_ospf6_damp_cmd,
       "debug ospf6 damp",
       DEBUG_STR
       OSPF6_STR
       "Flap-dampening information\n"
      )
{
  ospf6_damp_debug = 1;
  return CMD_SUCCESS;
}

DEFUN (no_debug_ospf6_damp,
       no_debug_ospf6_damp_cmd,
       "no debug ospf6 damp",
       NO_STR
       DEBUG_STR
       OSPF6_STR
       "Flap-dampening information\n"
      )
{
  ospf6_damp_debug = 0;
  return CMD_SUCCESS;
}

DEFUN (show_debug_ospf6_damp,
       show_debug_ospf6_damp_cmd,
       "show debugging ospf6 damp",
       SHOW_STR
       DEBUG_STR
       OSPF6_STR
       "Flap-dampening information\n"
      )
{
  vty_out (vty, "debugging ospf6 damp is ");
  if (IS_OSPF6_DEBUG_DAMP)
    vty_out (vty, "enabled.");
  else
    vty_out (vty, "disabled.");
  vty_out (vty, "%s", VTY_NEWLINE);
  return CMD_SUCCESS;
}

void
ospf6_damp_init ()
{
  int i;
  for (i = 0; i < OSPF6_DAMP_TYPE_MAX; i++)
    damp_info_table[i] = route_table_init ();

  install_element (VIEW_NODE, &show_ipv6_ospf6_route_flapping_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_route_flapping_cmd);
  install_element (ENABLE_NODE, &show_ipv6_ospf6_camp_config_cmd);
  install_element (OSPF6_NODE, &ospf6_flap_damping_route_cmd);

  install_element (ENABLE_NODE, &show_debug_ospf6_damp_cmd);
  install_element (CONFIG_NODE, &debug_ospf6_damp_cmd);
  install_element (CONFIG_NODE, &no_debug_ospf6_damp_cmd);

  thread_add_event (master, ospf6_damp_debug_thread, NULL, 0);
}

#endif /* HAVE_OSPF6_DAMP */