From: Martin Quinson Date: Sat, 17 Dec 2016 16:59:27 +0000 (+0100) Subject: no need for a lib to store the netcards. A dict is easier X-Git-Tag: v3_14~43 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0eead244337fde8f0508629f8f8473f946c19f88 no need for a lib to store the netcards. A dict is easier --- diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index 2675a83185..edeb6ef899 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -15,8 +15,7 @@ SG_BEGIN_DECL() XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level -XBT_PUBLIC_DATA(xbt_lib_t) as_router_lib; -XBT_PUBLIC_DATA(int) ROUTING_ASR_LEVEL; //Routing level +XBT_PUBLIC_DATA(xbt_dict_t) netcards_dict; XBT_PUBLIC_DATA(xbt_lib_t) storage_lib; XBT_PUBLIC_DATA(int) ROUTING_STORAGE_LEVEL; //Routing storage level diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 5f05440981..4ca29817ac 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -71,11 +71,11 @@ container_t PJ_container_new (const char *name, e_container_types kind, containe xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; case INSTR_ROUTER: - newContainer->netcard = static_cast(xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL)); + newContainer->netcard = static_cast(xbt_dict_get_or_null(netcards_dict, name)); xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; case INSTR_AS: - newContainer->netcard = static_cast(xbt_lib_get_or_null(as_router_lib,name,ROUTING_ASR_LEVEL)); + newContainer->netcard = static_cast(xbt_dict_get_or_null(netcards_dict, name)); xbt_assert(newContainer->netcard, "Element '%s' not found",name); break; default: diff --git a/src/kernel/routing/NetCard.cpp b/src/kernel/routing/NetCard.cpp index 3b9652b471..26f551cc53 100644 --- a/src/kernel/routing/NetCard.cpp +++ b/src/kernel/routing/NetCard.cpp @@ -27,5 +27,5 @@ simgrid::kernel::routing::NetCard* sg_netcard_by_name_or_null(const char* name) { sg_host_t host = sg_host_by_name(name); return (host != nullptr) ? host->pimpl_netcard - : static_cast(xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL)); + : static_cast(xbt_dict_get_or_null(netcards_dict, name)); } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 00a013898a..2944f7b332 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -27,11 +27,11 @@ public: NetZoneImpl::NetZoneImpl(NetZone* father, const char* name) : NetZone(father, name) { - xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL), - "Refusing to create a second NetZone called '%s'.", name); + xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, name), "Refusing to create a second NetZone called '%s'.", + name); netcard_ = new NetCard(name, NetCard::Type::NetZone, static_cast(father)); - xbt_lib_set(as_router_lib, name, ROUTING_ASR_LEVEL, static_cast(netcard_)); + xbt_dict_set(netcards_dict, name, static_cast(netcard_), nullptr); XBT_DEBUG("NetZone '%s' created with the id '%d'", name, netcard_->id()); } NetZoneImpl::~NetZoneImpl() diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index e665695598..04b14a6929 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -80,8 +80,8 @@ void VivaldiZone::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg if (src->isNetZone()) { char* srcName = bprintf("router_%s", src->cname()); char* dstName = bprintf("router_%s", dst->cname()); - route->gw_src = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, srcName, ROUTING_ASR_LEVEL); - route->gw_dst = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, dstName, ROUTING_ASR_LEVEL); + route->gw_src = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, srcName); + route->gw_dst = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, dstName); xbt_free(srcName); xbt_free(dstName); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 64b1151d25..af64bdeccb 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -115,12 +115,12 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router) if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base; - xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL), + xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, router->id), "Refusing to create a router named '%s': this name already describes a node.", router->id); simgrid::kernel::routing::NetCard* netcard = new simgrid::kernel::routing::NetCard(router->id, simgrid::kernel::routing::NetCard::Type::Router, current_routing); - xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, netcard); + xbt_dict_set(netcards_dict, router->id, netcard, nullptr); XBT_DEBUG("Router '%s' has the id %d", router->id, netcard->id()); if (router->coord && strcmp(router->coord, "")) @@ -128,7 +128,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router) auto cluster = dynamic_cast(current_routing); if(cluster != nullptr) - cluster->router_ = static_cast(xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL)); + cluster->router_ = static_cast(xbt_dict_get_or_null(netcards_dict, router->id)); if (TRACE_is_enabled() && TRACE_needs_platform()) sg_instr_new_router(router); @@ -307,7 +307,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster) if (!router.id || !strcmp(router.id, "")) router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix); sg_platf_new_router(&router); - current_as->router_ = (simgrid::kernel::routing::NetCard*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL); + current_as->router_ = (simgrid::kernel::routing::NetCard*)xbt_dict_get_or_null(netcards_dict, router.id); free(newid); //Make the backbone diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index dfd079987b..1171e7aa72 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -289,17 +289,14 @@ void surf_init(int *argc, char **argv) XBT_DEBUG("Create all Libs"); USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr); - as_router_lib = xbt_lib_new(); + netcards_dict = xbt_dict_new_homogeneous([](void* p) { + delete static_cast(p); + }); storage_lib = xbt_lib_new(); storage_type_lib = xbt_lib_new(); file_lib = xbt_lib_new(); watched_hosts_lib = xbt_dict_new_homogeneous(nullptr); - XBT_DEBUG("Add routing levels"); - ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib, [](void* p) { - delete static_cast(p); - }); - XBT_DEBUG("Add SURF levels"); SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free); @@ -327,7 +324,7 @@ void surf_exit() xbt_dynar_free(&surf_path); sg_host_exit(); - xbt_lib_free(&as_router_lib); + xbt_dict_free(&netcards_dict); xbt_lib_free(&storage_lib); sg_link_exit(); xbt_lib_free(&storage_type_lib); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 6cb01aa8d1..ef30cf2d60 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -3,7 +3,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/msg.h" +#include "xbt/dict.h" -xbt_lib_t as_router_lib; -int ROUTING_ASR_LEVEL = -1; //Routing level +xbt_dict_t netcards_dict; diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index effe0d52bd..291feebd01 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -122,8 +122,7 @@ int main(int argc, char **argv) } // Routers - xbt_lib_foreach(as_router_lib, cursor_src, key, value1) { - value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key, ROUTING_ASR_LEVEL); + xbt_dict_foreach (netcards_dict, cursor_src, key, value1) { if(value1->isRouter()) { std::printf(" \n",key); } @@ -164,8 +163,7 @@ int main(int argc, char **argv) } delete route; } - xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router - value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL); + xbt_dict_foreach (netcards_dict, cursor_dst, dst, value2) { // to router if(value2->isRouter()){ std::printf(" \n ", host1->cname(), dst); std::vector *route = new std::vector(); @@ -178,11 +176,9 @@ int main(int argc, char **argv) } } - xbt_lib_foreach(as_router_lib, cursor_src, src, value1){ // Routes from router - value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL); + xbt_dict_foreach (netcards_dict, cursor_src, src, value1) { // Routes from router if (value1->isRouter()){ - xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router - value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL); + xbt_dict_foreach (netcards_dict, cursor_dst, dst, value2) { // to router if(value2->isRouter()){ std::printf(" \n ", src, dst); std::vector *route = new std::vector(); diff --git a/teshsuite/simdag/is-router/is-router.cpp b/teshsuite/simdag/is-router/is-router.cpp index 77d1bdcc1e..ffef43b7de 100644 --- a/teshsuite/simdag/is-router/is-router.cpp +++ b/teshsuite/simdag/is-router/is-router.cpp @@ -15,7 +15,7 @@ int main(int argc, char **argv) SD_create_environment(argv[1]); xbt_dynar_t hosts = sg_hosts_as_dynar(); - int size = sg_host_count() + xbt_lib_length(as_router_lib); + int size = sg_host_count() + xbt_dict_length(netcards_dict); printf("Host number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size); @@ -31,7 +31,7 @@ int main(int argc, char **argv) xbt_lib_cursor_t cursor = nullptr; char* key; void *ignored; - xbt_lib_foreach(as_router_lib, cursor, key, ignored) { + xbt_dict_foreach (netcards_dict, cursor, key, ignored) { simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key); printf(" - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isNetZone() ? "netzone" : "host")); }