summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/graph.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-03-29 14:42:37 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-29 14:42:37 +0200
commite43fd05ba896ad5b4ac390f6097d6e6a06308f28 (patch)
tree326d07c63210916306825b40407116018a6b6bad /src/ipcpd/normal/graph.c
parent9097a5446c31b83ec224b3e1403a319b24025346 (diff)
downloadouroboros-e43fd05ba896ad5b4ac390f6097d6e6a06308f28.tar.gz
ouroboros-e43fd05ba896ad5b4ac390f6097d6e6a06308f28.zip
ipcpd: normal: Make graph undirected
This turns the directed graph into an undirected one. Only one side of the flow creates an FSDB entry. The graph structure creates an edge object for every vertex involved when an edge is updated or removed.
Diffstat (limited to 'src/ipcpd/normal/graph.c')
-rw-r--r--src/ipcpd/normal/graph.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/ipcpd/normal/graph.c b/src/ipcpd/normal/graph.c
index 5fd6fcb6..5de7c15b 100644
--- a/src/ipcpd/normal/graph.c
+++ b/src/ipcpd/normal/graph.c
@@ -1,7 +1,7 @@
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
- * Graph structure
+ * Undirected graph structure
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
@@ -205,6 +205,7 @@ int graph_update_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -237,9 +238,9 @@ int graph_update_edge(struct graph * graph,
e = add_edge(v, nb);
if (e == NULL) {
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);
log_err("Failed to add edge.");
return -ENOMEM;
@@ -248,6 +249,23 @@ int graph_update_edge(struct graph * graph,
e->qs = qs;
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ nb_e = add_edge(nb, v);
+ if (nb_e == NULL) {
+ del_edge(e);
+ if (list_is_empty(&v->edges))
+ del_vertex(graph, v);
+ if (list_is_empty(&nb->edges))
+ del_vertex(graph, nb);
+ pthread_mutex_unlock(&graph->lock);
+ log_err("Failed to add edge.");
+ return -ENOMEM;
+ }
+ }
+
+ nb_e->qs = qs;
+
pthread_mutex_unlock(&graph->lock);
return 0;
@@ -260,6 +278,7 @@ int graph_del_edge(struct graph * graph,
struct vertex * v;
struct edge * e;
struct vertex * nb;
+ struct edge * nb_e;
assert(graph);
@@ -286,14 +305,21 @@ int graph_del_edge(struct graph * graph,
return -1;
}
+ nb_e = find_edge_by_addr(nb, s_addr);
+ if (nb_e == NULL) {
+ pthread_mutex_unlock(&graph->lock);
+ log_err("No such edge.");
+ return -1;
+ }
+
del_edge(e);
+ del_edge(nb_e);
/* Removing vertex if it was the last edge */
if (list_is_empty(&v->edges))
- del_vertex(graph, v);
-
+ del_vertex(graph, v);
if (list_is_empty(&nb->edges))
- del_vertex(graph, v);
+ del_vertex(graph, nb);
pthread_mutex_unlock(&graph->lock);