Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
db59a92e58a97e2ebdeead3a5c154c304e1d9bc7
[simgrid.git] / src / surf / platf_generator.c
1
2
3 #include "simgrid/platf_generator.h"
4 #include "platf_generator_private.h"
5 #include "xbt.h"
6 #include "xbt/RngStream.h"
7 #include "surf/simgrid_dtd.h"
8 #include "surf_private.h"
9 #include <math.h>
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(platf_generator, surf, "Platform Generator");
12
13 static xbt_graph_t platform_graph = NULL;
14 static xbt_dynar_t promoter_dynar = NULL;
15 static xbt_dynar_t labeler_dynar = NULL;
16
17 static RngStream rng_stream = NULL;
18
19 static unsigned long last_link_id = 0;
20
21 xbt_graph_t platf_graph_get(void) {
22   // We need some debug, so let's add this function
23   // WARNING : should be removed when it becomes useless
24   return platform_graph;
25 }
26
27 /**
28  * \brief Set the seed of the platform generator RngStream
29  *
30  * This RngStream is used to generate all the random values needed to
31  * generate the platform
32  *
33  * \param seed A array of six integer; if NULL, the default seed will be used.
34  */
35 void platf_random_seed(unsigned long seed[6]) {
36
37   if(rng_stream == NULL) {
38     //stream not created yet, we do it now
39     rng_stream = RngStream_CreateStream(NULL);
40   }
41   if(seed != NULL) {
42     RngStream_SetSeed(rng_stream, seed);
43   }
44 }
45
46 /**
47  * \brief Initialize the platform generator
48  *
49  * This function create the graph and add node_count nodes to it
50  * \param node_count The number of nodes of the platform
51  */
52 void platf_graph_init(unsigned long node_count) {
53   unsigned long i;
54   platform_graph = xbt_graph_new_graph(FALSE, NULL);
55   if(rng_stream == NULL) {
56     rng_stream = RngStream_CreateStream(NULL);
57   }
58
59   for(i=0 ; i<node_count ; i++) {
60     context_node_t node_data = NULL;
61     node_data = xbt_new0(s_context_node_t, 1);
62     node_data->id = i+1;
63     node_data->x = 0;
64     node_data->y = 0;
65     node_data->degree = 0;
66     node_data->kind = ROUTER;
67     node_data->connect_checked = FALSE;
68     xbt_graph_new_node(platform_graph, (void*) node_data);
69   }
70
71   last_link_id = 0;
72
73 }
74
75 /**
76  * \brief Connect two nodes
77  * \param node1 The first node to connect
78  * \param node2 The second node to connect
79  */
80 void platf_node_connect(xbt_node_t node1, xbt_node_t node2) {
81   context_node_t node1_data;
82   context_node_t node2_data;
83   node1_data = (context_node_t) xbt_graph_node_get_data(node1);
84   node2_data = (context_node_t) xbt_graph_node_get_data(node2);
85   node1_data->degree++;
86   node2_data->degree++;
87
88   context_edge_t edge_data = NULL;
89   edge_data = xbt_new0(s_context_edge_t, 1);
90   edge_data->id = ++last_link_id;
91   edge_data->length = platf_node_distance(node1, node2);
92   edge_data->labeled = FALSE;
93   xbt_graph_new_edge(platform_graph, node1, node2, (void*)edge_data);
94 }
95
96 /**
97  * \brief Compute the distance between two nodes
98  * \param node1 The first node
99  * \param node2 The second node
100  * \return The distance between node1 and node2
101  */
102 double platf_node_distance(xbt_node_t node1, xbt_node_t node2) {
103   context_node_t node1_data;
104   context_node_t node2_data;
105   double delta_x;
106   double delta_y;
107   double distance;
108   node1_data = (context_node_t) xbt_graph_node_get_data(node1);
109   node2_data = (context_node_t) xbt_graph_node_get_data(node2);
110   delta_x = node1_data->x - node2_data->x;
111   delta_y = node1_data->y - node2_data->y;
112   distance = sqrt(delta_x*delta_x + delta_y*delta_y);
113   return distance;
114 }
115
116 /**
117  * \brief Initialize the platform, placing nodes uniformly on the unit square
118  * \param node_count The number of node
119  */
120 void platf_graph_uniform(unsigned long node_count) {
121   xbt_dynar_t dynar_nodes = NULL;
122   xbt_node_t graph_node = NULL;
123   context_node_t node_data = NULL;
124   unsigned int i;
125   platf_graph_init(node_count);
126   dynar_nodes = xbt_graph_get_nodes(platform_graph);
127   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
128     node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
129     node_data->x = RngStream_RandU01(rng_stream);
130     node_data->y = RngStream_RandU01(rng_stream);
131   }
132 }
133
134 /**
135  * \brief Initialize the platform, placing nodes in little clusters on the unit square
136  * \param node_count The number of node
137  */
138 void platf_graph_heavytailed(unsigned long node_count) {
139   xbt_dynar_t dynar_nodes = NULL;
140   xbt_node_t graph_node = NULL;
141   context_node_t node_data = NULL;
142   unsigned int i;
143   platf_graph_init(node_count);
144   dynar_nodes = xbt_graph_get_nodes(platform_graph);
145   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
146     node_data = (context_node_t) xbt_graph_node_get_data(graph_node);
147     node_data->x = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
148     node_data->y = random_pareto(0, 1, 1.0/*K*/, 10e9/*P*/, 1.0/*alpha*/);
149   }
150 }
151
152 /**
153  * \brief Creates a simple topology where all nodes are connected to the first one in a star fashion
154  */
155 void platf_graph_interconnect_star(void) {
156   xbt_dynar_t dynar_nodes = NULL;
157   xbt_node_t graph_node = NULL;
158   xbt_node_t first_node = NULL;
159   unsigned int i;
160
161   dynar_nodes = xbt_graph_get_nodes(platform_graph);
162   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
163     if(i==0) {
164       //Ok, we get the first node, let's keep it somewhere...
165       first_node = graph_node;
166     } else {
167       //All the other nodes are connected to the first one
168       platf_node_connect(graph_node, first_node);
169     }
170   }
171 }
172
173 /**
174  * \brief Creates a simple topology where all nodes are connected in line
175  */
176 void platf_graph_interconnect_line(void) {
177   xbt_dynar_t dynar_nodes = NULL;
178   xbt_node_t graph_node = NULL;
179   xbt_node_t old_node = NULL;
180   unsigned int i;
181
182   dynar_nodes = xbt_graph_get_nodes(platform_graph);
183   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
184     if(old_node != NULL) {
185       platf_node_connect(graph_node, old_node);
186     }
187     old_node = graph_node;
188   }
189 }
190
191 /**
192  * \brief Create a simple topology where all nodes are connected along a ring
193  */
194 void platf_graph_interconnect_ring(void) {
195   xbt_dynar_t dynar_nodes = NULL;
196   xbt_node_t graph_node = NULL;
197   xbt_node_t old_node = NULL;
198   xbt_node_t first_node = NULL;
199   unsigned int i;
200
201   dynar_nodes = xbt_graph_get_nodes(platform_graph);
202   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
203     if(i == 0) {
204       // this is the first node, let's keep it somewhere
205       first_node = graph_node;
206     } else {
207       //connect each node to the previous one
208       platf_node_connect(graph_node, old_node);
209     }
210     old_node = graph_node;
211   }
212   //we still have to connect the first and the last node together
213   platf_node_connect(first_node, graph_node);
214 }
215
216 /**
217  * \brief Create a simple topology where all nodes are connected to each other, in a clique manner
218  */
219 void platf_graph_interconnect_clique(void) {
220   xbt_dynar_t dynar_nodes = NULL;
221   xbt_node_t first_node = NULL;
222   xbt_node_t second_node = NULL;
223   unsigned int i,j;
224
225   dynar_nodes = xbt_graph_get_nodes(platform_graph);
226   xbt_dynar_foreach(dynar_nodes, i, first_node) {
227     xbt_dynar_foreach(dynar_nodes, j, second_node) {
228       if(j>=i)
229         break;
230       platf_node_connect(first_node, second_node);
231     }
232   }
233 }
234
235 /**
236  * \brief Creates a topology where the probability to connect two nodes is uniform (unrealistic, but simple)
237  * \param alpha Probability for two nodes to get connected
238  */
239 void platf_graph_interconnect_uniform(double alpha) {
240   xbt_dynar_t dynar_nodes = NULL;
241   xbt_node_t first_node = NULL;
242   xbt_node_t second_node = NULL;
243   unsigned int i,j;
244
245   dynar_nodes = xbt_graph_get_nodes(platform_graph);
246   xbt_dynar_foreach(dynar_nodes, i, first_node) {
247     xbt_dynar_foreach(dynar_nodes, j, second_node) {
248       if(j>=i)
249         break;
250       if(RngStream_RandU01(rng_stream) < alpha) {
251         platf_node_connect(first_node, second_node);
252       }
253     }
254   }
255 }
256
257 /**
258  * \brief Create a topology where the probability follows an exponential law
259  * \param alpha Number of edges increases with alpha
260  */
261 void platf_graph_interconnect_exponential(double alpha) {
262   xbt_dynar_t dynar_nodes = NULL;
263   xbt_node_t first_node = NULL;
264   xbt_node_t second_node = NULL;
265   unsigned int i,j;
266   double L = sqrt(2.0); /*  L = c*sqrt(2); c=side of placement square */
267   dynar_nodes = xbt_graph_get_nodes(platform_graph);
268   xbt_dynar_foreach(dynar_nodes, i, first_node) {
269     xbt_dynar_foreach(dynar_nodes, j, second_node) {
270       if(j>=i)
271         break;
272       double d = platf_node_distance(first_node, second_node);
273       if(RngStream_RandU01(rng_stream) < alpha*exp(-d/(L-d))) {
274         platf_node_connect(first_node, second_node);
275       }
276     }
277   }
278 }
279
280 /**
281  * \brief Create a topology where the probability follows the model of Waxman
282  *
283  * see Waxman, Routing of Multipoint Connections, IEEE J. on Selected Areas in Comm., 1988
284  *
285  * \param alpha Number of edges increases with alpha
286  * \param beta Edge length heterogeneity increases with beta
287  */
288 void platf_graph_interconnect_waxman(double alpha, double beta) {
289   xbt_dynar_t dynar_nodes = NULL;
290   xbt_node_t first_node = NULL;
291   xbt_node_t second_node = NULL;
292   unsigned int i,j;
293   double L = sqrt(2.0); /*  L = c*sqrt(2); c=side of placement square */
294   dynar_nodes = xbt_graph_get_nodes(platform_graph);
295   xbt_dynar_foreach(dynar_nodes, i, first_node) {
296     xbt_dynar_foreach(dynar_nodes, j, second_node) {
297       if(j>=i)
298         break;
299       double d = platf_node_distance(first_node, second_node);
300       if(RngStream_RandU01(rng_stream) < alpha*exp(-d/(L*beta))) {
301         platf_node_connect(first_node, second_node);
302       }
303     }
304   }
305 }
306
307 /**
308  * \brief Create a topology where the probability follows the model of Zegura
309  * see Zegura, Calvert, Donahoo, A quantitative comparison of graph-based models
310  * for Internet topology, IEEE/ACM Transactions on Networking, 1997.
311  *
312  * \param alpha Probability of connexion for short edges
313  * \param beta Probability of connexion for long edges
314  * \param r Limit between long and short edges (between 0 and sqrt(2) since nodes are placed on the unit square)
315  */
316 void platf_graph_interconnect_zegura(double alpha, double beta, double r) {
317   xbt_dynar_t dynar_nodes = NULL;
318   xbt_node_t first_node = NULL;
319   xbt_node_t second_node = NULL;
320   unsigned int i,j;
321   dynar_nodes = xbt_graph_get_nodes(platform_graph);
322   xbt_dynar_foreach(dynar_nodes, i, first_node) {
323     xbt_dynar_foreach(dynar_nodes, j, second_node) {
324       if(j>=i)
325         break;
326       double d = platf_node_distance(first_node, second_node);
327       double proba = d < r ? alpha : beta;
328       if(RngStream_RandU01(rng_stream) < proba) {
329         platf_node_connect(first_node, second_node);
330       }
331     }
332   }
333 }
334
335 /**
336  * \brief Create a topology constructed according to the Barabasi-Albert algorithm (follows power laws)
337  * see Barabasi and Albert, Emergence of scaling in random networks, Science 1999, num 59, p509­-512.
338  */
339 void platf_graph_interconnect_barabasi(void) {
340   xbt_dynar_t dynar_nodes = NULL;
341   xbt_node_t first_node = NULL;
342   xbt_node_t second_node = NULL;
343   context_node_t node_data = NULL;
344   unsigned int i,j;
345   unsigned long sum = 0;
346   dynar_nodes = xbt_graph_get_nodes(platform_graph);
347   xbt_dynar_foreach(dynar_nodes, i, first_node) {
348     xbt_dynar_foreach(dynar_nodes, j, second_node) {
349       if(j>=i)
350         break;
351       node_data = xbt_graph_node_get_data(second_node);
352       if(sum==0 || RngStream_RandU01(rng_stream) < ((double)(node_data->degree)/ (double)sum)) {
353         platf_node_connect(first_node, second_node);
354         sum += 2;
355       }
356     }
357   }
358 }
359
360 /**
361  * \brief Check if the produced graph is connected
362  *
363  * You should check if the produced graph is connected before doing anything
364  * on it. You probably don't want any isolated node or group of nodes...
365  *
366  * \return TRUE if the graph is connected, FALSE otherwise
367  */
368 int platf_graph_is_connected(void) {
369   xbt_dynar_t dynar_nodes = NULL;
370   xbt_dynar_t connected_nodes = NULL;
371   xbt_dynar_t outgoing_edges = NULL;
372   xbt_node_t graph_node = NULL;
373   context_node_t node_data = NULL;
374   xbt_edge_t outedge = NULL;
375   unsigned long iterator;
376   unsigned int i;
377   dynar_nodes = xbt_graph_get_nodes(platform_graph);
378   connected_nodes = xbt_dynar_new(sizeof(xbt_node_t), NULL);
379
380   //Let's just check if every nodes are connected to something
381   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
382     node_data = xbt_graph_node_get_data(graph_node);
383     if(node_data->degree==0) {
384       return FALSE;
385     }
386   }
387
388   //We still need a real check
389   //Initialize the connected node array with the first node
390   xbt_dynar_get_cpy(dynar_nodes, 0, &graph_node);
391   node_data = xbt_graph_node_get_data(graph_node);
392   node_data->connect_checked = TRUE;
393   xbt_dynar_push(connected_nodes, &graph_node);
394   iterator = 0;
395   do {
396     //Get the next node
397     xbt_dynar_get_cpy(connected_nodes, iterator, &graph_node);
398     node_data = xbt_graph_node_get_data(graph_node);
399
400     //add all the linked nodes to the connected node array
401     outgoing_edges = xbt_graph_node_get_outedges(graph_node);
402     xbt_dynar_foreach(outgoing_edges, i, outedge) {
403       xbt_node_t src = xbt_graph_edge_get_source(outedge);
404       xbt_node_t dst = xbt_graph_edge_get_target(outedge);
405       node_data = xbt_graph_node_get_data(src);
406       if(!node_data->connect_checked) {
407         xbt_dynar_push(connected_nodes, &src);
408         node_data->connect_checked = TRUE;
409       }
410       node_data = xbt_graph_node_get_data(dst);
411       if(!node_data->connect_checked) {
412         xbt_dynar_push(connected_nodes, &dst);
413         node_data->connect_checked = TRUE;
414       }
415     }
416   } while(++iterator < xbt_dynar_length(connected_nodes));
417
418   // The graph is connected if the connected node array has the same length
419   // as the graph node array
420   return xbt_dynar_length(connected_nodes) == xbt_dynar_length(dynar_nodes);
421 }
422
423
424 /**
425  * \brief Remove the links in the created topology
426  *
427  * This is useful when the created topology is not connected, and you want
428  * to generate a new one.
429  */
430 void platf_graph_clear_links(void) {
431   xbt_dynar_t dynar_nodes = NULL;
432   xbt_dynar_t dynar_edges = NULL;
433   xbt_node_t graph_node = NULL;
434   xbt_edge_t graph_edge = NULL;
435   context_node_t node_data = NULL;
436   unsigned int i;
437
438   //Delete edges from the graph
439   dynar_edges = xbt_graph_get_edges(platform_graph);
440   xbt_dynar_foreach(dynar_edges, i, graph_edge) {
441     xbt_graph_free_edge(platform_graph, graph_edge, xbt_free);
442   }
443
444   //All the nodes will be of degree 0, unchecked from connectedness
445   dynar_nodes = xbt_graph_get_nodes(platform_graph);
446   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
447     node_data = xbt_graph_node_get_data(graph_node);
448     node_data->degree = 0;
449     node_data->connect_checked = FALSE;
450   }
451 }
452
453 /**
454  * \brief Promote a node to a host
455  *
456  * This function should be called in callbacks registered with the
457  * platf_graph_promoter function.
458  *
459  * \param node The node to promote
460  * \param parameters The parameters needed to build the host
461  */
462 void platf_graph_promote_to_host(context_node_t node, sg_platf_host_cbarg_t parameters) {
463   node->kind = HOST;
464   memcpy(&(node->host_parameters), parameters, sizeof(s_sg_platf_host_cbarg_t));
465 }
466
467 /**
468  * \brief Promote a node to a cluster
469  *
470  * This function should be called in callbacks registered with the
471  * platf_graph_promoter function.
472  *
473  * \param node The node to promote
474  * \param parameters The parameters needed to build the cluster
475  */
476 void platf_graph_promote_to_cluster(context_node_t node, sg_platf_cluster_cbarg_t parameters) {
477   node->kind = CLUSTER;
478   memcpy(&(node->cluster_parameters), parameters, sizeof(s_sg_platf_cluster_cbarg_t));
479 }
480
481 /**
482  * \brief Set the parameters of a network link.
483  *
484  * This function should be called in callbacks registered with the
485  * platf_graph_labeler function.
486  *
487  * \param edge The edge to modify
488  * \param parameters The parameters of the network link
489  */
490 void platf_graph_link_label(context_edge_t edge, sg_platf_link_cbarg_t parameters) {
491   memcpy(&(edge->link_parameters), parameters, sizeof(s_sg_platf_link_cbarg_t));
492   edge->labeled = TRUE;
493 }
494
495 /**
496  * \brief Register a callback to promote nodes
497  *
498  * The best way to promote nodes into host or cluster is to write a function
499  * which takes one parameter, a #context_node_t, make every needed test on
500  * it, and call platf_graph_promote_to_host or platf_graph_promote_to_cluster
501  * if needed. Then, register the function with this one.
502  * You can register several callbacks: the first registered function will be
503  * called first. If the node have not been promoted yet, the second function
504  * will be called, and so on...
505  *
506  * \param promoter_callback The callback function
507  */
508 void platf_graph_promoter(platf_promoter_cb_t promoter_callback) {
509   if(promoter_dynar == NULL) {
510     promoter_dynar = xbt_dynar_new(sizeof(platf_promoter_cb_t), NULL);
511   }
512   xbt_dynar_push(promoter_dynar, &promoter_callback);
513 }
514
515 /**
516  * \brief Register a callback to label links
517  *
518  * Like the node promotion, it is better, to set links, to write a function
519  * which take one parameter, a #context_edge_t, make every needed test on
520  * it, and call platf_graph_link_label if needed.
521  * You can register several callbacks: the first registered function will be
522  * called first. If the link have not been labeled yet, the second function
523  * will be called, and so on... All the links must have been labeled after
524  * all the calls.
525  *
526  * \param labeler_callback The callback function
527  */
528 void platf_graph_labeler(platf_labeler_cb_t labeler_callback) {
529   if(labeler_dynar == NULL) {
530     labeler_dynar = xbt_dynar_new(sizeof(void*), NULL);
531   }
532   xbt_dynar_push(labeler_dynar, &labeler_callback);
533 }
534
535 /**
536  * \brief Call the registered promoters on all nodes
537  *
538  * The promoters are called on all nodes, in the order of their registration
539  * If some nodes are not promoted, they will be routers
540  */
541 void platf_do_promote(void) {
542   platf_promoter_cb_t promoter_callback;
543   xbt_node_t graph_node = NULL;
544   xbt_dynar_t dynar_nodes = NULL;
545   context_node_t node = NULL;
546   unsigned int i, j;
547   dynar_nodes = xbt_graph_get_nodes(platform_graph);
548   xbt_dynar_foreach(dynar_nodes, i, graph_node) {
549     node = (context_node_t) xbt_graph_node_get_data(graph_node);
550     xbt_dynar_foreach(promoter_dynar, j, promoter_callback) {
551       if(node->kind != ROUTER)
552         break;
553       promoter_callback(node);
554     }
555   }
556 }
557
558 /**
559  * \brief Call the registered labelers on all links
560  */
561 void platf_do_label(void) {
562   platf_labeler_cb_t labeler_callback;
563   xbt_edge_t graph_edge = NULL;
564   xbt_dynar_t dynar_edges = NULL;
565   context_edge_t edge = NULL;
566   unsigned int i, j;
567   dynar_edges = xbt_graph_get_edges(platform_graph);
568   xbt_dynar_foreach(dynar_edges, i, graph_edge) {
569     edge = (context_edge_t) xbt_graph_edge_get_data(graph_edge);
570     xbt_dynar_foreach(labeler_dynar, j, labeler_callback) {
571       if(edge->labeled)
572         break;
573       labeler_callback(edge);
574     }
575     if(!edge->labeled) {
576       XBT_ERROR("All links of the generated platform are not labeled.");
577       xbt_die("Please check your generation parameters.");
578     }
579   }
580 }
581
582 /**
583  * \brief putting into SURF the generated platform
584  *
585  * This function should be called when the generation is over and the platform
586  * is ready to be put in place in SURF. All the init function, like MSG_init,
587  * must have been called before, or this function will not do anything.
588  * After that function, it should be possible to list all the available hosts
589  * with the provided functions.
590  */
591 void platf_generate(void) {
592
593   xbt_dynar_t nodes = NULL;
594   xbt_node_t graph_node = NULL;
595   context_node_t node_data = NULL;
596   xbt_dynar_t edges = NULL;
597   xbt_edge_t graph_edge = NULL;
598   context_edge_t edge_data = NULL;
599   unsigned int i;
600
601   unsigned int last_host = 0;
602   unsigned int last_router = 0;
603   unsigned int last_cluster = 0;
604
605   sg_platf_host_cbarg_t host_parameters;
606   sg_platf_cluster_cbarg_t cluster_parameters;
607   sg_platf_link_cbarg_t link_parameters;
608   s_sg_platf_router_cbarg_t router_parameters; /* This one is not a pointer! */
609   s_sg_platf_route_cbarg_t route_parameters; /* neither this one! */
610
611   router_parameters.coord = NULL;
612   route_parameters.symmetrical = FALSE;
613   route_parameters.src = NULL;
614   route_parameters.dst = NULL;
615   route_parameters.gw_dst = NULL;
616   route_parameters.gw_src = NULL;
617   route_parameters.link_list = NULL;
618
619   nodes = xbt_graph_get_nodes(platform_graph);
620   edges = xbt_graph_get_edges(platform_graph);
621
622   sg_platf_begin();
623   surf_parse_init_callbacks();
624   routing_register_callbacks();
625
626
627   sg_platf_new_AS_begin("random platform", A_surfxml_AS_routing_Floyd);
628
629   //Generate hosts, clusters and routers
630   xbt_dynar_foreach(nodes, i, graph_node) {
631     node_data = xbt_graph_node_get_data(graph_node);
632     switch(node_data->kind) {
633       case HOST:
634         host_parameters = &node_data->host_parameters;
635         last_host++;
636         if(host_parameters->id == NULL) {
637           host_parameters->id = bprintf("host-%d", last_host);
638         }
639         sg_platf_new_host(host_parameters);
640         break;
641       case CLUSTER:
642         cluster_parameters = &node_data->cluster_parameters;
643         last_cluster++;
644         if(cluster_parameters->prefix == NULL) {
645           cluster_parameters->prefix = "host-";
646         }
647         if(cluster_parameters->suffix == NULL) {
648           cluster_parameters->suffix = bprintf(".cluster-%d", last_cluster);
649         }
650         if(cluster_parameters->id == NULL) {
651           cluster_parameters->id = bprintf("cluster-%d", last_cluster);
652         }
653         sg_platf_new_cluster(cluster_parameters);
654         break;
655       case ROUTER:
656         node_data->router_id = bprintf("router-%d", ++last_router);
657         router_parameters.id = node_data->router_id;
658         sg_platf_new_router(&router_parameters);
659     }
660   }
661
662   //Generate links and routes
663   xbt_dynar_foreach(edges, i, graph_edge) {
664     xbt_node_t src = xbt_graph_edge_get_source(graph_edge);
665     xbt_node_t dst = xbt_graph_edge_get_target(graph_edge);
666     context_node_t src_data = xbt_graph_node_get_data(src);
667     context_node_t dst_data = xbt_graph_node_get_data(dst);
668     edge_data = xbt_graph_edge_get_data(graph_edge);
669     const char* temp = NULL;
670
671     //Add a link to the platform
672     link_parameters = &edge_data->link_parameters;
673     if(link_parameters->id == NULL) {
674       link_parameters->id = bprintf("link-%ld", edge_data->id);
675     }
676     sg_platf_new_link(link_parameters);
677
678     //Add a route matching this link
679     switch(src_data->kind) {
680       case ROUTER:
681         route_parameters.src = src_data->router_id;
682         break;
683       case CLUSTER:
684         route_parameters.src = src_data->cluster_parameters.id;
685         break;
686       case HOST:
687         route_parameters.src = src_data->host_parameters.id;
688     }
689     switch(dst_data->kind) {
690       case ROUTER:
691         route_parameters.dst = dst_data->router_id;
692         break;
693       case CLUSTER:
694         route_parameters.dst = dst_data->cluster_parameters.id;
695         break;
696       case HOST:
697         route_parameters.dst = dst_data->host_parameters.id;
698     }
699     sg_platf_route_begin(&route_parameters);
700     sg_platf_route_add_link(link_parameters->id, &route_parameters);
701     sg_platf_route_end(&route_parameters);
702
703     //Create the symmertical route
704     temp = route_parameters.dst;
705     route_parameters.dst = route_parameters.src;
706     route_parameters.src = temp;
707     sg_platf_route_begin(&route_parameters);
708     sg_platf_route_add_link(link_parameters->id, &route_parameters);
709     sg_platf_route_end(&route_parameters);
710   }
711
712   sg_platf_new_AS_end();
713   sg_platf_end();
714 }
715
716 /* Functions used to generate interesting random values */
717
718 double random_pareto(double min, double max, double K, double P, double ALPHA) {
719   double x = RngStream_RandU01(rng_stream);
720   double den = pow(1.0 - x + x*pow(K/P, ALPHA), 1.0/ALPHA);
721   double res = (1/den);
722   res += min - 1; // pareto is on [1, infinity) by default
723   if (res>max) {
724     return max;
725   }
726   return res;
727 }