]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_damp.h
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[mirror_frr.git] / bgpd / bgp_damp.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP flap dampening
3 * Copyright (C) 2001 IP Infusion Inc.
4 */
5
6 #ifndef _QUAGGA_BGP_DAMP_H
7 #define _QUAGGA_BGP_DAMP_H
8
9 #include "bgpd/bgp_table.h"
10
11 /* Structure maintained on a per-route basis. */
12 struct bgp_damp_info {
13 /* Doubly linked list. This information must be linked to
14 reuse_list or no_reuse_list. */
15 struct bgp_damp_info *next;
16 struct bgp_damp_info *prev;
17
18 /* Figure-of-merit. */
19 unsigned int penalty;
20
21 /* Number of flapping. */
22 unsigned int flap;
23
24 /* First flap time */
25 time_t start_time;
26
27 /* Last time penalty was updated. */
28 time_t t_updated;
29
30 /* Time of route start to be suppressed. */
31 time_t suppress_time;
32
33 /* Back reference to bgp_path_info. */
34 struct bgp_path_info *path;
35
36 /* Back reference to bgp_node. */
37 struct bgp_dest *dest;
38
39 /* Current index in the reuse_list. */
40 int index;
41
42 /* Last time message type. */
43 uint8_t lastrecord;
44 #define BGP_RECORD_UPDATE 1U
45 #define BGP_RECORD_WITHDRAW 2U
46
47 afi_t afi;
48 safi_t safi;
49 };
50
51 /* Specified parameter set configuration. */
52 struct bgp_damp_config {
53 /* Value over which routes suppressed. */
54 unsigned int suppress_value;
55
56 /* Value below which suppressed routes reused. */
57 unsigned int reuse_limit;
58
59 /* Max time a route can be suppressed. */
60 time_t max_suppress_time;
61
62 /* Time during which accumulated penalty reduces by half. */
63 time_t half_life;
64
65 /* Non-configurable parameters but fixed at implementation time.
66 * To change this values, init_bgp_damp() should be modified.
67 */
68 time_t tmax; /* Max time previous instability retained */
69 unsigned int reuse_list_size; /* Number of reuse lists */
70 unsigned int reuse_index_size; /* Size of reuse index array */
71
72 /* Non-configurable parameters. Most of these are calculated from
73 * the configurable parameters above.
74 */
75 unsigned int ceiling; /* Max value a penalty can attain */
76 unsigned int decay_rate_per_tick; /* Calculated from half-life */
77 unsigned int decay_array_size; /* Calculated using config parameters */
78 double scale_factor;
79 unsigned int reuse_scale_factor;
80
81 /* Decay array per-set based. */
82 double *decay_array;
83
84 /* Reuse index array per-set based. */
85 int *reuse_index;
86
87 /* Reuse list array per-set based. */
88 struct bgp_damp_info **reuse_list;
89 int reuse_offset;
90
91 /* All dampening information which is not on reuse list. */
92 struct bgp_damp_info *no_reuse_list;
93
94 /* Reuse timer thread per-set base. */
95 struct event *t_reuse;
96
97 afi_t afi;
98 safi_t safi;
99 };
100
101 #define BGP_DAMP_NONE 0
102 #define BGP_DAMP_USED 1
103 #define BGP_DAMP_SUPPRESSED 2
104
105 /* Time granularity for reuse lists */
106 #define DELTA_REUSE 10
107
108 /* Time granularity for decay arrays */
109 #define DELTA_T 5
110
111 #define DEFAULT_PENALTY 1000
112
113 #define DEFAULT_HALF_LIFE 15
114 #define DEFAULT_REUSE 750
115 #define DEFAULT_SUPPRESS 2000
116
117 #define REUSE_LIST_SIZE 256
118 #define REUSE_ARRAY_SIZE 1024
119
120 extern int bgp_damp_enable(struct bgp *bgp, afi_t afi, safi_t safi, time_t half,
121 unsigned int reuse, unsigned int suppress,
122 time_t max);
123 extern int bgp_damp_disable(struct bgp *bgp, afi_t afi, safi_t safi);
124 extern int bgp_damp_withdraw(struct bgp_path_info *path, struct bgp_dest *dest,
125 afi_t afi, safi_t safi, int attr_change);
126 extern int bgp_damp_update(struct bgp_path_info *path, struct bgp_dest *dest,
127 afi_t afi, safi_t saff);
128 extern void bgp_damp_info_free(struct bgp_damp_info *path, int withdraw,
129 afi_t afi, safi_t safi);
130 extern void bgp_damp_info_clean(afi_t afi, safi_t safi);
131 extern int bgp_damp_decay(time_t tdiff, int penalty,
132 struct bgp_damp_config *damp);
133 extern void bgp_config_write_damp(struct vty *vty, afi_t afi, safi_t safi);
134 extern void bgp_damp_info_vty(struct vty *vty, struct bgp_path_info *path,
135 afi_t afi, safi_t safi, json_object *json_path);
136 extern const char *bgp_damp_reuse_time_vty(struct vty *vty,
137 struct bgp_path_info *path,
138 char *timebuf, size_t len, afi_t afi,
139 safi_t safi, bool use_json,
140 json_object *json);
141 extern int bgp_show_dampening_parameters(struct vty *vty, afi_t afi,
142 safi_t safi, uint16_t show_flags);
143
144 #endif /* _QUAGGA_BGP_DAMP_H */