]> git.proxmox.com Git - mirror_frr.git/blame - babeld/route.h
*: Initial Import of Babeld into FRR
[mirror_frr.git] / babeld / route.h
CommitLineData
ca10883e
DS
1/*
2Copyright (c) 2007, 2008 by Juliusz Chroboczek
3Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE 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
37struct 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
54struct route_stream;
55
56extern struct babel_route **routes;
57extern int kernel_metric;
58extern int diversity_kind, diversity_factor;
59extern int keep_unfeasible;
60extern int smoothing_half_life;
61
62static inline int
63route_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
69static inline int
70route_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
80struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
81 struct neighbour *neigh, const unsigned char *nexthop);
82struct babel_route *find_installed_route(const unsigned char *prefix,
83 unsigned char plen);
84int installed_routes_estimate(void);
85void flush_route(struct babel_route *route);
86void flush_all_routes(void);
87void flush_neighbour_routes(struct neighbour *neigh);
88void flush_interface_routes(struct interface *ifp, int v4only);
89struct route_stream *route_stream(int installed);
90struct babel_route *route_stream_next(struct route_stream *stream);
91void route_stream_done(struct route_stream *stream);
92void install_route(struct babel_route *route);
93void uninstall_route(struct babel_route *route);
94int route_feasible(struct babel_route *route);
95int route_old(struct babel_route *route);
96int route_expired(struct babel_route *route);
97int route_interferes(struct babel_route *route, struct interface *ifp);
98int update_feasible(struct source *src,
99 unsigned short seqno, unsigned short refmetric);
100void change_smoothing_half_life(int half_life);
101int route_smoothed_metric(struct babel_route *route);
102struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen,
103 int feasible, struct neighbour *exclude);
104struct babel_route *install_best_route(const unsigned char prefix[16],
105 unsigned char plen);
106void update_neighbour_metric(struct neighbour *neigh, int change);
107void update_interface_metric(struct interface *ifp);
108void update_route_metric(struct babel_route *route);
109struct 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);
115void retract_neighbour_routes(struct neighbour *neigh);
116void send_unfeasible_request(struct neighbour *neigh, int force,
117 unsigned short seqno, unsigned short metric,
118 struct source *src);
119void send_triggered_update(struct babel_route *route,
120 struct source *oldsrc, unsigned oldmetric);
121void route_changed(struct babel_route *route,
122 struct source *oldsrc, unsigned short oldmetric);
123void route_lost(struct source *src, unsigned oldmetric);
124void expire_routes(void);
125
126#endif