]> git.proxmox.com Git - mirror_frr.git/blob - babeld/route.h
Merge pull request #2035 from vincentbernat/fix/no-etag-esi-ignore
[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 #define DIVERSITY_NONE 0
31 #define DIVERSITY_INTERFACE_1 1
32 #define DIVERSITY_CHANNEL_1 2
33 #define DIVERSITY_CHANNEL 3
34
35 #define DIVERSITY_HOPS 8
36
37 struct babel_route {
38 struct source *src;
39 unsigned short refmetric;
40 unsigned short cost;
41 unsigned short add_metric;
42 unsigned short seqno;
43 struct neighbour *neigh;
44 unsigned char nexthop[16];
45 time_t time;
46 unsigned short hold_time; /* in seconds */
47 unsigned short smoothed_metric; /* for route selection */
48 time_t smoothed_metric_time;
49 short installed;
50 unsigned char channels[DIVERSITY_HOPS];
51 struct babel_route *next;
52 };
53
54 struct route_stream;
55
56 extern struct babel_route **routes;
57 extern int kernel_metric;
58 extern int diversity_kind, diversity_factor;
59 extern int keep_unfeasible;
60 extern int smoothing_half_life;
61
62 static inline int
63 route_metric(const struct babel_route *route)
64 {
65 int m = (int)route->refmetric + route->cost + route->add_metric;
66 return MIN(m, INFINITY);
67 }
68
69 static inline int
70 route_metric_noninterfering(const struct babel_route *route)
71 {
72 int m =
73 (int)route->refmetric +
74 (diversity_factor * route->cost + 128) / 256 +
75 route->add_metric;
76 m = MAX(m, route->refmetric + 1);
77 return MIN(m, INFINITY);
78 }
79
80 struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
81 struct neighbour *neigh, const unsigned char *nexthop);
82 struct babel_route *find_installed_route(const unsigned char *prefix,
83 unsigned char plen);
84 int installed_routes_estimate(void);
85 void flush_route(struct babel_route *route);
86 void flush_all_routes(void);
87 void flush_neighbour_routes(struct neighbour *neigh);
88 void flush_interface_routes(struct interface *ifp, int v4only);
89 struct route_stream *route_stream(int installed);
90 struct babel_route *route_stream_next(struct route_stream *stream);
91 void route_stream_done(struct route_stream *stream);
92 void install_route(struct babel_route *route);
93 void uninstall_route(struct babel_route *route);
94 int route_feasible(struct babel_route *route);
95 int route_old(struct babel_route *route);
96 int route_expired(struct babel_route *route);
97 int route_interferes(struct babel_route *route, struct interface *ifp);
98 int update_feasible(struct source *src,
99 unsigned short seqno, unsigned short refmetric);
100 void change_smoothing_half_life(int half_life);
101 int route_smoothed_metric(struct babel_route *route);
102 struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen,
103 int feasible, struct neighbour *exclude);
104 struct babel_route *install_best_route(const unsigned char prefix[16],
105 unsigned char plen);
106 void update_neighbour_metric(struct neighbour *neigh, int change);
107 void update_interface_metric(struct interface *ifp);
108 void update_route_metric(struct babel_route *route);
109 struct babel_route *update_route(const unsigned char *id,
110 const unsigned char *prefix, unsigned char plen,
111 unsigned short seqno, unsigned short refmetric,
112 unsigned short interval, struct neighbour *neigh,
113 const unsigned char *nexthop,
114 const unsigned char *channels, int channels_len);
115 void retract_neighbour_routes(struct neighbour *neigh);
116 void send_unfeasible_request(struct neighbour *neigh, int force,
117 unsigned short seqno, unsigned short metric,
118 struct source *src);
119 void send_triggered_update(struct babel_route *route,
120 struct source *oldsrc, unsigned oldmetric);
121 void route_changed(struct babel_route *route,
122 struct source *oldsrc, unsigned short oldmetric);
123 void route_lost(struct source *src, unsigned oldmetric);
124 void expire_routes(void);
125
126 #endif