Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
one step further to sort out the spagetti plate of AS creation
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 15 Oct 2016 15:31:43 +0000 (17:31 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 15 Oct 2016 15:31:43 +0000 (17:31 +0200)
src/kernel/routing/AsImpl.cpp
src/s4u/s4u_host.cpp
src/surf/sg_platf.cpp

index 38b857e..2f50e55 100644 (file)
@@ -16,6 +16,9 @@ namespace simgrid {
 
   AsImpl::AsImpl(As* father, const char* name) : As(father, name)
   {
+    xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL),
+               "Refusing to create a second AS called \"%s\".", name);
+
     netcard_ = new simgrid::kernel::routing::NetCardImpl(name, simgrid::kernel::routing::NetCard::Type::As,
                                                          static_cast<AsImpl*>(father));
     xbt_lib_set(as_router_lib, name, ROUTING_ASR_LEVEL, (void*)netcard_);
index 66a13a9..a6022e6 100644 (file)
@@ -40,6 +40,7 @@ simgrid::xbt::signal<void(Host&)> Host::onStateChange;
 Host::Host(const char* name)
   : name_(name)
 {
+  xbt_dict_set(host_list, name, this, nullptr);
 }
 
 Host::~Host() {
@@ -68,10 +69,9 @@ Host* Host::by_name_or_null(const char* name)
 Host* Host::by_name_or_create(const char* name)
 {
   Host* host = by_name_or_null(name);
-  if (host == nullptr) {
+  if (host == nullptr)
     host = new Host(name);
-    xbt_dict_set(host_list, name, host, nullptr);
-  }
+
   return host;
 }
 
index 2cf2472..db14195 100644 (file)
@@ -811,9 +811,6 @@ simgrid::s4u::As * sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
     surf_config_models_setup();
   }
 
-  xbt_assert(nullptr == 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; /* HACK: direct access to the global controlling the level of configuration to prevent
                             * any further config now that we created some real content */
 
@@ -859,14 +856,14 @@ simgrid::s4u::As * sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
 
   if (current_routing == nullptr && routing_platf->root_ == nullptr) { /* it is the first one */
     routing_platf->root_ = new_as;
-  } else if (current_routing != nullptr && routing_platf->root_ != nullptr) {
 
-    xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id), "The AS '%s' already exists", AS->id);
+  } else if (current_routing != nullptr && routing_platf->root_ != nullptr) {
     /* set the father behavior */
     if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset)
       current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::recursive;
     /* add to the sons dictionary */
     xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, nullptr);
+
   } else {
     THROWF(arg_error, 0, "All defined components must belong to a AS");
   }