+ if(!edge->labeled) {
+ XBT_ERROR("All links of the generated platform are not labeled.");
+ xbt_die("Please check your generation parameters.");
+ }
+ }
+}
+
+/**
+ * \brief putting into SURF the generated platform
+ *
+ * This function should be called when the generation is over and the platform
+ * is ready to be put in place in SURF. All the init function, like MSG_init,
+ * must have been called before, or this function will not do anything.
+ * After that function, it should be possible to list all the available hosts
+ * with the provided functions.
+ */
+void platf_generate(void) {
+
+ xbt_dynar_t nodes = NULL;
+ xbt_node_t graph_node = NULL;
+ context_node_t node_data = NULL;
+ xbt_dynar_t edges = NULL;
+ xbt_edge_t graph_edge = NULL;
+ context_edge_t edge_data = NULL;
+ unsigned int i;
+
+ unsigned int last_host = 0;
+ unsigned int last_router = 0;
+ unsigned int last_cluster = 0;
+
+ sg_platf_host_cbarg_t host_parameters;
+ sg_platf_cluster_cbarg_t cluster_parameters;
+ sg_platf_link_cbarg_t link_parameters;
+ s_sg_platf_router_cbarg_t router_parameters; /* This one is not a pointer! */
+ s_sg_platf_route_cbarg_t route_parameters; /* neither this one! */
+
+ router_parameters.coord = NULL;
+ route_parameters.symmetrical = FALSE;
+ route_parameters.src = NULL;
+ route_parameters.dst = NULL;
+ route_parameters.gw_dst = NULL;
+ route_parameters.gw_src = NULL;
+ route_parameters.link_list = NULL;
+
+ nodes = xbt_graph_get_nodes(platform_graph);
+ edges = xbt_graph_get_edges(platform_graph);
+
+ sg_platf_begin();
+ surf_parse_init_callbacks();
+ routing_register_callbacks();
+
+ s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
+ AS.id = "random platform";
+ AS.routing = A_surfxml_AS_routing_Floyd;
+ sg_platf_new_AS_begin(&AS);
+
+ //Generate hosts, clusters and routers
+ xbt_dynar_foreach(nodes, i, graph_node) {
+ node_data = xbt_graph_node_get_data(graph_node);
+ switch(node_data->kind) {
+ case HOST:
+ host_parameters = &node_data->host_parameters;
+ last_host++;
+ if(host_parameters->id == NULL) {
+ host_parameters->id = bprintf("host-%d", last_host);
+ }
+ sg_platf_new_host(host_parameters);
+ break;
+ case CLUSTER:
+ cluster_parameters = &node_data->cluster_parameters;
+ last_cluster++;
+ if(cluster_parameters->prefix == NULL) {
+ cluster_parameters->prefix = "host-";
+ }
+ if(cluster_parameters->suffix == NULL) {
+ cluster_parameters->suffix = bprintf(".cluster-%d", last_cluster);
+ }
+ if(cluster_parameters->id == NULL) {
+ cluster_parameters->id = bprintf("cluster-%d", last_cluster);
+ }
+ sg_platf_new_cluster(cluster_parameters);
+ break;
+ case ROUTER:
+ node_data->router_id = bprintf("router-%d", ++last_router);
+ router_parameters.id = node_data->router_id;
+ sg_platf_new_router(&router_parameters);
+ break;
+ }
+ }
+
+ //Generate links and routes
+ xbt_dynar_foreach(edges, i, graph_edge) {
+ xbt_node_t src = xbt_graph_edge_get_source(graph_edge);
+ xbt_node_t dst = xbt_graph_edge_get_target(graph_edge);
+ context_node_t src_data = xbt_graph_node_get_data(src);
+ context_node_t dst_data = xbt_graph_node_get_data(dst);
+ edge_data = xbt_graph_edge_get_data(graph_edge);
+ const char* temp = NULL;
+
+ //Add a link to the platform
+ link_parameters = &edge_data->link_parameters;
+ if(link_parameters->id == NULL) {
+ link_parameters->id = bprintf("link-%ld", edge_data->id);
+ }
+ sg_platf_new_link(link_parameters);
+
+ //Add a route matching this link
+ switch(src_data->kind) {
+ case ROUTER:
+ route_parameters.src = src_data->router_id;
+ break;
+ case CLUSTER:
+ route_parameters.src = src_data->cluster_parameters.id;
+ break;
+ case HOST:
+ route_parameters.src = src_data->host_parameters.id;
+ break;
+ }
+ switch(dst_data->kind) {
+ case ROUTER:
+ route_parameters.dst = dst_data->router_id;
+ break;
+ case CLUSTER:
+ route_parameters.dst = dst_data->cluster_parameters.id;
+ break;
+ case HOST:
+ route_parameters.dst = dst_data->host_parameters.id;
+ break;
+ }
+ sg_platf_route_begin(&route_parameters);
+ sg_platf_route_add_link(link_parameters->id, &route_parameters);
+ sg_platf_route_end(&route_parameters);
+
+ //Create the symmertical route
+ temp = route_parameters.dst;
+ route_parameters.dst = route_parameters.src;
+ route_parameters.src = temp;
+ sg_platf_route_begin(&route_parameters);
+ sg_platf_route_add_link(link_parameters->id, &route_parameters);
+ sg_platf_route_end(&route_parameters);