Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
initialize field As::p_linkUpDownList at declaration (+ cosmetics)
[simgrid.git] / src / surf / surf_routing.cpp
index 66f1972..119b9ab 100644 (file)
@@ -101,8 +101,8 @@ struct s_model_type routing_models[] = {
    model_none_create},
   {"Vivaldi", "Vivaldi routing", model_vivaldi_create},
   {"Cluster", "Cluster routing", model_cluster_create},
-  {"Torus_Cluster", "Torus Cluster routing", model_torus_cluster_create},
-  {"Fat_Tree_Cluster", "Fat Tree Cluster routing", model_fat_tree_cluster_create},
+  {"TorusCluster", "Torus Cluster routing", model_torus_cluster_create},
+  {"FatTreeCluster", "Fat Tree Cluster routing", model_fat_tree_cluster_create},
   {NULL, NULL, NULL}
 };
 
@@ -125,9 +125,6 @@ void sg_platf_new_netcard(sg_platf_host_link_cbarg_t netcard)
   xbt_assert(link_up_down.link_up, "Link '%s' not found!",netcard->link_up);
   xbt_assert(link_up_down.link_down, "Link '%s' not found!",netcard->link_down);
 
-  if(!current_routing->p_linkUpDownList)
-    current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
-
   // If dynar is is greater than netcard id and if the host_link is already defined
   if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > info->getId() &&
       xbt_dynar_get_as(current_routing->p_linkUpDownList, info->getId(), void*))
@@ -168,9 +165,8 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
   XBT_DEBUG("routing_AS_begin");
   routing_model_description_t model = NULL;
 
-  xbt_assert(!xbt_lib_get_or_null
-             (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
-             "The AS \"%s\" already exists", AS->id);
+  xbt_assert(NULL == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL),
+      "Refusing to create a second AS called \"%s\".", AS->id);
 
   _sg_cfg_init_status = 2; /* horrible hack: direct access to the global
                             * controlling the level of configuration to prevent
@@ -179,8 +175,8 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
   /* search the routing model */
   switch(AS->routing){
     case A_surfxml_AS_routing_Cluster:               model = &routing_models[SURF_MODEL_CLUSTER];break;
-    case A_surfxml_AS_routing_Cluster___torus:       model = &routing_models[SURF_MODEL_TORUS_CLUSTER];break;
-    case A_surfxml_AS_routing_Cluster___fat___tree:  model = &routing_models[SURF_MODEL_FAT_TREE_CLUSTER];break;
+    case A_surfxml_AS_routing_ClusterTorus:    model = &routing_models[SURF_MODEL_TORUS_CLUSTER];break;
+    case A_surfxml_AS_routing_ClusterFatTree:  model = &routing_models[SURF_MODEL_FAT_TREE_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;
@@ -198,17 +194,13 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
   new_as->p_hierarchy = SURF_ROUTING_NULL;
   new_as->p_name = xbt_strdup(AS->id);
 
-  simgrid::surf::NetCard *info =
-    new simgrid::surf::NetCardImpl(xbt_strdup(new_as->p_name),
-                                            -1,
-                                            SURF_NETWORK_ELEMENT_AS,
-                                            current_routing);
+  simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->p_name, SURF_NETWORK_ELEMENT_AS, current_routing);
   if (current_routing == NULL && routing_platf->p_root == NULL) {
 
     /* it is the first one */
     new_as->p_routingFather = NULL;
     routing_platf->p_root = new_as;
-    info->setId(-1);
+    netcard->setId(-1);
   } else if (current_routing != NULL && routing_platf->p_root != NULL) {
 
     xbt_assert(!xbt_dict_get_or_null
@@ -223,20 +215,20 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
     xbt_dict_set(current_routing->p_routingSons, AS->id,
                  (void *) new_as, NULL);
     /* add to the father element list */
-    info->setId(current_routing->parseAS(info));
+    netcard->setId(current_routing->parseAS(netcard));
   } else {
     THROWF(arg_error, 0, "All defined components must belong to a AS");
   }
 
-  xbt_lib_set(as_router_lib, info->getName(), ROUTING_ASR_LEVEL,
-              (void *) info);
-  XBT_DEBUG("Having set name '%s' id '%d'", new_as->p_name, info->getId());
+  xbt_lib_set(as_router_lib, netcard->getName(), ROUTING_ASR_LEVEL,
+              (void *) netcard);
+  XBT_DEBUG("Having set name '%s' id '%d'", new_as->p_name, netcard->getId());
 
   /* set the new current component of the tree */
   current_routing = new_as;
-  current_routing->p_netcard = info;
+  current_routing->p_netcard = netcard;
 
-  simgrid::surf::netcardCreatedCallbacks(info);
+  simgrid::surf::netcardCreatedCallbacks(netcard);
   simgrid::surf::asCreatedCallbacks(new_as);
 }
 
@@ -253,13 +245,9 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
  */
 void routing_AS_end()
 {
-
-  if (current_routing == NULL) {
-    THROWF(arg_error, 0, "Close an AS, but none was under construction");
-  } else {
-    current_routing->Seal();
-    current_routing = current_routing->p_routingFather;
-  }
+  xbt_assert(current_routing, "Cannot seal the current AS: none under construction");
+  current_routing->Seal();
+  current_routing = current_routing->p_routingFather;
 }
 
 /* Aux Business methods */
@@ -598,8 +586,6 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer)
   AS.routing               = A_surfxml_AS_routing_Cluster;
   sg_platf_new_AS_begin(&AS);
 
-  current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
-
   XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->speed);
   s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
   memset(&host, 0, sizeof(host));