1 /* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/kernel/routing/NetPoint.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/NetZone.hpp"
10 #include "simgrid/zone.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_netzone, "S4U Networking Zones");
17 simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
18 kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
19 std::vector<kernel::resource::LinkImpl*>& link_list)>
20 NetZone::onRouteCreation;
21 simgrid::xbt::signal<void(NetZone&)> NetZone::onCreation;
22 simgrid::xbt::signal<void(NetZone&)> NetZone::onSeal;
24 NetZone::NetZone(NetZone* father, std::string name) : father_(father), name_(name)
26 children_ = new std::vector<NetZone*>();
36 for (auto const& nz : *children_)
41 std::unordered_map<std::string, std::string>* NetZone::getProperties()
43 return simgrid::simix::kernelImmediate([this] {
48 /** Retrieve the property value (or nullptr if not set) */
49 const char* NetZone::getProperty(const char* key)
51 return properties_.at(key).c_str();
53 void NetZone::setProperty(const char* key, const char* value)
55 simgrid::simix::kernelImmediate([this,key,value] {
56 properties_[key] = value;
60 /** @brief Returns the list of direct children (no grand-children)
62 * This function returns the internal copy of the children, not a copy. Don't mess with it!
64 std::vector<NetZone*>* NetZone::getChildren()
69 const char* NetZone::get_cname() const
73 NetZone* NetZone::getFather()
78 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
80 for (auto const& card : vertices_) {
81 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
83 whereto->push_back(host);
87 int NetZone::getHostCount()
90 for (auto const& card : vertices_) {
91 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
98 int NetZone::addComponent(kernel::routing::NetPoint* elm)
100 vertices_.push_back(elm);
101 return vertices_.size() - 1; // The rank of the newly created object
104 void NetZone::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::NetPoint* /*dst*/,
105 kernel::routing::NetPoint* /*gw_src*/, kernel::routing::NetPoint* /*gw_dst*/,
106 std::vector<kernel::resource::LinkImpl*>& /*link_list*/, bool /*symmetrical*/)
108 xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str());
112 } // namespace simgrid
114 /* **************************** Public C interface *************************** */
116 sg_netzone_t sg_zone_get_root()
118 return simgrid::s4u::Engine::getInstance()->getNetRoot();
121 const char* sg_zone_get_name(sg_netzone_t netzone)
123 return netzone->get_cname();
126 sg_netzone_t sg_zone_get_by_name(const char* name)
128 return simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(name);
131 void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto)
133 for (auto const& elem : *netzone->getChildren()) {
134 xbt_dict_set(whereto, elem->get_cname(), static_cast<void*>(elem), nullptr);
138 const char* sg_zone_get_property_value(sg_netzone_t netzone, const char* name)
140 return netzone->getProperty(name);
143 void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* value)
145 netzone->setProperty(name, value);
148 void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto)
150 /* converts vector to dynar */
151 std::vector<simgrid::s4u::Host*> hosts;
152 netzone->getHosts(&hosts);
153 for (auto const& host : hosts)
154 xbt_dynar_push(whereto, &host);