Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use type network_element_t instead of void*, and avoid unnecessary casts.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 23 Mar 2012 10:25:59 +0000 (11:25 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 23 Mar 2012 13:54:29 +0000 (14:54 +0100)
15 files changed:
src/include/surf/surf.h
src/instr/instr_private.h
src/instr/instr_routing.c
src/surf/network.c
src/surf/network_constant.c
src/surf/network_gtnets.c
src/surf/network_ns3.c
src/surf/surf.c
src/surf/surf_private.h
src/surf/surf_routing.c
src/surf/surf_routing_dijkstra.c
src/surf/surf_routing_floyd.c
src/surf/surf_routing_full.c
src/surf/surf_routing_rulebased.c
src/surf/workstation_ptask_L07.c

index 9ce016d..d1adedc 100644 (file)
@@ -176,6 +176,8 @@ typedef struct surf_cpu_model_extension_public {
   void (*add_traces) (void);
 } s_surf_model_extension_cpu_t;
 
+typedef struct s_network_element_info *network_element_t;
+
      /* Network model */
 
      /** \brief Network model extension public
@@ -184,9 +186,9 @@ typedef struct surf_cpu_model_extension_public {
       *  Public functions specific to the network model
       */
 typedef struct surf_network_model_extension_public {
-  surf_action_t(*communicate) (void* src,
-                               void* dst,
-                               double size, double rate);
+  surf_action_t (*communicate) (network_element_t src,
+                                network_element_t dst,
+                                double size, double rate);
   xbt_dynar_t(*get_route) (void *src, void *dst); //FIXME: kill field? That is done by the routing nowadays
   double (*get_link_bandwidth) (const void *link);
   double (*get_link_latency) (const void *link);
index 91923dd..d53a145 100644 (file)
@@ -63,7 +63,7 @@ typedef enum {
 
 typedef struct s_container *container_t;
 typedef struct s_container {
-  void *net_elm;  /* network_element_t */
+  network_element_t net_elm;
   char *name;     /* Unique name of this container */
   char *id;       /* Unique id of this container */
   type_t type;    /* Type of this container */
index 69a8673..bbe392c 100644 (file)
@@ -146,9 +146,8 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t
       //get the route
       route_t route = xbt_new0(s_route_t,1);
       route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
-      rc->get_route_and_latency (rc,
-          (network_element_t)(child1->net_elm),
-          (network_element_t)(child2->net_elm),route, NULL);
+      rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
+                                route, NULL);
 
       //user might want to extract a graph using routes with only one link
       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
@@ -472,9 +471,8 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb
       //get the route
       route_t route = xbt_new0(s_route_t,1);
       route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
-      rc->get_route_and_latency (rc,
-          (network_element_t)(child1->net_elm),
-          (network_element_t)(child2->net_elm),route, NULL);
+      rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
+                                route, NULL);
 
       //user might want to extract a graph using routes with only one link
       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
index 6c37f1e..b2887af 100644 (file)
@@ -743,9 +743,9 @@ static void net_update_resource_state(void *id,
 }
 
 
-static surf_action_t net_communicate(void *src,
-                                     void *dst, double size,
-                                     double rate)
+static surf_action_t net_communicate(network_element_t src,
+                                     network_element_t dst,
+                                     double size, double rate)
 {
   unsigned int i;
   link_CM02_t link;
@@ -758,12 +758,12 @@ static surf_action_t net_communicate(void *src,
 
   xbt_dynar_t route = xbt_dynar_new(global_routing->size_of_link, NULL);
 
-  XBT_IN("(%s,%s,%g,%g)", ((network_element_t)src)->name, ((network_element_t)dst)->name, size, rate);
+  XBT_IN("(%s,%s,%g,%g)", src->name, dst->name, size, rate);
 
-  routing_get_route_and_latency((network_element_t)src, (network_element_t)dst, &route, &latency);
+  routing_get_route_and_latency(src, dst, &route, &latency);
   xbt_assert(!xbt_dynar_is_empty(route) || latency,
              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
-             ((network_element_t)src)->name, ((network_element_t)dst)->name);
+             src->name, dst->name);
 
   xbt_dynar_foreach(route, i, link) {
     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
@@ -772,7 +772,7 @@ static surf_action_t net_communicate(void *src,
     }
   }
   if (sg_network_crosstraffic == 1) {
-    routing_get_route_and_latency((network_element_t)dst, (network_element_t)src, &back_route, NULL);
+    routing_get_route_and_latency(dst, src, &back_route, NULL);
     xbt_dynar_foreach(back_route, i, link) {
       if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
         failed = 1;
@@ -822,7 +822,7 @@ static surf_action_t net_communicate(void *src,
     link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0);
     gap_append(size, link, action);
     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
-              action, ((network_element_t)src)->name, ((network_element_t)dst)->name, action->sender.gap,
+              action, src->name, dst->name, action->sender.gap,
               action->latency);
   }
 
index fc5580d..3279f4d 100644 (file)
@@ -109,14 +109,14 @@ static void netcste_update_resource_state(void *id,
   DIE_IMPOSSIBLE;
 }
 
-static surf_action_t netcste_communicate(void *src,
-                                         void *dst, double size,
-                                         double rate)
+static surf_action_t netcste_communicate(network_element_t src,
+                                         network_element_t dst,
+                                         double size, double rate)
 {
   surf_action_network_Constant_t action = NULL;
 
-  char *src_name = ((network_element_t)src)->name;
-  char *dst_name = ((network_element_t)dst)->name;
+  char *src_name = src->name;
+  char *dst_name = dst->name;
 
   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
 
index 7cedacf..99590b7 100644 (file)
@@ -333,16 +333,16 @@ static void update_resource_state(void *id,
 }
 
 /* Max durations are not supported */
-static surf_action_t communicate(void *src_card,
-                                 void *dst_card, double size,
-                                 double rate)
+static surf_action_t communicate(network_element_t src_card,
+                                 network_element_t dst_card,
+                                 double size, double rate)
 {
   surf_action_network_GTNETS_t action = NULL;
 
-  int src = ((network_element_t)src_card)->id;
-  int dst = ((network_element_t)dst_card)->id;
-  char *src_name = ((network_element_t)src_card)->name;
-  char *dst_name = ((network_element_t)dst_card)->name;
+  int src = src_card->id;
+  int dst = dst_card->id;
+  char *src_name = src_card->name;
+  char *dst_name = dst_card->name;
 
   xbt_assert((src >= 0
                && dst >= 0), "Either src or dst have invalid id (id<0)");
index e5684d7..b235051 100644 (file)
@@ -26,8 +26,9 @@ static double time_to_next_flow_completion = -1;
 static double ns3_share_resources(double min);
 static void ns3_update_actions_state(double now, double delta);
 static void finalize(void);
-static surf_action_t ns3_communicate(void *src_elm, void *dst_elm,
-    double size, double rate);
+static surf_action_t ns3_communicate(network_element_t src_elm,
+                                     network_element_t dst_elm,
+                                     double size, double rate);
 static void action_suspend(surf_action_t action);
 static void action_resume(surf_action_t action);
 static int action_is_suspended(surf_action_t action);
@@ -260,8 +261,8 @@ static void create_ns3_topology(void)
   onelink_t onelink;
   unsigned int iter;
   xbt_dynar_foreach(onelink_routes, iter, onelink) {
-    char *src = ((network_element_t)onelink->src)->name;
-    char *dst = ((network_element_t)onelink->dst)->name;
+    char *src = onelink->src->name;
+    char *dst = onelink->dst->name;
     void *link = onelink->link_ptr;
     if( strcmp(src,dst) && ((surf_ns3_link_t)link)->created){
       XBT_DEBUG("Route from '%s' to '%s' with link '%s'",src,dst,((surf_ns3_link_t)link)->data->id);
@@ -478,15 +479,16 @@ static void ns3_update_actions_state(double now, double delta)
 }
 
 /* Max durations are not supported */
-static surf_action_t ns3_communicate(void *src_elm,
-    void *dst_elm, double size, double rate)
+static surf_action_t ns3_communicate(network_element_t src_elm,
+                                     network_element_t dst_elm,
+                                     double size, double rate)
 {
   surf_action_network_ns3_t action = NULL;
 
-  XBT_DEBUG("Communicate from %s to %s",((network_element_t)src_elm)->name,((network_element_t)dst_elm)->name);
+  XBT_DEBUG("Communicate from %s to %s", src_elm->name, dst_elm->name);
   action = surf_action_new(sizeof(s_surf_action_network_ns3_t), size, surf_network_model, 0);
 
-  ns3_create_flow(((network_element_t)src_elm)->name, ((network_element_t)dst_elm)->name, surf_get_clock(), size, action);
+  ns3_create_flow(src_elm->name, dst_elm->name, surf_get_clock(), size, action);
 
 #ifdef HAVE_TRACING
   action->last_sent = 0;
index 5618234..3386132 100644 (file)
@@ -307,7 +307,7 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_network_gtnets);
 
 static XBT_INLINE void routing_asr_host_free(void *p)
 {
-  network_element_t elm = (network_element_t)p;
+  network_element_t elm = p;
   free(elm->name);
   xbt_free(elm);
 }
index a55186e..a50e6cc 100644 (file)
@@ -108,7 +108,7 @@ typedef struct s_network_element_info {
   e_surf_network_element_type_t rc_type;
   int id;
   char *name;
-} s_network_element_t, *network_element_t;
+} s_network_element_t;
 
 /*
  * Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
index 29947c5..d2de87b 100644 (file)
@@ -293,17 +293,20 @@ static void routing_parse_E_ASroute(void)
   route_t e_route = xbt_new0(s_route_t, 1);
   e_route->link_list = parsed_link_list;
 
-  if(!strcmp(current_routing->model_desc->name,"RuleBased")) {
+  if (!strcmp(current_routing->model_desc->name,"RuleBased")) {
     e_route->src_gateway = (network_element_t) gw_src; // DIRTY HACK possible only
     e_route->dst_gateway = (network_element_t) gw_dst; // because of what is in routing_parse_E_ASroute
-  }
-  else{
-  e_route->src_gateway =  ((network_element_t)xbt_lib_get_or_null(as_router_lib,gw_src,ROUTING_ASR_LEVEL));
-  if(!e_route->src_gateway)
-    e_route->src_gateway = ((network_element_t)xbt_lib_get_or_null(host_lib,gw_src,ROUTING_HOST_LEVEL));
-  e_route->dst_gateway =  ((network_element_t)xbt_lib_get_or_null(as_router_lib,gw_dst,ROUTING_ASR_LEVEL));
-  if(!e_route->dst_gateway)
-    e_route->dst_gateway = ((network_element_t)xbt_lib_get_or_null(host_lib,gw_dst,ROUTING_HOST_LEVEL));
+  } else {
+    e_route->src_gateway =  xbt_lib_get_or_null(as_router_lib, gw_src,
+                                                ROUTING_ASR_LEVEL);
+    if (!e_route->src_gateway)
+      e_route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src,
+                                                 ROUTING_HOST_LEVEL);
+    e_route->dst_gateway =  xbt_lib_get_or_null(as_router_lib, gw_dst,
+                                                ROUTING_ASR_LEVEL);
+    if (!e_route->dst_gateway)
+      e_route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst,
+                                                 ROUTING_HOST_LEVEL);
   }
   xbt_assert(current_routing->parse_ASroute,
              "no defined method \"set_ASroute\" in \"%s\"",
@@ -324,12 +327,16 @@ static void routing_parse_E_bypassRoute(void)
 {
   route_t e_route = xbt_new0(s_route_t, 1);
   e_route->link_list = parsed_link_list;
-  e_route->src_gateway =  ((network_element_t)xbt_lib_get_or_null(as_router_lib,gw_src,ROUTING_ASR_LEVEL));
-  if(!e_route->src_gateway)
-    e_route->src_gateway = ((network_element_t)xbt_lib_get_or_null(host_lib,gw_src,ROUTING_HOST_LEVEL));
-  e_route->dst_gateway =  ((network_element_t)xbt_lib_get_or_null(as_router_lib,gw_dst,ROUTING_ASR_LEVEL));
-  if(!e_route->dst_gateway)
-    e_route->dst_gateway = ((network_element_t)xbt_lib_get_or_null(host_lib,gw_dst,ROUTING_HOST_LEVEL));
+  e_route->src_gateway = xbt_lib_get_or_null(as_router_lib, gw_src,
+                                             ROUTING_ASR_LEVEL);
+  if (!e_route->src_gateway)
+    e_route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src,
+                                               ROUTING_HOST_LEVEL);
+  e_route->dst_gateway = xbt_lib_get_or_null(as_router_lib, gw_dst,
+                                             ROUTING_ASR_LEVEL);
+  if (!e_route->dst_gateway)
+    e_route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst,
+                                               ROUTING_HOST_LEVEL);
   xbt_assert(current_routing->parse_bypassroute,
              "Bypassing mechanism not implemented by routing '%s'",
              current_routing->name);
@@ -619,7 +626,8 @@ static void _get_route_and_latency(network_element_t src, network_element_t dst,
  * walk through the routing components tree and find a route between hosts
  * by calling the differents "get_route" functions in each routing component.
  */
-void routing_get_route_and_latency(network_element_t src, network_element_t dst,
+void routing_get_route_and_latency(network_element_t src,
+                                   network_element_t dst,
                                    xbt_dynar_t * route, double *latency)
 {
   if (!*route) {
index 1c403c7..8fc6756 100644 (file)
@@ -474,10 +474,12 @@ void model_dijkstra_both_parse_route (AS_t asg, const char *src,
        as_dijkstra_t as = (as_dijkstra_t) asg;
     network_element_t src_net_elm, dst_net_elm;
 
-    src_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
-    dst_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
-    if(!src_net_elm) src_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
-    if(!dst_net_elm) dst_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
+    src_net_elm = xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
+    dst_net_elm = xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
+    if (!src_net_elm)
+      src_net_elm = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
+    if (!dst_net_elm)
+      dst_net_elm = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
 
     xbt_assert(src_net_elm, "Network elements %s not found", src);
     xbt_assert(dst_net_elm, "Network elements %s not found", dst);
index d262408..540b5ef 100644 (file)
@@ -256,10 +256,12 @@ void model_floyd_parse_route(AS_t rc, const char *src,
        size_t table_size = xbt_dynar_length(rc->index_network_elm);
     network_element_t src_net_elm, dst_net_elm;
 
-    src_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
-    dst_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
-    if(!src_net_elm) src_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
-    if(!dst_net_elm) dst_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
+    src_net_elm = xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
+    dst_net_elm = xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
+    if (!src_net_elm)
+      src_net_elm = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
+    if (!dst_net_elm)
+      dst_net_elm = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
 
        xbt_assert(src_net_elm, "Network elements %s not found", src);
        xbt_assert(dst_net_elm, "Network elements %s not found", dst);
index bafd2fa..acee99d 100644 (file)
@@ -161,10 +161,12 @@ void model_full_set_route(AS_t rc, const char *src,
 {
   network_element_t src_net_elm, dst_net_elm;
 
-  src_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
-  dst_net_elm = (network_element_t)xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
-  if(!src_net_elm) src_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
-  if(!dst_net_elm) dst_net_elm = (network_element_t)xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
+  src_net_elm = xbt_lib_get_or_null(host_lib, src, ROUTING_HOST_LEVEL);
+  dst_net_elm = xbt_lib_get_or_null(host_lib, dst, ROUTING_HOST_LEVEL);
+  if (!src_net_elm)
+    src_net_elm = xbt_lib_get_or_null(as_router_lib, src, ROUTING_ASR_LEVEL);
+  if (!dst_net_elm)
+    dst_net_elm = xbt_lib_get_or_null(as_router_lib, dst, ROUTING_ASR_LEVEL);
 
   xbt_assert(src_net_elm, "Network elements %s not found", src);
   xbt_assert(dst_net_elm, "Network elements %s not found", dst);
index 0932e04..c994cf5 100644 (file)
@@ -348,22 +348,30 @@ static void rulebased_get_route_and_latency(AS_t rc,
         (rule_route_extended_t) ruleroute;
     char *gw_src_name = remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
         list_dst, rc_dst);
-    route->src_gateway = (network_element_t)xbt_lib_get_or_null(host_lib, gw_src_name, ROUTING_HOST_LEVEL);
-    route->src_gateway = (network_element_t)xbt_lib_get_or_null(host_lib, gw_src_name, ROUTING_HOST_LEVEL);
-    if(!route->src_gateway)
-      route->src_gateway = (network_element_t)xbt_lib_get_or_null(as_router_lib, gw_src_name, ROUTING_ASR_LEVEL);
-    if(!route->src_gateway)
-      route->src_gateway = (network_element_t)xbt_lib_get_or_null(as_router_lib, gw_src_name, ROUTING_ASR_LEVEL);
+    route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src_name,
+                                             ROUTING_HOST_LEVEL);
+    route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src_name,
+                                             ROUTING_HOST_LEVEL);
+    if (!route->src_gateway)
+      route->src_gateway = xbt_lib_get_or_null(as_router_lib, gw_src_name,
+                                               ROUTING_ASR_LEVEL);
+    if (!route->src_gateway)
+      route->src_gateway = xbt_lib_get_or_null(as_router_lib, gw_src_name,
+                                               ROUTING_ASR_LEVEL);
     xbt_free(gw_src_name);
 
     char *gw_dst_name = remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
         list_dst, rc_dst);
-    route->dst_gateway = (network_element_t)xbt_lib_get_or_null(host_lib, gw_dst_name, ROUTING_HOST_LEVEL);
-    route->dst_gateway = (network_element_t)xbt_lib_get_or_null(host_lib, gw_dst_name, ROUTING_HOST_LEVEL);
-    if(!route->dst_gateway)
-      route->dst_gateway = (network_element_t)xbt_lib_get_or_null(as_router_lib, gw_dst_name, ROUTING_ASR_LEVEL);
-    if(!route->dst_gateway)
-      route->dst_gateway = (network_element_t)xbt_lib_get_or_null(as_router_lib, gw_dst_name, ROUTING_ASR_LEVEL);
+    route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst_name,
+                                             ROUTING_HOST_LEVEL);
+    route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst_name,
+                                             ROUTING_HOST_LEVEL);
+    if (!route->dst_gateway)
+      route->dst_gateway = xbt_lib_get_or_null(as_router_lib, gw_dst_name,
+                                               ROUTING_ASR_LEVEL);
+    if (!route->dst_gateway)
+      route->dst_gateway = xbt_lib_get_or_null(as_router_lib, gw_dst_name,
+                                               ROUTING_ASR_LEVEL);
     xbt_free(gw_dst_name);
   }
 
index 5e73d18..d0a27e3 100644 (file)
@@ -69,7 +69,9 @@ static int ptask_host_count = 0;
 static xbt_dict_t ptask_parallel_task_link_set = NULL;
 lmm_system_t ptask_maxmin_system = NULL;
 
-static surf_action_t die_impossible_communicate (void *src, void *dst, double size, double rate)
+static surf_action_t die_impossible_communicate (network_element_t src,
+                                                 network_element_t dst,
+                                                 double size, double rate)
 {
   DIE_IMPOSSIBLE;
   return NULL;
@@ -638,7 +640,7 @@ static void* ptask_cpu_create_resource(const char *name, double power_scale,
           surf_workstation_model, name,cpu_properties);
 
   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
-  cpu->info = (network_element_t)xbt_lib_get_or_null(host_lib,name,ROUTING_HOST_LEVEL);
+  cpu->info = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
   if(!(cpu->info)) xbt_die("Don't find ROUTING_HOST_LEVEL for '%s'",name);
 
   cpu->power_scale = power_scale;