]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_damp.h
Merge pull request #8820 from anlancs/master-vtysh-hostname
[mirror_frr.git] / bgpd / bgp_damp.h
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _QUAGGA_BGP_DAMP_H
22 #define _QUAGGA_BGP_DAMP_H
23
24 #include "bgpd/bgp_table.h"
25
26 /* Structure maintained on a per-route basis. */
27 struct bgp_damp_info {
28 /* Figure-of-merit. */
29 unsigned int penalty;
30
31 /* Number of flapping. */
32 unsigned int flap;
33
34 /* First flap time */
35 time_t start_time;
36
37 /* Last time penalty was updated. */
38 time_t t_updated;
39
40 /* Time of route start to be suppressed. */
41 time_t suppress_time;
42
43 /* Back reference to associated dampening configuration. */
44 struct bgp_damp_config *config;
45
46 /* Back reference to bgp_path_info. */
47 struct bgp_path_info *path;
48
49 /* Back reference to bgp_node. */
50 struct bgp_dest *dest;
51
52 /* Current index in the reuse_list. */
53 int index;
54 #define BGP_DAMP_NO_REUSE_LIST_INDEX \
55 (-1) /* index for elements on no_reuse_list */
56
57 /* Last time message type. */
58 uint8_t lastrecord;
59 #define BGP_RECORD_UPDATE 1U
60 #define BGP_RECORD_WITHDRAW 2U
61
62 afi_t afi;
63 safi_t safi;
64 };
65
66 struct reuselist_node {
67 SLIST_ENTRY(reuselist_node) entry;
68 struct bgp_damp_info *info;
69 };
70
71 SLIST_HEAD(reuselist, reuselist_node);
72
73 /* Specified parameter set configuration. */
74 struct bgp_damp_config {
75 /* Value over which routes suppressed. */
76 unsigned int suppress_value;
77
78 /* Value below which suppressed routes reused. */
79 unsigned int reuse_limit;
80
81 /* Max time a route can be suppressed. */
82 time_t max_suppress_time;
83
84 /* Time during which accumulated penalty reduces by half. */
85 time_t half_life;
86
87 /* Non-configurable parameters but fixed at implementation time.
88 * To change this values, init_bgp_damp() should be modified.
89 */
90 time_t tmax; /* Max time previous instability retained */
91 unsigned int reuse_list_size; /* Number of reuse lists */
92 unsigned int reuse_index_size; /* Size of reuse index array */
93
94 /* Non-configurable parameters. Most of these are calculated from
95 * the configurable parameters above.
96 */
97 unsigned int ceiling; /* Max value a penalty can attain */
98 unsigned int decay_rate_per_tick; /* Calculated from half-life */
99 unsigned int decay_array_size; /* Calculated using config parameters */
100 double scale_factor;
101 unsigned int reuse_scale_factor;
102
103 /* Decay array per-set based. */
104 double *decay_array;
105
106 /* Reuse index array per-set based. */
107 int *reuse_index;
108
109 /* Reuse list array per-set based. */
110 struct reuselist *reuse_list;
111 unsigned int reuse_offset;
112
113 /* All dampening information which is not on reuse list. */
114 struct reuselist no_reuse_list;
115
116 /* Reuse timer thread per-set base. */
117 struct thread *t_reuse;
118
119 afi_t afi;
120 safi_t safi;
121 };
122
123 #define BGP_DAMP_NONE 0
124 #define BGP_DAMP_USED 1
125 #define BGP_DAMP_SUPPRESSED 2
126
127 /* Time granularity for reuse lists */
128 #define DELTA_REUSE 10
129
130 /* Time granularity for decay arrays */
131 #define DELTA_T 5
132
133 #define DEFAULT_PENALTY 1000
134
135 #define DEFAULT_HALF_LIFE 15
136 #define DEFAULT_REUSE 750
137 #define DEFAULT_SUPPRESS 2000
138
139 #define REUSE_LIST_SIZE 256
140 #define REUSE_ARRAY_SIZE 1024
141
142 extern struct bgp_damp_config *get_active_bdc_from_pi(struct bgp_path_info *pi,
143 afi_t afi, safi_t safi);
144 extern int bgp_damp_enable(struct bgp *, afi_t, safi_t, time_t, unsigned int,
145 unsigned int, time_t);
146 extern int bgp_damp_disable(struct bgp *, afi_t, safi_t);
147 extern int bgp_damp_withdraw(struct bgp_path_info *path, struct bgp_dest *dest,
148 afi_t afi, safi_t safi, int attr_change);
149 extern int bgp_damp_update(struct bgp_path_info *path, struct bgp_dest *dest,
150 afi_t afi, safi_t saff);
151 extern void bgp_damp_info_free(struct bgp_damp_info **path,
152 struct bgp_damp_config *bdc, int withdraw,
153 afi_t afi, safi_t safi);
154 extern void bgp_damp_info_clean(struct bgp *bgp, struct bgp_damp_config *bdc,
155 afi_t afi, safi_t safi);
156 extern void bgp_damp_config_clean(struct bgp_damp_config *bdc);
157 extern int bgp_damp_decay(time_t, int, struct bgp_damp_config *damp);
158 extern void bgp_config_write_damp(struct vty *vty, struct bgp *bgp, afi_t afi,
159 safi_t safi);
160 extern void bgp_damp_info_vty(struct vty *vty, struct bgp *bgp,
161 struct bgp_path_info *path, afi_t afi,
162 safi_t safi, json_object *json_path);
163 extern const char *bgp_damp_reuse_time_vty(struct vty *vty,
164 struct bgp_path_info *path,
165 char *timebuf, size_t len, afi_t afi,
166 safi_t safi, bool use_json,
167 json_object *json);
168 extern int bgp_show_dampening_parameters(struct vty *vty, afi_t, safi_t,
169 uint16_t);
170 extern void bgp_peer_damp_enable(struct peer *peer, afi_t afi, safi_t safi,
171 time_t half, unsigned int reuse,
172 unsigned int suppress, time_t max);
173 extern void bgp_peer_damp_disable(struct peer *peer, afi_t afi, safi_t safi);
174 extern void bgp_config_write_peer_damp(struct vty *vty, struct peer *peer,
175 afi_t afi, safi_t safi);
176 extern void bgp_show_peer_dampening_parameters(struct vty *vty,
177 struct peer *peer, afi_t afi,
178 safi_t safi, bool use_json);
179
180 #endif /* _QUAGGA_BGP_DAMP_H */