+
+ if(cluster->limiter_link!=0){
+ current_as->linkCountPerNode_++;
+ current_as->hasLimiter_ = 1;
+ }
+
+ for (int i : *cluster->radicals) {
+ char * host_id = bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
+ char * link_id = bprintf("%s_link_%d", cluster->id, i);
+
+ XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, cluster->speed);
+
+ s_sg_platf_host_cbarg_t host;
+ memset(&host, 0, sizeof(host));
+ host.id = host_id;
+ if ((cluster->properties != nullptr) && (!xbt_dict_is_empty(cluster->properties))) {
+ xbt_dict_cursor_t cursor=nullptr;
+ char *key,*data;
+ host.properties = xbt_dict_new_homogeneous(free);
+
+ xbt_dict_foreach(cluster->properties,cursor,key,data) {
+ xbt_dict_set(host.properties, key, xbt_strdup(data), nullptr);
+ }
+ }
+
+ host.speed_per_pstate.push_back(cluster->speed);
+ host.pstate = 0;
+ host.core_amount = cluster->core_amount;
+ host.coord = "";
+ sg_platf_new_host(&host);
+ XBT_DEBUG("</host>");
+
+ XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id, cluster->bw, cluster->lat);
+
+ s_surf_parsing_link_up_down_t info_lim;
+ s_surf_parsing_link_up_down_t info_loop;
+ // All links are saved in a matrix;
+ // every row describes a single node; every node may have multiple links.
+ // the first column may store a link from x to x if p_has_loopback is set
+ // the second column may store a limiter link if p_has_limiter is set
+ // other columns are to store one or more link for the node
+
+ //add a loopback link
+ 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);
+
+ memset(&link, 0, sizeof(link));
+ link.id = tmp_link;
+ link.bandwidth = cluster->loopback_bw;
+ link.latency = cluster->loopback_lat;
+ link.policy = SURF_LINK_FATPIPE;
+ sg_platf_new_link(&link);
+ info_loop.linkUp = Link::byName(tmp_link);
+ info_loop.linkDown = Link::byName(tmp_link);
+ free(tmp_link);
+
+ auto as_cluster = static_cast<AsCluster*>(current_as);
+ as_cluster->privateLinks_.insert({rankId*as_cluster->linkCountPerNode_, info_loop});
+ }
+
+ //add a limiter link (shared link to account for maximal bandwidth of the node)
+ if(cluster->limiter_link!=0){
+ char *tmp_link = bprintf("%s_limiter", link_id);
+ XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->limiter_link);
+
+ memset(&link, 0, sizeof(link));
+ link.id = tmp_link;
+ link.bandwidth = cluster->limiter_link;
+ link.latency = 0;
+ link.policy = SURF_LINK_SHARED;
+ sg_platf_new_link(&link);
+ info_lim.linkUp = info_lim.linkDown = Link::byName(tmp_link);
+ free(tmp_link);
+ current_as->privateLinks_.insert(
+ {rankId * current_as->linkCountPerNode_ + current_as->hasLoopback_ , info_lim});
+ }
+
+ //call the cluster function that adds the others links
+ if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
+ static_cast<AsClusterFatTree*>(current_as)->addProcessingNode(i);
+ }
+ else {
+ current_as->create_links_for_node(cluster, i, rankId,
+ rankId*current_as->linkCountPerNode_ + current_as->hasLoopback_ + current_as->hasLimiter_ );
+ }
+ xbt_free(link_id);
+ xbt_free(host_id);
+ rankId++;
+ }
+
+ // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
+ // and it's very useful to connect clusters together
+ XBT_DEBUG(" ");
+ XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
+ char *newid = nullptr;
+ s_sg_platf_router_cbarg_t router;
+ memset(&router, 0, sizeof(router));
+ router.id = cluster->router_id;
+ if (!router.id || !strcmp(router.id, ""))
+ router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
+ sg_platf_new_router(&router);
+ current_as->router_ = (simgrid::kernel::routing::NetCard*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
+ free(newid);
+
+ //Make the backbone
+ if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
+
+ memset(&link, 0, sizeof(link));
+ link.id = bprintf("%s_backbone", cluster->id);
+ link.bandwidth = cluster->bb_bw;
+ link.latency = cluster->bb_lat;
+ link.policy = cluster->bb_sharing_policy;
+
+ 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));
+ free((char*)link.id);
+ }
+
+ XBT_DEBUG("</AS>");
+ sg_platf_new_AS_seal();
+
+ simgrid::surf::on_cluster(cluster);
+ delete cluster->radicals;
+}
+void routing_cluster_add_backbone(simgrid::surf::Link* bb) {
+ simgrid::kernel::routing::AsCluster *cluster = dynamic_cast<simgrid::kernel::routing::AsCluster*>(current_routing);
+
+ xbt_assert(cluster, "Only hosts from Cluster can get a backbone.");
+ xbt_assert(nullptr == cluster->backbone_, "Cluster %s already has a backbone link!", cluster->name());
+
+ cluster->backbone_ = bb;
+ XBT_DEBUG("Add a backbone to AS '%s'", current_routing->name());
+}
+
+void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
+{
+ for (int radical : *cabinet->radicals) {
+ char *hostname = bprintf("%s%d%s", cabinet->prefix, radical, cabinet->suffix);
+ s_sg_platf_host_cbarg_t host;
+ memset(&host, 0, sizeof(host));
+ host.pstate = 0;
+ host.core_amount = 1;
+ host.id = hostname;
+ host.speed_per_pstate.push_back(cabinet->speed);
+ sg_platf_new_host(&host);
+
+ s_sg_platf_link_cbarg_t link;
+ memset(&link, 0, sizeof(link));
+ link.policy = SURF_LINK_FULLDUPLEX;
+ link.latency = cabinet->lat;
+ link.bandwidth = cabinet->bw;
+ link.id = bprintf("link_%s",hostname);
+ sg_platf_new_link(&link);
+ free((char*)link.id);
+
+ s_sg_platf_host_link_cbarg_t host_link;
+ memset(&host_link, 0, sizeof(host_link));
+ host_link.id = hostname;
+ host_link.link_up = bprintf("link_%s_UP",hostname);
+ host_link.link_down = bprintf("link_%s_DOWN",hostname);
+ sg_platf_new_hostlink(&host_link);
+ free((char*)host_link.link_up);
+ free((char*)host_link.link_down);
+
+ free(hostname);
+ }
+ delete cabinet->radicals;