Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Minor Sonar smells (const, etc).
[simgrid.git] / src / kernel / routing / DragonflyZone.cpp
index a2fde68..ce0f59b 100644 (file)
@@ -18,10 +18,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-DragonflyZone::DragonflyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel)
-    : ClusterZone(father, name, netmodel)
-{
-}
+DragonflyZone::DragonflyZone(const std::string& name) : ClusterZone(name) {}
 
 DragonflyZone::Coords DragonflyZone::rankId_to_coords(int rankId) const
 {
@@ -124,7 +121,7 @@ void DragonflyZone::parse_specific_arguments(ClusterCreationArgs* cluster)
 }
 
 /* Generate the cluster once every node is created */
-void DragonflyZone::seal()
+void DragonflyZone::do_seal()
 {
   if (this->num_nodes_per_blade_ == 0) {
     return;
@@ -144,25 +141,18 @@ void DragonflyZone::generate_routers()
 }
 
 void DragonflyZone::generate_link(const std::string& id, int numlinks, resource::LinkImpl** linkup,
-                                  resource::LinkImpl** linkdown) const
+                                  resource::LinkImpl** linkdown)
 {
+  XBT_DEBUG("Generating link %s", id.c_str());
   *linkup   = nullptr;
   *linkdown = nullptr;
-  LinkCreationArgs linkTemplate;
-  linkTemplate.bandwidths.push_back(this->bw_ * numlinks);
-  linkTemplate.latency   = this->lat_;
-  linkTemplate.policy    = this->sharing_policy_;
-  linkTemplate.id        = id;
-  sg_platf_new_link(&linkTemplate);
-  XBT_DEBUG("Generating link %s", linkTemplate.id.c_str());
-  resource::LinkImpl* link;
-  if (this->sharing_policy_ == s4u::Link::SharingPolicy::SPLITDUPLEX) {
-    *linkup   = s4u::Link::by_name(linkTemplate.id + "_UP")->get_impl();   // check link?
-    *linkdown = s4u::Link::by_name(linkTemplate.id + "_DOWN")->get_impl(); // check link ?
+  if (sharing_policy_ == s4u::Link::SharingPolicy::SPLITDUPLEX) {
+    *linkup   = create_link(id + "_UP", std::vector<double>{bw_ * numlinks})->set_latency(lat_)->seal()->get_impl();
+    *linkdown = create_link(id + "_DOWN", std::vector<double>{bw_ * numlinks})->set_latency(lat_)->seal()->get_impl();
+
   } else {
-    link      = s4u::Link::by_name(linkTemplate.id)->get_impl();
-    *linkup   = link;
-    *linkdown = link;
+    *linkup   = create_link(id, std::vector<double>{bw_ * numlinks})->set_latency(lat_)->seal()->get_impl();
+    *linkdown = *linkup;
   }
 }
 
@@ -215,7 +205,7 @@ void DragonflyZone::generate_links()
       for (unsigned int k = j + 1; k < this->num_chassis_per_group_; k++) {
         for (unsigned int l = 0; l < this->num_blades_per_chassis_; l++) {
           std::string id = "black_link_in_group_" + std::to_string(i) + "_between_chassis_" + std::to_string(j) +
-              "_and_" + std::to_string(k) +"_blade_" + std::to_string(l) + "_" + std::to_string(uniqueId);
+                           "_and_" + std::to_string(k) + "_blade_" + std::to_string(l) + "_" + std::to_string(uniqueId);
           this->generate_link(id, this->num_links_black_, &linkup, &linkdown);
 
           this->routers_[i * num_blades_per_chassis_ * num_chassis_per_group_ + j * num_blades_per_chassis_ + l]
@@ -233,10 +223,11 @@ void DragonflyZone::generate_links()
   // FIXME: in reality blue links may be attached to several different routers
   for (unsigned int i = 0; i < this->num_groups_; i++) {
     for (unsigned int j = i + 1; j < this->num_groups_; j++) {
-      unsigned int routernumi                 = i * num_blades_per_chassis_ * num_chassis_per_group_ + j;
-      unsigned int routernumj                 = j * num_blades_per_chassis_ * num_chassis_per_group_ + i;
-      std::string id = "blue_link_between_group_"+ std::to_string(i) +"_and_" + std::to_string(j) +"_routers_" +
-          std::to_string(routernumi) + "_and_" + std::to_string(routernumj) + "_" + std::to_string(uniqueId);
+      unsigned int routernumi = i * num_blades_per_chassis_ * num_chassis_per_group_ + j;
+      unsigned int routernumj = j * num_blades_per_chassis_ * num_chassis_per_group_ + i;
+      std::string id = "blue_link_between_group_" + std::to_string(i) + "_and_" + std::to_string(j) + "_routers_" +
+                       std::to_string(routernumi) + "_and_" + std::to_string(routernumj) + "_" +
+                       std::to_string(uniqueId);
       this->generate_link(id, this->num_links_blue_, &linkup, &linkdown);
 
       this->routers_[routernumi].blue_link_ = linkup;
@@ -257,12 +248,12 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
   XBT_VERB("dragonfly getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(),
            dst->id());
 
-  if ((src->id() == dst->id()) && has_loopback_) {
-    std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
+  if ((src->id() == dst->id()) && has_loopback()) {
+    resource::LinkImpl* uplink = get_uplink_from(node_pos(src->id()));
 
-    route->link_list.push_back(info.first);
+    route->link_list.push_back(uplink);
     if (latency)
-      *latency += info.first->get_latency();
+      *latency += uplink->get_latency();
     return;
   }
 
@@ -273,9 +264,9 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
   XBT_DEBUG("dst : %u group, %u chassis, %u blade, %u node", targetCoords.group, targetCoords.chassis,
             targetCoords.blade, targetCoords.node);
 
-  DragonflyRouter* myRouter = &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
+  DragonflyRouter* myRouter      = &routers_[myCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
                                         myCoords.chassis * num_blades_per_chassis_ + myCoords.blade];
-  DragonflyRouter* targetRouter = &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
+  DragonflyRouter* targetRouter  = &routers_[targetCoords.group * (num_chassis_per_group_ * num_blades_per_chassis_) +
                                             targetCoords.chassis * num_blades_per_chassis_ + targetCoords.blade];
   DragonflyRouter* currentRouter = myRouter;
 
@@ -284,9 +275,8 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
   if (latency)
     *latency += myRouter->my_nodes_[myCoords.node * num_links_per_link_]->get_latency();
 
-  if (has_limiter_) { // limiter for sender
-    std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(src->id()));
-    route->link_list.push_back(info.first);
+  if (has_limiter()) { // limiter for sender
+    route->link_list.push_back(get_uplink_from(node_pos_with_loopback(src->id())));
   }
 
   if (targetRouter != myRouter) {
@@ -336,9 +326,8 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
     }
   }
 
-  if (has_limiter_) { // limiter for receiver
-    std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos_with_loopback(dst->id()));
-    route->link_list.push_back(info.first);
+  if (has_limiter()) { // limiter for receiver
+    route->link_list.push_back(get_downlink_to(node_pos_with_loopback(dst->id())));
   }
 
   // router->node local link
@@ -348,6 +337,14 @@ void DragonflyZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationA
     *latency +=
         targetRouter->my_nodes_[targetCoords.node * num_links_per_link_ + num_links_per_link_ - 1]->get_latency();
 }
+} // namespace routing
+} // namespace kernel
+
+namespace s4u {
+NetZone* create_dragonfly_zone(const std::string& name)
+{
+  return (new kernel::routing::DragonflyZone(name))->get_iface();
 }
-}
-} // namespace
+} // namespace s4u
+
+} // namespace simgrid