1 /*
2 *
3 * Copyright (c) 2003 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31
32 #ifndef GLS_H_
33 #define GLS_H_
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <assert.h>
38 #include <limits.h>
39 #include <math.h>
40 #include <string.h>
41
42 #include <sys/types.h>
43 #include <netinet/in.h>
44
45 #include <emrun/emrun.h>
46 #include <link/link.h>
47 #include <link/neighbor.h>
48
49 #include <libmisc/local_types.h>
50 #include <libmisc/misc.h>
51
52 #include <libdev/status_dev.h>
53 #include <glib.h>
54 #include <libdev/glib_dev.h>
55
56 #define BACKDOOR /* use logring as backchannel for neighborlist flooding */
57
58 /* this needs to be unique to this application */
59 /* #define GLS_IOCTL_APP_TYPE 189 */
60 #define ROUTEDEV_IOCTL_APP_TYPE 189
61
62 #define ROUTEDEV_NEXT_HOP \
63 _IOWR(ROUTEDEV_IOCTL_APP_TYPE, 1, struct routedev_ioctl_data)
64
65 /* name of the routing table device device */
66 #define ROUTEDEV_NAME "routedev"
67
68 /* max number of hops before gls routing gives up */
69 #define GLS_DEFAULT_MAX_TTL 10
70
71 #define RECOMPUTE_TIMER_SLEEP_TIME 2
72
73 /* Set FLOOD_TIMEOUT to 120000 and MAX_HOLDOFF to 3 and periodicity
74 of neighbor to -p 120000 for the contention case */
75
76 #define FLOOD_TIMEOUT 120000
77 #define MAX_HOLDOFFS 8
78
79 /* max number of flood interfaces that can be opened - WTF?? */
80 #define MAX_IFACES 5
81
82 #ifdef __cplusplus
83 extern "C"
84 {
85 #endif
86
87 /* this describes an (underlying) link/transport interface */
88 typedef struct gls_iface {
89 link_opts_t if_opts;
90 link_context_t *if_context;
91 } gls_iface_t;
92
93 /* arguments to the function handling neighborlist updates processing */
94 typedef struct gls_state
95 {
96 /* when we receive an update, we start a 'recompute timer'. If another
97 * update is received, we add it to the list of updates and reset a timer.
98 * When the timer fires, we'll recompute the tables (also see
99 * 'max_timer_resets) (milliseconds) */
100 time_t recompute_timer_sleeptime;
101 /* its possible to keep receiving updates forever (ie. you receive an
102 * update, wait almost for 'recompute_timer_sleeptime', receive another
103 * update, reset timer). We want to have a bound of some sort on how often
104 * the tables are recomputed. Hence, we check this variable. When we have
105 * reset the timer maximum number of times, we'll force a recompute and not
106 * wait for any more updates */
107 int max_timer_resets;
108 /* number of resets (see max_timer_resets) */
109 int num_timer_resets;
110 /* list of updates to be processed when the recompute timer goes off (we're
111 * using a queue data structue, since we need FIFO behavior for updates. If
112 * we were to use a list, every time we'd have to append an element, we'd
113 * have to walk the whole update list, which is stupid. At least that's what
114 * glib's lists force us to do) */
115 GQueue *updates;
116 g_event_t *recompute_timer;
117
118 /* tables routing device operates on */
119 struct routedev_info *info;
120 /* configuration of the node we're running on */
121 struct nodeconf *nodecfg;
122
123 /* current neighbor list */
124 neighbor_t *nb_list;
125 int nb_list_count;
126
127 /* flood event */
128 g_event_t *holdoff_timer_event;
129 int num_holdoffs;
130
131 /* link state used for flooding neighbor lists */
132 link_context_t *flood_link;
133 /* link state used for gls routing */
134 link_context_t *gls_link;
135
136 /* state for upper interface (link we provide) */
137 link_opts_t pd_link_opts;
138 pd_context_t *pd_context;
139 uint16_t last_nonce;
140
141 /* state for lower interfaces (links we use) */
142 gls_iface_t iface;
143 int num_ifaces;
144
145 #ifdef BACKDOOR
146 int logring_fd;
147 #endif
148
149 } gls_state_t;
150
151 #define gls_dev_name(g) link_name(&(g)->pd_link_opts)
152
153 /* Our header structure */
154 typedef struct gls_pkt
155 {
156 gls_addr_t original_src;
157 gls_addr_t final_dst;
158 // uint8_t ttl;
159 uint8_t inner_type;
160 /* data field */
161 uint8_t data[0]; /* user payload */
162 } __attribute__((packed)) gls_pkt_t;
163
164 /* information needed to determine how to route traffic to the node */
165 struct routedev_nodeinfo
166 {
167 /* NOTE: hash table manipulation routines rely on 'id' being the first
168 * member of this structure. don't change a thing */
169
170 /* id of the node to route to */
171 ulong id;
172 /* id of the next-hop node */
173 ulong next_hop;
174 };
175
176 struct routedev_info
177 {
178 /* routing table. Given a node id, contains information about how to get
179 * there (routedev_nodeinfo structure) */
180 GHashTable *rtable;
181 status_context_t *rtablestatus; /* handle to status interface */
182 buf_t *rtablebuf;
183
184 status_context_t *adjstatus; /* handle to status interface */
185 buf_t *adjbuf;
186
187 /*
188 * The following tables contain 'nodeconf' structures. Actually, there is
189 * only one structure that's indexed by all 3 tables.
190 */
191
192 /* indexes nodes by their nodeId */
193 GHashTable *nodeid;
194 /* indexes nodes by their geo_info structure */
195 GHashTable *geo;
196 /* indexes nodes by their ip/port combinations */
197 GHashTable *udp;
198 };
199
200 /* TODO: header here */
201 void compute_routing_table(struct routedev_info *tables, struct nodeconf *config);
202
203 /* gls_upper */
204 void gls_register_packetdev(gls_state_t *gls_state);
205
206 int get_nexthop_to_dest_loc(gls_addr_t *in, gls_addr_t *out,
207 gboolean *result, struct routedev_info *tables);
208
209 /* gls_lower */
210 void gls_open_link(gls_state_t *g, int link_index);
211
212 void gls_forward (gls_state_t *gls_state, link_pkt_t *pkt,
213 int data_len, node_id_t next_hop);
214
215 /* route_table.c */
216 void tables_status_init(struct routedev_info *tables);
217
218 /* gls_nblist.c */
219 void gls_nblist_open(gls_state_t *gls_state);
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif /* GLS_H_ */
226
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.