]> git.proxmox.com Git - mirror_frr.git/blob - babeld/route.h
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / babeld / route.h
1 /*
2 Copyright (c) 2007, 2008 by Juliusz Chroboczek
3 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23
24 #ifndef BABEL_ROUTE_H
25 #define BABEL_ROUTE_H
26
27 #include "babel_interface.h"
28 #include "source.h"
29
30 enum babel_diversity {
31 DIVERSITY_NONE,
32 DIVERSITY_INTERFACE_1,
33 DIVERSITY_CHANNEL_1,
34 DIVERSITY_CHANNEL,
35 };
36
37 #define DIVERSITY_HOPS 8
38
39 struct babel_route {
40 struct source *src;
41 unsigned short refmetric;
42 unsigned short cost;
43 unsigned short add_metric;
44 unsigned short seqno;
45 struct neighbour *neigh;
46 unsigned char nexthop[16];
47 time_t time;
48 unsigned short hold_time; /* in seconds */
49 unsigned short smoothed_metric; /* for route selection */
50 time_t smoothed_metric_time;
51 short installed;
52 unsigned char channels[DIVERSITY_HOPS];
53 struct babel_route *next;
54 };
55
56 struct route_stream;
57
58 extern struct babel_route **routes;
59 extern int kernel_metric;
60 extern enum babel_diversity diversity_kind;
61 extern int diversity_factor;
62 extern int keep_unfeasible;
63 extern int smoothing_half_life;
64
65 static inline int
66 route_metric(const struct babel_route *route)
67 {
68 int m = (int)route->refmetric + route->cost + route->add_metric;
69 return MIN(m, INFINITY);
70 }
71
72 static inline int
73 route_metric_noninterfering(const struct babel_route *route)
74 {
75 int m =
76 (int)route->refmetric +
77 (diversity_factor * route->cost + 128) / 256 +
78 route->add_metric;
79 m = MAX(m, route->refmetric + 1);
80 return MIN(m, INFINITY);
81 }
82
83 struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
84 struct neighbour *neigh, const unsigned char *nexthop);
85 struct babel_route *find_installed_route(const unsigned char *prefix,
86 unsigned char plen);
87 int installed_routes_estimate(void);
88 void flush_route(struct babel_route *route);
89 void flush_all_routes(void);
90 void flush_neighbour_routes(struct neighbour *neigh);
91 void flush_interface_routes(struct interface *ifp, int v4only);
92 struct route_stream *route_stream(int installed);
93 struct babel_route *route_stream_next(struct route_stream *stream);
94 void route_stream_done(struct route_stream *stream);
95 void install_route(struct babel_route *route);
96 void uninstall_route(struct babel_route *route);
97 int route_feasible(struct babel_route *route);
98 int route_old(struct babel_route *route);
99 int route_expired(struct babel_route *route);
100 int route_interferes(struct babel_route *route, struct interface *ifp);
101 int update_feasible(struct source *src,
102 unsigned short seqno, unsigned short refmetric);
103 void change_smoothing_half_life(int half_life);
104 int route_smoothed_metric(struct babel_route *route);
105 struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen,
106 int feasible, struct neighbour *exclude);
107 struct babel_route *install_best_route(const unsigned char prefix[16],
108 unsigned char plen);
109 void update_neighbour_metric(struct neighbour *neigh, int change);
110 void update_interface_metric(struct interface *ifp);
111 void update_route_metric(struct babel_route *route);
112 struct babel_route *update_route(const unsigned char *id,
113 const unsigned char *prefix, unsigned char plen,
114 unsigned short seqno, unsigned short refmetric,
115 unsigned short interval, struct neighbour *neigh,
116 const unsigned char *nexthop,
117 const unsigned char *channels, int channels_len);
118 void retract_neighbour_routes(struct neighbour *neigh);
119 void send_unfeasible_request(struct neighbour *neigh, int force,
120 unsigned short seqno, unsigned short metric,
121 struct source *src);
122 void send_triggered_update(struct babel_route *route,
123 struct source *oldsrc, unsigned oldmetric);
124 void route_changed(struct babel_route *route,
125 struct source *oldsrc, unsigned short oldmetric);
126 void route_lost(struct source *src, unsigned oldmetric);
127 void expire_routes(void);
128
129 #endif