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::on_route_creation;
21 simgrid::xbt::signal<void(NetZone&)> NetZone::on_creation;
22 simgrid::xbt::signal<void(NetZone&)> NetZone::on_seal;
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::get_properties()
43 return simgrid::simix::simcall([this] { return &properties_; });
46 /** Retrieve the property value (or nullptr if not set) */
47 const char* NetZone::get_property(const char* key)
49 return properties_.at(key).c_str();
51 void NetZone::set_property(const char* key, const char* value)
53 simgrid::simix::simcall([this, key, value] { properties_[key] = value; });
56 /** @brief Returns the list of direct children (no grand-children)
58 * This function returns the internal copy of the children, not a copy. Don't mess with it!
60 std::vector<NetZone*>* NetZone::get_children()
65 const char* NetZone::get_cname() const
69 NetZone* NetZone::get_father()
74 /** @brief Returns the list of the hosts found in this NetZone (not recursively)
76 * Only the hosts that are directly contained in this NetZone are retrieved,
77 * not the ones contained in sub-netzones.
79 std::vector<Host*> NetZone::get_all_hosts()
81 std::vector<Host*> res;
82 for (auto const& card : vertices_) {
83 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
90 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
92 for (auto const& card : vertices_) {
93 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
95 whereto->push_back(host);
99 int NetZone::get_host_count()
102 for (auto const& card : vertices_) {
103 s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
110 int NetZone::add_component(kernel::routing::NetPoint* elm)
112 vertices_.push_back(elm);
113 return vertices_.size() - 1; // The rank of the newly created object
116 void NetZone::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::NetPoint* /*dst*/,
117 kernel::routing::NetPoint* /*gw_src*/, kernel::routing::NetPoint* /*gw_dst*/,
118 std::vector<kernel::resource::LinkImpl*>& /*link_list*/, bool /*symmetrical*/)
120 xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str());
124 } // namespace simgrid
126 /* **************************** Public C interface *************************** */
128 sg_netzone_t sg_zone_get_root()
130 return simgrid::s4u::Engine::get_instance()->get_netzone_root();
133 const char* sg_zone_get_name(sg_netzone_t netzone)
135 return netzone->get_cname();
138 sg_netzone_t sg_zone_get_by_name(const char* name)
140 return simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(name);
143 void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto)
145 for (auto const& elem : *netzone->get_children()) {
146 xbt_dict_set(whereto, elem->get_cname(), static_cast<void*>(elem), nullptr);
150 const char* sg_zone_get_property_value(sg_netzone_t netzone, const char* name)
152 return netzone->get_property(name);
155 void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* value)
157 netzone->set_property(name, value);
160 void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto)
162 /* converts vector to dynar */
163 std::vector<simgrid::s4u::Host*> hosts = netzone->get_all_hosts();
164 for (auto const& host : hosts)
165 xbt_dynar_push(whereto, &host);