Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
check that AS->get_route don't return NULL on non-existant route, but throw an exception
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 07:45:05 +0000 (08:45 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 07:45:05 +0000 (08:45 +0100)
src/surf/surf_routing_dijkstra.c
src/surf/surf_routing_floyd.c
src/surf/surf_routing_full.c
src/surf/surf_routing_none.c
src/surf/surf_routing_rulebased.c

index 2c65d60..3c98c82 100644 (file)
@@ -206,10 +206,6 @@ static void dijkstra_get_route(AS_t asg,
                                const char *src, const char *dst,
                                route_t route)
 {
-  xbt_assert(asg && src
-              && dst,
-              "Invalid params for \"get_route\" function at AS \"%s\"",
-              asg->name);
 
   /* set utils vars */
   as_dijkstra_t as = (as_dijkstra_t) asg;
@@ -217,10 +213,8 @@ static void dijkstra_get_route(AS_t asg,
   generic_src_dst_check(asg, src, dst);
   int *src_id = xbt_dict_get_or_null(asg->to_index, src);
   int *dst_id = xbt_dict_get_or_null(asg->to_index, dst);
-  xbt_assert(src_id
-              && dst_id,
-              "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
-              src, dst);
+  if (!src_id || !dst_id)
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   int *pred_arr = NULL;
   int src_node_id = 0;
@@ -240,15 +234,13 @@ static void dijkstra_get_route(AS_t asg,
       graph_node_map_search(as, *src_id);
   graph_node_map_element_t dst_elm =
       graph_node_map_search(as, *dst_id);
-  xbt_assert(src_elm != NULL
-              && dst_elm != NULL, "src %d or dst %d does not exist",
-              *src_id, *dst_id);
+
   src_node_id = ((graph_node_data_t)
                  xbt_graph_node_get_data(src_elm->node))->graph_id;
   dst_node_id = ((graph_node_data_t)
                  xbt_graph_node_get_data(dst_elm->node))->graph_id;
 
-  /* if the src and dst are the same *//* fixed, missing in the previous version */
+  /* if the src and dst are the same */
   if (src_node_id == dst_node_id) {
 
     xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
@@ -256,8 +248,8 @@ static void dijkstra_get_route(AS_t asg,
     xbt_edge_t edge =
         xbt_graph_get_edge(as->route_graph, node_s_v, node_e_v);
 
-    xbt_assert(edge != NULL, "no route between host %d and %d", *src_id,
-                *dst_id);
+    if (edge == NULL)
+      THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
     e_route = (route_t) xbt_graph_edge_get_data(edge);
 
@@ -346,8 +338,8 @@ static void dijkstra_get_route(AS_t asg,
     xbt_edge_t edge =
         xbt_graph_get_edge(as->route_graph, node_pred_v, node_v);
 
-    xbt_assert(edge != NULL, "no route between host %d and %d", *src_id,
-                *dst_id);
+    if (edge == NULL)
+      THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
     prev_gw_src = gw_src;
 
@@ -362,8 +354,8 @@ static void dijkstra_get_route(AS_t asg,
         && strcmp(gw_dst, prev_gw_src)) {
       xbt_dynar_t e_route_as_to_as=NULL;
       routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
-      xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
-                  gw_dst, prev_gw_src);
+      if (edge == NULL)
+        THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
       links = e_route_as_to_as;
       int pos = 0;
       xbt_dynar_foreach(links, cpt, link) {
index a17aabc..ab3706d 100644 (file)
@@ -61,10 +61,6 @@ static xbt_dynar_t floyd_get_onelink_routes(AS_t asg)
 
 static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t res)
 {
-  xbt_assert(asg && src
-              && dst,
-              "Invalid params for \"get_route\" function at AS \"%s\"",
-              asg->name);
 
   /* set utils vars */
   as_floyd_t as = (as_floyd_t)asg;
@@ -73,10 +69,8 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t
   generic_src_dst_check(asg, src, dst);
   int *src_id = xbt_dict_get_or_null(asg->to_index, src);
   int *dst_id = xbt_dict_get_or_null(asg->to_index, dst);
-  xbt_assert(src_id
-              && dst_id,
-              "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
-              src, dst);
+  if (src_id == NULL || dst_id == NULL)
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   /* create a result route */
 
@@ -110,8 +104,6 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t
         && strcmp(gw_dst, prev_gw_src)) {
       xbt_dynar_t e_route_as_to_as=NULL;
       routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
-      xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
-                  gw_dst, prev_gw_src);
       links = e_route_as_to_as;
       int pos = 0;
       xbt_dynar_foreach(links, cpt, link) {
@@ -127,14 +119,13 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t
     first = 0;
 
   } while (pred != *src_id);
-  xbt_assert(pred != -1, "no route from host %d to %d (\"%s\" to \"%s\")",
-              *src_id, *dst_id, src, dst);
+  if (pred == -1)
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   if (asg->hierarchy == SURF_ROUTING_RECURSIVE) {
     res->src_gateway = xbt_strdup(gw_src);
     res->dst_gateway = xbt_strdup(first_gw);
   }
-
 }
 
 static void floyd_finalize(AS_t rc)
index 9c7dc71..1263e94 100644 (file)
@@ -65,10 +65,6 @@ static void full_get_route(AS_t rc,
                            const char *src, const char *dst,
                            route_t res)
 {
-  xbt_assert(rc && src
-              && dst,
-              "Invalid params for \"get_route\" function at AS \"%s\"",
-              rc->name);
 
   /* set utils vars */
   routing_component_full_t routing = (routing_component_full_t) rc;
@@ -76,10 +72,9 @@ static void full_get_route(AS_t rc,
 
   int *src_id = xbt_dict_get_or_null(routing->generic_routing.to_index, src);
   int *dst_id = xbt_dict_get_or_null(routing->generic_routing.to_index, dst);
-  xbt_assert(src_id
-              && dst_id,
-              "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",
-              src, dst);
+
+  if (!src_id || !dst_id)
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   route_t e_route = NULL;
   void *link;
index fddd109..3c2f02a 100644 (file)
@@ -28,7 +28,7 @@ static void none_parse_PU(AS_t rc, const char *name) {
 }
 
 static void none_parse_AS(AS_t rc, const char *name) {
-  /* even don't care about sub-ASes */
+  /* even don't care about sub-ASes -- I'm as nihilist as an old punk*/
 }
 
 /* Creation routing model functions */
index 53e39b6..21fe445 100644 (file)
@@ -285,8 +285,7 @@ static void rulebased_get_route(AS_t rc,
     are_processing_units = 0;
     rule_list = routing->list_ASroute;
   } else
-    xbt_die("Ask for route \"from\"(%s)  or \"to\"(%s) no found in "
-            "the local table", src, dst);
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   int rc_src = -1;
   int rc_dst = -1;
@@ -336,7 +335,8 @@ static void rulebased_get_route(AS_t rc,
   } else if (!strcmp(src, dst) && are_processing_units) {
     xbt_dynar_push(route->link_list, &(global_routing->loopback));
   } else {
-    xbt_dynar_reset(route->link_list);
+    THROWF(arg_error,0,"No route from '%s' to '%s'??",src,dst);
+    //xbt_dynar_reset(route->link_list);
   }
 
   if (!are_processing_units && !xbt_dynar_is_empty(route->link_list)) {