paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* BGP flap dampening |
| 2 | Copyright (C) 2001 IP Infusion Inc. |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 2, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | /* Structure maintained on a per-route basis. */ |
| 22 | struct bgp_damp_info |
| 23 | { |
| 24 | /* Doubly linked list. This information must be linked to |
| 25 | reuse_list or no_reuse_list. */ |
| 26 | struct bgp_damp_info *next; |
| 27 | struct bgp_damp_info *prev; |
| 28 | |
| 29 | /* Figure-of-merit. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 30 | unsigned int penalty; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | |
| 32 | /* Number of flapping. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 33 | unsigned int flap; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 34 | |
| 35 | /* First flap time */ |
| 36 | time_t start_time; |
| 37 | |
| 38 | /* Last time penalty was updated. */ |
| 39 | time_t t_updated; |
| 40 | |
| 41 | /* Time of route start to be suppressed. */ |
| 42 | time_t suppress_time; |
| 43 | |
| 44 | /* Back reference to bgp_info. */ |
| 45 | struct bgp_info *binfo; |
| 46 | |
| 47 | /* Back reference to bgp_node. */ |
| 48 | struct bgp_node *rn; |
| 49 | |
| 50 | /* Current index in the reuse_list. */ |
| 51 | int index; |
| 52 | |
| 53 | /* Last time message type. */ |
| 54 | u_char lastrecord; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 55 | #define BGP_RECORD_UPDATE 1U |
| 56 | #define BGP_RECORD_WITHDRAW 2U |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | |
| 58 | afi_t afi; |
| 59 | safi_t safi; |
| 60 | }; |
| 61 | |
| 62 | /* Specified parameter set configuration. */ |
| 63 | struct bgp_damp_config |
| 64 | { |
| 65 | /* Value over which routes suppressed. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 66 | unsigned int suppress_value; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 67 | |
| 68 | /* Value below which suppressed routes reused. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 69 | unsigned int reuse_limit; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | |
| 71 | /* Max time a route can be suppressed. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 72 | time_t max_suppress_time; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | |
| 74 | /* Time during which accumulated penalty reduces by half. */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 75 | time_t half_life; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | |
| 77 | /* Non-configurable parameters but fixed at implementation time. |
| 78 | * To change this values, init_bgp_damp() should be modified. |
| 79 | */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 80 | time_t tmax; /* Max time previous instability retained */ |
| 81 | unsigned int reuse_list_size; /* Number of reuse lists */ |
| 82 | unsigned int reuse_index_size; /* Size of reuse index array */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | |
| 84 | /* Non-configurable parameters. Most of these are calculated from |
| 85 | * the configurable parameters above. |
| 86 | */ |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 87 | unsigned int ceiling; /* Max value a penalty can attain */ |
| 88 | unsigned int decay_rate_per_tick; /* Calculated from half-life */ |
| 89 | unsigned int decay_array_size; /* Calculated using config parameters */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 90 | double scale_factor; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 91 | unsigned int reuse_scale_factor; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | |
| 93 | /* Decay array per-set based. */ |
| 94 | double *decay_array; |
| 95 | |
| 96 | /* Reuse index array per-set based. */ |
| 97 | int *reuse_index; |
| 98 | |
| 99 | /* Reuse list array per-set based. */ |
| 100 | struct bgp_damp_info **reuse_list; |
| 101 | int reuse_offset; |
| 102 | |
| 103 | /* All dampening information which is not on reuse list. */ |
| 104 | struct bgp_damp_info *no_reuse_list; |
| 105 | |
| 106 | /* Reuse timer thread per-set base. */ |
| 107 | struct thread* t_reuse; |
| 108 | }; |
| 109 | |
| 110 | #define BGP_DAMP_NONE 0 |
| 111 | #define BGP_DAMP_USED 1 |
| 112 | #define BGP_DAMP_SUPPRESSED 2 |
| 113 | |
| 114 | /* Time granularity for reuse lists */ |
| 115 | #define DELTA_REUSE 10 |
| 116 | |
| 117 | /* Time granularity for decay arrays */ |
| 118 | #define DELTA_T 5 |
| 119 | |
| 120 | #define DEFAULT_PENALTY 1000 |
| 121 | |
| 122 | #define DEFAULT_HALF_LIFE 15 |
| 123 | #define DEFAULT_REUSE 750 |
| 124 | #define DEFAULT_SUPPRESS 2000 |
| 125 | |
| 126 | #define REUSE_LIST_SIZE 256 |
| 127 | #define REUSE_ARRAY_SIZE 1024 |
| 128 | |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 129 | int bgp_damp_enable (struct bgp *, afi_t, safi_t, time_t, unsigned int, |
| 130 | unsigned int, time_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | int bgp_damp_disable (struct bgp *, afi_t, safi_t); |
| 132 | int bgp_damp_withdraw (struct bgp_info *, struct bgp_node *, |
| 133 | afi_t, safi_t, int); |
| 134 | int bgp_damp_update (struct bgp_info *, struct bgp_node *, afi_t, safi_t); |
| 135 | int bgp_damp_scan (struct bgp_info *, afi_t, safi_t); |
| 136 | void bgp_damp_info_free (struct bgp_damp_info *, int); |
| 137 | void bgp_damp_info_clean (); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame^] | 138 | char * bgp_get_reuse_time (unsigned int, char*, size_t); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | int bgp_damp_decay (time_t, int); |
| 140 | int bgp_config_write_damp (struct vty *); |
| 141 | void bgp_damp_info_vty (struct vty *, struct bgp_info *); |
| 142 | char * bgp_damp_reuse_time_vty (struct vty *, struct bgp_info *); |