namespace s4u {
class NetZone;
class Host;
+ class Link;
class Mailbox;
}
namespace kernel {
typedef simgrid::s4u::NetZone simgrid_NetZone;
typedef simgrid::s4u::Host simgrid_Host;
+typedef simgrid::s4u::Link Link;
typedef simgrid::kernel::activity::ActivityImpl kernel_Activity;
typedef simgrid::kernel::routing::NetPoint routing_NetPoint;
typedef simgrid::surf::Cpu surf_Cpu;
-typedef simgrid::surf::LinkImpl Link;
typedef simgrid::surf::Resource surf_Resource;
typedef simgrid::trace_mgr::trace tmgr_Trace;
/*** Called on each newly created regular route (not on bypass routes) */
static simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
- std::vector<Link*>* link_list)>
+ std::vector<surf::LinkImpl*>* link_list)>
onRouteCreation;
protected:
class Comm;
class Engine;
class Host;
+class Link;
class Mailbox;
using MailboxPtr = boost::intrusive_ptr<Mailbox>;
boost::unordered_map<std::string, Storage*> const &mountedStorages();
void routeTo(Host * dest, std::vector<Link*> * links, double* latency);
+ void routeTo(Host * dest, std::vector<surf::LinkImpl*> * links, double* latency);
private:
simgrid::xbt::string name_ = "noname";
--- /dev/null
+/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef S4U_LINK_HPP_
+#define S4U_LINK_HPP_
+
+#include <xbt/base.h>
+
+#include <unordered_map>
+
+#include "xbt/dict.h"
+#include "xbt/fifo.h"
+
+#include "simgrid/link.h"
+
+/***********
+ * Classes *
+ ***********/
+
+namespace simgrid {
+namespace surf {
+class LinkImpl;
+}
+namespace s4u {
+/** @brief A Link represents the network facilities between [hosts](\ref simgrid::s4u::Host) */
+class Link {
+ friend simgrid::surf::LinkImpl;
+
+private:
+ // Links are created from the NetZone, and destroyed by their private implementation when the simulation ends
+ explicit Link(surf::LinkImpl* pimpl) : pimpl_(pimpl) {}
+ virtual ~Link() = default;
+ // The private implementation, that never changes
+ surf::LinkImpl* const pimpl_;
+
+public:
+ /** @brief Retrieve a link from its name */
+ static Link* byName(const char* name);
+
+ /** @brief Get da name */
+ const char* name();
+
+ /** @brief Get the bandwidth in bytes per second of current Link */
+ double bandwidth();
+
+ /** @brief Get the latency in seconds of current Link */
+ double latency();
+
+ /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX)
+ */
+ int sharingPolicy();
+
+ /** @brief Check if the Link is used */
+ bool isUsed();
+
+ void turnOn();
+ void turnOff();
+
+ void* getData();
+ void setData(void* d);
+
+ void setStateTrace(tmgr_trace_t trace); /*< setup the trace file with states events (ON or OFF). Trace must contain
+ boolean values. */
+ void
+ setBandwidthTrace(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). */
+ void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to
+ external load). Trace must contain absolute values */
+};
+}
+}
+
+#endif /* SURF_NETWORK_INTERFACE_HPP_ */
+
+/* Blueprint for the s4u/kernel split
+
+namespace s4u {
+ class Link {
+ public:
+ Link(kernel::Link* pimpl) : pimpl_(pimpl) {}
+ private:
+ kernel::Link* pimpl_;
+ };
+}
+
+namespace kernel {
+ class Link : public util::refcounted<Link> {
+ private:
+ s4u::Link user_;
+ };
+}
+ */
if(!dst_elm)
xbt_die("Element '%s' not found!",dst);
- std::vector<Link*> route;
+ std::vector<simgrid::surf::LinkImpl*> route;
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(src_elm, dst_elm, &route, nullptr);
for (auto link : route)
instr_user_variable (time, link->getName(), variable, father_type, value, what, nullptr, user_link_variables);
if ((src->id() == dst->id()) && hasLoopback_) {
xbt_assert(!src->isRouter(), "Routing from a cluster private router to itself is meaningless");
- std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
route->link_list->push_back(info.first);
if (lat)
*lat += info.first->latency();
if (!src->isRouter()) { // No private link for the private router
if (hasLimiter_) { // limiter for sender
- std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
+ privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0));
route->link_list->push_back(info.first);
}
- std::pair<Link*, Link*> info =
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
privateLinks_.at(src->id() * linkCountPerNode_ + (hasLoopback_ ? 1 : 0) + (hasLimiter_ ? 1 : 0));
if (info.first) { // link up
route->link_list->push_back(info.first);
if (!dst->isRouter()) { // No specific link for router
- std::pair<Link*, Link*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info =
+ privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_ + hasLimiter_);
if (info.second) { // link down
route->link_list->push_back(info.second);
if (lat)
if (!src->isRouter()) {
xbt_node_t previous = new_xbt_graph_node(graph, src->cname(), nodes);
- std::pair<Link*, Link*> info = privateLinks_.at(src->id());
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
if (info.first) { // link up
xbt_node_t current = new_xbt_graph_node(graph, info.first->getName(), nodes);
link.policy = cluster->sharing_policy;
sg_platf_new_link(&link);
- Link *linkUp, *linkDown;
+ surf::LinkImpl *linkUp, *linkDown;
if (link.policy == SURF_LINK_FULLDUPLEX) {
char* tmp_link = bprintf("%s_UP", link_id);
- linkUp = Link::byName(tmp_link);
+ linkUp = surf::LinkImpl::byName(tmp_link);
xbt_free(tmp_link);
tmp_link = bprintf("%s_DOWN", link_id);
- linkDown = Link::byName(tmp_link);
+ linkDown = surf::LinkImpl::byName(tmp_link);
xbt_free(tmp_link);
} else {
- linkUp = Link::byName(link_id);
+ linkUp = surf::LinkImpl::byName(link_id);
linkDown = linkUp;
}
privateLinks_.insert({position, {linkUp, linkDown}});
/* We use a map instead of a std::vector here because that's a sparse vector. Some values may not exist */
/* The pair is {linkUp, linkDown} */
- std::unordered_map<unsigned int, std::pair<Link*, Link*>> privateLinks_;
+ std::unordered_map<unsigned int, std::pair<surf::LinkImpl*, surf::LinkImpl*>> privateLinks_;
- Link* backbone_ = nullptr;
+ surf::LinkImpl* backbone_ = nullptr;
void* loopback_ = nullptr;
NetPoint* router_ = nullptr;
bool hasLimiter_ = false;
if (!found) {
sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
- e_route->link_list = new std::vector<Link*>();
+ e_route->link_list = new std::vector<surf::LinkImpl*>();
e_route->link_list->push_back(surf_network_model->loopback_);
xbt_graph_new_edge(routeGraph_, node, node, e_route);
}
for (auto link : *e_route->link_list) {
route->link_list->insert(route->link_list->begin(), link);
if (lat)
- *lat += static_cast<Link*>(link)->latency();
+ *lat += static_cast<surf::LinkImpl*>(link)->latency();
}
}
if (hierarchy_ == RoutingMode::recursive && v != dst_node_id &&
strcmp(gw_dst->name().c_str(), prev_gw_src->name().c_str())) {
- std::vector<Link*>* e_route_as_to_as = new std::vector<Link*>();
+ std::vector<surf::LinkImpl*> e_route_as_to_as;
- getGlobalRoute(gw_dst_net_elm, prev_gw_src_net_elm, e_route_as_to_as, nullptr);
+ getGlobalRoute(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, nullptr);
auto pos = route->link_list->begin();
- for (auto link : *e_route_as_to_as) {
+ for (auto link : e_route_as_to_as) {
route->link_list->insert(pos, link);
if (lat)
*lat += link->latency();
for (auto link : *e_route->link_list) {
route->link_list->insert(route->link_list->begin(), link);
if (lat)
- *lat += static_cast<Link*>(link)->latency();
+ *lat += static_cast<surf::LinkImpl*>(link)->latency();
}
size++;
}
}
}
-void DragonflyZone::createLink(char* id, int numlinks, Link** linkup, Link** linkdown)
+void DragonflyZone::createLink(char* id, int numlinks, surf::LinkImpl** linkup, surf::LinkImpl** linkdown)
{
*linkup = nullptr;
*linkdown = nullptr;
linkTemplate.id = id;
sg_platf_new_link(&linkTemplate);
XBT_DEBUG("Generating link %s", id);
- Link* link;
+ surf::LinkImpl* link;
std::string tmpID;
if (this->cluster_->sharing_policy == SURF_LINK_FULLDUPLEX) {
tmpID = std::string(linkTemplate.id) + "_UP";
- link = Link::byName(tmpID.c_str());
+ link = surf::LinkImpl::byName(tmpID.c_str());
*linkup = link; // check link?
tmpID = std::string(linkTemplate.id) + "_DOWN";
- link = Link::byName(tmpID.c_str());
+ link = surf::LinkImpl::byName(tmpID.c_str());
*linkdown = link; // check link ?
} else {
- link = Link::byName(linkTemplate.id);
+ link = surf::LinkImpl::byName(linkTemplate.id);
*linkup = link;
*linkdown = link;
}
static int uniqueId = 0;
char* id = nullptr;
- Link* linkup;
- Link* linkdown;
+ surf::LinkImpl* linkup;
+ surf::LinkImpl* linkdown;
unsigned int numRouters = this->numGroups_ * this->numChassisPerGroup_ * this->numBladesPerChassis_;
// Links from routers to their local nodes.
for (unsigned int i = 0; i < numRouters; i++) {
// allocate structures
- this->routers_[i]->myNodes_ =
- static_cast<Link**>(xbt_malloc0(numLinksperLink_ * this->numNodesPerBlade_ * sizeof(Link*)));
- this->routers_[i]->greenLinks_ = static_cast<Link**>(xbt_malloc0(this->numBladesPerChassis_ * sizeof(Link*)));
- this->routers_[i]->blackLinks_ = static_cast<Link**>(xbt_malloc0(this->numChassisPerGroup_ * sizeof(Link*)));
+ this->routers_[i]->myNodes_ = static_cast<surf::LinkImpl**>(
+ xbt_malloc0(numLinksperLink_ * this->numNodesPerBlade_ * sizeof(surf::LinkImpl*)));
+ this->routers_[i]->greenLinks_ =
+ static_cast<surf::LinkImpl**>(xbt_malloc0(this->numBladesPerChassis_ * sizeof(surf::LinkImpl*)));
+ this->routers_[i]->blackLinks_ =
+ static_cast<surf::LinkImpl**>(xbt_malloc0(this->numChassisPerGroup_ * sizeof(surf::LinkImpl*)));
for (unsigned int j = 0; j < numLinksperLink_ * this->numNodesPerBlade_; j += numLinksperLink_) {
id = bprintf("local_link_from_router_%d_to_node_%d_%d", i, j / numLinksperLink_, uniqueId);
for (unsigned int j = i + 1; j < this->numGroups_; j++) {
unsigned int routernumi = i * numBladesPerChassis_ * numChassisPerGroup_ + j;
unsigned int routernumj = j * numBladesPerChassis_ * numChassisPerGroup_ + i;
- this->routers_[routernumi]->blueLinks_ = static_cast<Link**>(xbt_malloc0(sizeof(Link*)));
- this->routers_[routernumj]->blueLinks_ = static_cast<Link**>(xbt_malloc0(sizeof(Link*)));
+ this->routers_[routernumi]->blueLinks_ = static_cast<surf::LinkImpl**>(xbt_malloc0(sizeof(surf::LinkImpl*)));
+ this->routers_[routernumj]->blueLinks_ = static_cast<surf::LinkImpl**>(xbt_malloc0(sizeof(surf::LinkImpl*)));
id = bprintf("blue_link_between_group_%d_and_%d_routers_%d_and_%d_%d", i, j, routernumi, routernumj, uniqueId);
this->createLink(id, this->numLinksBlue_, &linkup, &linkdown);
this->routers_[routernumi]->blueLinks_[0] = linkup;
dst->id());
if ((src->id() == dst->id()) && hasLoopback_) {
- std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
route->link_list->push_back(info.first);
if (latency)
*latency += myRouter->myNodes_[myCoords[3] * numLinksperLink_]->latency();
if (hasLimiter_) { // limiter for sender
- std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_ + hasLoopback_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_ + hasLoopback_);
route->link_list->push_back(info.first);
}
}
if (hasLimiter_) { // limiter for receiver
- std::pair<Link*, Link*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(dst->id() * linkCountPerNode_ + hasLoopback_);
route->link_list->push_back(info.first);
}
void seal() override;
void generateRouters();
void generateLinks();
- void createLink(char* id, int numlinks, Link** linkup, Link** linkdown);
+ void createLink(char* id, int numlinks, surf::LinkImpl** linkup, surf::LinkImpl** linkdown);
unsigned int* rankId_to_coords(int rankId);
private:
linkTemplate.policy = SURF_LINK_SHARED;
linkTemplate.id = bprintf("limiter_%d", id);
sg_platf_new_link(&linkTemplate);
- this->limiterLink = Link::byName(linkTemplate.id);
+ this->limiterLink = surf::LinkImpl::byName(linkTemplate.id);
free(const_cast<char*>(linkTemplate.id));
}
if (cluster->loopback_bw || cluster->loopback_lat) {
linkTemplate.policy = SURF_LINK_FATPIPE;
linkTemplate.id = bprintf("loopback_%d", id);
sg_platf_new_link(&linkTemplate);
- this->loopback = Link::byName(linkTemplate.id);
+ this->loopback = surf::LinkImpl::byName(linkTemplate.id);
free(const_cast<char*>(linkTemplate.id));
}
}
if (cluster->sharing_policy == SURF_LINK_FULLDUPLEX) {
std::string tmpID = std::string(linkTemplate.id) + "_UP";
- this->upLink = Link::byName(tmpID.c_str()); // check link?
+ this->upLink = surf::LinkImpl::byName(tmpID.c_str()); // check link?
tmpID = std::string(linkTemplate.id) + "_DOWN";
- this->downLink = Link::byName(tmpID.c_str()); // check link ?
+ this->downLink = surf::LinkImpl::byName(tmpID.c_str()); // check link ?
} else {
- this->upLink = Link::byName(linkTemplate.id);
+ this->upLink = surf::LinkImpl::byName(linkTemplate.id);
this->downLink = this->upLink;
}
free(const_cast<char*>(linkTemplate.id));
/** Virtual link standing for the node global capacity.
*/
- Link* limiterLink;
+ surf::LinkImpl* limiterLink;
/** If present, communications from this node to this node will pass through it
* instead of passing by an upper level switch.
*/
- Link* loopback;
+ surf::LinkImpl* loopback;
FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position);
};
public:
FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* source, FatTreeNode* destination);
/** Link going up in the tree */
- Link* upLink;
+ surf::LinkImpl* upLink;
/** Link going down in the tree */
- Link* downLink;
+ surf::LinkImpl* downLink;
/** Upper end of the link */
FatTreeNode* upNode;
/** Lower end of the link */
e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
e_route->gw_src = nullptr;
e_route->gw_dst = nullptr;
- e_route->link_list = new std::vector<Link*>();
+ e_route->link_list = new std::vector<surf::LinkImpl*>();
e_route->link_list->push_back(surf_network_model->loopback_);
TO_FLOYD_LINK(i, i) = e_route;
TO_FLOYD_PRED(i, i) = i;
e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
e_route->gw_src = nullptr;
e_route->gw_dst = nullptr;
- e_route->link_list = new std::vector<Link*>();
+ e_route->link_list = new std::vector<surf::LinkImpl*>();
e_route->link_list->push_back(surf_network_model->loopback_);
TO_ROUTE_FULL(i, i) = e_route;
}
explicit BypassRoute(NetPoint* gwSrc, NetPoint* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {}
const NetPoint* gw_src;
const NetPoint* gw_dst;
- std::vector<Link*> links;
+ std::vector<surf::LinkImpl*> links;
};
NetZoneImpl::NetZoneImpl(NetZone* father, const char* name) : NetZone(father, name)
continue;
sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
- route->link_list = new std::vector<Link*>();
+ route->link_list = new std::vector<surf::LinkImpl*>();
getLocalRoute(my_src, my_dst, route, nullptr);
sg_platf_route_cbarg_t result;
result = xbt_new0(s_sg_platf_route_cbarg_t, 1);
- result->link_list = new std::vector<Link*>();
+ result->link_list = new std::vector<surf::LinkImpl*>();
xbt_assert(hierarchy == RoutingMode::base || hierarchy == RoutingMode::recursive,
"The hierarchy of this netzone is neither BASIC nor RECURSIVE, I'm lost here.");
link.latency = cluster->lat;
link.policy = cluster->sharing_policy;
sg_platf_new_link(&link);
- Link* linkUp;
- Link* linkDown;
+ surf::LinkImpl* linkUp;
+ surf::LinkImpl* linkDown;
if (link.policy == SURF_LINK_FULLDUPLEX) {
char* tmp_link = bprintf("%s_UP", link_id);
- linkUp = Link::byName(tmp_link);
+ linkUp = surf::LinkImpl::byName(tmp_link);
free(tmp_link);
tmp_link = bprintf("%s_DOWN", link_id);
- linkDown = Link::byName(tmp_link);
+ linkDown = surf::LinkImpl::byName(tmp_link);
free(tmp_link);
} else {
- linkUp = Link::byName(link_id);
+ linkUp = surf::LinkImpl::byName(link_id);
linkDown = linkUp;
}
/*
return;
if (src->id() == dst->id() && hasLoopback_) {
- std::pair<Link*, Link*> info = privateLinks_.at(src->id() * linkCountPerNode_);
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id() * linkCountPerNode_);
route->link_list->push_back(info.first);
if (lat)
dim_product *= cur_dim;
}
- std::pair<Link*, Link*> info;
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info;
if (hasLimiter_) { // limiter for sender
info = privateLinks_.at(nodeOffset + hasLoopback_);
std::string link_up = "link_" + netpoint->name() + "_UP";
std::string link_down = "link_" + netpoint->name() + "_DOWN";
- Link* linkUp = surf_network_model->createLink(link_up.c_str(), bw_out, 0, SURF_LINK_SHARED);
- Link* linkDown = surf_network_model->createLink(link_down.c_str(), bw_in, 0, SURF_LINK_SHARED);
+ surf::LinkImpl* linkUp = surf_network_model->createLink(link_up.c_str(), bw_out, 0, SURF_LINK_SHARED);
+ surf::LinkImpl* linkDown = surf_network_model->createLink(link_down.c_str(), bw_in, 0, SURF_LINK_SHARED);
privateLinks_.insert({netpoint->id(), {linkUp, linkDown}});
}
/* Retrieve the private links */
if (privateLinks_.find(src->id()) != privateLinks_.end()) {
- std::pair<Link*, Link*> info = privateLinks_.at(src->id());
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
if (info.first) {
route->link_list->push_back(info.first);
if (lat)
}
}
if (privateLinks_.find(dst->id()) != privateLinks_.end()) {
- std::pair<Link*, Link*> info = privateLinks_.at(dst->id());
+ std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(dst->id());
if (info.second) {
route->link_list->push_back(info.second);
if (lat)
* by calling each "get_route" function in each routing component.
*/
void Host::routeTo(Host* dest, std::vector<Link*>* links, double* latency)
+{
+ std::vector<surf::LinkImpl*> linkImpls;
+ this->routeTo(dest, &linkImpls, latency);
+ for (surf::LinkImpl* l : linkImpls)
+ links->push_back(&l->piface_);
+}
+/** @brief Just like Host::routeTo, but filling an array of link implementations */
+void Host::routeTo(Host* dest, std::vector<surf::LinkImpl*>* links, double* latency)
{
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(pimpl_netpoint, dest->pimpl_netpoint, links, latency);
if (XBT_LOG_ISENABLED(surf_route, xbt_log_priority_debug)) {
--- /dev/null
+/* Copyright (c) 2013-2015. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <algorithm>
+
+#include "simgrid/s4u/link.hpp"
+#include "simgrid/sg_config.h"
+#include "simgrid/simix.hpp"
+#include "src/surf/network_interface.hpp"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links");
+
+/*********
+ * C API *
+ *********/
+
+extern "C" {
+
+const char* sg_link_name(Link* link)
+{
+ return link->name();
+}
+Link* sg_link_by_name(const char* name)
+{
+ return Link::byName(name);
+}
+
+int sg_link_is_shared(Link* link)
+{
+ return link->sharingPolicy();
+}
+double sg_link_bandwidth(Link* link)
+{
+ return link->bandwidth();
+}
+double sg_link_latency(Link* link)
+{
+ return link->latency();
+}
+void* sg_link_data(Link* link)
+{
+ return link->getData();
+}
+void sg_link_data_set(Link* link, void* data)
+{
+ link->setData(data);
+}
+int sg_link_count()
+{
+ return simgrid::surf::LinkImpl::linksCount();
+}
+Link** sg_link_list()
+{
+ simgrid::surf::LinkImpl** list = simgrid::surf::LinkImpl::linksList();
+ Link** res = (Link**)list; // Use the same memory area
+
+ int size = sg_link_count();
+ for (int i = 0; i < size; i++)
+ res[i] = &(list[i]->piface_); // Convert each entry into its interface
+
+ return res;
+}
+void sg_link_exit()
+{
+ simgrid::surf::LinkImpl::linksExit();
+}
+}
+
+/***********
+ * C++ API *
+ ***********/
+
+namespace simgrid {
+namespace s4u {
+Link* Link::byName(const char* name)
+{
+ surf::LinkImpl* res = surf::LinkImpl::byName(name);
+ if (res == nullptr)
+ return nullptr;
+ return &res->piface_;
+}
+const char* Link::name()
+{
+ return pimpl_->getName();
+}
+bool Link::isUsed()
+{
+ return pimpl_->isUsed();
+}
+
+double Link::latency()
+{
+ return pimpl_->latency();
+}
+
+double Link::bandwidth()
+{
+ return pimpl_->bandwidth();
+}
+
+int Link::sharingPolicy()
+{
+ return pimpl_->sharingPolicy();
+}
+
+void Link::turnOn()
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->turnOn();
+ });
+}
+void Link::turnOff()
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->turnOff();
+ });
+}
+
+void* Link::getData()
+{
+ return pimpl_->getData();
+}
+void Link::setData(void* d)
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->setData(d);
+ });
+}
+
+void Link::setStateTrace(tmgr_trace_t trace)
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->setStateTrace(trace);
+ });
+}
+void Link::setBandwidthTrace(tmgr_trace_t trace)
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->setBandwidthTrace(trace);
+ });
+}
+void Link::setLatencyTrace(tmgr_trace_t trace)
+{
+ simgrid::simix::kernelImmediate([&]() {
+ this->pimpl_->setLatencyTrace(trace);
+ });
+}
+}
+}
simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
- std::vector<Link*>* link_list)>
+ std::vector<surf::LinkImpl*>* link_list)>
NetZone::onRouteCreation;
NetZone::NetZone(NetZone* father, const char* name) : father_(father), name_(xbt_strdup(name))
surf_network_model = new simgrid::surf::NetworkIBModel();
all_existing_models->push_back(surf_network_model);
networkActionStateChangedCallbacks.connect(IB_action_state_changed_callback);
- Link::onCommunicate.connect(IB_action_init_callback);
+ simgrid::surf::LinkImpl::onCommunicate.connect(IB_action_init_callback);
simgrid::s4u::Host::onCreation.connect(IB_create_host_callback);
xbt_cfg_setdefault_double("network/weight-S", 8775);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf, "Logging specific to the SURF network module");
-/*********
- * C API *
- *********/
-
-extern "C" {
-
- const char* sg_link_name(Link *link) {
- return link->getName();
- }
- Link * sg_link_by_name(const char* name) {
- return Link::byName(name);
- }
-
- int sg_link_is_shared(Link *link){
- return link->sharingPolicy();
- }
- double sg_link_bandwidth(Link *link){
- return link->bandwidth();
- }
- double sg_link_latency(Link *link){
- return link->latency();
- }
- void* sg_link_data(Link *link) {
- return link->getData();
- }
- void sg_link_data_set(Link *link,void *data) {
- link->setData(data);
- }
- int sg_link_count() {
- return Link::linksCount();
- }
- Link** sg_link_list() {
- return Link::linksList();
- }
- void sg_link_exit() {
- Link::linksExit();
- }
-
-}
-
-/*****************
- * List of links *
- *****************/
-
namespace simgrid {
namespace surf {
+ /* List of links */
std::unordered_map<std::string, LinkImpl*>* LinkImpl::links = new std::unordered_map<std::string, LinkImpl*>();
+
LinkImpl* LinkImpl::byName(const char* name)
{
if (links->find(name) == links->end())
return nullptr;
return links->at(name);
- }
- /** @brief Returns the amount of links in the platform */
- int LinkImpl::linksCount()
- {
- return links->size();
+ }
+ /** @brief Returns the amount of links in the platform */
+ int LinkImpl::linksCount()
+ {
+ return links->size();
}
/** @brief Returns a list of all existing links */
LinkImpl** LinkImpl::linksList()
************/
LinkImpl::LinkImpl(simgrid::surf::NetworkModel* model, const char* name, lmm_constraint_t constraint)
- : Resource(model, name, constraint)
+ : Resource(model, name, constraint), piface_(Link(this))
{
+
if (strcmp(name,"__loopback__"))
xbt_assert(!LinkImpl::byName(name), "Link '%s' declared several times in the platform.", name);
#include "src/surf/PropertyHolder.hpp"
#include "simgrid/link.h"
+#include "simgrid/s4u/link.hpp"
/***********
* Classes *
bool currentlyDestroying_ = false;
public:
+ /** @brief Public interface */
+ s4u::Link piface_;
/** @brief Callback signal fired when a new Link is created */
static simgrid::xbt::signal<void(surf::LinkImpl*)> onCreation;
names.push_back(xbt_strdup(link->id));
}
for (auto link_name : names) {
- Link* l = surf_network_model->createLink(link_name, link->bandwidth, link->latency, link->policy);
+ simgrid::surf::LinkImpl* l =
+ surf_network_model->createLink(link_name, link->bandwidth, link->latency, link->policy);
if (link->properties) {
xbt_dict_cursor_t cursor = nullptr;
// other columns are to store one or more link for the node
//add a loopback link
- Link* linkUp = nullptr;
- Link* linkDown = nullptr;
+ simgrid::surf::LinkImpl* linkUp = nullptr;
+ simgrid::surf::LinkImpl* linkDown = nullptr;
if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
char *tmp_link = bprintf("%s_loopback", link_id);
XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->loopback_bw);
link.latency = cluster->loopback_lat;
link.policy = SURF_LINK_FATPIPE;
sg_platf_new_link(&link);
- linkUp = Link::byName(tmp_link);
- linkDown = Link::byName(tmp_link);
+ linkUp = simgrid::surf::LinkImpl::byName(tmp_link);
+ linkDown = simgrid::surf::LinkImpl::byName(tmp_link);
free(tmp_link);
auto as_cluster = static_cast<ClusterZone*>(current_as);
link.latency = 0;
link.policy = SURF_LINK_SHARED;
sg_platf_new_link(&link);
- linkUp = linkDown = Link::byName(tmp_link);
+ linkUp = linkDown = simgrid::surf::LinkImpl::byName(tmp_link);
free(tmp_link);
current_as->privateLinks_.insert(
{rankId * current_as->linkCountPerNode_ + current_as->hasLoopback_, {linkUp, linkDown}});
XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id, cluster->bb_bw, cluster->bb_lat);
sg_platf_new_link(&link);
- routing_cluster_add_backbone(Link::byName(link.id));
+ routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id));
free((char*)link.id);
}
xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
"Only hosts from Cluster and Vivaldi ASes can get an host_link.");
- simgrid::surf::LinkImpl* linkUp = Link::byName(hostlink->link_up);
- simgrid::surf::LinkImpl* linkDown = Link::byName(hostlink->link_down);
+ simgrid::surf::LinkImpl* linkUp = simgrid::surf::LinkImpl::byName(hostlink->link_up);
+ simgrid::surf::LinkImpl* linkDown = simgrid::surf::LinkImpl::byName(hostlink->link_down);
xbt_assert(linkUp, "Link '%s' not found!", hostlink->link_up);
xbt_assert(linkDown, "Link '%s' not found!", hostlink->link_down);
sg_netpoint_t dst;
sg_netpoint_t gw_src;
sg_netpoint_t gw_dst;
- std::vector<Link*> *link_list;
+ std::vector<simgrid::surf::LinkImpl*>* link_list;
} s_sg_platf_route_cbarg_t;
typedef struct s_sg_platf_cluster_cbarg *sg_platf_cluster_cbarg_t;
#define SG_PLATF_AS_INITIALIZER {nullptr,0}
/********** Routing **********/
-void routing_cluster_add_backbone(Link* bb);
+void routing_cluster_add_backbone(simgrid::surf::LinkImpl* bb);
/*** END of the parsing cruft ***/
XBT_PUBLIC(void) sg_platf_begin(); // Start a new platform
switch (A_surfxml_link___ctn_direction) {
case AU_surfxml_link___ctn_direction:
case A_surfxml_link___ctn_direction_NONE:
- link = Link::byName(A_surfxml_link___ctn_id);
+ link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
break;
case A_surfxml_link___ctn_direction_UP:
link_name = bprintf("%s_UP", A_surfxml_link___ctn_id);
- link = Link::byName(link_name);
+ link = simgrid::surf::LinkImpl::byName(link_name);
break;
case A_surfxml_link___ctn_direction_DOWN:
link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
- link = Link::byName(link_name);
+ link = simgrid::surf::LinkImpl::byName(link_name);
break;
}
xbt_free(link_name); // no-op if it's already nullptr
link.policy = SURF_LINK_SHARED;
sg_platf_new_link(&link);
- routing_cluster_add_backbone(sg_link_by_name(A_surfxml_backbone_id));
+ routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
}
void STag_surfxml_route(){
route.dst = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
route.gw_src = nullptr;
route.gw_dst = nullptr;
- route.link_list = new std::vector<Link*>();
+ route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
for (auto link: parsed_link_list)
ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___src); // tested to not be nullptr in start tag
ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_ASroute_gw___dst); // tested to not be nullptr in start tag
- ASroute.link_list = new std::vector<Link*>();
+ ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
for (auto link: parsed_link_list)
ASroute.link_list->push_back(link);
route.gw_src = nullptr;
route.gw_dst = nullptr;
route.symmetrical = false;
- route.link_list = new std::vector<Link*>();
+ route.link_list = new std::vector<simgrid::surf::LinkImpl*>();
for (auto link: parsed_link_list)
route.link_list->push_back(link);
ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_src);
ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_bypassASroute_dst);
- ASroute.link_list = new std::vector<Link*>();
+ ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
for (auto link: parsed_link_list)
ASroute.link_list->push_back(link);
parsed_link_list.clear();
simgrid::kernel::routing::NetPoint* netcardSrc = host1->pimpl_netpoint;
for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
simgrid::s4u::Host* host2 = hosts[it_dst];
- std::vector<Link*> route;
+ std::vector<simgrid::surf::LinkImpl*> route;
simgrid::kernel::routing::NetPoint* netcardDst = host2->pimpl_netpoint;
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(netcardSrc, netcardDst, &route, nullptr);
if (!route.empty()) {
for (auto netcardDst : netcardList) { // to router
if (netcardDst->isRouter()) {
std::printf(" <route src=\"%s\" dst=\"%s\">\n ", host1->cname(), netcardDst->cname());
- std::vector<Link*> route;
+ std::vector<simgrid::surf::LinkImpl*> route;
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(netcardSrc, netcardDst, &route, nullptr);
for (auto link : route)
std::printf("<link_ctn id=\"%s\"/>",link->getName());
for (auto value2 : netcardList) { // to router
if (value2->isRouter()) {
std::printf(" <route src=\"%s\" dst=\"%s\">\n ", value1->cname(), value2->cname());
- std::vector<Link*> route;
+ std::vector<simgrid::surf::LinkImpl*> route;
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, value2, &route, nullptr);
for (auto link : route)
std::printf("<link_ctn id=\"%s\"/>",link->getName());
for (unsigned int it_dst = 0; it_dst < totalHosts; it_dst++) { // Routes to host
simgrid::s4u::Host* host2 = hosts[it_dst];
std::printf(" <route src=\"%s\" dst=\"%s\">\n ", value1->cname(), host2->cname());
- std::vector<Link*> route;
+ std::vector<simgrid::surf::LinkImpl*> route;
simgrid::kernel::routing::NetPoint* netcardDst = host2->pimpl_netpoint;
simgrid::kernel::routing::NetZoneImpl::getGlobalRoute(value1, netcardDst, &route, nullptr);
for (auto link : route)
src/s4u/s4u_engine.cpp
src/s4u/s4u_file.cpp
src/s4u/s4u_host.cpp
+ src/s4u/s4u_link.cpp
src/s4u/s4u_mailbox.cpp
src/s4u/s4u_mutex.cpp
src/s4u/s4u_netzone.cpp
include/simgrid/s4u/engine.hpp
include/simgrid/s4u/file.hpp
include/simgrid/s4u/host.hpp
+ include/simgrid/s4u/link.hpp
include/simgrid/s4u/Mailbox.hpp
include/simgrid/s4u/Mutex.hpp
include/simgrid/s4u/NetZone.hpp