1 // SPDX-License-Identifier: MIT
3 Copyright (c) 2007, 2008 by Juliusz Chroboczek
4 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
10 #include "babel_interface.h"
13 enum babel_diversity
{
15 DIVERSITY_INTERFACE_1
,
20 #define DIVERSITY_HOPS 8
24 unsigned short refmetric
;
26 unsigned short add_metric
;
28 struct neighbour
*neigh
;
29 unsigned char nexthop
[16];
31 unsigned short hold_time
; /* in seconds */
32 unsigned short smoothed_metric
; /* for route selection */
33 time_t smoothed_metric_time
;
35 unsigned char channels
[DIVERSITY_HOPS
];
36 struct babel_route
*next
;
41 extern struct babel_route
**routes
;
42 extern int kernel_metric
;
43 extern enum babel_diversity diversity_kind
;
44 extern int diversity_factor
;
45 extern int keep_unfeasible
;
46 extern int smoothing_half_life
;
49 route_metric(const struct babel_route
*route
)
51 int m
= (int)route
->refmetric
+ route
->cost
+ route
->add_metric
;
52 return MIN(m
, INFINITY
);
56 route_metric_noninterfering(const struct babel_route
*route
)
59 (int)route
->refmetric
+
60 (diversity_factor
* route
->cost
+ 128) / 256 +
62 m
= MAX(m
, route
->refmetric
+ 1);
63 return MIN(m
, INFINITY
);
66 struct babel_route
*find_route(const unsigned char *prefix
, unsigned char plen
,
67 struct neighbour
*neigh
, const unsigned char *nexthop
);
68 struct babel_route
*find_installed_route(const unsigned char *prefix
,
70 int installed_routes_estimate(void);
71 void flush_route(struct babel_route
*route
);
72 void flush_all_routes(void);
73 void flush_neighbour_routes(struct neighbour
*neigh
);
74 void flush_interface_routes(struct interface
*ifp
, int v4only
);
75 struct route_stream
*route_stream(int installed
);
76 struct babel_route
*route_stream_next(struct route_stream
*stream
);
77 void route_stream_done(struct route_stream
*stream
);
78 void install_route(struct babel_route
*route
);
79 void uninstall_route(struct babel_route
*route
);
80 int route_feasible(struct babel_route
*route
);
81 int route_old(struct babel_route
*route
);
82 int route_expired(struct babel_route
*route
);
83 int route_interferes(struct babel_route
*route
, struct interface
*ifp
);
84 int update_feasible(struct source
*src
,
85 unsigned short seqno
, unsigned short refmetric
);
86 void change_smoothing_half_life(int half_life
);
87 int route_smoothed_metric(struct babel_route
*route
);
88 struct babel_route
*find_best_route(const unsigned char *prefix
, unsigned char plen
,
89 int feasible
, struct neighbour
*exclude
);
90 struct babel_route
*install_best_route(const unsigned char prefix
[16],
92 void update_neighbour_metric(struct neighbour
*neigh
, int change
);
93 void update_interface_metric(struct interface
*ifp
);
94 void update_route_metric(struct babel_route
*route
);
95 struct babel_route
*update_route(const unsigned char *id
,
96 const unsigned char *prefix
, unsigned char plen
,
97 unsigned short seqno
, unsigned short refmetric
,
98 unsigned short interval
, struct neighbour
*neigh
,
99 const unsigned char *nexthop
,
100 const unsigned char *channels
, int channels_len
);
101 void retract_neighbour_routes(struct neighbour
*neigh
);
102 void send_unfeasible_request(struct neighbour
*neigh
, int force
,
103 unsigned short seqno
, unsigned short metric
,
105 void send_triggered_update(struct babel_route
*route
,
106 struct source
*oldsrc
, unsigned oldmetric
);
107 void route_changed(struct babel_route
*route
,
108 struct source
*oldsrc
, unsigned short oldmetric
);
109 void route_lost(struct source
*src
, unsigned oldmetric
);
110 void expire_routes(void);