summaryrefslogtreecommitdiffstats
path: root/tests/isisd/test_isis_vertex_queue.c
blob: d2d9f6293ad9ef74507dac9403d130c01c7d0b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <zebra.h>

#include "isisd/isis_spf.c"

#include "test_common.h"

static struct isis_vertex **vertices;
static size_t vertex_count;

static void setup_test_vertices(void)
{
	struct isis_spftree t = {
	};
	struct prefix_pair p = {
	};
	uint8_t node_id[7];

	vertices = XMALLOC(MTYPE_TMP, sizeof(*vertices) * 16);

	p.dest.family = AF_INET;
	p.dest.prefixlen = 24;
	inet_pton(AF_INET, "192.168.1.0", &p.dest.u.prefix4);
	vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
	vertices[vertex_count]->d_N = 20;
	vertex_count++;

	p.dest.family = AF_INET;
	p.dest.prefixlen = 24;
	inet_pton(AF_INET, "192.168.2.0", &p.dest.u.prefix4);
	vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
	vertices[vertex_count]->d_N = 20;
	vertex_count++;

	memset(node_id, 0, sizeof(node_id));
	node_id[6] = 1;
	vertices[vertex_count] = isis_vertex_new(&t, node_id,
						 VTYPE_PSEUDO_TE_IS);
	vertices[vertex_count]->d_N = 15;
	vertex_count++;

	memset(node_id, 0, sizeof(node_id));
	node_id[5] = 2;
	vertices[vertex_count] = isis_vertex_new(&t, node_id,
						 VTYPE_NONPSEUDO_TE_IS);
	vertices[vertex_count]->d_N = 15;
	vertex_count++;

	p.dest.family = AF_INET;
	p.dest.prefixlen = 24;
	inet_pton(AF_INET, "192.168.3.0", &p.dest.u.prefix4);
	vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
	vertices[vertex_count]->d_N = 20;
	vertex_count++;
};

static void cleanup_test_vertices(void)
{
	for (size_t i = 0; i < vertex_count; i++)
		isis_vertex_del(vertices[i]);
	XFREE(MTYPE_TMP, vertices);
	vertex_count = 0;
}

static void test_ordered(void)
{
	struct isis_vertex_queue q;

	isis_vertex_queue_init(&q, NULL, true);
	for (size_t i = 0; i < vertex_count; i++)
		isis_vertex_queue_insert(&q, vertices[i]);

	assert(isis_vertex_queue_count(&q) == vertex_count);

	for (size_t i = 0; i < vertex_count; i++) {
		assert(isis_find_vertex(&q, &vertices[i]->N, vertices[i]->type) == vertices[i]);
	}

	assert(isis_vertex_queue_pop(&q) == vertices[2]);
	assert(isis_find_vertex(&q, &vertices[2]->N, vertices[2]->type) == NULL);

	assert(isis_vertex_queue_pop(&q) == vertices[3]);
	assert(isis_find_vertex(&q, &vertices[3]->N, vertices[3]->type) == NULL);

	assert(isis_vertex_queue_pop(&q) == vertices[0]);
	assert(isis_find_vertex(&q, &vertices[0]->N, vertices[0]->type) == NULL);

	assert(isis_vertex_queue_pop(&q) == vertices[1]);
	assert(isis_find_vertex(&q, &vertices[1]->N, vertices[1]->type) == NULL);

	isis_vertex_queue_delete(&q, vertices[4]);
	assert(isis_find_vertex(&q, &vertices[4]->N, vertices[4]->type) == NULL);

	assert(isis_vertex_queue_count(&q) == 0);
	assert(isis_vertex_queue_pop(&q) == NULL);

	isis_vertex_queue_free(&q);
}

int main(int argc, char **argv)
{
	setup_test_vertices();
	test_ordered();
	cleanup_test_vertices();

	return 0;
}