Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is free software: you may copy, redistribute and/or modify it |
| 3 | * under the terms of the GNU General Public License as published by the |
| 4 | * Free Software Foundation, either version 2 of the License, or (at your |
| 5 | * option) any later version. |
| 6 | * |
| 7 | * This file is distributed in the hope that it will be useful, but |
| 8 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 | * General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | * |
| 15 | * This file incorporates work covered by the following copyright and |
| 16 | * permission notice: |
| 17 | * |
| 18 | Copyright (c) 2007, 2008 by Juliusz Chroboczek |
| 19 | Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek |
| 20 | |
| 21 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 22 | of this software and associated documentation files (the "Software"), to deal |
| 23 | in the Software without restriction, including without limitation the rights |
| 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 25 | copies of the Software, and to permit persons to whom the Software is |
| 26 | furnished to do so, subject to the following conditions: |
| 27 | |
| 28 | The above copyright notice and this permission notice shall be included in |
| 29 | all copies or substantial portions of the Software. |
| 30 | |
| 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 37 | THE SOFTWARE. |
| 38 | */ |
| 39 | |
Matthieu Boutier | 1f39f46 | 2012-01-18 20:01:31 +0100 | [diff] [blame] | 40 | #ifndef BABEL_ROUTE_H |
| 41 | #define BABEL_ROUTE_H |
| 42 | |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 43 | #include "babel_interface.h" |
| 44 | #include "source.h" |
| 45 | |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 46 | #define DIVERSITY_NONE 0 |
| 47 | #define DIVERSITY_INTERFACE_1 1 |
| 48 | #define DIVERSITY_CHANNEL_1 2 |
| 49 | #define DIVERSITY_CHANNEL 3 |
| 50 | |
| 51 | #define DIVERSITY_HOPS 8 |
| 52 | |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 53 | struct babel_route { |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 54 | struct source *src; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 55 | unsigned short refmetric; |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 56 | unsigned short cost; |
| 57 | unsigned short add_metric; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 58 | unsigned short seqno; |
| 59 | struct neighbour *neigh; |
| 60 | unsigned char nexthop[16]; |
| 61 | time_t time; |
| 62 | unsigned short hold_time; /* in seconds */ |
| 63 | short installed; |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 64 | unsigned char channels[DIVERSITY_HOPS]; |
| 65 | struct babel_route *next; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 68 | extern struct babel_route **routes; |
| 69 | extern int kernel_metric, allow_duplicates; |
| 70 | extern int diversity_kind, diversity_factor; |
| 71 | extern int keep_unfeasible; |
| 72 | |
| 73 | static inline int |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 74 | route_metric(const struct babel_route *route) |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 75 | { |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 76 | int m = (int)route->refmetric + route->cost + route->add_metric; |
| 77 | return MIN(m, INFINITY); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 80 | static inline int |
| 81 | route_metric_noninterfering(const struct babel_route *route) |
| 82 | { |
| 83 | int m = |
| 84 | (int)route->refmetric + |
| 85 | (diversity_factor * route->cost + 128) / 256 + |
| 86 | route->add_metric; |
| 87 | m = MAX(m, route->refmetric + 1); |
| 88 | return MIN(m, INFINITY); |
| 89 | } |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 90 | |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 91 | struct babel_route *find_route(const unsigned char *prefix, unsigned char plen, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 92 | struct neighbour *neigh, const unsigned char *nexthop); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 93 | struct babel_route *find_installed_route(const unsigned char *prefix, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 94 | unsigned char plen); |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 95 | int installed_routes_estimate(void); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 96 | void flush_route(struct babel_route *route); |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 97 | void flush_all_routes(void); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 98 | void flush_neighbour_routes(struct neighbour *neigh); |
| 99 | void flush_interface_routes(struct interface *ifp, int v4only); |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 100 | void for_all_routes(void (*f)(struct babel_route*, void*), void *closure); |
| 101 | void for_all_installed_routes(void (*f)(struct babel_route*, void*), void *closure); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 102 | void install_route(struct babel_route *route); |
| 103 | void uninstall_route(struct babel_route *route); |
| 104 | void switch_route(struct babel_route *old, struct babel_route *new); |
| 105 | int route_feasible(struct babel_route *route); |
| 106 | int route_old(struct babel_route *route); |
| 107 | int route_expired(struct babel_route *route); |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 108 | int route_interferes(struct babel_route *route, struct interface *ifp); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 109 | int update_feasible(struct source *src, |
| 110 | unsigned short seqno, unsigned short refmetric); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 111 | struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 112 | int feasible, struct neighbour *exclude); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 113 | struct babel_route *install_best_route(const unsigned char prefix[16], |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 114 | unsigned char plen); |
| 115 | void update_neighbour_metric(struct neighbour *neigh, int change); |
| 116 | void update_interface_metric(struct interface *ifp); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 117 | void update_route_metric(struct babel_route *route); |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 118 | struct babel_route *update_route(const unsigned char *id, |
| 119 | const unsigned char *prefix, unsigned char plen, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 120 | unsigned short seqno, unsigned short refmetric, |
| 121 | unsigned short interval, struct neighbour *neigh, |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 122 | const unsigned char *nexthop, |
| 123 | const unsigned char *channels, int channels_len); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 124 | void retract_neighbour_routes(struct neighbour *neigh); |
| 125 | void send_unfeasible_request(struct neighbour *neigh, int force, |
| 126 | unsigned short seqno, unsigned short metric, |
| 127 | struct source *src); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 128 | void send_triggered_update(struct babel_route *route, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 129 | struct source *oldsrc, unsigned oldmetric); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 130 | void route_changed(struct babel_route *route, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 131 | struct source *oldsrc, unsigned short oldmetric); |
| 132 | void route_lost(struct source *src, unsigned oldmetric); |
| 133 | void expire_routes(void); |
| 134 | |
Matthieu Boutier | 1f39f46 | 2012-01-18 20:01:31 +0100 | [diff] [blame] | 135 | #endif |