Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add two new tag for routing cluster (only):
[simgrid.git] / src / surf / surf_routing.c
index 53a5d62..3849709 100644 (file)
@@ -27,6 +27,8 @@ int SD_HOST_LEVEL;              //Simdag level
 int COORD_HOST_LEVEL=0;         //Coordinates level
 int NS3_HOST_LEVEL;             //host node for ns3
 
+xbt_dict_t watched_hosts_lib;
+
 /**
  * @ingroup SURF_build_api
  * @brief A library containing all known links
@@ -109,6 +111,36 @@ struct s_model_type routing_models[] = {
   {NULL, NULL, NULL, NULL}
 };
 
+/**
+ * \brief Add a "host_link" to the network element list
+ */
+static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
+{
+  sg_routing_edge_t info = NULL;
+  info = xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL);
+  xbt_assert(info, "Host '%s' not found!",host->id);
+  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER],
+      "You have to be in model Cluster to use tag host_link!");
+
+  s_surf_parsing_link_up_down_t link_up_down;
+  link_up_down.link_up = xbt_lib_get_or_null(link_lib, host->link_up, SURF_LINK_LEVEL);
+  link_up_down.link_down = xbt_lib_get_or_null(link_lib, host->link_down, SURF_LINK_LEVEL);
+
+  xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up);
+  xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down);
+
+  if(!current_routing->link_up_down_list)
+    current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
+
+  // If dynar is is greater than edge id and if the host_link is already defined
+  if(xbt_dynar_length(current_routing->link_up_down_list) > info->id &&
+      xbt_dynar_get_as(current_routing->link_up_down_list,info->id,void*))
+    xbt_die("Host_link for '%s' is already defined!",host->id);
+
+  XBT_INFO("Push Host_link for host '%s' to position %d",info->name,info->id);
+  xbt_dynar_set_as(current_routing->link_up_down_list,info->id,s_surf_parsing_link_up_down_t,link_up_down);
+}
+
 /**
  * \brief Add a "host" to the network element list
  */
@@ -373,28 +405,25 @@ static void routing_parse_E_bypassASroute(void)
  * @param AS_id name of this autonomous system. Must be unique in the platform
  * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
  */
-void routing_AS_begin(const char *AS_id, const char *wanted_routing_type)
+void routing_AS_begin(const char *AS_id, int wanted_routing_type)
 {
   AS_t new_as;
   routing_model_description_t model = NULL;
-  int cpt;
 
   xbt_assert(!xbt_lib_get_or_null
              (as_router_lib, AS_id, ROUTING_ASR_LEVEL),
              "The AS \"%s\" already exists", AS_id);
 
   /* search the routing model */
-  for (cpt = 0; routing_models[cpt].name; cpt++)
-    if (!strcmp(wanted_routing_type, routing_models[cpt].name))
-      model = &routing_models[cpt];
-  /* if its not exist, error */
-  if (model == NULL) {
-    fprintf(stderr, "Routing model %s not found. Existing models:\n",
-            wanted_routing_type);
-    for (cpt = 0; routing_models[cpt].name; cpt++)
-      fprintf(stderr, "   %s: %s\n", routing_models[cpt].name,
-              routing_models[cpt].desc);
-    xbt_die("dying");
+  switch(wanted_routing_type){
+    case A_surfxml_AS_routing_Cluster:       model = &routing_models[SURF_MODEL_CLUSTER];break;
+    case A_surfxml_AS_routing_Dijkstra:      model = &routing_models[SURF_MODEL_DIJKSTRA];break;
+    case A_surfxml_AS_routing_DijkstraCache: model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break;
+    case A_surfxml_AS_routing_Floyd:         model = &routing_models[SURF_MODEL_FLOYD];break;
+    case A_surfxml_AS_routing_Full:          model = &routing_models[SURF_MODEL_FULL];break;
+    case A_surfxml_AS_routing_None:          model = &routing_models[SURF_MODEL_NONE];break;
+    case A_surfxml_AS_routing_RuleBased:     model = &routing_models[SURF_MODEL_RULEBASED];break;
+    case A_surfxml_AS_routing_Vivaldi:       model = &routing_models[SURF_MODEL_VIVALDI];break;
   }
 
   /* make a new routing component */
@@ -576,17 +605,16 @@ static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
 
   /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
   if (e_route_bypass) {
-    xbt_dynar_merge(links,&(e_route_bypass->link_list));
+    xbt_dynar_merge(links, &e_route_bypass->link_list);
     generic_free_route(e_route_bypass);
     return;
   }
 
   /* If src and dst are in the same AS, life is good */
   if (src_father == dst_father) {       /* SURF_ROUTING_BASE */
-
     route.link_list = *links;
-
     common_father->get_route_and_latency(common_father, src, dst, &route,latency);
+    // if vivaldi latency+=vivaldi(src,dst)
     return;
   }
 
@@ -597,7 +625,9 @@ static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
   sg_routing_edge_t src_father_net_elm = src_father->net_elem;
   sg_routing_edge_t dst_father_net_elm = dst_father->net_elem;
 
-  common_father->get_route_and_latency(common_father, src_father_net_elm, dst_father_net_elm, &route,latency);
+  common_father->get_route_and_latency(common_father,
+                                       src_father_net_elm, dst_father_net_elm,
+                                       &route, latency);
 
   xbt_assert((route.src_gateway != NULL) && (route.dst_gateway != NULL),
       "bad gateways for route from \"%s\" to \"%s\"", src->name, dst->name);
@@ -608,15 +638,13 @@ static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
   /* If source gateway is not our source, we have to recursively find our way up to this point */
   if (src != src_gateway_net_elm)
     _get_route_and_latency(src, src_gateway_net_elm, links, latency);
-
-  xbt_dynar_merge(links,&(route.link_list));
+  xbt_dynar_merge(links, &route.link_list);
 
   /* If dest gateway is not our destination, we have to recursively find our way from this point */
-  // FIXME why can't I factorize it the same way than [src;src_gw] without breaking the examples??
-  if (dst_gateway_net_elm != dst) {
+  if (dst_gateway_net_elm != dst)
     _get_route_and_latency(dst_gateway_net_elm, dst, links, latency);
-  }
-  xbt_dynar_free(&route.link_list);
+
+  // if vivaldi latency+=vivaldi(src_gateway,dst_gateway)
 }
 
 /**
@@ -748,6 +776,14 @@ void routing_model_create( void *loopback)
 /* ************************************************************************** */
 /* ************************* GENERIC PARSE FUNCTIONS ************************ */
 
+void routing_cluster_add_backbone(void* bb) {
+  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER],
+        "You have to be in model Cluster to use tag backbone!");
+  xbt_assert(!((as_cluster_t)current_routing)->backbone,"The backbone link is already defined!");
+  ((as_cluster_t)current_routing)->backbone = bb;
+  XBT_DEBUG("Add a backbone to AS '%s'",current_routing->name);
+}
+
 static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
 {
   char *host_id, *groups, *link_id = NULL;
@@ -770,7 +806,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
   }
 
   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", cluster->id);
-  sg_platf_new_AS_begin(cluster->id, "Cluster");
+  sg_platf_new_AS_begin(cluster->id, A_surfxml_AS_routing_Cluster);
 
   current_routing->link_up_down_list
             = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
@@ -806,7 +842,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
         xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
         char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
         XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
-        host.power_trace = tmgr_trace_new(avail_file);
+        host.power_trace = tmgr_trace_new_from_file(avail_file);
         xbt_free(avail_file);
       } else {
         XBT_DEBUG("\tavailability_file=\"\"");
@@ -815,7 +851,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
       if (strcmp(cluster->state_trace, "")) {
         char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
         XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
-        host.state_trace = tmgr_trace_new(avail_file);
+        host.state_trace = tmgr_trace_new_from_file(avail_file);
         xbt_free(avail_file);
       } else {
         XBT_DEBUG("\tstate_file=\"\"");
@@ -895,7 +931,7 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
 
     sg_platf_new_link(&link);
 
-    surf_routing_cluster_add_backbone(current_routing, xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL));
+    routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL));
 
     free(link_backbone);
   }
@@ -924,7 +960,7 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
   surfxml_bufferstack_push(1);
 
   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer->id);
-  sg_platf_new_AS_begin(peer->id, "Full");
+  sg_platf_new_AS_begin(peer->id, A_surfxml_AS_routing_Full);
 
   XBT_DEBUG(" ");
   host_id = HOST_PEER(peer->id);
@@ -1148,6 +1184,7 @@ void routing_register_callbacks()
 {
   sg_platf_host_add_cb(parse_S_host);
   sg_platf_router_add_cb(parse_S_router);
+  sg_platf_host_link_add_cb(parse_S_host_link);
 
   surfxml_add_callback(STag_surfxml_random_cb_list, &routing_parse_Srandom);