SG_BEGIN_DECL()
+XBT_PUBLIC(void) sg_host_exit();
+
XBT_PUBLIC(size_t) sg_host_count();
XBT_PUBLIC(sg_host_t *) sg_host_list();
SG_BEGIN_DECL()
-XBT_PUBLIC_DATA(xbt_dict_t) host_list;
XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL; //Coordinates level
*/
int MSG_get_host_number()
{
- return xbt_dict_length(host_list);
+ return sg_host_count();
}
/** \ingroup m_host_management
{
/* make sure the VM of the same name does not exit */
{
- simgrid::s4u::Host* ind_host_tmp = (simgrid::s4u::Host*) xbt_dict_get_or_null(host_list, name);
+ simgrid::s4u::Host* ind_host_tmp = sg_host_by_name(name);
if (ind_host_tmp != nullptr && sg_host_simix(ind_host_tmp) != nullptr) {
XBT_ERROR("host %s already exits", name);
return nullptr;
#include "simgrid/s4u/host.hpp"
#include "simgrid/s4u/storage.hpp"
+xbt_dict_t host_list = nullptr; // FIXME: make it a static field of Host
+
int MSG_HOST_LEVEL = -1;
int USER_HOST_LEVEL = -1;
}
Host* Host::by_name_or_null(const char* name)
{
+ if (host_list == nullptr)
+ host_list = xbt_dict_new_homogeneous([](void*p) {
+ simgrid::s4u::Host* host = static_cast<simgrid::s4u::Host*>(p);
+ simgrid::s4u::Host::onDestruction(*host);
+ delete host;
+ });
return (Host*) xbt_dict_get_or_null(host_list, name);
}
Host* Host::by_name_or_create(const char* name)
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts");
+extern xbt_dict_t host_list; // FIXME:killme don't dupplicate the content of s4u::Host this way
+
+void sg_host_exit()
+{
+ xbt_dict_free(&host_list);
+}
+
size_t sg_host_count()
{
return xbt_dict_length(host_list);
msg->used -= 3;
xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
+ break;
}
}
msg->data[msg->used-3]='\0';
void surf_init(int *argc, char **argv)
{
- if (host_list != nullptr) // Already initialized
+ if (USER_HOST_LEVEL != -1) // Already initialized
return;
XBT_DEBUG("Create all Libs");
- host_list = xbt_dict_new_homogeneous([](void*p) {
- simgrid::s4u::Host* host = static_cast<simgrid::s4u::Host*>(p);
- simgrid::s4u::Host::onDestruction(*host);
- delete host;
- });
USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
as_router_lib = xbt_lib_new();
xbt_dynar_free(&surf_path);
- xbt_dict_free(&host_list);
+ sg_host_exit();
xbt_lib_free(&as_router_lib);
xbt_lib_free(&storage_lib);
sg_link_exit();
* @ingroup SURF_build_api
* @brief A library containing all known hosts
*/
-xbt_dict_t host_list = nullptr;
int COORD_HOST_LEVEL = -1; //Coordinates level
}
sg_host_t host1, host2;
- xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
- value1 = sg_host_by_name(src)->pimpl_netcard;
- xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
+ for (unsigned int it_src = 0; it_src < totalHosts; it_src++) { // Routes from host
+ host1 = hosts[it_src];
+ value1 = sg_host_by_name(host1->name().c_str())->pimpl_netcard;
+ for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
+ host2 = hosts[it_dst];
std::vector<Link*> *route = new std::vector<Link*>();
- value2 = sg_host_by_name(dst)->pimpl_netcard;
+ value2 = host2->pimpl_netcard;
routing_platf->getRouteAndLatency(value1, value2, route,nullptr);
if (! route->empty()){
- std::printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
+ std::printf(" <route src=\"%s\" dst=\"%s\">\n ", host1->name().c_str(), host2->name().c_str());
for (auto link: *route)
std::printf("<link_ctn id=\"%s\"/>",link->getName());
std::printf("\n </route>\n");
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);
if(value2->isRouter()){
- std::printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
+ std::printf(" <route src=\"%s\" dst=\"%s\">\n ", host1->name().c_str(), dst);
std::vector<Link*> *route = new std::vector<Link*>();
routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,nullptr);
for (auto link : *route)
std::printf("\n </route>\n");
}
}
- xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
- std::printf(" <route src=\"%s\" dst=\"%s\">\n ",src, dst);
+ for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
+ host2 = hosts[it_dst];
+ std::printf(" <route src=\"%s\" dst=\"%s\">\n ",src, host2->name().c_str());
std::vector<Link*> *route = new std::vector<Link*>();
- value2 = sg_host_by_name(dst)->pimpl_netcard;
+ value2 = host2->pimpl_netcard;
routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, nullptr);
for(auto link : *route)
std::printf("<link_ctn id=\"%s\"/>",link->getName());
#include <stdio.h>
#include "simgrid/simdag.h"
#include "src/surf/surf_routing.hpp"
+#include "simgrid/s4u/host.hpp"
+
int main(int argc, char **argv)
{
/* SD initialization */
- int size;
- xbt_lib_cursor_t cursor = nullptr;
char *key, *data;
SD_init(&argc, argv);
-
- /* creation of the environment */
SD_create_environment(argv[1]);
- size = xbt_dict_length(host_list) + xbt_lib_length(as_router_lib);
+ xbt_dynar_t hosts = sg_hosts_as_dynar();
+ int size = sg_host_count() + xbt_lib_length(as_router_lib);
printf("Host number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
- xbt_dict_foreach(host_list, cursor, key, data) {
- simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key);
- printf(" - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
+ int it;
+ xbt_dynar_foreach(hosts, it, data) {
+ sg_host_t host = (sg_host_t)data;
+ simgrid::kernel::routing::NetCard * nc = host->pimpl_netcard;
+ printf(" - Seen: \"%s\". Type: %s\n", host->name().c_str(), nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
}
+ xbt_dynar_free(&hosts);
+ xbt_lib_cursor_t cursor = nullptr;
xbt_lib_foreach(as_router_lib, cursor, key, data) {
simgrid::kernel::routing::NetCard * nc = sg_netcard_by_name_or_null(key);
printf(" - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));