virtual void turn_on();
/** @brief Turn off the current Resource */
virtual void turn_off();
+ /** @brief setup the trace file with states events (ON or OFF). Trace must contain boolean values. */
+ virtual void set_state_trace(tmgr_trace_t trace);
private:
std::string name_;
private:
kernel::lmm::Constraint* const constraint_ = nullptr;
+public:
+ TraceEvent* state_event_ = nullptr;
+
protected:
struct Metric {
double peak; /**< The peak of the metric, ie its max value */
XBT_PUBLIC void sg_link_data_set(sg_link_t link, void* data);
XBT_PUBLIC int sg_link_count();
XBT_PUBLIC sg_link_t* sg_link_list();
-XBT_PUBLIC void sg_link_exit();
SG_END_DECL()
#endif /* INCLUDE_SIMGRID_LINK_H_ */
protected:
friend s4u::Host;
+ friend s4u::Link;
friend s4u::Storage;
friend kernel::routing::NetPoint;
friend kernel::routing::NetZoneImpl;
+ friend kernel::resource::LinkImpl;
void host_register(std::string name, simgrid::s4u::Host* host);
void host_unregister(std::string name);
+ void link_register(std::string name, simgrid::s4u::Link* link);
+ void link_unregister(std::string name);
void storage_register(std::string name, simgrid::s4u::Storage* storage);
void storage_unregister(std::string name);
void netpoint_register(simgrid::kernel::routing::NetPoint* card);
size_t get_link_count();
std::vector<Link*> get_all_links();
std::vector<Link*> get_filtered_links(std::function<bool(Link*)> filter);
+ simgrid::s4u::Link* link_by_name(std::string name);
+ simgrid::s4u::Link* link_by_name_or_null(std::string name);
size_t get_actor_count();
std::vector<ActorPtr> get_all_actors();
// The private implementation, that never changes
kernel::resource::LinkImpl* const pimpl_;
+private:
+ bool currentlyDestroying_ = false;
+
public:
enum class SharingPolicy { SPLITDUPLEX = 2, SHARED = 1, FATPIPE = 0 };
+ virtual void destroy();
+ kernel::resource::LinkImpl* get_impl() { return pimpl_; }
+
/** @brief Retrieve a link from its name */
- static Link* by_name(const char* name);
+ static Link* by_name(std::string name);
+ static Link* by_name_or_null(std::string name);
/** @brief Retrieves the name of that link as a C++ string */
const std::string& get_name() const;
link.policy = link_policy_get_by_name(policy);
sg_platf_new_link(&link);
- routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl::byName(link.id));
+ routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl::by_name(link.id));
return 0;
}
boost::split(names, str, boost::is_any_of(", \t\r\n"));
if (names.empty()) {
/* unique name */
- route.link_list.push_back(simgrid::kernel::resource::LinkImpl::byName(lua_tostring(L, -1)));
+ route.link_list.push_back(simgrid::kernel::resource::LinkImpl::by_name(lua_tostring(L, -1)));
} else {
// Several names separated by , \t\r\n
for (auto const& name : names) {
if (name.length() > 0) {
- simgrid::kernel::resource::LinkImpl* link = simgrid::kernel::resource::LinkImpl::byName(name);
+ simgrid::kernel::resource::LinkImpl* link = simgrid::kernel::resource::LinkImpl::by_name(name);
route.link_list.push_back(link);
}
}
boost::split(names, str, boost::is_any_of(", \t\r\n"));
if (names.empty()) {
/* unique name with no comma */
- ASroute.link_list.push_back(simgrid::kernel::resource::LinkImpl::byName(lua_tostring(L, -1)));
+ ASroute.link_list.push_back(simgrid::kernel::resource::LinkImpl::by_name(lua_tostring(L, -1)));
} else {
// Several names separated by , \t\r\n
for (auto const& name : names) {
if (name.length() > 0) {
- simgrid::kernel::resource::LinkImpl* link = simgrid::kernel::resource::LinkImpl::byName(name);
+ simgrid::kernel::resource::LinkImpl* link = simgrid::kernel::resource::LinkImpl::by_name(name);
ASroute.link_list.push_back(link);
}
}
#include "simgrid/kernel/routing/NetPoint.hpp"
#include "simgrid/kernel/routing/NetZoneImpl.hpp"
#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Link.hpp"
#include "src/surf/StorageImpl.hpp"
#include <algorithm>
for (auto const& kv : storages_)
if (kv.second)
kv.second->getImpl()->destroy();
+ for (auto const& kv : links_)
+ if (kv.second)
+ (kv.second)->destroy();
}
}
}
private:
std::map<std::string, simgrid::s4u::Host*> hosts_;
+ std::map<std::string, simgrid::s4u::Link*> links_;
std::map<std::string, simgrid::s4u::Storage*> storages_;
std::unordered_map<std::string, simgrid::kernel::routing::NetPoint*> netpoints_;
friend simgrid::s4u::Engine;
#include "simgrid/kernel/resource/Resource.hpp"
#include "src/kernel/lmm/maxmin.hpp" // Constraint
#include "src/surf/surf_interface.hpp"
+#include "src/surf/trace_mgr.hpp"
namespace simgrid {
namespace kernel {
return name_ == other.name_;
}
+void Resource::set_state_trace(tmgr_trace_t trace)
+{
+ xbt_assert(state_event_ == nullptr, "Cannot set a second state trace to %s", get_cname());
+
+ state_event_ = future_evt_set->add_trace(trace, this);
+}
+
kernel::lmm::Constraint* Resource::get_constraint() const
{
return constraint_;
std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
route->link_list.push_back(info.first);
if (lat)
- *lat += info.first->latency();
+ *lat += info.first->get_latency();
return;
}
if (info.first) { // link up
route->link_list.push_back(info.first);
if (lat)
- *lat += info.first->latency();
+ *lat += info.first->get_latency();
}
}
if (backbone_) {
route->link_list.push_back(backbone_);
if (lat)
- *lat += backbone_->latency();
+ *lat += backbone_->get_latency();
}
if (not dst->is_router()) { // No specific link for router
if (info.second) { // link down
route->link_list.push_back(info.second);
if (lat)
- *lat += info.second->latency();
+ *lat += info.second->get_latency();
}
if (has_limiter_) { // limiter for receiver
info = private_links_.at(node_pos_with_loopback(dst->id()));
link.policy = cluster->sharing_policy;
sg_platf_new_link(&link);
- resource::LinkImpl* linkUp;
- resource::LinkImpl* linkDown;
+ s4u::Link* linkUp;
+ s4u::Link* linkDown;
if (link.policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) {
- linkUp = resource::LinkImpl::byName(link_id + "_UP");
- linkDown = resource::LinkImpl::byName(link_id + "_DOWN");
+ linkUp = s4u::Link::by_name(link_id + "_UP");
+ linkDown = s4u::Link::by_name(link_id + "_DOWN");
} else {
- linkUp = resource::LinkImpl::byName(link_id);
+ linkUp = s4u::Link::by_name(link_id);
linkDown = linkUp;
}
- private_links_.insert({position, {linkUp, linkDown}});
+ private_links_.insert({position, {linkUp->get_impl(), linkDown->get_impl()}});
}
}
}
for (auto const& link : e_route->link_list) {
route->link_list.insert(route->link_list.begin(), link);
if (lat)
- *lat += static_cast<resource::LinkImpl*>(link)->latency();
+ *lat += static_cast<resource::LinkImpl*>(link)->get_latency();
}
}
for (auto const& link : e_route_as_to_as) {
route->link_list.insert(pos, link);
if (lat)
- *lat += link->latency();
+ *lat += link->get_latency();
pos++;
}
}
for (auto const& link : e_route->link_list) {
route->link_list.insert(route->link_list.begin(), link);
if (lat)
- *lat += static_cast<resource::LinkImpl*>(link)->latency();
+ *lat += static_cast<resource::LinkImpl*>(link)->get_latency();
}
}
XBT_DEBUG("Generating link %s", id.c_str());
resource::LinkImpl* link;
if (this->sharing_policy_ == s4u::Link::SharingPolicy::SPLITDUPLEX) {
- *linkup = resource::LinkImpl::byName(linkTemplate.id + "_UP"); // check link?
- *linkdown = resource::LinkImpl::byName(linkTemplate.id + "_DOWN"); // check link ?
+ *linkup = s4u::Link::by_name(linkTemplate.id + "_UP")->get_impl(); // check link?
+ *linkdown = s4u::Link::by_name(linkTemplate.id + "_DOWN")->get_impl(); // check link ?
} else {
- link = resource::LinkImpl::byName(linkTemplate.id);
+ link = s4u::Link::by_name(linkTemplate.id)->get_impl();
*linkup = link;
*linkdown = link;
}
route->link_list.push_back(info.first);
if (latency)
- *latency += info.first->latency();
+ *latency += info.first->get_latency();
return;
}
// node->router local link
route->link_list.push_back(myRouter->my_nodes_[myCoords[3] * num_links_per_link_]);
if (latency)
- *latency += myRouter->my_nodes_[myCoords[3] * num_links_per_link_]->latency();
+ *latency += myRouter->my_nodes_[myCoords[3] * 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()));
// go to the nth router in our chassis
route->link_list.push_back(currentRouter->green_links_[targetCoords[0]]);
if (latency)
- *latency += currentRouter->green_links_[targetCoords[0]]->latency();
+ *latency += currentRouter->green_links_[targetCoords[0]]->get_latency();
currentRouter = routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
myCoords[1] * num_blades_per_chassis_ + targetCoords[0]];
}
// go to the first chassis of our group
route->link_list.push_back(currentRouter->black_links_[0]);
if (latency)
- *latency += currentRouter->black_links_[0]->latency();
+ *latency += currentRouter->black_links_[0]->get_latency();
currentRouter = routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[0]];
}
// go to destination group - the only optical hop
route->link_list.push_back(currentRouter->blue_links_[0]);
if (latency)
- *latency += currentRouter->blue_links_[0]->latency();
+ *latency += currentRouter->blue_links_[0]->get_latency();
currentRouter = routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + myCoords[0]];
}
if (targetRouter->blade_ != currentRouter->blade_) {
route->link_list.push_back(currentRouter->green_links_[targetCoords[2]]);
if (latency)
- *latency += currentRouter->green_links_[targetCoords[2]]->latency();
+ *latency += currentRouter->green_links_[targetCoords[2]]->get_latency();
currentRouter = routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[2]];
}
if (targetRouter->chassis_ != currentRouter->chassis_) {
route->link_list.push_back(currentRouter->black_links_[targetCoords[1]]);
if (latency)
- *latency += currentRouter->black_links_[targetCoords[1]]->latency();
+ *latency += currentRouter->black_links_[targetCoords[1]]->get_latency();
}
}
// router->node local link
route->link_list.push_back(targetRouter->my_nodes_[targetCoords[3] * num_links_per_link_ + num_links_per_link_ - 1]);
if (latency)
- *latency += targetRouter->my_nodes_[targetCoords[3] * num_links_per_link_ + num_links_per_link_ - 1]->latency();
+ *latency += targetRouter->my_nodes_[targetCoords[3] * num_links_per_link_ + num_links_per_link_ - 1]->get_latency();
}
}
}
if (source->id == destination->id && this->has_loopback_) {
into->link_list.push_back(source->loopback);
if (latency)
- *latency += source->loopback->latency();
+ *latency += source->loopback->get_latency();
return;
}
into->link_list.push_back(currentNode->parents[d]->up_link_);
if (latency)
- *latency += currentNode->parents[d]->up_link_->latency();
+ *latency += currentNode->parents[d]->up_link_->get_latency();
if (this->has_limiter_)
into->link_list.push_back(currentNode->limiter_link_);
if (i % this->num_children_per_node_[currentNode->level - 1] == destination->label[currentNode->level - 1]) {
into->link_list.push_back(currentNode->children[i]->down_link_);
if (latency)
- *latency += currentNode->children[i]->down_link_->latency();
+ *latency += currentNode->children[i]->down_link_->get_latency();
currentNode = currentNode->children[i]->down_node_;
if (this->has_limiter_)
into->link_list.push_back(currentNode->limiter_link_);
linkTemplate.policy = s4u::Link::SharingPolicy::SHARED;
linkTemplate.id = "limiter_"+std::to_string(id);
sg_platf_new_link(&linkTemplate);
- this->limiter_link_ = resource::LinkImpl::byName(linkTemplate.id);
+ this->limiter_link_ = s4u::Link::by_name(linkTemplate.id)->get_impl();
}
if (cluster->loopback_bw || cluster->loopback_lat) {
linkTemplate.bandwidth = cluster->loopback_bw;
linkTemplate.policy = s4u::Link::SharingPolicy::FATPIPE;
linkTemplate.id = "loopback_"+ std::to_string(id);
sg_platf_new_link(&linkTemplate);
- this->loopback = resource::LinkImpl::byName(linkTemplate.id);
+ this->loopback = s4u::Link::by_name(linkTemplate.id)->get_impl();
}
}
sg_platf_new_link(&linkTemplate);
if (cluster->sharing_policy == s4u::Link::SharingPolicy::SPLITDUPLEX) {
- std::string tmpID = std::string(linkTemplate.id) + "_UP";
- this->up_link_ = resource::LinkImpl::byName(tmpID); // check link?
- tmpID = std::string(linkTemplate.id) + "_DOWN";
- this->down_link_ = resource::LinkImpl::byName(tmpID); // check link ?
+ this->up_link_ = s4u::Link::by_name(linkTemplate.id + "_UP")->get_impl(); // check link?
+ this->down_link_ = s4u::Link::by_name(linkTemplate.id + "_DOWN")->get_impl(); // check link ?
} else {
- this->up_link_ = resource::LinkImpl::byName(linkTemplate.id);
+ this->up_link_ = s4u::Link::by_name(linkTemplate.id)->get_impl();
this->down_link_ = this->up_link_;
}
uniqueId++;
for (auto const& link : e_route->link_list) {
route->link_list.push_back(link);
if (lat)
- *lat += link->latency();
+ *lat += link->get_latency();
}
prev_dst_gw = e_route->gw_dst;
for (auto const& link : e_route->link_list) {
res->link_list.push_back(link);
if (lat)
- *lat += link->latency();
+ *lat += link->get_latency();
}
}
}
for (resource::LinkImpl* const& link : bypassedRoute->links) {
links.push_back(link);
if (latency)
- *latency += link->latency();
+ *latency += link->get_latency();
}
XBT_DEBUG("Found a bypass route from '%s' to '%s' with %zu links", src->get_cname(), dst->get_cname(),
bypassedRoute->links.size());
for (resource::LinkImpl* const& link : bypassedRoute->links) {
links.push_back(link);
if (latency)
- *latency += link->latency();
+ *latency += link->get_latency();
}
if (dst != key.second)
get_global_route(bypassedRoute->gw_dst, dst, links, latency);
resource::LinkImpl* linkUp;
resource::LinkImpl* linkDown;
if (link.policy == s4u::Link::SharingPolicy::SPLITDUPLEX) {
- std::string tmp_link = link_id + "_UP";
- linkUp = resource::LinkImpl::byName(tmp_link);
- tmp_link = link_id + "_DOWN";
- linkDown = resource::LinkImpl::byName(tmp_link);
+ linkUp = s4u::Link::by_name(link_id + "_UP")->get_impl();
+ linkDown = s4u::Link::by_name(link_id + "_DOWN")->get_impl();
} else {
- linkUp = resource::LinkImpl::byName(link_id);
+ linkUp = s4u::Link::by_name(link_id)->get_impl();
linkDown = linkUp;
}
/*
route->link_list.push_back(info.first);
if (lat)
- *lat += info.first->latency();
+ *lat += info.first->get_latency();
return;
}
if (use_lnk_up == false) {
route->link_list.push_back(info.second);
if (lat)
- *lat += info.second->latency();
+ *lat += info.second->get_latency();
} else {
route->link_list.push_back(info.first);
if (lat)
- *lat += info.first->latency();
+ *lat += info.first->get_latency();
}
current_node = next_node;
next_node = 0;
if (info.first) {
route->link_list.push_back(info.first);
if (lat)
- *lat += info.first->latency();
+ *lat += info.first->get_latency();
}
} else {
XBT_DEBUG("Source of private link (%u) doesn't exist", src->id());
if (info.second) {
route->link_list.push_back(info.second);
if (lat)
- *lat += info.second->latency();
+ *lat += info.second->get_latency();
}
} else {
XBT_DEBUG("Destination of private link (%u) doesn't exist", dst->id());
return host == pimpl->hosts_.end() ? nullptr : host->second;
}
+simgrid::s4u::Link* Engine::link_by_name(std::string name)
+{
+ return pimpl->links_.at(name); // Will raise a std::out_of_range if the host does not exist
+}
+
+simgrid::s4u::Link* Engine::link_by_name_or_null(std::string name)
+{
+ auto link = pimpl->links_.find(name);
+ return link == pimpl->links_.end() ? nullptr : link->second;
+}
+
+void Engine::link_register(std::string name, simgrid::s4u::Link* link)
+{
+ pimpl->links_[name] = link;
+}
+
+void Engine::link_unregister(std::string name)
+{
+ pimpl->links_.erase(name);
+}
+
/** @brief Returns the amount of storages in the platform */
size_t Engine::get_storage_count()
{
/** @brief Returns the amount of links in the platform */
size_t Engine::get_link_count()
{
- return kernel::resource::LinkImpl::linksCount();
+ return pimpl->links_.size();
}
/** @brief Returns the list of all links found in the platform */
std::vector<Link*> Engine::get_all_links()
{
std::vector<Link*> res;
- kernel::resource::LinkImpl::linksList(&res);
+ for (auto const& kv : pimpl->links_)
+ res.push_back(kv.second);
return res;
}
std::vector<Link*> Engine::get_filtered_links(std::function<bool(Link*)> filter)
{
- // FIXME: This is a terrible implementation and should be done
- // without getting all links first.
- std::vector<Link*> res;
- kernel::resource::LinkImpl::linksList(&res);
std::vector<Link*> filtered_list;
- for (auto& link : res) {
- if (filter(link))
- filtered_list.push_back(link);
- }
+ for (auto const& kv : pimpl->links_)
+ if (filter(kv.second))
+ filtered_list.push_back(kv.second);
return filtered_list;
}
#include <algorithm>
+#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Link.hpp"
#include "simgrid/sg_config.hpp"
#include "simgrid/simix.hpp"
simgrid::xbt::signal<void(kernel::resource::NetworkAction*, Host* src, Host* dst)> Link::on_communicate;
simgrid::xbt::signal<void(kernel::resource::NetworkAction*)> Link::on_communication_state_change;
-Link* Link::by_name(const char* name)
+void Link::destroy()
{
- kernel::resource::LinkImpl* res = kernel::resource::LinkImpl::byName(name);
- if (res == nullptr)
- return nullptr;
- return &res->piface_;
+ if (not currentlyDestroying_) {
+ currentlyDestroying_ = true;
+ on_destruction(*this);
+ Engine::get_instance()->link_unregister(std::string(pimpl_->get_cname()));
+ }
}
+
+Link* Link::by_name(std::string name)
+{
+ return Engine::get_instance()->link_by_name(name);
+}
+
+Link* Link::by_name_or_null(std::string name)
+{
+ return Engine::get_instance()->link_by_name_or_null(name);
+}
+
const std::string& Link::get_name() const
{
return this->pimpl_->get_name();
double Link::get_latency()
{
- return this->pimpl_->latency();
+ return this->pimpl_->get_latency();
}
double Link::get_bandwidth()
{
- return this->pimpl_->bandwidth();
+ return this->pimpl_->get_bandwidth();
}
Link::SharingPolicy Link::get_sharing_policy()
{
- return this->pimpl_->sharingPolicy();
+ return this->pimpl_->get_sharing_policy();
}
double Link::get_usage()
void* Link::get_data()
{
- return this->pimpl_->getData();
+ return this->pimpl_->get_data();
}
void Link::set_data(void* d)
{
- simgrid::simix::simcall([this, d]() { this->pimpl_->setData(d); });
+ simgrid::simix::simcall([this, d]() { this->pimpl_->set_data(d); });
}
void Link::set_state_trace(tmgr_trace_t trace)
{
- simgrid::simix::simcall([this, trace]() { this->pimpl_->setStateTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->set_state_trace(trace); });
}
void Link::set_bandwidth_trace(tmgr_trace_t trace)
{
- simgrid::simix::simcall([this, trace]() { this->pimpl_->setBandwidthTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->set_bandwidth_trace(trace); });
}
void Link::set_latency_trace(tmgr_trace_t trace)
{
- simgrid::simix::simcall([this, trace]() { this->pimpl_->setLatencyTrace(trace); });
+ simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_trace(trace); });
}
const char* Link::get_property(const char* key)
}
int sg_link_count()
{
- return simgrid::kernel::resource::LinkImpl::linksCount();
+ return simgrid::s4u::Engine::get_instance()->get_link_count();
}
+
sg_link_t* sg_link_list()
{
- simgrid::kernel::resource::LinkImpl** list = simgrid::kernel::resource::LinkImpl::linksList();
- sg_link_t* res = (sg_link_t*)list; // Use the same memory area
+ std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
- int size = sg_link_count();
- for (int i = 0; i < size; i++)
- res[i] = &(list[i]->piface_); // Convert each entry into its interface
+ sg_link_t* res = (sg_link_t*)malloc(sizeof(sg_link_t) * links.size());
+ memcpy(res, links.data(), sizeof(sg_link_t) * links.size());
return res;
}
-void sg_link_exit()
-{
- simgrid::kernel::resource::LinkImpl::linksExit();
-}
return core_count_;
}
-void Cpu::set_state_trace(tmgr_trace_t trace)
-{
- xbt_assert(state_event_ == nullptr, "Cannot set a second state trace to Host %s", host_->get_cname());
-
- state_event_ = future_evt_set->add_trace(trace, this);
-}
void Cpu::set_speed_trace(tmgr_trace_t trace)
{
xbt_assert(speed_.event == nullptr, "Cannot set a second speed trace to Host %s", host_->get_cname());
std::vector<double> speed_per_pstate_; /*< List of supported CPU capacities (pstate related) */
public:
- /** @brief Setup the trace file with states events (ON or OFF).
- * Trace must contain boolean values (0 or 1).
- */
- virtual void set_state_trace(tmgr_trace_t trace);
/*< @brief Setup the trace file with availability events (peak speed changes due to external load).
* Trace must contain relative values (ratio between 0 and 1)
*/
virtual void set_speed_trace(tmgr_trace_t trace);
protected:
- tmgr_trace_event_t state_event_ = nullptr;
Metric speed_ = {1.0, 0, nullptr};
};
if (sg_weight_S_parameter > 0) {
action->weight_ =
std::accumulate(route.begin(), route.end(), action->weight_, [](double total, LinkImpl* const& link) {
- return total + sg_weight_S_parameter / link->bandwidth();
+ return total + sg_weight_S_parameter / link->get_bandwidth();
});
}
- double bandwidth_bound = route.empty() ? -1.0 : bandwidthFactor(size) * route.front()->bandwidth();
+ double bandwidth_bound = route.empty() ? -1.0 : bandwidthFactor(size) * route.front()->get_bandwidth();
for (auto const& link : route)
- bandwidth_bound = std::min(bandwidth_bound, bandwidthFactor(size) * link->bandwidth());
+ bandwidth_bound = std::min(bandwidth_bound, bandwidthFactor(size) * link->get_bandwidth());
action->lat_current_ = action->latency_;
action->latency_ *= latencyFactor(size);
{
/* Find out which of my iterators was triggered, and react accordingly */
if (triggered == bandwidth_.event) {
- setBandwidth(value);
+ set_bandwidth(value);
tmgr_trace_event_unref(&bandwidth_.event);
} else if (triggered == latency_.event) {
- setLatency(value);
+ set_latency(value);
tmgr_trace_event_unref(&latency_.event);
- } else if (triggered == stateEvent_) {
+ } else if (triggered == state_event_) {
if (value > 0)
turn_on();
else {
}
}
}
- tmgr_trace_event_unref(&stateEvent_);
+ tmgr_trace_event_unref(&state_event_);
} else {
xbt_die("Unknown event!\n");
}
get_constraint());
}
-void NetworkCm02Link::setBandwidth(double value)
+void NetworkCm02Link::set_bandwidth(double value)
{
bandwidth_.peak = value;
}
}
-void NetworkCm02Link::setLatency(double value)
+void NetworkCm02Link::set_latency(double value)
{
double delta = value - latency_.peak;
kernel::lmm::Variable* var = nullptr;
s4u::Link::SharingPolicy policy, lmm::System* system);
virtual ~NetworkCm02Link() = default;
void apply_event(tmgr_trace_event_t event, double value) override;
- void setBandwidth(double value) override;
- void setLatency(double value) override;
+ void set_bandwidth(double value) override;
+ void set_latency(double value) override;
};
/**********
* 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::byName(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 *
*********/
{
if (name != "__loopback__")
- xbt_assert(not LinkImpl::byName(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());
}
return get_model()->get_maxmin_system()->constraint_used(get_constraint());
}
-double LinkImpl::latency()
+double LinkImpl::get_latency()
{
return latency_.peak * latency_.scale;
}
-double LinkImpl::bandwidth()
+double LinkImpl::get_bandwidth()
{
return bandwidth_.peak * bandwidth_.scale;
}
-s4u::Link::SharingPolicy LinkImpl::sharingPolicy()
+s4u::Link::SharingPolicy LinkImpl::get_sharing_policy()
{
return get_constraint()->get_sharing_policy();
}
s4u::Link::on_bandwidth_change(this->piface_);
}
-void LinkImpl::setStateTrace(tmgr_trace_t trace)
-{
- xbt_assert(stateEvent_ == nullptr, "Cannot set a second state trace to Link %s", get_cname());
- stateEvent_ = future_evt_set->add_trace(trace, this);
-}
-void LinkImpl::setBandwidthTrace(tmgr_trace_t trace)
+void LinkImpl::set_bandwidth_trace(tmgr_trace_t trace)
{
xbt_assert(bandwidth_.event == nullptr, "Cannot set a second bandwidth trace to Link %s", get_cname());
bandwidth_.event = future_evt_set->add_trace(trace, this);
}
-void LinkImpl::setLatencyTrace(tmgr_trace_t trace)
+
+void LinkImpl::set_latency_trace(tmgr_trace_t trace)
{
xbt_assert(latency_.event == nullptr, "Cannot set a second latency trace to Link %s", get_cname());
latency_.event = future_evt_set->add_trace(trace, this);
s4u::Link piface_;
/** @brief Get the bandwidth in bytes per second of current Link */
- virtual double bandwidth();
+ virtual double get_bandwidth();
/** @brief Update the bandwidth in bytes per second of current Link */
- virtual void setBandwidth(double value) = 0;
+ virtual void set_bandwidth(double value) = 0;
/** @brief Get the latency in seconds of current Link */
- virtual double latency();
+ virtual double get_latency();
/** @brief Update the latency in seconds of current Link */
- virtual void setLatency(double value) = 0;
+ virtual void set_latency(double value) = 0;
/** @brief The sharing policy */
- virtual s4u::Link::SharingPolicy sharingPolicy();
+ virtual s4u::Link::SharingPolicy get_sharing_policy();
/** @brief Check if the Link is used */
bool is_used() override;
void on_bandwidth_change();
- virtual void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF).
- Trace must contain boolean values. */
- virtual void setBandwidthTrace(
+ virtual void set_bandwidth_trace(
tmgr_trace_t trace); /*< setup the trace file with bandwidth events (peak speed changes due to external load).
Trace must contain percentages (value between 0 and 1). */
- virtual void setLatencyTrace(
+ virtual void set_latency_trace(
tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to external load).
Trace must contain absolute values */
- tmgr_trace_event_t stateEvent_ = nullptr;
Metric latency_ = {1.0, 0, nullptr};
Metric bandwidth_ = {1.0, 0, nullptr};
/* User data */
- void* getData() { return userData; }
- void setData(void* d) { userData = d; }
+ void* get_data() { return userdata_; }
+ void set_data(void* d) { userdata_ = d; }
private:
- void* userData = nullptr;
-
- /* List of all links. FIXME: should move to the Engine */
- static std::unordered_map<std::string, LinkImpl*>* links;
-
-public:
- static LinkImpl* byName(std::string name);
- static int linksCount();
- static LinkImpl** linksList();
- static void linksList(std::vector<s4u::Link*>* linkList);
- static void linksExit();
+ void* userdata_ = nullptr;
};
/**********
(symmetrical ? "(symmetrical)" : "(not symmetrical)"));
// XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id);
- XBT_DEBUG("\tLink (%s) bw:%fbps lat:%fs", link->get_cname(), link->bandwidth(), link->latency());
+ XBT_DEBUG("\tLink (%s) bw:%fbps lat:%fs", link->get_cname(), link->get_bandwidth(), link->get_latency());
// create link ns3
NetPointNs3* host_src = src->extension<NetPointNs3>();
xbt_assert(host_src != nullptr, "Network element %s does not seem to be NS3-ready", src->get_cname());
xbt_assert(host_dst != nullptr, "Network element %s does not seem to be NS3-ready", dst->get_cname());
- ns3_add_link(host_src, host_dst, link->bandwidth(), link->latency());
+ ns3_add_link(host_src, host_dst, link->get_bandwidth(), link->get_latency());
} else {
static bool warned_about_long_routes = false;
{
THROW_UNIMPLEMENTED;
}
-void LinkNS3::setBandwidthTrace(tmgr_trace_t trace) {
+void LinkNS3::set_bandwidth_trace(tmgr_trace_t trace)
+{
xbt_die("The NS3 network model doesn't support bandwidth traces");
}
-void LinkNS3::setLatencyTrace(tmgr_trace_t trace) {
+void LinkNS3::set_latency_trace(tmgr_trace_t trace)
+{
xbt_die("The NS3 network model doesn't support latency traces");
}
~LinkNS3();
void apply_event(tmgr_trace_event_t event, double value) override;
- void setBandwidth(double value) override { THROW_UNIMPLEMENTED; }
- void setLatency(double value) override { THROW_UNIMPLEMENTED; }
- void setBandwidthTrace(tmgr_trace_t trace) override;
- void setLatencyTrace(tmgr_trace_t trace) override;
+ void set_bandwidth(double value) override { THROW_UNIMPLEMENTED; }
+ void set_latency(double value) override { THROW_UNIMPLEMENTED; }
+ void set_bandwidth_trace(tmgr_trace_t trace) override;
+ void set_latency_trace(tmgr_trace_t trace) override;
};
/**********
{
XBT_DEBUG("Updating link %s (%p) with value=%f", get_cname(), this, value);
if (triggered == bandwidth_.event) {
- setBandwidth(value);
+ set_bandwidth(value);
tmgr_trace_event_unref(&bandwidth_.event);
} else if (triggered == latency_.event) {
- setLatency(value);
+ set_latency(value);
tmgr_trace_event_unref(&latency_.event);
- } else if (triggered == stateEvent_) {
+ } else if (triggered == state_event_) {
if (value > 0)
turn_on();
else
turn_off();
- tmgr_trace_event_unref(&stateEvent_);
+ tmgr_trace_event_unref(&state_event_);
} else {
xbt_die("Unknown event ! \n");
}
}
-void LinkL07::setBandwidth(double value)
+void LinkL07::set_bandwidth(double value)
{
bandwidth_.peak = value;
LinkImpl::on_bandwidth_change();
get_model()->get_maxmin_system()->update_constraint_bound(get_constraint(), bandwidth_.peak * bandwidth_.scale);
}
-void LinkL07::setLatency(double value)
+void LinkL07::set_latency(double value)
{
kernel::lmm::Variable* var = nullptr;
L07Action *action;
~LinkL07() override;
bool is_used() override;
void apply_event(tmgr_trace_event_t event, double value) override;
- void setBandwidth(double value) override;
- void setLatency(double value) override;
+ void set_bandwidth(double value) override;
+ void set_latency(double value) override;
};
/**********
}
if (link->latency_trace)
- l->setLatencyTrace(link->latency_trace);
+ l->set_latency_trace(link->latency_trace);
if (link->bandwidth_trace)
- l->setBandwidthTrace(link->bandwidth_trace);
+ l->set_bandwidth_trace(link->bandwidth_trace);
if (link->state_trace)
- l->setStateTrace(link->state_trace);
+ l->set_state_trace(link->state_trace);
}
delete link->properties;
}
// other columns are to store one or more link for the node
//add a loopback link
- simgrid::kernel::resource::LinkImpl* linkUp = nullptr;
- simgrid::kernel::resource::LinkImpl* linkDown = nullptr;
+ simgrid::s4u::Link* linkUp = nullptr;
+ simgrid::s4u::Link* linkDown = nullptr;
if(cluster->loopback_bw > 0 || cluster->loopback_lat > 0){
std::string tmp_link = link_id + "_loopback";
XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link.c_str(), cluster->loopback_bw);
link.latency = cluster->loopback_lat;
link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE;
sg_platf_new_link(&link);
- linkUp = simgrid::kernel::resource::LinkImpl::byName(tmp_link);
- linkDown = simgrid::kernel::resource::LinkImpl::byName(tmp_link);
+ linkUp = simgrid::s4u::Link::by_name_or_null(tmp_link);
+ linkDown = simgrid::s4u::Link::by_name_or_null(tmp_link);
auto* as_cluster = static_cast<ClusterZone*>(current_as);
- as_cluster->private_links_.insert({as_cluster->node_pos(rankId), {linkUp, linkDown}});
+ as_cluster->private_links_.insert({as_cluster->node_pos(rankId), {linkUp->get_impl(), linkDown->get_impl()}});
}
//add a limiter link (shared link to account for maximal bandwidth of the node)
link.latency = 0;
link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
sg_platf_new_link(&link);
- linkDown = simgrid::kernel::resource::LinkImpl::byName(tmp_link);
+ linkDown = simgrid::s4u::Link::by_name_or_null(tmp_link);
linkUp = linkDown;
- current_as->private_links_.insert({current_as->node_pos_with_loopback(rankId), {linkUp, linkDown}});
+ current_as->private_links_.insert(
+ {current_as->node_pos_with_loopback(rankId), {linkUp->get_impl(), linkDown->get_impl()}});
}
//call the cluster function that adds the others links
XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id.c_str(), cluster->bb_bw, cluster->bb_lat);
sg_platf_new_link(&link);
- routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl::byName(link.id));
+ routing_cluster_add_backbone(simgrid::s4u::Link::by_name(link.id)->get_impl());
}
XBT_DEBUG("</AS>");
xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
"Only hosts from Cluster and Vivaldi ASes can get an host_link.");
- simgrid::kernel::resource::LinkImpl* linkUp = simgrid::kernel::resource::LinkImpl::byName(hostlink->link_up);
- simgrid::kernel::resource::LinkImpl* linkDown = simgrid::kernel::resource::LinkImpl::byName(hostlink->link_down);
+ simgrid::s4u::Link* linkUp = simgrid::s4u::Link::by_name_or_null(hostlink->link_up);
+ simgrid::s4u::Link* linkDown = simgrid::s4u::Link::by_name_or_null(hostlink->link_down);
xbt_assert(linkUp, "Link '%s' not found!", hostlink->link_up.c_str());
xbt_assert(linkDown, "Link '%s' not found!", hostlink->link_down.c_str());
surf_parse_error(std::string("Host_link for '") + hostlink->id.c_str() + "' is already defined!");
XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->get_cname(), netpoint->id());
- as_cluster->private_links_.insert({netpoint->id(), {linkUp, linkDown}});
+ as_cluster->private_links_.insert({netpoint->id(), {linkUp->get_impl(), linkDown->get_impl()}});
}
void sg_platf_new_trace(simgrid::kernel::routing::TraceCreationArgs* trace)
void surf_exit()
{
simgrid::s4u::Engine::shutdown();
- sg_link_exit();
for (auto const& e : storage_types) {
simgrid::surf::StorageType* stype = e.second;
delete stype->properties;
switch (A_surfxml_link___ctn_direction) {
case AU_surfxml_link___ctn_direction:
case A_surfxml_link___ctn_direction_NONE:
- link = simgrid::kernel::resource::LinkImpl::byName(A_surfxml_link___ctn_id);
+ link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl();
break;
case A_surfxml_link___ctn_direction_UP:
- link = simgrid::kernel::resource::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
+ link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl();
break;
case A_surfxml_link___ctn_direction_DOWN:
- link = simgrid::kernel::resource::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
+ link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl();
break;
default:
surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
link.policy = simgrid::s4u::Link::SharingPolicy::SHARED;
sg_platf_new_link(&link);
- routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl::byName(A_surfxml_backbone_id));
+ routing_cluster_add_backbone(simgrid::s4u::Link::by_name(std::string(A_surfxml_backbone_id))->get_impl());
}
void STag_surfxml_route(){