1 diff -Nur olsrd-0.4.10.orig/src/duplicate_set.c olsrd-0.4.10/src/duplicate_set.c
2 --- olsrd-0.4.10.orig/src/duplicate_set.c 2005-02-27 19:39:43.000000000 +0100
3 +++ olsrd-0.4.10/src/duplicate_set.c 2006-11-12 09:33:49.000000000 +0100
7 /* Hash the senders address */
8 - hash = olsr_hashing(originator);
9 + hash = HASHMASK & seqno;
11 new_dup_entry = olsr_malloc(sizeof(struct dup_entry), "New dup entry");
14 struct dup_entry *tmp_dup_table;
16 /* Hash the senders address */
17 - hash = olsr_hashing(originator);
18 + hash = HASHMASK & seqno;
21 for(tmp_dup_table = dup_set[hash].next;
23 struct dup_entry *tmp_dup_table;
25 /* Hash the senders address */
26 - hash = olsr_hashing(originator);
27 + hash = HASHMASK & seqno;
30 for(tmp_dup_table = dup_set[hash].next;
32 struct dup_iface *new_iface;
34 /* Hash the senders address */
35 - hash = olsr_hashing(originator);
36 + hash = HASHMASK & seqno;
41 struct dup_entry *tmp_dup_table;
43 /* Hash the senders address */
44 - hash = olsr_hashing(originator);
45 + hash = HASHMASK & seqno;
48 for(tmp_dup_table = dup_set[hash].next;
49 diff -Nur olsrd-0.4.10.orig/src/hashing.c olsrd-0.4.10/src/hashing.c
50 --- olsrd-0.4.10.orig/src/hashing.c 2005-02-20 19:52:18.000000000 +0100
51 +++ olsrd-0.4.10/src/hashing.c 2006-11-12 09:33:49.000000000 +0100
54 if(olsr_cnf->ip_version == AF_INET)
56 - hash = (ntohl(address->v4));
57 + hash = address->v4x[0] ^ address->v4x[1] ^ address->v4x[2] ^ address->v4x[3];
61 diff -Nur olsrd-0.4.10.orig/src/hashing.h olsrd-0.4.10/src/hashing.h
62 --- olsrd-0.4.10.orig/src/hashing.h 2005-02-20 19:52:18.000000000 +0100
63 +++ olsrd-0.4.10/src/hashing.h 2006-11-12 09:33:49.000000000 +0100
70 #define HASHMASK (HASHSIZE - 1)
72 #include "olsr_types.h"
73 diff -Nur olsrd-0.4.10.orig/src/lq_avl.c olsrd-0.4.10/src/lq_avl.c
74 --- olsrd-0.4.10.orig/src/lq_avl.c 2005-01-22 15:30:57.000000000 +0100
75 +++ olsrd-0.4.10/src/lq_avl.c 2006-11-12 09:33:49.000000000 +0100
80 +#ifndef DISABLE_SVEN_OLA
90 +#ifndef DISABLE_SVEN_OLA
91 +static struct avl_node *avl_find_rec_ipv4(struct avl_node *node, void *key)
93 + if (*(unsigned int *)key < *(unsigned int *)node->key) {
94 + if (node->left != NULL) {
95 + return avl_find_rec_ipv4(node->left, key);
98 + else if (*(unsigned int *)key > *(unsigned int *)node->key) {
99 + if (node->right != NULL) {
100 + return avl_find_rec_ipv4(node->right, key);
107 static struct avl_node *avl_find_rec(struct avl_node *node, void *key,
108 int (*comp)(void *, void *))
112 +#ifndef DISABLE_SVEN_OLA
114 + return avl_find_rec_ipv4(node, key);
117 diff = (*comp)(key, node->key);
122 node = avl_find_rec(tree->root, key, tree->comp);
124 +#ifndef DISABLE_SVEN_OLA
125 + if (0 == tree->comp) {
126 + if (0 != svenola_avl_comp_ipv4(node->key, key))
131 if ((*tree->comp)(node->key, key) != 0)
136 node = avl_find_rec(tree->root, new->key, tree->comp);
138 +#ifndef DISABLE_SVEN_OLA
139 + if (0 == tree->comp) {
140 + diff = svenola_avl_comp_ipv4(new->key, node->key);
144 diff = (*tree->comp)(new->key, node->key);
147 diff -Nur olsrd-0.4.10.orig/src/lq_avl.h olsrd-0.4.10/src/lq_avl.h
148 --- olsrd-0.4.10.orig/src/lq_avl.h 2005-02-20 19:52:18.000000000 +0100
149 +++ olsrd-0.4.10/src/lq_avl.h 2006-11-12 09:33:49.000000000 +0100
151 struct avl_node *avl_find(struct avl_tree *, void *);
152 int avl_insert(struct avl_tree *, struct avl_node *);
154 +#ifndef DISABLE_SVEN_OLA
155 +#define svenola_avl_comp_ipv4(ip1, ip2) \
156 + (*(unsigned int *)ip1 == *(unsigned int *)ip2 ? 0 : \
157 + *(unsigned int *)ip1 < *(unsigned int *)ip2 ? -1 : +1)
160 diff -Nur olsrd-0.4.10.orig/src/lq_list.c olsrd-0.4.10/src/lq_list.c
161 --- olsrd-0.4.10.orig/src/lq_list.c 2004-12-04 18:06:57.000000000 +0100
162 +++ olsrd-0.4.10/src/lq_list.c 2006-11-12 09:33:49.000000000 +0100
167 +#ifdef DISABLE_SVEN_OLA
168 struct list_node *list_get_head(struct list *list)
177 void list_add_head(struct list *list, struct list_node *node)
179 diff -Nur olsrd-0.4.10.orig/src/lq_list.h olsrd-0.4.10/src/lq_list.h
180 --- olsrd-0.4.10.orig/src/lq_list.h 2005-02-20 19:52:18.000000000 +0100
181 +++ olsrd-0.4.10/src/lq_list.h 2006-11-12 09:33:49.000000000 +0100
184 void list_init(struct list *list);
186 +#ifndef DISABLE_SVEN_OLA
187 +#define list_get_head(node) (node)->head
188 +#define list_get_tail(node) (node)->tail
189 +#define list_get_next(node) (node)->next
190 +#define list_get_prev(node) (node)->prev
192 struct list_node *list_get_head(struct list *list);
193 struct list_node *list_get_tail(struct list *list);
195 struct list_node *list_get_next(struct list_node *node);
196 struct list_node *list_get_prev(struct list_node *node);
199 void list_add_head(struct list *list, struct list_node *node);
200 void list_add_tail(struct list *list, struct list_node *node);
201 diff -Nur olsrd-0.4.10.orig/src/lq_route.c olsrd-0.4.10/src/lq_route.c
202 --- olsrd-0.4.10.orig/src/lq_route.c 2005-11-29 19:37:58.000000000 +0100
203 +++ olsrd-0.4.10/src/lq_route.c 2006-11-12 09:34:46.000000000 +0100
206 // add the vertex to the list, if it's not us
208 +#ifndef DISABLE_SVEN_OLA
210 + if (svenola_avl_comp_ipv4(&main_addr, node->key) != 0)
212 + vert->node.data = vert;
213 + list_add_tail(vertex_list, &vert->node);
218 if ((*comp)(&main_addr, node->key) != 0)
220 vert->node.data = vert;
221 @@ -266,6 +276,154 @@
224 // XXX - bad complexity
229 + * The function extract_best() is most expensive (>50% CPU in profiling).
230 + * It is called in two modes: while doing Dijkstra route calculation and
231 + * while searching for a direct route/hna. The latter can be optimized
232 + * because the stored verices do not change from call to call and it is
233 + * more sufficient to have them sorted/popped from a list rather than
234 + * searching the complete list by every call. Sven-Ola@gmx.de, 11/2006
238 +static struct dijk_vertex **etx_cache = 0;
239 +static int etx_cache_count;
240 +static int etx_cache_get;
241 +static int etx_cache_saved = 0;
243 +static int etx_cache_compare(const void *a, const void *b)
245 + // Oh jeah. I love this macro assembler :)
247 + if ((*(struct dijk_vertex **)a)->path_etx > (*(struct dijk_vertex **)b)->path_etx) return 1;
248 + if ((*(struct dijk_vertex **)a)->path_etx < (*(struct dijk_vertex **)b)->path_etx) return -1;
250 + // This is for debugging only: etx==etx then compare pointers
251 + // to make it possible to compare to the original search algo.
252 + if (*(struct dijk_vertex **)a > *(struct dijk_vertex **)b) return 1;
253 + if (*(struct dijk_vertex **)a < *(struct dijk_vertex **)b) return -1;
258 +static struct dijk_vertex *extract_best_route(struct list *vertex_list)
261 + float best_etx = INFINITE_ETX + 1.0;
263 + struct list_node *node;
264 + struct dijk_vertex *vert;
265 + struct dijk_vertex *res = NULL;
268 + node = list_get_head(vertex_list);
270 + // loop through all vertices
272 + while (node != NULL)
276 + // see whether the current vertex is better than what we have
278 + if (!vert->done && vert->path_etx < best_etx)
280 + best_etx = vert->path_etx;
283 + else if (!vert->done && vert->path_etx == best_etx && vert < res)
285 + // Otherwise order is undefined if etx==etx and debug will complain
286 + best_etx = vert->path_etx;
290 + node = list_get_next(node);
293 + if (NULL == etx_cache)
296 + node = list_get_head(vertex_list);
297 + while (node != NULL)
300 + if (!vert->done && vert->path_etx < INFINITE_ETX) count++;
301 + node = list_get_next(node);
305 + etx_cache = olsr_malloc(sizeof(etx_cache[0]) * count, "ETX Cache");
307 + printf("count=%d, Malloc(%d)=%p\n", count, sizeof(etx_cache[0]) * count, etx_cache);
309 + node = list_get_head(vertex_list);
310 + etx_cache_count = 0;
312 + while (node != NULL)
315 + if (!vert->done && vert->path_etx < INFINITE_ETX)
317 + etx_cache[etx_cache_count] = vert;
320 + node = list_get_next(node);
323 + printf("qsort(etx_cache_count=%d)\n", etx_cache_count);
325 + qsort(etx_cache, etx_cache_count, sizeof(etx_cache[0]), etx_cache_compare);
327 + if (0 < etx_cache_count)
330 + while(i < etx_cache_count && i < 10)
332 + printf("%d: %p=%f\n", i, etx_cache[i], etx_cache[i]->path_etx);
341 + if (NULL != etx_cache)
343 + struct dijk_vertex *rescache = NULL;
344 + if (etx_cache_get < etx_cache_count)
346 + rescache = etx_cache[etx_cache_get++];
348 + if (res != rescache)
350 + printf("miss: etx_cache_get=%d, res=%p,%f != rescache=%p,%f\n",
351 + etx_cache_get, res, (NULL != res ? res->path_etx : -1), rescache, (NULL != rescache ? rescache->path_etx : -1));
359 + if (NULL != etx_cache && etx_cache_get < etx_cache_count)
361 + res = etx_cache[etx_cache_get++];
365 + // if we've found a vertex, remove it from the set
368 + res->done = OLSR_TRUE;
374 static struct dijk_vertex *extract_best(struct list *vertex_list)
377 struct interface *inter;
380 +#ifndef DISABLE_SVEN_OLA
383 avl_comp = avl_comp_ipv4;
387 avl_comp = avl_comp_ipv6;
388 @@ -614,13 +776,27 @@
390 // add HNA routes - the set of unprocessed network nodes contains
391 // all reachable network nodes
394 + printf("free etx_cache, saved compares=%d, etx_cache=%p\n", etx_cache_saved, etx_cache);
395 + etx_cache_saved = 0;
397 + if (NULL != etx_cache) {
405 // extract the network node with the best ETX and remove it
406 // from the set of unprocessed network nodes
409 + vert = extract_best_route(&vertex_list);
411 vert = extract_best(&vertex_list);
414 // no more nodes left
416 diff -Nur olsrd-0.4.10.orig/src/olsr_types.h olsrd-0.4.10/src/olsr_types.h
417 --- olsrd-0.4.10.orig/src/olsr_types.h 2005-05-15 14:57:24.000000000 +0200
418 +++ olsrd-0.4.10/src/olsr_types.h 2006-11-12 09:33:49.000000000 +0100