Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further snake_case NetZone
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Jun 2018 15:17:53 +0000 (17:17 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 10 Jun 2018 21:09:45 +0000 (23:09 +0200)
examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp
include/simgrid/s4u/NetZone.hpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/NetPoint.cpp
src/kernel/routing/RoutedZone.cpp
src/s4u/s4u_Netzone.cpp

index 8f7f622..21b5837 100644 (file)
@@ -19,11 +19,9 @@ int main(int argc, char* argv[])
 
   for (auto c : clusters) {
     XBT_INFO("%s", c->get_cname());
 
   for (auto c : clusters) {
     XBT_INFO("%s", c->get_cname());
-    std::vector<simgrid::s4u::Host*>* hosts = new std::vector<simgrid::s4u::Host*>;
-    c->getHosts(hosts);
-    for (auto h : *hosts)
+    std::vector<simgrid::s4u::Host*> hosts = c->get_all_hosts();
+    for (auto h : hosts)
       XBT_INFO("   %s", h->get_cname());
       XBT_INFO("   %s", h->get_cname());
-    delete hosts;
   }
 
   std::vector<simgrid::kernel::routing::DragonflyZone*> dragonfly_clusters =
   }
 
   std::vector<simgrid::kernel::routing::DragonflyZone*> dragonfly_clusters =
index d8e242b..4b485bb 100644 (file)
@@ -39,23 +39,24 @@ public:
   const char* get_cname() const;
   NetZone* get_father();
 
   const char* get_cname() const;
   NetZone* get_father();
 
+  std::vector<Host*> get_all_hosts();
+
   std::vector<NetZone*>* getChildren();             // Sub netzones
   std::vector<NetZone*>* getChildren();             // Sub netzones
-  void getHosts(std::vector<s4u::Host*> * whereto); // retrieve my content as a vector of hosts
   int getHostCount();
 
 private:
   std::unordered_map<std::string, std::string> properties_;
 
 public:
   int getHostCount();
 
 private:
   std::unordered_map<std::string, std::string> properties_;
 
 public:
-  /** Get the properties assigned to a host */
-  std::unordered_map<std::string, std::string>* getProperties();
+  /** Get the properties assigned to a netzone */
+  std::unordered_map<std::string, std::string>* get_properties();
 
   /** Retrieve the property value (or nullptr if not set) */
   const char* get_property(const char* key);
   void set_property(const char* key, const char* value);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
 
   /** Retrieve the property value (or nullptr if not set) */
   const char* get_property(const char* key);
   void set_property(const char* key, const char* value);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
-  virtual int addComponent(kernel::routing::NetPoint * elm); /* A host, a router or a netzone, whatever */
+  virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
   virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
                          std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
   virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
                          kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
                          std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
@@ -71,7 +72,23 @@ public:
   static simgrid::xbt::signal<void(NetZone&)> on_creation;
   static simgrid::xbt::signal<void(NetZone&)> on_seal;
 
   static simgrid::xbt::signal<void(NetZone&)> on_creation;
   static simgrid::xbt::signal<void(NetZone&)> on_seal;
 
-  // Deprecation wrappers
+private:
+  // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
+  std::vector<kernel::routing::NetPoint*> vertices_;
+
+protected:
+  unsigned int get_table_size() { return vertices_.size(); }
+  std::vector<kernel::routing::NetPoint*> get_vertices() { return vertices_; }
+
+private:
+  NetZone* father_ = nullptr;
+  std::string name_;
+
+  bool sealed_ = false; // We cannot add more content when sealed
+
+  std::vector<NetZone*>* children_ = nullptr; // sub-netzones
+
+public: // Deprecation wrappers
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_cname()") const char* getCname() const { return get_cname(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_cname()") const char* getCname() const { return get_cname(); }
@@ -87,6 +104,11 @@ public:
   {
     add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
   }
   {
     add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
   }
+  XBT_ATTRIB_DEPRECATED_v323(
+      "Please use NetZone::get_properties()") std::unordered_map<std::string, std::string>* getProperties()
+  {
+    return get_properties();
+  }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_property()") const char* getProperty(const char* key)
   {
     return get_property(key);
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_property()") const char* getProperty(const char* key)
   {
     return get_property(key);
@@ -95,22 +117,17 @@ public:
   {
     set_property(key, value);
   }
   {
     set_property(key, value);
   }
-
-private:
-  // our content, as known to our graph routing algorithm (maps vertexId -> vertex)
-  std::vector<kernel::routing::NetPoint*> vertices_;
-
-protected:
-  unsigned int get_table_size() { return vertices_.size(); }
-  std::vector<kernel::routing::NetPoint*> getVertices() { return vertices_; }
-
-private:
-  NetZone* father_ = nullptr;
-  std::string name_;
-
-  bool sealed_ = false; // We cannot add more content when sealed
-
-  std::vector<NetZone*>* children_ = nullptr; // sub-netzones
+  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") virtual int addComponent(
+      kernel::routing::NetPoint* elm)
+  {
+    return add_component(elm);
+  }
+  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector<kernel::routing::NetPoint*> getVertices()
+  {
+    return get_vertices();
+  }
+  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_all_hosts()") void getHosts(
+      std::vector<s4u::Host*>* whereto); // retrieve my content as a vector of hosts
 };
 }
 }; // Namespace simgrid::s4u
 };
 }
 }; // Namespace simgrid::s4u
index 26c7a1e..3013d78 100644 (file)
@@ -89,7 +89,7 @@ void ClusterZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>
     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
   }
 
     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
   }
 
-  for (auto const& src : getVertices()) {
+  for (auto const& src : get_vertices()) {
     if (not src->is_router()) {
       xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
 
     if (not src->is_router()) {
       xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes);
 
index 04f9a23..6326cf2 100644 (file)
@@ -19,7 +19,7 @@ NetPoint::NetPoint(std::string name, NetPoint::Type componentType, NetZoneImpl*
     : name_(name), component_type_(componentType), englobing_zone_(netzone_p)
 {
   if (netzone_p != nullptr)
     : name_(name), component_type_(componentType), englobing_zone_(netzone_p)
 {
   if (netzone_p != nullptr)
-    id_ = netzone_p->addComponent(this);
+    id_ = netzone_p->add_component(this);
   else
     id_ = static_cast<decltype(id_)>(-1);
   simgrid::s4u::Engine::get_instance()->netpoint_register(this);
   else
     id_ = static_cast<decltype(id_)>(-1);
   simgrid::s4u::Engine::get_instance()->netpoint_register(this);
index f6585e6..2de68c1 100644 (file)
@@ -66,7 +66,7 @@ RoutedZone::RoutedZone(NetZone* father, std::string name) : NetZoneImpl(father,
 void RoutedZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
                            std::map<std::string, xbt_edge_t>* edges)
 {
 void RoutedZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
                            std::map<std::string, xbt_edge_t>* edges)
 {
-  std::vector<kernel::routing::NetPoint*> vertices = getVertices();
+  std::vector<kernel::routing::NetPoint*> vertices = get_vertices();
 
   for (auto const& my_src : vertices) {
     for (auto const& my_dst : vertices) {
 
   for (auto const& my_src : vertices) {
     for (auto const& my_dst : vertices) {
index a46eb0a..a01bd94 100644 (file)
@@ -38,7 +38,7 @@ NetZone::~NetZone()
   delete children_;
 }
 
   delete children_;
 }
 
-std::unordered_map<std::string, std::string>* NetZone::getProperties()
+std::unordered_map<std::string, std::string>* NetZone::get_properties()
 {
   return simgrid::simix::simcall([this] { return &properties_; });
 }
 {
   return simgrid::simix::simcall([this] { return &properties_; });
 }
@@ -71,6 +71,22 @@ NetZone* NetZone::get_father()
   return father_;
 }
 
   return father_;
 }
 
+/** @brief Returns the list of the hosts found in this NetZone (not recursively)
+ *
+ * Only the hosts that are directly contained in this NetZone are retrieved,
+ * not the ones contained in sub-netzones.
+ */
+std::vector<Host*> NetZone::get_all_hosts()
+{
+  std::vector<Host*> res;
+  for (auto const& card : vertices_) {
+    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
+    if (host != nullptr)
+      res.push_back(host);
+  }
+  return res;
+}
+
 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
 {
   for (auto const& card : vertices_) {
 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
 {
   for (auto const& card : vertices_) {
@@ -91,7 +107,7 @@ int NetZone::getHostCount()
   return count;
 }
 
   return count;
 }
 
-int NetZone::addComponent(kernel::routing::NetPoint* elm)
+int NetZone::add_component(kernel::routing::NetPoint* elm)
 {
   vertices_.push_back(elm);
   return vertices_.size() - 1; // The rank of the newly created object
 {
   vertices_.push_back(elm);
   return vertices_.size() - 1; // The rank of the newly created object
@@ -144,8 +160,7 @@ void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* va
 void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto)
 {
   /* converts vector to dynar */
 void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto)
 {
   /* converts vector to dynar */
-  std::vector<simgrid::s4u::Host*> hosts;
-  netzone->getHosts(&hosts);
+  std::vector<simgrid::s4u::Host*> hosts = netzone->get_all_hosts();
   for (auto const& host : hosts)
     xbt_dynar_push(whereto, &host);
 }
   for (auto const& host : hosts)
     xbt_dynar_push(whereto, &host);
 }