Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
attempt to fully trace ptasks
[simgrid.git] / src / surf / network_interface.cpp
index a01dfef..056d773 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_interface.hpp"
+#include "simgrid/s4u/Engine.hpp"
 #include "simgrid/sg_config.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf, "Logging specific to the SURF network module");
 
-namespace simgrid {
-namespace kernel {
-namespace resource {
-
-/* List of links */
-std::unordered_map<std::string, LinkImpl*>* LinkImpl::links = new std::unordered_map<std::string, LinkImpl*>();
-
-LinkImpl* LinkImpl::by_name(std::string name)
-{
-  auto link = links->find(name);
-  return link == links->end() ? nullptr : link->second;
-}
-/** @brief Returns the amount of links in the platform */
-int LinkImpl::linksCount()
-{
-  return links->size();
-}
-void LinkImpl::linksList(std::vector<s4u::Link*>* linkList)
-{
-  for (auto const& kv : *links) {
-    linkList->push_back(&kv.second->piface_);
-  }
-}
-
-/** @brief Returns a list of all existing links */
-LinkImpl** LinkImpl::linksList()
-{
-  LinkImpl** res = xbt_new(LinkImpl*, (int)links->size());
-  int i          = 0;
-  for (auto const& kv : *links) {
-    res[i] = kv.second;
-    i++;
-  }
-  return res;
-}
-/** @brief destructor of the static data */
-void LinkImpl::linksExit()
-{
-  for (auto const& kv : *links)
-    (kv.second)->destroy();
-  delete links;
-}
-}
-}
-} // namespace simgrid
-
 /*********
  * Model *
  *********/
@@ -83,17 +38,17 @@ simgrid::config::Flag<bool> NetworkModel::cfg_crosstraffic(
 
 NetworkModel::~NetworkModel() = default;
 
-double NetworkModel::latencyFactor(double /*size*/)
+double NetworkModel::get_latency_factor(double /*size*/)
 {
   return sg_latency_factor;
 }
 
-double NetworkModel::bandwidthFactor(double /*size*/)
+double NetworkModel::get_bandwidth_factor(double /*size*/)
 {
   return sg_bandwidth_factor;
 }
 
-double NetworkModel::bandwidthConstraint(double rate, double /*bound*/, double /*size*/)
+double NetworkModel::get_bandwidth_constraint(double rate, double /*bound*/, double /*size*/)
 {
   return rate;
 }
@@ -122,19 +77,19 @@ LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint
 {
 
   if (name != "__loopback__")
-    xbt_assert(not LinkImpl::by_name(name), "Link '%s' declared several times in the platform.", name.c_str());
+    xbt_assert(not s4u::Link::by_name_or_null(name), "Link '%s' declared several times in the platform.", name.c_str());
 
   latency_.scale   = 1;
   bandwidth_.scale = 1;
 
-  links->insert({name, this});
+  s4u::Engine::get_instance()->link_register(name, &piface_);
   XBT_DEBUG("Create link '%s'", name.c_str());
 }
 
 /** @brief use destroy() instead of this destructor */
 LinkImpl::~LinkImpl()
 {
-  xbt_assert(currentlyDestroying_, "Don't delete Links directly. Call destroy() instead.");
+  xbt_assert(currently_destroying_, "Don't delete Links directly. Call destroy() instead.");
 }
 /** @brief Fire the required callbacks and destroy the object
  *
@@ -142,8 +97,8 @@ LinkImpl::~LinkImpl()
  */
 void LinkImpl::destroy()
 {
-  if (not currentlyDestroying_) {
-    currentlyDestroying_ = true;
+  if (not currently_destroying_) {
+    currently_destroying_ = true;
     s4u::Link::on_destruction(this->piface_);
     delete this;
   }
@@ -211,7 +166,7 @@ void NetworkAction::set_state(Action::State state)
   Action::State previous = get_state();
   Action::set_state(state);
   if (previous != state) // Trigger only if the state changed
-    s4u::Link::on_communication_state_change(this);
+    s4u::Link::on_communication_state_change(this, previous);
 }
 
 /** @brief returns a list of all Links that this action is using */