]> git.proxmox.com Git - mirror_frr.git/blob - tests/isisd/test_isis_vertex_queue.c
Merge pull request #6455 from GalaxyGorilla/bfd_ospf_topotest
[mirror_frr.git] / tests / isisd / test_isis_vertex_queue.c
1 #include <zebra.h>
2
3 #include "isisd/isis_spf.c"
4
5 #include "test_common.h"
6
7 static struct isis_vertex **vertices;
8 static size_t vertex_count;
9
10 static void setup_test_vertices(void)
11 {
12 struct isis_spftree t = {
13 };
14 struct prefix_pair p = {
15 };
16 uint8_t node_id[7];
17
18 vertices = XMALLOC(MTYPE_TMP, sizeof(*vertices) * 16);
19
20 p.dest.family = AF_INET;
21 p.dest.prefixlen = 24;
22 inet_pton(AF_INET, "192.168.1.0", &p.dest.u.prefix4);
23 vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
24 vertices[vertex_count]->d_N = 20;
25 vertex_count++;
26
27 p.dest.family = AF_INET;
28 p.dest.prefixlen = 24;
29 inet_pton(AF_INET, "192.168.2.0", &p.dest.u.prefix4);
30 vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
31 vertices[vertex_count]->d_N = 20;
32 vertex_count++;
33
34 memset(node_id, 0, sizeof(node_id));
35 node_id[6] = 1;
36 vertices[vertex_count] = isis_vertex_new(&t, node_id,
37 VTYPE_PSEUDO_TE_IS);
38 vertices[vertex_count]->d_N = 15;
39 vertex_count++;
40
41 memset(node_id, 0, sizeof(node_id));
42 node_id[5] = 2;
43 vertices[vertex_count] = isis_vertex_new(&t, node_id,
44 VTYPE_NONPSEUDO_TE_IS);
45 vertices[vertex_count]->d_N = 15;
46 vertex_count++;
47
48 p.dest.family = AF_INET;
49 p.dest.prefixlen = 24;
50 inet_pton(AF_INET, "192.168.3.0", &p.dest.u.prefix4);
51 vertices[vertex_count] = isis_vertex_new(&t, &p, VTYPE_IPREACH_TE);
52 vertices[vertex_count]->d_N = 20;
53 vertex_count++;
54 };
55
56 static void cleanup_test_vertices(void)
57 {
58 for (size_t i = 0; i < vertex_count; i++)
59 isis_vertex_del(vertices[i]);
60 XFREE(MTYPE_TMP, vertices);
61 vertex_count = 0;
62 }
63
64 static void test_ordered(void)
65 {
66 struct isis_vertex_queue q;
67
68 isis_vertex_queue_init(&q, NULL, true);
69 for (size_t i = 0; i < vertex_count; i++)
70 isis_vertex_queue_insert(&q, vertices[i]);
71
72 assert(isis_vertex_queue_count(&q) == vertex_count);
73
74 for (size_t i = 0; i < vertex_count; i++) {
75 assert(isis_find_vertex(&q, &vertices[i]->N, vertices[i]->type) == vertices[i]);
76 }
77
78 assert(isis_vertex_queue_pop(&q) == vertices[2]);
79 assert(isis_find_vertex(&q, &vertices[2]->N, vertices[2]->type) == NULL);
80
81 assert(isis_vertex_queue_pop(&q) == vertices[3]);
82 assert(isis_find_vertex(&q, &vertices[3]->N, vertices[3]->type) == NULL);
83
84 assert(isis_vertex_queue_pop(&q) == vertices[0]);
85 assert(isis_find_vertex(&q, &vertices[0]->N, vertices[0]->type) == NULL);
86
87 assert(isis_vertex_queue_pop(&q) == vertices[1]);
88 assert(isis_find_vertex(&q, &vertices[1]->N, vertices[1]->type) == NULL);
89
90 isis_vertex_queue_delete(&q, vertices[4]);
91 assert(isis_find_vertex(&q, &vertices[4]->N, vertices[4]->type) == NULL);
92
93 assert(isis_vertex_queue_count(&q) == 0);
94 assert(isis_vertex_queue_pop(&q) == NULL);
95
96 isis_vertex_queue_free(&q);
97 }
98
99 int main(int argc, char **argv)
100 {
101 setup_test_vertices();
102 test_ordered();
103 cleanup_test_vertices();
104
105 return 0;
106 }