Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (7.75 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 S_)        /* Default hello intervals in seconds */
36
#define BABEL_HELLO_INTERVAL_WIRELESS        (4 S_)
37
#define BABEL_UPDATE_INTERVAL_FACTOR        4
38
#define BABEL_IHU_INTERVAL_FACTOR        3
39
#define BABEL_IHU_EXPIRY_FACTOR(X)        ((btime)(X)*3/2)        /* 1.5 */
40
#define BABEL_HELLO_EXPIRY_FACTOR(X)        ((btime)(X)*3/2)        /* 1.5 */
41
#define BABEL_ROUTE_EXPIRY_FACTOR(X)        ((btime)(X)*7/2)        /* 3.5 */
42
#define BABEL_ROUTE_REFRESH_INTERVAL        (2 S_)        /* Time before route expiry to send route request */
43
#define BABEL_HOLD_TIME                        (10 S_)        /* Expiry time for our own routes */
44
#define BABEL_SEQNO_REQUEST_EXPIRY        (60 S_)
45
#define BABEL_GARBAGE_INTERVAL                (300 S_)
46
#define BABEL_RXCOST_WIRED                96
47
#define BABEL_RXCOST_WIRELESS                256
48
#define BABEL_INITIAL_HOP_COUNT                255
49
#define BABEL_MAX_SEND_INTERVAL                5        /* Unused ? */
50

    
51
/* Max interval that will not overflow when carried as 16-bit centiseconds */
52
#define BABEL_TIME_UNITS                10000        /* On-wire times are counted in centiseconds */
53
#define BABEL_MIN_INTERVAL                (0x0001 * BABEL_TIME_UNITS)
54
#define BABEL_MAX_INTERVAL                (0xFFFF * BABEL_TIME_UNITS)
55

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

    
59

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

    
82
enum babel_subtlv_type {
83
  BABEL_SUBTLV_PAD1                = 0,
84
  BABEL_SUBTLV_PADN                = 1
85
};
86

    
87
enum babel_iface_type {
88
  /* In practice, UNDEF and WIRED give equivalent behaviour */
89
  BABEL_IFACE_TYPE_UNDEF        = 0,
90
  BABEL_IFACE_TYPE_WIRED        = 1,
91
  BABEL_IFACE_TYPE_WIRELESS        = 2,
92
  BABEL_IFACE_TYPE_MAX
93
};
94

    
95
enum babel_ae_type {
96
  BABEL_AE_WILDCARD                = 0,
97
  BABEL_AE_IP4                        = 1,
98
  BABEL_AE_IP6                        = 2,
99
  BABEL_AE_IP6_LL                = 3,
100
  BABEL_AE_MAX
101
};
102

    
103

    
104
struct babel_config {
105
  struct proto_config c;
106

    
107
  list iface_list;              /* Patterns configured -- keep it first; see babel_reconfigure why */
108
};
109

    
110
struct babel_iface_config {
111
  struct iface_patt i;
112

    
113
  u16 rxcost;
114
  u8 type;
115
  u8 check_link;
116
  uint port;
117
  uint hello_interval;                        /* Hello interval, in us */
118
  uint ihu_interval;                        /* IHU interval, in us */
119
  uint update_interval;                        /* Update interval, in us */
120

    
121
  u16 rx_buffer;                        /* RX buffer size, 0 for MTU */
122
  u16 tx_length;                        /* TX packet length limit (including headers), 0 for MTU */
123
  int tx_tos;
124
  int tx_priority;
125

    
126
  ip_addr next_hop_ip4;
127
  ip_addr next_hop_ip6;
128
};
129

    
130
struct babel_proto {
131
  struct proto p;
132
  timer *timer;
133
  struct fib ip4_rtable;
134
  struct fib ip6_rtable;
135

    
136
  struct channel *ip4_channel;
137
  struct channel *ip6_channel;
138

    
139
  list interfaces;                        /* Interfaces we really know about (struct babel_iface) */
140
  u64 router_id;
141
  u16 update_seqno;                        /* To be increased on request */
142
  u8 triggered;                                /* For triggering global updates */
143

    
144
  slab *route_slab;
145
  slab *source_slab;
146
  slab *msg_slab;
147

    
148
  slab *seqno_slab;
149
  list seqno_cache;                        /* Seqno requests in the cache (struct babel_seqno_request) */
150

    
151
  struct tbf log_pkt_tbf;                /* TBF for packet messages */
152
};
153

    
154
struct babel_iface {
155
  node n;
156

    
157
  struct babel_proto *proto;
158
  struct iface *iface;
159

    
160
  struct babel_iface_config *cf;
161

    
162
  u8 up;
163

    
164
  pool *pool;
165
  char *ifname;
166
  sock *sk;
167
  ip_addr addr;
168
  ip_addr next_hop_ip4;
169
  ip_addr next_hop_ip6;
170
  int tx_length;
171
  list neigh_list;                        /* List of neighbors seen on this iface (struct babel_neighbor) */
172
  list msg_queue;
173

    
174
  u16 hello_seqno;                        /* To be increased on each hello */
175

    
176
  btime next_hello;
177
  btime next_regular;
178
  btime next_triggered;
179
  btime want_triggered;
180

    
181
  timer *timer;
182
  event *send_event;
183
};
184

    
185
struct babel_neighbor {
186
  node n;
187
  struct babel_iface *ifa;
188

    
189
  ip_addr addr;
190
  u16 txcost;
191
  u8 hello_cnt;
192
  u16 hello_map;
193
  u16 next_hello_seqno;
194
  uint last_hello_int;
195
  /* expiry timers */
196
  btime hello_expiry;
197
  btime ihu_expiry;
198

    
199
  list routes;                                /* Routes this neighbour has sent us (struct babel_route) */
200
};
201

    
202
struct babel_source {
203
  node n;
204

    
205
  u64 router_id;
206
  u16 seqno;
207
  u16 metric;
208
  btime expires;
209
};
210

    
211
struct babel_route {
212
  node n;
213
  node neigh_route;
214
  struct babel_entry    *e;
215
  struct babel_neighbor *neigh;
216

    
217
  u16 seqno;
218
  u16 advert_metric;
219
  u16 metric;
220
  u64 router_id;
221
  ip_addr next_hop;
222
  btime refresh_time;
223
  btime expires;
224
  btime expiry_interval;
225
};
226

    
227
struct babel_entry {
228
  struct babel_proto *proto;
229
  struct babel_route *selected_in;
230
  struct babel_route *selected_out;
231

    
232
  btime updated;
233

    
234
  list sources;                                /* Source entries for this prefix (struct babel_source). */
235
  list routes;                                /* Routes for this prefix (struct babel_route) */
236

    
237
  struct fib_node n;
238
};
239

    
240
/* Stores forwarded seqno requests for duplicate suppression. */
241
struct babel_seqno_request {
242
  node n;
243
  net_addr net;
244
  u64 router_id;
245
  u16 seqno;
246
  btime updated;
247
};
248

    
249

    
250
/*
251
 *        Internal TLV messages
252
 */
253

    
254
struct babel_msg_ack_req {
255
  u8 type;
256
  u16 nonce;
257
  uint interval;
258
  ip_addr sender;
259
};
260

    
261
struct babel_msg_ack {
262
  u8 type;
263
  u16 nonce;
264
};
265

    
266
struct babel_msg_hello {
267
  u8 type;
268
  u16 seqno;
269
  uint interval;
270
  ip_addr sender;
271
};
272

    
273
struct babel_msg_ihu {
274
  u8 type;
275
  u8 ae;
276
  u16 rxcost;
277
  uint interval;
278
  ip_addr addr;
279
  ip_addr sender;
280
};
281

    
282
struct babel_msg_update {
283
  u8 type;
284
  u8 wildcard;
285
  uint interval;
286
  u16 seqno;
287
  u16 metric;
288
  u64 router_id;
289
  net_addr net;
290
  ip_addr next_hop;
291
  ip_addr sender;
292
};
293

    
294
struct babel_msg_route_request {
295
  u8 type;
296
  u8 full;
297
  net_addr net;
298
};
299

    
300
struct babel_msg_seqno_request {
301
  u8 type;
302
  u8 hop_count;
303
  u16 seqno;
304
  u64 router_id;
305
  net_addr net;
306
  ip_addr sender;
307
};
308

    
309
union babel_msg {
310
  u8 type;
311
  struct babel_msg_ack_req ack_req;
312
  struct babel_msg_ack ack;
313
  struct babel_msg_hello hello;
314
  struct babel_msg_ihu ihu;
315
  struct babel_msg_update update;
316
  struct babel_msg_route_request route_request;
317
  struct babel_msg_seqno_request seqno_request;
318
};
319

    
320
struct babel_msg_node {
321
  node n;
322
  union babel_msg msg;
323
};
324

    
325

    
326
/* babel.c */
327
void babel_handle_ack_req(union babel_msg *msg, struct babel_iface *ifa);
328
void babel_handle_ack(union babel_msg *msg, struct babel_iface *ifa);
329
void babel_handle_hello(union babel_msg *msg, struct babel_iface *ifa);
330
void babel_handle_ihu(union babel_msg *msg, struct babel_iface *ifa);
331
void babel_handle_router_id(union babel_msg *msg, struct babel_iface *ifa);
332
void babel_handle_update(union babel_msg *msg, struct babel_iface *ifa);
333
void babel_handle_route_request(union babel_msg *msg, struct babel_iface *ifa);
334
void babel_handle_seqno_request(union babel_msg *msg, struct babel_iface *ifa);
335

    
336
void babel_show_interfaces(struct proto *P, char *iff);
337
void babel_show_neighbors(struct proto *P, char *iff);
338
void babel_show_entries(struct proto *P);
339

    
340
/* packets.c */
341
void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);
342
void babel_send_unicast(union babel_msg *msg, struct babel_iface *ifa, ip_addr dest);
343
int babel_open_socket(struct babel_iface *ifa);
344
void babel_send_queue(void *arg);
345

    
346

    
347
#endif