ospf6d: replace pqueue_* with DECLARE_SKIPLIST

As the previous commit, this replaces ospf6d's pqueue_* usage in SPF
calculations with a DECLARE_SKIPLIST_* skiplist.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-01-31 03:09:21 +01:00 committed by David Lamparter
parent 7c198e4e1a
commit 4ab0496e38
2 changed files with 17 additions and 17 deletions

View File

@ -27,7 +27,6 @@
#include "command.h"
#include "vty.h"
#include "prefix.h"
#include "pqueue.h"
#include "linklist.h"
#include "thread.h"
#include "lib_errors.h"
@ -76,16 +75,18 @@ static unsigned int ospf6_spf_get_ifindex_from_nh(struct ospf6_vertex *v)
return 0;
}
static int ospf6_vertex_cmp(void *a, void *b)
static int ospf6_vertex_cmp(const struct ospf6_vertex *va,
const struct ospf6_vertex *vb)
{
struct ospf6_vertex *va = (struct ospf6_vertex *)a;
struct ospf6_vertex *vb = (struct ospf6_vertex *)b;
/* ascending order */
if (va->cost != vb->cost)
return (va->cost - vb->cost);
return (va->hops - vb->hops);
if (va->hops != vb->hops)
return (va->hops - vb->hops);
return 0;
}
DECLARE_SKIPLIST_NONUNIQ(vertex_pqueue, struct ospf6_vertex, pqi,
ospf6_vertex_cmp)
static int ospf6_vertex_id_cmp(void *a, void *b)
{
@ -461,7 +462,7 @@ void ospf6_spf_calculation(uint32_t router_id,
struct ospf6_route_table *result_table,
struct ospf6_area *oa)
{
struct pqueue *candidate_list;
struct vertex_pqueue_head candidate_list;
struct ospf6_vertex *root, *v, *w;
int size;
caddr_t lsdesc;
@ -481,8 +482,7 @@ void ospf6_spf_calculation(uint32_t router_id,
}
/* initialize */
candidate_list = pqueue_create();
candidate_list->cmp = ospf6_vertex_cmp;
vertex_pqueue_init(&candidate_list);
root = ospf6_vertex_create(lsa);
root->area = oa;
@ -492,13 +492,10 @@ void ospf6_spf_calculation(uint32_t router_id,
inet_pton(AF_INET6, "::1", &address);
/* Actually insert root to the candidate-list as the only candidate */
pqueue_enqueue(root, candidate_list);
vertex_pqueue_add(&candidate_list, root);
/* Iterate until candidate-list becomes empty */
while (candidate_list->size) {
/* get closest candidate from priority queue */
v = pqueue_dequeue(candidate_list);
while ((v = vertex_pqueue_pop(&candidate_list))) {
/* installing may result in merging or rejecting of the vertex
*/
if (ospf6_spf_install(v, result_table) < 0)
@ -557,12 +554,11 @@ void ospf6_spf_calculation(uint32_t router_id,
zlog_debug(
" New candidate: %s hops %d cost %d",
w->name, w->hops, w->cost);
pqueue_enqueue(w, candidate_list);
vertex_pqueue_add(&candidate_list, w);
}
}
pqueue_delete(candidate_list);
//vertex_pqueue_fini(&candidate_list);
ospf6_remove_temp_router_lsa(oa);

View File

@ -21,6 +21,7 @@
#ifndef OSPF6_SPF_H
#define OSPF6_SPF_H
#include "typesafe.h"
#include "ospf6_top.h"
/* Debug option */
@ -33,6 +34,7 @@ extern unsigned char conf_debug_ospf6_spf;
#define IS_OSPF6_DEBUG_SPF(level) \
(conf_debug_ospf6_spf & OSPF6_DEBUG_SPF_##level)
PREDECL_SKIPLIST_NONUNIQ(vertex_pqueue)
/* Transit Vertex */
struct ospf6_vertex {
/* type of this vertex */
@ -41,6 +43,8 @@ struct ospf6_vertex {
/* Vertex Identifier */
struct prefix vertex_id;
struct vertex_pqueue_item pqi;
/* Identifier String */
char name[128];