summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipcpd/unicast/pol/tests/graph_test.c149
1 files changed, 100 insertions, 49 deletions
diff --git a/src/ipcpd/unicast/pol/tests/graph_test.c b/src/ipcpd/unicast/pol/tests/graph_test.c
index 266ca9d7..ea4c0e59 100644
--- a/src/ipcpd/unicast/pol/tests/graph_test.c
+++ b/src/ipcpd/unicast/pol/tests/graph_test.c
@@ -133,6 +133,46 @@ int graph_test_single_link(void)
return 0;
}
+static int distance_check(int dst,
+ int nhop,
+ enum routing_algo algo)
+{
+ (void) algo;
+
+ /* Same distances for all algorithms at the moment. */
+ if (dst == 2 && nhop != 2) {
+ printf("Wrong entry: 2.\n");
+ return -1;
+ }
+
+ if (dst == 3 && nhop != 3) {
+ printf("Wrong entry: 3.\n");
+ return -1;
+ }
+
+ if (dst == 4 && nhop != 3) {
+ printf("Wrong entry: 4.\n");
+ return -1;
+ }
+
+ if (dst == 5 && nhop != 3) {
+ printf("Wrong entry: 5.\n");
+ return -1;
+ }
+
+ if (dst == 6 && nhop != 2) {
+ printf("Wrong entry: 6.\n");
+ return -1;
+ }
+
+ if (dst == 7 && nhop != 3) {
+ printf("Wrong entry: 7.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
int graph_test(int argc,
char ** argv)
{
@@ -188,7 +228,6 @@ int graph_test(int argc,
return -1;
}
-
if (graph_test_double_link()) {
graph_destroy(graph);
return -1;
@@ -196,40 +235,32 @@ int graph_test(int argc,
if (graph_del_edge(graph, 2, 3)) {
printf("Failed to delete edge.\n");
- graph_destroy(graph);
- return -1;
+ goto fail_graph;
}
if (graph_del_edge(graph, 3, 2)) {
printf("Failed to delete edge.\n");
- graph_destroy(graph);
- return -1;
+ goto fail_graph;
}
- if (graph_test_single_link()) {
- graph_destroy(graph);
- return -1;
- }
+ if (graph_test_single_link())
+ goto fail_graph;
graph_update_edge(graph, 2, 3, qs);
graph_update_edge(graph, 3, 2, qs);
graph_update_edge(graph, 1, 3, qs);
graph_update_edge(graph, 3, 1, qs);
- if (graph_test_entries(2)) {
- graph_destroy(graph);
- return -1;
- }
+ if (graph_test_entries(2))
+ goto fail_graph;
graph_update_edge(graph, 3, 4, qs);
graph_update_edge(graph, 4, 3, qs);
graph_update_edge(graph, 4, 5, qs);
graph_update_edge(graph, 5, 4, qs);
- if (graph_test_entries(4)) {
- graph_destroy(graph);
- return -1;
- }
+ if (graph_test_entries(4))
+ goto fail_graph;
graph_update_edge(graph, 2, 6, qs);
graph_update_edge(graph, 6, 2, qs);
@@ -238,14 +269,13 @@ int graph_test(int argc,
graph_update_edge(graph, 3, 7, qs);
graph_update_edge(graph, 7, 3, qs);
- if (graph_test_entries(6)) {
- graph_destroy(graph);
- return -1;
- }
+ if (graph_test_entries(6))
+ goto fail_graph;
+
if (graph_routing_table(graph, ROUTING_SIMPLE, 1, &table)) {
printf("Failed to get routing table.\n");
- return -1;
+ goto fail_graph;
}
list_for_each(p, &table) {
@@ -257,44 +287,65 @@ int graph_test(int argc,
dst = t->dst;
nhop = n->nhop;
- if (dst == 3 && nhop != 3) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
+ if (distance_check(dst, nhop, ROUTING_SIMPLE)) {
+ printf("Simple distance check failed.\n");
+ goto fail_routing;
}
+ }
- if (dst == 2 && nhop != 2) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
- }
+ graph_free_routing_table(graph, &table);
- if (dst == 6 && nhop != 2) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
- }
+ if (graph_routing_table(graph, ROUTING_LFA, 1, &table)) {
+ printf("Failed to get routing table for LFA.\n");
+ goto fail_graph;
+ }
- if (dst == 4 && nhop != 3) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
- }
+ list_for_each(p, &table) {
+ struct routing_table * t =
+ list_entry(p, struct routing_table, next);
+ struct nhop * n =
+ list_first_entry(&t->nhops, struct nhop, next);
- if (dst == 5 && nhop != 3) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
+ dst = t->dst;
+ nhop = n->nhop;
+
+ if (distance_check(dst, nhop, ROUTING_LFA)) {
+ printf("LFA distance check failed.\n");
+ goto fail_routing;
}
+ }
- if (dst == 7 && nhop != 3) {
- printf("Wrong entry.");
- graph_free_routing_table(graph, &table);
- return -1;
+ graph_free_routing_table(graph, &table);
+
+ if (graph_routing_table(graph, ROUTING_ECMP, 1, &table)) {
+ printf("Failed to get routing table for ECMP.\n");
+ goto fail_graph;
+ }
+
+ list_for_each(p, &table) {
+ struct routing_table * t =
+ list_entry(p, struct routing_table, next);
+ struct nhop * n =
+ list_first_entry(&t->nhops, struct nhop, next);
+
+ dst = t->dst;
+ nhop = n->nhop;
+
+ if (distance_check(dst, nhop, ROUTING_LFA)) {
+ printf("LFA distance check failed.\n");
+ goto fail_routing;
}
}
graph_free_routing_table(graph, &table);
+ graph_destroy(graph);
+
return 0;
+
+ fail_routing:
+ graph_free_routing_table(graph, &table);
+ fail_graph:
+ graph_destroy(graph);
+ return -1;
}