* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: lq_route.c,v 1.47 2007/07/05 22:43:46 bernd67 Exp $
+ * Implementation of Dijkstras algorithm. Initially all nodes
+ * are initialized to infinite cost. First we put ourselves
+ * on the heap of reachable nodes. Our heap implementation
+ * is based on an AVL tree which gives interesting performance
+ * characteristics for the frequent operations of minimum key
+ * extraction and re-keying. Next all neighbors of a node are
+ * explored and put on the heap if the cost of reaching them is
+ * better than reaching the current candidate node.
+ * The SPF calculation is terminated if there are no more nodes
+ * on the heap.
*/
+#include "ipcalc.h"
#include "defs.h"
#include "olsr.h"
#include "tc_set.h"
#include "routing_table.h"
#include "mid_set.h"
#include "hna_set.h"
-#include "lq_list.h"
-#include "lq_avl.h"
+#include "common/list.h"
+#include "common/avl.h"
#include "lq_route.h"
+#include "net_olsr.h"
+#include "lq_plugin.h"
-struct olsr_spf_edge
-{
- struct avl_node tree_node;
- struct olsr_spf_vertex *dest;
- float etx;
-};
-
-struct olsr_spf_vertex
-{
- struct avl_node tree_node; /* node keyed by ip address */
- struct avl_node cand_tree_node; /* node keyed by etx */
- struct avl_node path_tree_node; /* node keyed by etx */
- union olsr_ip_addr addr;
- struct avl_tree edge_tree;
- union olsr_ip_addr *next_hop; /* the gateway router */
- float path_etx;
- olsr_u8_t hops;
-};
+struct timer_entry *spf_backoff_timer = NULL;
/*
* avl_comp_etx
* after compiler optimization.
*/
static int
-avl_comp_etx (void *etx1, void *etx2)
+avl_comp_etx (const void *etx1, const void *etx2)
{
- if (*(float *)etx1 < *(float *)etx2) {
+ if (*(const olsr_linkcost *)etx1 < *(const olsr_linkcost *)etx2) {
return -1;
}
- if (*(float *)etx1 > *(float *)etx2) {
+ if (*(const olsr_linkcost *)etx1 > *(const olsr_linkcost *)etx2) {
return +1;
}
*/
static void
olsr_spf_add_cand_tree (struct avl_tree *tree,
- struct olsr_spf_vertex *vert)
+ struct tc_entry *tc)
{
- vert->cand_tree_node.key = &vert->path_etx;
- vert->cand_tree_node.data = vert;
+#if !defined(NODEBUG) && defined(DEBUG)
+ struct ipaddr_str buf;
+ struct lqtextbuffer lqbuffer;
+#endif
+ tc->cand_tree_node.key = &tc->path_cost;
#ifdef DEBUG
- OLSR_PRINTF(1, "SPF: insert candidate %s, cost %f\n",
- olsr_ip_to_string(&(vert->addr)),
- vert->path_etx);
+ OLSR_PRINTF(2, "SPF: insert candidate %s, cost %s\n",
+ olsr_ip_to_string(&buf, &tc->addr),
+ get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
#endif
- avl_insert(tree, &vert->cand_tree_node, 1);
+ avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
}
/*
*/
static void
olsr_spf_del_cand_tree (struct avl_tree *tree,
- struct olsr_spf_vertex *vert)
+ struct tc_entry *tc)
{
#ifdef DEBUG
- OLSR_PRINTF(1, "SPF: delete candidate %s, cost %f\n",
- olsr_ip_to_string(&(vert->addr)),
- vert->path_etx);
+#ifndef NODEBUG
+ struct ipaddr_str buf;
+ struct lqtextbuffer lqbuffer;
+#endif
+ OLSR_PRINTF(2, "SPF: delete candidate %s, cost %s\n",
+ olsr_ip_to_string(&buf, &tc->addr),
+ get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
#endif
- avl_delete(tree, &vert->cand_tree_node);
+ avl_delete(tree, &tc->cand_tree_node);
}
/*
- * olsr_spf_add_path_tree
+ * olsr_spf_add_path_list
*
- * Key an existing vertex to a path tree.
+ * Insert an SPF result at the end of the path list.
*/
static void
-olsr_spf_add_path_tree (struct avl_tree *tree,
- struct olsr_spf_vertex *vert)
+olsr_spf_add_path_list (struct list_node *head, int *path_count,
+ struct tc_entry *tc)
{
- vert->path_tree_node.key = &vert->path_etx;
- vert->path_tree_node.data = vert;
+#if !defined(NODEBUG) && defined(DEBUG)
+ struct ipaddr_str pathbuf, nbuf;
+ struct lqtextbuffer lqbuffer;
+#endif
#ifdef DEBUG
- OLSR_PRINTF(1, "SPF: insert path %s, cost %f, via %s\n",
- olsr_ip_to_string(&(vert->addr)),
- vert->path_etx,
- olsr_ip_to_string(vert->next_hop));
+ OLSR_PRINTF(2, "SPF: append path %s, cost %s, via %s\n",
+ olsr_ip_to_string(&pathbuf, &tc->addr),
+ get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer),
+ tc->next_hop ? olsr_ip_to_string(
+ &nbuf, &tc->next_hop->neighbor_iface_addr) : "-");
#endif
- avl_insert(tree, &vert->path_tree_node, 1);
-}
-
-/*
- * olsr_spf_add_vertex
- *
- * Add a node to the tree of all nodes in the network.
- */
-static struct olsr_spf_vertex *
-olsr_spf_add_vertex (struct avl_tree *vertex_tree,
- union olsr_ip_addr *addr, float path_etx)
-{
- struct avl_node *node;
- struct olsr_spf_vertex *vert;
-
- // see whether this destination is already in our tree
-
- node = avl_find(vertex_tree, addr);
-
- if (node) {
- return node->data;
- }
-
- // if it's not in our list, add it
-
- vert = olsr_malloc(sizeof (struct olsr_spf_vertex), "Dijkstra vertex");
-
- vert->tree_node.data = vert;
- vert->tree_node.key = &vert->addr;
-
- COPY_IP(&vert->addr, addr);
-
- vert->path_etx = path_etx;
- vert->next_hop = NULL;
- vert->hops = 0;
-
- avl_init(&vert->edge_tree, avl_comp_default);
-
- avl_insert(vertex_tree, &vert->tree_node, 0);
- return vert;
-}
-
-static void
-olsr_spf_add_edge (struct avl_tree *vertex_tree,
- union olsr_ip_addr *src, union olsr_ip_addr *dst,
- float etx)
-{
- struct avl_node *node;
- struct olsr_spf_vertex *svert;
- struct olsr_spf_vertex *dvert;
- struct olsr_spf_edge *edge;
-
- // source lookup
-
- node = avl_find(vertex_tree, src);
-
- // source vertex does not exist
-
- if (node == NULL)
- return;
-
- svert = node->data;
-
- // destination lookup
-
- node = avl_find(vertex_tree, dst);
-
- // destination vertex does not exist
-
- if (node == NULL)
- return;
-
- dvert = node->data;
-
- // check for existing forward edge
-
- if (avl_find(&svert->edge_tree, dst) == NULL)
- {
- // add forward edge
-
- edge = olsr_malloc(sizeof (struct olsr_spf_vertex), "Dijkstra forward edge");
-
- edge->tree_node.data = edge;
- edge->tree_node.key = &dvert->addr;
-
- edge->dest = dvert;
- edge->etx = etx;
-
- avl_insert(&svert->edge_tree, &edge->tree_node, 0);
- }
-
- // check for existing inverse edge
-
- if (avl_find(&dvert->edge_tree, src) == NULL)
- {
- // add inverse edge
-
- edge = olsr_malloc(sizeof (struct olsr_spf_vertex), "Dijkstra inverse edge");
-
- edge->tree_node.data = edge;
- edge->tree_node.key = &svert->addr;
-
- edge->dest = svert;
- edge->etx = etx;
-
- avl_insert(&dvert->edge_tree, &edge->tree_node, 0);
- }
-}
-
-static void olsr_free_everything(struct avl_tree *vertex_tree)
-{
- struct avl_node *vert_node;
- struct avl_node *edge_node;
- struct olsr_spf_vertex *vert;
- struct olsr_spf_edge *edge;
-
- vert_node = avl_walk_first(vertex_tree);
-
- // loop through all vertices
-
- while (vert_node)
- {
- vert = vert_node->data;
- edge_node = avl_walk_first(&vert->edge_tree);
-
- // loop through all edges of the current vertex
-
- while (edge_node != NULL)
- {
- edge = edge_node->data;
- edge_node = avl_walk_next(edge_node);
- free(edge);
- }
-
- vert_node = avl_walk_next(vert_node);
- free(vert);
- }
+ list_add_before(head, &tc->path_list_node);
+ *path_count = *path_count + 1;
}
/*
*
* return the node with the minimum pathcost.
*/
-static struct olsr_spf_vertex *
+static struct tc_entry *
olsr_spf_extract_best (struct avl_tree *tree)
{
- struct avl_node *node;
+ struct avl_node *node = avl_walk_first(tree);
- node = avl_walk_first(tree);
-
- return (node ? node->data : NULL);
+ return (node ? cand_tree2tc(node) : NULL);
}
-#ifdef DEBUG
-static char *olsr_etx_to_string(float etx)
-{
- static char buff[20];
-
- if (etx == INFINITE_ETX)
- return "INF";
-
- snprintf(buff, 20, "%.6f", etx);
- return buff;
-}
-#endif
-
-
/*
* olsr_spf_relax
*
* path cost is better.
*/
static void
-olsr_spf_relax (struct avl_tree *cand_tree, struct olsr_spf_vertex *vert)
+olsr_spf_relax (struct avl_tree *cand_tree, struct tc_entry *tc)
{
- struct olsr_spf_edge *edge;
struct avl_node *edge_node;
- float new_etx;
+ olsr_linkcost new_cost;
#ifdef DEBUG
- OLSR_PRINTF(1, "SPF: exploring node %s, cost %f\n",
- olsr_ip_to_string(&(vert->addr)),
- vert->path_etx);
+#ifndef NODEBUG
+ struct ipaddr_str buf, nbuf;
+ struct lqtextbuffer lqbuffer;
+#endif
+ OLSR_PRINTF(2, "SPF: exploring node %s, cost %s\n",
+ olsr_ip_to_string(&buf, &tc->addr),
+ get_linkcost_text(tc->path_cost, OLSR_FALSE, &lqbuffer));
#endif
- edge_node = avl_walk_first(&vert->edge_tree);
+ /*
+ * loop through all edges of this vertex.
+ */
+ for (edge_node = avl_walk_first(&tc->edge_tree);
+ edge_node;
+ edge_node = avl_walk_next(edge_node)) {
- // loop through all edges of this vertex
+ struct tc_entry *new_tc;
+ struct tc_edge_entry *tc_edge = edge_tree2tc_edge(edge_node);
- while (edge_node != NULL)
- {
- edge = edge_node->data;
+ /*
+ * We are not interested in dead-end or dying edges.
+ */
+ if (!tc_edge->edge_inv ||
+ ((tc_edge->flags | tc_edge->edge_inv->flags) & OLSR_TC_EDGE_DOWN)) {
+#ifdef DEBUG
+ OLSR_PRINTF(2, "SPF: ignoring edge %s\n",
+ olsr_ip_to_string(&buf, &tc_edge->T_dest_addr));
+ if (!tc_edge->edge_inv) {
+ OLSR_PRINTF(2, "SPF: no inverse edge\n");
+ }
+
+ if (tc_edge->flags & OLSR_TC_EDGE_DOWN) {
+ OLSR_PRINTF(2, "SPF: edge down\n");
+ }
+ if (!tc_edge->edge_inv) {
+ OLSR_PRINTF(2, "SPF: no inverse edge\n");
+ } else if (tc_edge->edge_inv->flags & OLSR_TC_EDGE_DOWN){
+ OLSR_PRINTF(2, "SPF: inverse edge down\n");
+ }
+#endif
+ continue;
+ }
- // total quality of the path through this vertex to the
- // destination of this edge
+ /*
+ * total quality of the path through this vertex
+ * to the destination of this edge
+ */
+ new_cost = tc->path_cost + tc_edge->cost;
- new_etx = vert->path_etx + edge->etx;
+#ifdef DEBUG
+ OLSR_PRINTF(2, "SPF: exploring edge %s, cost %s\n",
+ olsr_ip_to_string(&buf, &tc_edge->T_dest_addr),
+ get_linkcost_text(new_cost, OLSR_TRUE, &lqbuffer));
+#endif
- // if it's better than the current path quality of this
- // edge's destination, then we've found a better path to
- // this destination
+ /*
+ * if it's better than the current path quality of this edge's
+ * destination node, then we've found a better path to this node.
+ */
+ new_tc = tc_edge->edge_inv->tc;
+
+ if (new_cost < new_tc->path_cost) {
- if (new_etx < edge->dest->path_etx)
- {
/* if this node has been on the candidate tree delete it */
- if (edge->dest->path_etx != INFINITE_ETX) {
- olsr_spf_del_cand_tree(cand_tree, edge->dest);
+ if (new_tc->path_cost < ROUTE_COST_BROKEN) {
+ olsr_spf_del_cand_tree(cand_tree, new_tc);
}
/* re-insert on candidate tree with the better metric */
- edge->dest->path_etx = new_etx;
- olsr_spf_add_cand_tree(cand_tree, edge->dest);
+ new_tc->path_cost = new_cost;
+ olsr_spf_add_cand_tree(cand_tree, new_tc);
/* pull-up the next-hop and bump the hop count */
- if (vert->next_hop) {
- edge->dest->next_hop = vert->next_hop;
+ if (tc->next_hop) {
+ new_tc->next_hop = tc->next_hop;
}
- edge->dest->hops = vert->hops + 1;
+ new_tc->hops = tc->hops + 1;
#ifdef DEBUG
- OLSR_PRINTF(1, "SPF: better path to %s, cost %s -> %s, via %s, hops %u\n",
- olsr_ip_to_string(&(edge->dest->addr)),
- olsr_etx_to_string(edge->dest->path_etx),
- olsr_etx_to_string(new_etx),
- olsr_ip_to_string(vert->next_hop),
- edge->dest->hops);
+ OLSR_PRINTF(2, "SPF: better path to %s, cost %s, via %s, hops %u\n",
+ olsr_ip_to_string(&buf, &new_tc->addr),
+ get_linkcost_text(new_cost, OLSR_TRUE, &lqbuffer),
+ tc->next_hop ? olsr_ip_to_string(
+ &nbuf, &tc->next_hop->neighbor_iface_addr) : "<none>",
+ new_tc->hops);
#endif
}
-
- edge_node = avl_walk_next(edge_node);
}
}
*
* Run the Dijkstra algorithm.
*
- * We are using two trees: the candidate and the path tree.
* A node gets added to the candidate tree when one of its edges has
* an overall better root path cost than the node itself.
* The node with the shortest metric gets moved from the candidate to
- * the path tree every pass.
+ * the path list every pass.
* The SPF computation is completed when there are no more nodes
* on the candidate tree.
*/
static void
-olsr_spf_run_full (struct avl_tree *cand_tree, struct avl_tree *path_tree)
+olsr_spf_run_full (struct avl_tree *cand_tree, struct list_node *path_list,
+ int *path_count)
{
- struct olsr_spf_vertex *vert;
+ struct tc_entry *tc;
+
+ *path_count = 0;
- while ((vert = olsr_spf_extract_best(cand_tree))) {
+ while ((tc = olsr_spf_extract_best(cand_tree))) {
- olsr_spf_relax(cand_tree, vert);
+ olsr_spf_relax(cand_tree, tc);
/*
* move the best path from the candidate tree
- * to the path tree.
+ * to the path list.
*/
- olsr_spf_del_cand_tree(cand_tree, vert);
- olsr_spf_add_path_tree(path_tree, vert);
+ olsr_spf_del_cand_tree(cand_tree, tc);
+ olsr_spf_add_path_list(path_list, path_count, tc);
}
}
+/**
+ * Callback for the SPF backoff timer.
+ */
+static void
+olsr_expire_spf_backoff(void *context __attribute__((unused)))
+{
+ spf_backoff_timer = NULL;
+}
+
void
-olsr_calculate_lq_routing_table (void)
+olsr_calculate_routing_table (void *context __attribute__((unused)))
{
- struct avl_tree vertex_tree, cand_tree, path_tree;
- struct avl_node *tree_node;
- int i;
- struct tc_entry *tcsrc;
- struct topo_dst *tcdst;
- struct olsr_spf_vertex *vert, *myself;
- struct link_entry *link;
- struct neighbor_entry *neigh;
- struct mid_address *mid_walker;
- float etx;
- struct hna_entry *hna_gw;
- struct hna_net *hna;
- struct rt_entry *gw_rt, *hna_rt, *head_rt;
- struct neighbor_2_entry *neigh2;
-#if 0
- struct neighbor_list_entry *neigh_walker;
+#ifdef SPF_PROFILING
+ struct timeval t1, t2, t3, t4, t5, spf_init, spf_run, route, kernel, total;
#endif
- struct interface *inter;
-
- if (olsr_cnf->ipsize != 4)
- avl_comp_default = avl_comp_ipv6;
+ struct avl_tree cand_tree;
+ struct avl_node *rtp_tree_node;
+ struct list_node path_list; /* head of the path_list */
+ struct tc_entry *tc;
+ struct rt_path *rtp;
+ struct tc_edge_entry *tc_edge;
+ struct neighbor_entry *neigh;
+ struct link_entry *link;
+ int path_count = 0;
+
+ /* We are done if our backoff timer is running */
+ if (!spf_backoff_timer) {
+ spf_backoff_timer =
+ olsr_start_timer(1000, 5, OLSR_TIMER_ONESHOT, &olsr_expire_spf_backoff,
+ NULL, 0);
+ } else {
+ return;
+ }
- // initialize the graph
+#ifdef SPF_PROFILING
+ gettimeofday(&t1, NULL);
+#endif
- avl_init(&vertex_tree, avl_comp_default);
+ /*
+ * Prepare the candidate tree and result list.
+ */
avl_init(&cand_tree, avl_comp_etx);
- avl_init(&path_tree, avl_comp_etx);
+ list_head_init(&path_list);
+ olsr_bump_routingtree_version();
- // add ourselves to the vertex and candidate tree
+ /*
+ * Initialize vertices in the lsdb.
+ */
+ OLSR_FOR_ALL_TC_ENTRIES(tc) {
+ tc->next_hop = NULL;
+ tc->path_cost = ROUTE_COST_BROKEN;
+ tc->hops = 0;
+ } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
- myself = olsr_spf_add_vertex(&vertex_tree, &olsr_cnf->main_addr, ZERO_ETX);
- olsr_spf_add_cand_tree(&cand_tree, myself);
+ /*
+ * zero ourselves and add us to the candidate tree.
+ */
+ olsr_change_myself_tc();
+ tc_myself->path_cost = ZERO_ROUTE_COST;
+ olsr_spf_add_cand_tree(&cand_tree, tc_myself);
/*
- * Add our neighbours.
+ * add edges to and from our neighbours.
*/
- for (i = 0; i < HASHSIZE; i++)
- for (neigh = neighbortable[i].next; neigh != &neighbortable[i];
- neigh = neigh->next) {
- if (neigh->status == SYM) {
+ OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
- vert = olsr_spf_add_vertex(&vertex_tree, &neigh->neighbor_main_addr,
- INFINITE_ETX);
+ if (neigh->status == SYM) {
- /*
- * Set the next-hop pointer to ourselves.
- * During olsr_spf_relax() the next_hop pointer will be
- * pulled up to the new candidate node.
- * At the End of the SPF computation every reachable node has
- * a pointer to its corresponding first hop router.
- */
- vert->next_hop = &vert->addr;
+ tc_edge = olsr_lookup_tc_edge(tc_myself, &neigh->neighbor_main_addr);
+ link = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
+ if (!link) {
/*
- * one hop neighbors are just one hop away.
+ * If there is no best link to this neighbor
+ * and we had an edge before then flush the edge.
*/
- vert->hops = 1;
+ if (tc_edge) {
+ olsr_delete_tc_edge_entry(tc_edge);
+ }
+ continue;
}
- }
-
- // add our two-hop neighbours
-
- for (i = 0; i < HASHSIZE; i++)
- for (neigh2 = two_hop_neighbortable[i].next;
- neigh2 != &two_hop_neighbortable[i];
- neigh2 = neigh2->next) {
- vert = olsr_spf_add_vertex(&vertex_tree, &neigh2->neighbor_2_addr,
- INFINITE_ETX);
+ /* find the interface for the link */
+ if (link->if_name) {
+ link->inter = if_ifwithname(link->if_name);
+ } else {
+ link->inter = if_ifwithaddr(&link->local_iface_addr);
+ }
/*
- * two hop neighbors are two hops away.
+ * Set the next-hops of our neighbors.
*/
- vert->hops = 2;
- }
- // add remaining vertices
-
- for (i = 0; i < HASHSIZE; i++)
- for (tcsrc = tc_table[i].next; tcsrc != &tc_table[i]; tcsrc = tcsrc->next)
- {
- // add source
-
- olsr_spf_add_vertex(&vertex_tree, &tcsrc->T_last_addr, INFINITE_ETX);
-
- // add destinations of this source
-
- for (tcdst = tcsrc->destinations.next; tcdst != &tcsrc->destinations;
- tcdst = tcdst->next)
- olsr_spf_add_vertex(&vertex_tree, &tcdst->T_dest_addr, INFINITE_ETX);
- }
-
- // add edges to and from our neighbours
-
- for (i = 0; i < HASHSIZE; i++)
- for (neigh = neighbortable[i].next; neigh != &neighbortable[i];
- neigh = neigh->next)
- if (neigh->status == SYM)
- {
- link = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
-
- if(!link)
- continue;
-
- if (link->loss_link_quality2 >= MIN_LINK_QUALITY &&
- link->neigh_link_quality2 >= MIN_LINK_QUALITY)
- {
- etx = 1.0 / (link->loss_link_quality2 * link->neigh_link_quality2);
-
- olsr_spf_add_edge(&vertex_tree, &neigh->neighbor_main_addr, &olsr_cnf->main_addr, etx);
- }
+ if (!tc_edge) {
+ tc_edge = olsr_add_tc_edge_entry(tc_myself, &neigh->neighbor_main_addr,
+ 0, link->vtime);
+ } else {
+ /*
+ * Update LQ and timers, such that the edge does not get deleted.
+ */
+ olsr_copylq_link_entry_2_tc_edge_entry(tc_edge, link);
+ olsr_set_tc_edge_timer(tc_edge, link->vtime*1000);
+ olsr_calc_tc_edge_entry_etx(tc_edge);
}
-
-// we now rely solely on TC messages for routes to our two-hop neighbours
-
-#if 0
-
- // add edges between our neighbours and our two-hop neighbours
-
- for (i = 0; i < HASHSIZE; i++)
- for (neigh2 = two_hop_neighbortable[i].next;
- neigh2 != &two_hop_neighbortable[i];
- neigh2 = neigh2->next)
- for (neigh_walker = neigh2->neighbor_2_nblist.next;
- neigh_walker != &neigh2->neighbor_2_nblist;
- neigh_walker = neigh_walker->next)
- {
- if (neigh_walker->second_hop_link_quality >=
- MIN_LINK_QUALITY * MIN_LINK_QUALITY)
- {
- neigh = neigh_walker->neighbor;
-
- etx = 1.0 / neigh_walker->second_hop_link_quality;
-
- olsr_spf_add_edge(&vertex_tree, &neigh2->neighbor_2_addr,
- &neigh->neighbor_main_addr, etx);
- }
+ if (tc_edge->edge_inv) {
+ tc_edge->edge_inv->tc->next_hop = link;
}
+ }
+ } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+#ifdef SPF_PROFILING
+ gettimeofday(&t2, NULL);
#endif
- // add remaining edges
-
- for (i = 0; i < HASHSIZE; i++)
- for (tcsrc = tc_table[i].next; tcsrc != &tc_table[i]; tcsrc = tcsrc->next)
- for (tcdst = tcsrc->destinations.next; tcdst != &tcsrc->destinations;
- tcdst = tcdst->next)
- {
- if (tcdst->link_quality >= MIN_LINK_QUALITY &&
- tcdst->inverse_link_quality >= MIN_LINK_QUALITY)
- {
- etx = 1.0 / (tcdst->link_quality * tcdst->inverse_link_quality);
-
- olsr_spf_add_edge(&vertex_tree, &tcdst->T_dest_addr, &tcsrc->T_last_addr,
- etx);
- }
- }
-
/*
* Run the SPF calculation.
*/
- olsr_spf_run_full(&cand_tree, &path_tree);
-
- // save the old routing table
+ olsr_spf_run_full(&cand_tree, &path_list, &path_count);
- olsr_move_route_table(routingtable, old_routes);
+ OLSR_PRINTF(2, "\n--- %s ------------------------------------------------- DIJKSTRA\n\n",
+ olsr_wallclock_string());
- OLSR_PRINTF(2, "\n--- %02d:%02d:%02d.%02d ------------------------------------------------- DIJKSTRA\n\n",
- nowtm->tm_hour,
- nowtm->tm_min,
- nowtm->tm_sec,
- (int)now.tv_usec/10000);
+#ifdef SPF_PROFILING
+ gettimeofday(&t3, NULL);
+#endif
/*
- * In the path tree we have all the reachable nodes
- * in our topology sorted by etx metric.
+ * In the path list we have all the reachable nodes in our topology.
*/
- for (tree_node = avl_walk_first(&path_tree);
- tree_node != NULL;
- tree_node = avl_walk_next(tree_node)) {
+ for (; !list_is_empty(&path_list); list_remove(path_list.next)) {
- vert = tree_node->data;
+ tc = pathlist2tc(path_list.next);
+ link = tc->next_hop;
- if (!vert->next_hop) {
- OLSR_PRINTF(2, "%s no next-hop\n", olsr_ip_to_string(&vert->addr));
+ if (!link) {
+#ifdef DEBUG
+ /*
+ * Supress the error msg when our own tc_entry
+ * does not contain a next-hop.
+ */
+ if (tc != tc_myself) {
+#ifndef NODEBUG
+ struct ipaddr_str buf;
+#endif
+ OLSR_PRINTF(2, "SPF: %s no next-hop\n", olsr_ip_to_string(&buf, &tc->addr));
+ }
+#endif
continue;
}
- // find the best link to the one-hop neighbour
-
- link = get_best_link_to_neighbor(vert->next_hop);
-
- // we may see NULL here, if the one-hop neighbour is not in the
- // link and neighbour sets any longer, but we have derived an edge
- // between us and the one-hop neighbour from the TC set
-
- if (link != NULL)
- {
- // find the interface for the found link
- inter = link->if_name ? if_ifwithname(link->if_name) :
- if_ifwithaddr(&link->local_iface_addr);
-
- // we may see NULL here if the interface is down, but we have
- // links that haven't timed out, yet
-
- if (inter != NULL)
- {
- // XXX - fix me: structurally prevent duplicates, don't test via
- // olsr_lookup_routing_table()
-
- // route addition, case A - add a route to the main address of the
- // destination node
-
- if (olsr_lookup_routing_table(&vert->addr) == NULL)
- olsr_insert_routing_table(&vert->addr, &link->neighbor_iface_addr,
- inter, vert->hops, vert->path_etx);
+ /*
+ * Now walk all prefixes advertised by that node.
+ * Since the node is reachable, insert the prefix into the global RIB.
+ * If the prefix is already in the RIB, refresh the entry such
+ * that olsr_delete_outdated_routes() does not purge it off.
+ */
+ for (rtp_tree_node = avl_walk_first(&tc->prefix_tree);
+ rtp_tree_node;
+ rtp_tree_node = avl_walk_next(rtp_tree_node)) {
- // route addition, case B - add routes to the remaining interfaces
- // of the destination node
+ rtp = rtp_prefix_tree2rtp(rtp_tree_node);
- for (mid_walker = mid_lookup_aliases(&vert->addr); mid_walker != NULL;
- mid_walker = mid_walker->next_alias)
- if (olsr_lookup_routing_table(&mid_walker->alias) == NULL)
- olsr_insert_routing_table(&mid_walker->alias,
- &link->neighbor_iface_addr, inter, vert->hops,
- vert->path_etx);
+ if (rtp->rtp_rt) {
- // XXX - we used to use olsr_lookup_routing_table() only here, but
- // this assumed that case A or case B had already happened for
- // this destination; if case A or case B happened after case C
- // for the same destination, we had duplicates, as cases A and
- // B would not test whether case C had already happened
+ /*
+ * If there is a route entry, the prefix is already in the global RIB.
+ */
+ olsr_update_rt_path(rtp, tc, link);
- // route addition, case C - make sure that we have a route to the
- // router - e.g. in case the router's not the main address and it's
- // MID entry has timed out
+ } else {
- if (olsr_lookup_routing_table(&link->neighbor_iface_addr) == NULL)
- olsr_insert_routing_table(&link->neighbor_iface_addr,
- &link->neighbor_iface_addr, inter, 1,
- vert->path_etx);
+ /*
+ * The prefix is reachable and not yet in the global RIB.
+ * Build a rt_entry for it.
+ */
+ olsr_insert_rt_path(rtp, tc, link);
}
}
}
- // save the old HNA routing table
-
- olsr_move_route_table(hna_routes, old_hna);
-
- // add HNA routes
-
- /*
- * In the path tree we have all the reachable nodes
- * in our topology sorted by etx metric.
- */
- for (tree_node = avl_walk_first(&path_tree);
- tree_node;
- tree_node = avl_walk_next(tree_node)) {
-
- if (!(vert = tree_node->data)) {
- break;
- }
-
- // find the node's HNAs
-
- hna_gw = olsr_lookup_hna_gw(&vert->addr);
-
- // node doesn't announce any HNAs
-
- if (hna_gw == NULL)
- continue;
-
- // find route to the node
-
- gw_rt = olsr_lookup_routing_table(&hna_gw->A_gateway_addr);
+ /* Update the RIB based on the new SPF results */
- // maybe we haven't found a link or an interface for the gateway above
- // and hence haven't added a route - skip the HNA in this case
+ olsr_update_rib_routes();
- if (gw_rt == NULL)
- continue;
-
- // loop through the node's HNAs
-
- for (hna = hna_gw->networks.next; hna != &hna_gw->networks;
- hna = hna->next)
- {
- // we already have a route via a previous (better) node
-
- if (olsr_lookup_hna_routing_table(&hna->A_network_addr) != NULL)
- continue;
-
- // create route for the HNA
-
- hna_rt = olsr_malloc(sizeof(struct rt_entry), "LQ HNA route entry");
-
- // set HNA IP address and netmask
-
- COPY_IP(&hna_rt->rt_dst, &hna->A_network_addr);
- hna_rt->rt_mask = hna->A_netmask;
-
- // copy remaining fields from the node's route
-
- COPY_IP(&hna_rt->rt_router, &gw_rt->rt_router);
- hna_rt->rt_metric = gw_rt->rt_metric;
- hna_rt->rt_etx = gw_rt->rt_etx;
- hna_rt->rt_if = gw_rt->rt_if;
-
- // we're not a host route
-
- hna_rt->rt_flags = RTF_UP | RTF_GATEWAY;
-
- // find the correct list
-
- head_rt = &hna_routes[olsr_hashing(&hna->A_network_addr)];
-
- // enqueue
-
- head_rt->next->prev = hna_rt;
- hna_rt->next = head_rt->next;
-
- head_rt->next = hna_rt;
- hna_rt->prev = head_rt;
- }
- }
-
- // free the graph
-
- olsr_free_everything(&vertex_tree);
+#ifdef SPF_PROFILING
+ gettimeofday(&t4, NULL);
+#endif
- // move the route changes into the kernel
+ /* move the route changes into the kernel */
olsr_update_kernel_routes();
- olsr_update_kernel_hna_routes();
- // free the saved routing table
+#ifdef SPF_PROFILING
+ gettimeofday(&t5, NULL);
+#endif
- olsr_free_routing_table(old_routes);
- olsr_free_routing_table(old_hna);
+#ifdef SPF_PROFILING
+ timersub(&t2, &t1, &spf_init);
+ timersub(&t3, &t2, &spf_run);
+ timersub(&t4, &t3, &route);
+ timersub(&t5, &t4, &kernel);
+ timersub(&t5, &t1, &total);
+ OLSR_PRINTF(1, "\n--- SPF-stats for %d nodes, %d routes (total/init/run/route/kern): "
+ "%d, %d, %d, %d, %d\n",
+ path_count, routingtree.count,
+ (int)total.tv_usec, (int)spf_init.tv_usec, (int)spf_run.tv_usec,
+ (int)route.tv_usec, (int)kernel.tv_usec);
+#endif
}
/*