Statistics
| Branch: | Revision:

iof-bird-daemon / proto / babel / babel.h @ 5e8df049

History | View | Annotate | Download (7.32 KB)

1
/*
2
 *        BIRD -- The Babel protocol
3
 *
4
 *        Copyright (c) 2015--2016 Toke Hoiland-Jorgensen
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 *
8
 *        This file contains the data structures used by Babel.
9
 */
10

    
11
#ifndef _BIRD_BABEL_H_
12
#define _BIRD_BABEL_H_
13

    
14
#include "nest/bird.h"
15
#include "nest/cli.h"
16
#include "nest/iface.h"
17
#include "nest/route.h"
18
#include "nest/protocol.h"
19
#include "nest/locks.h"
20
#include "lib/resource.h"
21
#include "lib/lists.h"
22
#include "lib/socket.h"
23
#include "lib/string.h"
24
#include "sysdep/unix/timer.h"
25

    
26
#define EA_BABEL_METRIC                EA_CODE(EAP_BABEL, 0)
27
#define EA_BABEL_ROUTER_ID        EA_CODE(EAP_BABEL, 1)
28

    
29
#define BABEL_MAGIC                42
30
#define BABEL_VERSION                2
31
#define BABEL_PORT                6696
32
#define BABEL_INFINITY                0xFFFF
33

    
34

    
35
#define BABEL_HELLO_INTERVAL_WIRED        4        /* Default hello intervals in seconds */
36
#define BABEL_HELLO_INTERVAL_WIRELESS        4
37
#define BABEL_UPDATE_INTERVAL_FACTOR        4
38
#define BABEL_IHU_INTERVAL_FACTOR        3
39
#define BABEL_IHU_EXPIRY_FACTOR(X)        ((X)*3/2)        /* 1.5 */
40
#define BABEL_HELLO_EXPIRY_FACTOR(X)        ((X)*3/2)        /* 1.5 */
41
#define BABEL_ROUTE_EXPIRY_FACTOR(X)        ((X)*7/2)        /* 3.5 */
42
#define BABEL_ROUTE_REFRESH_INTERVAL        2        /* Seconds before route expiry to send route request */
43
#define BABEL_HOLD_TIME                        10        /* Expiry time for our own routes */
44
#define BABEL_RXCOST_WIRED                96
45
#define BABEL_RXCOST_WIRELESS                256
46
#define BABEL_INITIAL_HOP_COUNT                255
47
#define BABEL_MAX_SEND_INTERVAL                5
48
#define BABEL_TIME_UNITS                100        /* On-wire times are counted in centiseconds */
49
#define BABEL_SEQNO_REQUEST_EXPIRY        60
50
#define BABEL_GARBAGE_INTERVAL                300
51

    
52
/* Max interval that will not overflow when carried as 16-bit centiseconds */
53
#define BABEL_MAX_INTERVAL                (0xFFFF/BABEL_TIME_UNITS)
54

    
55
#define BABEL_OVERHEAD                (IP6_HEADER_LENGTH+UDP_HEADER_LENGTH)
56
#define BABEL_MIN_MTU                (512 + BABEL_OVERHEAD)
57

    
58

    
59
enum babel_tlv_type {
60
  BABEL_TLV_PAD1                = 0,
61
  BABEL_TLV_PADN                = 1,
62
  BABEL_TLV_ACK_REQ                = 2,
63
  BABEL_TLV_ACK                        = 3,
64
  BABEL_TLV_HELLO                = 4,
65
  BABEL_TLV_IHU                 = 5,
66
  BABEL_TLV_ROUTER_ID                = 6,
67
  BABEL_TLV_NEXT_HOP                = 7,
68
  BABEL_TLV_UPDATE                = 8,
69
  BABEL_TLV_ROUTE_REQUEST        = 9,
70
  BABEL_TLV_SEQNO_REQUEST        = 10,
71
  /* extensions - not implemented
72
  BABEL_TLV_TS_PC                = 11,
73
  BABEL_TLV_HMAC                = 12,
74
  BABEL_TLV_SS_UPDATE                = 13,
75
  BABEL_TLV_SS_REQUEST                = 14,
76
  BABEL_TLV_SS_SEQNO_REQUEST        = 15,
77
  */
78
  BABEL_TLV_MAX
79
};
80

    
81
enum babel_iface_type {
82
  /* In practice, UNDEF and WIRED give equivalent behaviour */
83
  BABEL_IFACE_TYPE_UNDEF        = 0,
84
  BABEL_IFACE_TYPE_WIRED        = 1,
85
  BABEL_IFACE_TYPE_WIRELESS        = 2,
86
  BABEL_IFACE_TYPE_MAX
87
};
88

    
89
enum babel_ae_type {
90
  BABEL_AE_WILDCARD                = 0,
91
  BABEL_AE_IP4                        = 1,
92
  BABEL_AE_IP6                        = 2,
93
  BABEL_AE_IP6_LL                = 3,
94
  BABEL_AE_MAX
95
};
96

    
97

    
98
struct babel_config {
99
  struct proto_config c;
100

    
101
  list iface_list;              /* Patterns configured -- keep it first; see babel_reconfigure why */
102
};
103

    
104
struct babel_iface_config {
105
  struct iface_patt i;
106

    
107
  u16 rxcost;
108
  u8 type;
109
  u8 check_link;
110
  uint port;
111
  u16 hello_interval;
112
  u16 ihu_interval;
113
  u16 update_interval;
114

    
115
  u16 rx_buffer;                        /* RX buffer size, 0 for MTU */
116
  u16 tx_length;                        /* TX packet length limit (including headers), 0 for MTU */
117
  int tx_tos;
118
  int tx_priority;
119
};
120

    
121
struct babel_proto {
122
  struct proto p;
123
  timer *timer;
124
  struct fib rtable;
125
  list interfaces;                        /* Interfaces we really know about (struct babel_iface) */
126
  u64 router_id;
127
  u16 update_seqno;                        /* To be increased on request */
128
  u8 triggered;                                /* For triggering global updates */
129

    
130
  slab *route_slab;
131
  slab *source_slab;
132
  slab *msg_slab;
133

    
134
  slab *seqno_slab;
135
  list seqno_cache;                        /* Seqno requests in the cache (struct babel_seqno_request) */
136

    
137
  struct tbf log_pkt_tbf;                /* TBF for packet messages */
138
};
139

    
140
struct babel_iface {
141
  node n;
142

    
143
  struct babel_proto *proto;
144
  struct iface *iface;
145

    
146
  struct babel_iface_config *cf;
147

    
148
  u8 up;
149

    
150
  pool *pool;
151
  char *ifname;
152
  sock *sk;
153
  ip_addr addr;
154
  int tx_length;
155
  list neigh_list;                        /* List of neighbors seen on this iface (struct babel_neighbor) */
156
  list msg_queue;
157

    
158
  u16 hello_seqno;                        /* To be increased on each hello */
159

    
160
  bird_clock_t next_hello;
161
  bird_clock_t next_regular;
162
  bird_clock_t next_triggered;
163
  bird_clock_t want_triggered;
164

    
165
  timer *timer;
166
  event *send_event;
167
};
168

    
169
struct babel_neighbor {
170
  node n;
171
  struct babel_iface *ifa;
172

    
173
  ip_addr addr;
174
  u16 txcost;
175
  u8 hello_cnt;
176
  u16 hello_map;
177
  u16 next_hello_seqno;
178
  /* expiry timers */
179
  bird_clock_t hello_expiry;
180
  bird_clock_t ihu_expiry;
181

    
182
  list routes;                                /* Routes this neighbour has sent us (struct babel_route) */
183
};
184

    
185
struct babel_source {
186
  node n;
187

    
188
  u64 router_id;
189
  u16 seqno;
190
  u16 metric;
191
  bird_clock_t expires;
192
};
193

    
194
struct babel_route {
195
  node n;
196
  node neigh_route;
197
  struct babel_entry    *e;
198
  struct babel_neighbor *neigh;
199

    
200
  u16 seqno;
201
  u16 advert_metric;
202
  u16 metric;
203
  u64 router_id;
204
  ip_addr next_hop;
205
  bird_clock_t refresh_time;
206
  bird_clock_t expires;
207
  u16 expiry_interval;
208
};
209

    
210
struct babel_entry {
211
  struct babel_proto *proto;
212
  struct babel_route *selected_in;
213
  struct babel_route *selected_out;
214

    
215
  bird_clock_t updated;
216

    
217
  list sources;                                /* Source entries for this prefix (struct babel_source). */
218
  list routes;                                /* Routes for this prefix (struct babel_route) */
219

    
220
  struct fib_node n;
221
};
222

    
223
/* Stores forwarded seqno requests for duplicate suppression. */
224
struct babel_seqno_request {
225
  node n;
226
  net_addr net;
227
  u64 router_id;
228
  u16 seqno;
229
  bird_clock_t updated;
230
};
231

    
232

    
233
/*
234
 *        Internal TLV messages
235
 */
236

    
237
struct babel_msg_ack_req {
238
  u8 type;
239
  u16 nonce;
240
  u16 interval;
241
  ip_addr sender;
242
};
243

    
244
struct babel_msg_ack {
245
  u8 type;
246
  u16 nonce;
247
};
248

    
249
struct babel_msg_hello {
250
  u8 type;
251
  u16 seqno;
252
  u16 interval;
253
  ip_addr sender;
254
};
255

    
256
struct babel_msg_ihu {
257
  u8 type;
258
  u8 ae;
259
  u16 rxcost;
260
  u16 interval;
261
  ip_addr addr;
262
  ip_addr sender;
263
};
264

    
265
struct babel_msg_update {
266
  u8 type;
267
  u8 wildcard;
268
  u16 interval;
269
  u16 seqno;
270
  u16 metric;
271
  u64 router_id;
272
  net_addr net;
273
  ip_addr next_hop;
274
  ip_addr sender;
275
};
276

    
277
struct babel_msg_route_request {
278
  u8 type;
279
  u8 full;
280
  net_addr net;
281
};
282

    
283
struct babel_msg_seqno_request {
284
  u8 type;
285
  u8 hop_count;
286
  u16 seqno;
287
  u64 router_id;
288
  net_addr net;
289
  ip_addr sender;
290
};
291

    
292
union babel_msg {
293
  u8 type;
294
  struct babel_msg_ack_req ack_req;
295
  struct babel_msg_ack ack;
296
  struct babel_msg_hello hello;
297
  struct babel_msg_ihu ihu;
298
  struct babel_msg_update update;
299
  struct babel_msg_route_request route_request;
300
  struct babel_msg_seqno_request seqno_request;
301
};
302

    
303
struct babel_msg_node {
304
  node n;
305
  union babel_msg msg;
306
};
307

    
308

    
309
/* babel.c */
310
void babel_handle_ack_req(union babel_msg *msg, struct babel_iface *ifa);
311
void babel_handle_ack(union babel_msg *msg, struct babel_iface *ifa);
312
void babel_handle_hello(union babel_msg *msg, struct babel_iface *ifa);
313
void babel_handle_ihu(union babel_msg *msg, struct babel_iface *ifa);
314
void babel_handle_router_id(union babel_msg *msg, struct babel_iface *ifa);
315
void babel_handle_update(union babel_msg *msg, struct babel_iface *ifa);
316
void babel_handle_route_request(union babel_msg *msg, struct babel_iface *ifa);
317
void babel_handle_seqno_request(union babel_msg *msg, struct babel_iface *ifa);
318

    
319
void babel_show_interfaces(struct proto *P, char *iff);
320
void babel_show_neighbors(struct proto *P, char *iff);
321
void babel_show_entries(struct proto *P);
322

    
323
/* packets.c */
324
void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);
325
void babel_send_unicast(union babel_msg *msg, struct babel_iface *ifa, ip_addr dest);
326
int babel_open_socket(struct babel_iface *ifa);
327
void babel_send_queue(void *arg);
328

    
329

    
330
#endif