diff options
Diffstat (limited to 'ospf6d/ospf6_spf.c')
-rw-r--r-- | ospf6d/ospf6_spf.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index bfb6df2e..cb549618 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -50,7 +50,9 @@ ospf6_vertex_cmp (void *a, void *b) struct ospf6_vertex *vb = (struct ospf6_vertex *) b; /* ascending order */ - return (va->cost - vb->cost); + if (va->cost != vb->cost) + return (va->cost - vb->cost); + return (va->hops - vb->hops); } static int @@ -320,22 +322,8 @@ ospf6_spf_install (struct ospf6_vertex *v, } prev = (struct ospf6_vertex *) route->route_option; - if (prev->hops > v->hops) - { - for (ALL_LIST_ELEMENTS (prev->child_list, node, nnode, w)) - { - assert (w->parent == prev); - w->parent = v; - listnode_add_sort (v->child_list, w); - } - listnode_delete (prev->parent->child_list, prev); - listnode_add_sort (v->parent->child_list, v); - - ospf6_vertex_delete (prev); - route->route_option = v; - } - else - ospf6_vertex_delete (v); + assert (prev->hops <= v->hops); + ospf6_vertex_delete (v); return -1; } @@ -404,18 +392,19 @@ ospf6_spf_calculation (u_int32_t router_id, caddr_t lsdesc; struct ospf6_lsa *lsa; - /* initialize */ - candidate_list = pqueue_create (); - candidate_list->cmp = ospf6_vertex_cmp; - - ospf6_spf_table_finish (result_table); - /* Install the calculating router itself as the root of the SPF tree */ /* construct root vertex */ lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_ROUTER), htonl (0), router_id, oa->lsdb); if (lsa == NULL) return; + + /* initialize */ + candidate_list = pqueue_create (); + candidate_list->cmp = ospf6_vertex_cmp; + + ospf6_spf_table_finish (result_table); + root = ospf6_vertex_create (lsa); root->area = oa; root->cost = 0; |