Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Storage parsing skip empty line
[simgrid.git] / src / surf / instr_routing.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "instr/instr_private.h"
8 #include "mc/mc.h"
9
10 #ifdef HAVE_TRACING
11 #include "surf/surf_private.h"
12 #include "surf/network_private.h"
13 #include "xbt/graph.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
16
17 extern xbt_dict_t defined_types; /* from instr_interface.c */
18
19 static int platform_created = 0;            /* indicate whether the platform file has been traced */
20 static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */
21
22 static const char *instr_node_name (xbt_node_t node)
23 {
24   void *data = xbt_graph_node_get_data(node);
25   char *str = (char*)data;
26   return str;
27 }
28
29
30 static container_t lowestCommonAncestor (container_t a1, container_t a2)
31 {
32   //this is only an optimization (since most of a1 and a2 share the same parent)
33   if (a1->father == a2->father) return a1->father;
34
35   //create an array with all ancestors of a1
36   xbt_dynar_t ancestors_a1 = xbt_dynar_new(sizeof(container_t), NULL);
37   container_t p;
38   p = a1->father;
39   while (p){
40     xbt_dynar_push_as (ancestors_a1, container_t, p);
41     p = p->father;
42   }
43
44   //create an array with all ancestors of a2
45   xbt_dynar_t ancestors_a2 = xbt_dynar_new(sizeof(container_t), NULL);
46   p = a2->father;
47   while (p){
48     xbt_dynar_push_as (ancestors_a2, container_t, p);
49     p = p->father;
50   }
51
52   //find the lowest ancestor
53   p = NULL;
54   int i = xbt_dynar_length (ancestors_a1) - 1;
55   int j = xbt_dynar_length (ancestors_a2) - 1;
56   while (i >= 0 && j >= 0){
57     container_t a1p = *(container_t*)xbt_dynar_get_ptr (ancestors_a1, i);
58     container_t a2p = *(container_t*)xbt_dynar_get_ptr (ancestors_a2, j);
59     if (a1p == a2p){
60       p = a1p;
61     }else{
62       break;
63     }
64     i--;
65     j--;
66   }
67   xbt_dynar_free (&ancestors_a1);
68   xbt_dynar_free (&ancestors_a2);
69   return p;
70 }
71
72 static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
73 {
74   //ignore loopback
75   if (strcmp (src->name, "__loopback__") == 0 || strcmp (dst->name, "__loopback__") == 0){
76     XBT_DEBUG ("  linkContainers: ignoring loopback link");
77     return;
78   }
79
80   //find common father
81   container_t father = lowestCommonAncestor (src, dst);
82   if (!father){
83     xbt_die ("common father unknown, this is a tracing problem");
84   }
85
86   if (filter != NULL){
87     //check if we already register this pair (we only need one direction)
88     char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE];
89     snprintf (aux1, INSTR_DEFAULT_STR_SIZE, "%s%s", src->name, dst->name);
90     snprintf (aux2, INSTR_DEFAULT_STR_SIZE, "%s%s", dst->name, src->name);
91     if (xbt_dict_get_or_null (filter, aux1)){
92       XBT_DEBUG ("  linkContainers: already registered %s <-> %s (1)", src->name, dst->name);
93       return;
94     }
95     if (xbt_dict_get_or_null (filter, aux2)){
96       XBT_DEBUG ("  linkContainers: already registered %s <-> %s (2)", dst->name, src->name);
97       return;
98     }
99
100     //ok, not found, register it
101     xbt_dict_set (filter, aux1, xbt_strdup ("1"), NULL);
102     xbt_dict_set (filter, aux2, xbt_strdup ("1"), NULL);
103   }
104
105   //declare type
106   char link_typename[INSTR_DEFAULT_STR_SIZE];
107   snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s%s-%s%s",
108             father->type->name,
109             src->type->name, src->type->id,
110             dst->type->name, dst->type->id);
111   type_t link_type = PJ_type_get_or_null (link_typename, father->type);
112   if (link_type == NULL){
113     link_type = PJ_type_link_new (link_typename, father->type, src->type, dst->type);
114   }
115
116   //register EDGE types for triva configuration
117   xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), NULL);
118
119   //create the link
120   static long long counter = 0;
121
122   if(MC_is_active())
123     MC_ignore_data_bss(&counter, sizeof(counter));
124
125   char key[INSTR_DEFAULT_STR_SIZE];
126   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
127   new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "topology", key);
128   new_pajeEndLink(SIMIX_get_clock(), father, link_type, dst, "topology", key);
129
130   XBT_DEBUG ("  linkContainers %s <-> %s", src->name, dst->name);
131 }
132
133 static int graph_extraction_filter_out (container_t c1, container_t c2)
134 {
135   if (c1->kind == INSTR_LINK ||
136       c1->kind == INSTR_SMPI ||
137       c1->kind == INSTR_MSG_PROCESS ||
138       c1->kind == INSTR_MSG_TASK ||
139       (c2 && strcmp (c1->name, c2->name) == 0))
140     return 1;
141   else
142     return 0;
143 }
144
145 static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t filter)
146 {
147   if (!TRACE_platform_topology()){
148     XBT_DEBUG("Graph extracing disable by user.");
149     return;
150   }
151   XBT_DEBUG ("Graph extraction for routing_component = %s", rc->name);
152   if (!xbt_dict_is_empty(rc->routing_sons)){
153     xbt_dict_cursor_t cursor = NULL;
154     AS_t rc_son;
155     char *child_name;
156     //bottom-up recursion
157     xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
158       container_t child_container = xbt_dict_get (container->children, rc_son->name);
159       recursiveGraphExtraction (rc_son, child_container, filter);
160     }
161   }
162
163   //let's get routes
164   xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
165   container_t child1, child2;
166   const char *child1_name, *child2_name;
167   xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
168     //if child1 is not a link, a smpi node, a msg process, a msg vm or a msg task
169     if (child1->kind == INSTR_LINK || child1->kind == INSTR_SMPI || child1->kind == INSTR_MSG_PROCESS || child1->kind == INSTR_MSG_VM || child1->kind == INSTR_MSG_TASK) continue;
170
171     xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
172       //if child2 is not a link, a smpi node, a msg process, a msg vm or a msg task
173       if (child2->kind == INSTR_LINK || child2->kind == INSTR_SMPI || child2->kind == INSTR_MSG_PROCESS || child2->kind == INSTR_MSG_VM || child2->kind == INSTR_MSG_TASK) continue;
174
175       //if child1 is not child2
176       if (strcmp (child1_name, child2_name) == 0) continue;
177
178       //get the route
179       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
180       route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
181       rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
182                                 route, NULL);
183
184       //user might want to extract a graph using routes with only one link
185       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
186       if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1){
187         generic_free_route(route);
188         continue;
189       }
190
191       //traverse the route connecting the containers
192       unsigned int cpt;
193       void *link;
194       container_t current, previous;
195       if (route->gw_src){
196         previous = PJ_container_get(route->gw_src->name);
197       }else{
198         previous = child1;
199       }
200
201       xbt_dynar_foreach (route->link_list, cpt, link) {
202         //FIXME (TODO): Should have a cleaner way to get the link name
203         char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
204         current = PJ_container_get(link_name);
205         linkContainers(previous, current, filter);
206         previous = current;
207       }
208       if (route->gw_dst){
209         current = PJ_container_get(route->gw_dst->name);
210       }else{
211         current = child2;
212       }
213       linkContainers(previous, current, filter);
214       generic_free_route(route);
215     }
216   }
217 }
218
219 /*
220  * Callbacks
221  */
222 static void instr_routing_parse_start_AS (sg_platf_AS_cbarg_t AS)
223 {
224   const char*id = AS->id;
225
226   if (PJ_container_get_root() == NULL){
227     PJ_container_alloc ();
228     PJ_type_alloc();
229     container_t root = PJ_container_new (id, INSTR_AS, NULL);
230     PJ_container_set_root (root);
231
232     if (TRACE_smpi_is_enabled()) {
233       if (!TRACE_smpi_is_grouped()){
234         type_t mpi = PJ_type_get_or_null ("MPI", root->type);
235         if (mpi == NULL){
236           mpi = PJ_type_container_new("MPI", root->type);
237           PJ_type_state_new ("MPI_STATE", mpi);
238           PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi);
239         }
240       }
241     }
242
243     if (TRACE_needs_platform()){
244       currentContainer = xbt_dynar_new (sizeof(container_t), NULL);
245       xbt_dynar_push (currentContainer, &root);
246     }
247     return;
248   }
249
250   if (TRACE_needs_platform()){
251     container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
252     container_t new = PJ_container_new (id, INSTR_AS, father);
253     xbt_dynar_push (currentContainer, &new);
254   }
255 }
256
257 static void instr_routing_parse_end_AS ()
258 {
259   if (TRACE_needs_platform()){
260     xbt_dynar_pop_ptr (currentContainer);
261   }
262 }
263
264 static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link)
265 {
266   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
267
268   double bandwidth_value = link->bandwidth;
269   double latency_value = link->latency;
270   xbt_dynar_t links_to_create = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
271
272   if (link->policy == SURF_LINK_FULLDUPLEX){
273     char *up = bprintf("%s_UP", link->id);
274     char *down = bprintf("%s_DOWN", link->id);
275     xbt_dynar_push_as (links_to_create, char*, xbt_strdup(up));
276     xbt_dynar_push_as (links_to_create, char*, xbt_strdup(down));
277     free (up);
278     free (down);
279   }else{
280     xbt_dynar_push_as (links_to_create, char*, strdup(link->id));
281   }
282
283   char *link_name = NULL;
284   unsigned int i;
285   xbt_dynar_foreach (links_to_create, i, link_name){
286
287     container_t new = PJ_container_new (link_name, INSTR_LINK, father);
288
289     if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()){
290       type_t bandwidth = PJ_type_get_or_null ("bandwidth", new->type);
291       if (bandwidth == NULL){
292         bandwidth = PJ_type_variable_new ("bandwidth", NULL, new->type);
293       }
294       type_t latency = PJ_type_get_or_null ("latency", new->type);
295       if (latency == NULL){
296         latency = PJ_type_variable_new ("latency", NULL, new->type);
297       }
298       new_pajeSetVariable (0, new, bandwidth, bandwidth_value);
299       new_pajeSetVariable (0, new, latency, latency_value);
300     }
301     if (TRACE_uncategorized()){
302       type_t bandwidth_used = PJ_type_get_or_null ("bandwidth_used", new->type);
303       if (bandwidth_used == NULL){
304         bandwidth_used = PJ_type_variable_new ("bandwidth_used", "0.5 0.5 0.5", new->type);
305       }
306     }
307   }
308
309   xbt_dynar_free (&links_to_create);
310 }
311
312 static void instr_routing_parse_start_host (sg_platf_host_cbarg_t host)
313 {
314   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
315   container_t new = PJ_container_new (host->id, INSTR_HOST, father);
316
317   if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
318     type_t power = PJ_type_get_or_null ("power", new->type);
319     if (power == NULL){
320       power = PJ_type_variable_new ("power", NULL, new->type);
321     }
322     new_pajeSetVariable (0, new, power, host->power_peak);
323   }
324   if (TRACE_uncategorized()){
325     type_t power_used = PJ_type_get_or_null ("power_used", new->type);
326     if (power_used == NULL){
327       power_used = PJ_type_variable_new ("power_used", "0.5 0.5 0.5", new->type);
328     }
329   }
330
331   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()){
332     type_t mpi = PJ_type_get_or_null ("MPI", new->type);
333     if (mpi == NULL){
334       mpi = PJ_type_container_new("MPI", new->type);
335       PJ_type_state_new ("MPI_STATE", mpi);
336       PJ_type_link_new ("MPI_LINK", PJ_type_get_root(), mpi, mpi);
337     }
338   }
339
340   if (TRACE_msg_process_is_enabled()) {
341     type_t msg_process = PJ_type_get_or_null ("MSG_PROCESS", new->type);
342     if (msg_process == NULL){
343       msg_process = PJ_type_container_new("MSG_PROCESS", new->type);
344       type_t state = PJ_type_state_new ("MSG_PROCESS_STATE", msg_process);
345       PJ_value_new ("suspend", "1 0 1", state);
346       PJ_value_new ("sleep", "1 1 0", state);
347       PJ_value_new ("receive", "1 0 0", state);
348       PJ_value_new ("send", "0 0 1", state);
349       PJ_value_new ("task_execute", "0 1 1", state);
350       PJ_type_link_new ("MSG_PROCESS_LINK", PJ_type_get_root(), msg_process, msg_process);
351       PJ_type_link_new ("MSG_PROCESS_TASK_LINK", PJ_type_get_root(), msg_process, msg_process);
352     }
353   }
354
355   if (TRACE_msg_vm_is_enabled()) {
356     type_t msg_vm = PJ_type_get_or_null ("MSG_VM", new->type);
357     if (msg_vm == NULL){
358       msg_vm = PJ_type_container_new("MSG_VM", new->type);
359       type_t state = PJ_type_state_new ("MSG_VM_STATE", msg_vm);
360       PJ_value_new ("suspend", "1 0 1", state);
361       PJ_value_new ("sleep", "1 1 0", state);
362       PJ_value_new ("receive", "1 0 0", state);
363       PJ_value_new ("send", "0 0 1", state);
364       PJ_value_new ("task_execute", "0 1 1", state);
365       PJ_type_link_new ("MSG_VM_LINK", PJ_type_get_root(), msg_vm, msg_vm);
366       PJ_type_link_new ("MSG_VM_PROCESS_LINK", PJ_type_get_root(), msg_vm, msg_vm);
367     }
368   }
369
370 }
371
372 static void instr_routing_parse_start_router (sg_platf_router_cbarg_t router)
373 {
374   container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
375   PJ_container_new (router->id, INSTR_ROUTER, father);
376 }
377
378 static void instr_routing_parse_end_platform ()
379 {
380   xbt_dynar_free(&currentContainer);
381   currentContainer = NULL;
382   xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free);
383   XBT_DEBUG ("Starting graph extraction.");
384   recursiveGraphExtraction (routing_platf->root, PJ_container_get_root(), filter);
385   XBT_DEBUG ("Graph extraction finished.");
386   xbt_dict_free(&filter);
387   platform_created = 1;
388   TRACE_paje_dump_buffer(1);
389 }
390
391 void instr_routing_define_callbacks ()
392 {
393   if (!TRACE_is_enabled()) return;
394   //always need the call backs to ASes (we need only the root AS),
395   //to create the rootContainer and the rootType properly
396   sg_platf_AS_begin_add_cb(instr_routing_parse_start_AS);
397   sg_platf_AS_end_add_cb(instr_routing_parse_end_AS);
398   if (!TRACE_needs_platform()) return;
399   sg_platf_link_add_cb(instr_routing_parse_start_link);
400   sg_platf_host_add_cb(instr_routing_parse_start_host);
401   sg_platf_router_add_cb(instr_routing_parse_start_router);
402
403   sg_platf_postparse_add_cb(instr_routing_parse_end_platform);
404 }
405
406 /*
407  * user categories support
408  */
409 static void recursiveNewVariableType (const char *new_typename, const char *color, type_t root)
410 {
411   if (!strcmp (root->name, "HOST")){
412     char tnstr[INSTR_DEFAULT_STR_SIZE];
413     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename);
414     PJ_type_variable_new (tnstr, color, root);
415   }
416   if (!strcmp (root->name, "MSG_VM")){
417     char tnstr[INSTR_DEFAULT_STR_SIZE];
418     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename);
419     PJ_type_variable_new (tnstr, color, root);
420   }
421  if (!strcmp (root->name, "LINK")){
422     char tnstr[INSTR_DEFAULT_STR_SIZE];
423     snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename);
424     PJ_type_variable_new (tnstr, color, root);
425   }
426   xbt_dict_cursor_t cursor = NULL;
427   type_t child_type;
428   char *name;
429   xbt_dict_foreach(root->children, cursor, name, child_type) {
430     recursiveNewVariableType (new_typename, color, child_type);
431   }
432 }
433
434 void instr_new_variable_type (const char *new_typename, const char *color)
435 {
436   recursiveNewVariableType (new_typename, color, PJ_type_get_root());
437 }
438
439 static void recursiveNewUserVariableType (const char *father_type, const char *new_typename, const char *color, type_t root)
440 {
441   if (!strcmp (root->name, father_type)){
442     PJ_type_variable_new (new_typename, color, root);
443   }
444   xbt_dict_cursor_t cursor = NULL;
445   type_t child_type;
446   char *name;
447   xbt_dict_foreach(root->children, cursor, name, child_type) {
448     recursiveNewUserVariableType (father_type, new_typename, color, child_type);
449   }
450 }
451
452 void instr_new_user_variable_type  (const char *father_type, const char *new_typename, const char *color)
453 {
454   recursiveNewUserVariableType (father_type, new_typename, color, PJ_type_get_root());
455 }
456
457 static void recursiveNewUserStateType (const char *father_type, const char *new_typename, type_t root)
458 {
459   if (!strcmp (root->name, father_type)){
460     PJ_type_state_new (new_typename, root);
461   }
462   xbt_dict_cursor_t cursor = NULL;
463   type_t child_type;
464   char *name;
465   xbt_dict_foreach(root->children, cursor, name, child_type) {
466     recursiveNewUserStateType (father_type, new_typename, child_type);
467   }
468 }
469
470 void instr_new_user_state_type (const char *father_type, const char *new_typename)
471 {
472   recursiveNewUserStateType (father_type, new_typename, PJ_type_get_root());
473 }
474
475 static void recursiveNewValueForUserStateType (const char *typename, const char *value, const char *color, type_t root)
476 {
477   if (!strcmp (root->name, typename)){
478     PJ_value_new (value, color, root);
479   }
480   xbt_dict_cursor_t cursor = NULL;
481   type_t child_type;
482   char *name;
483   xbt_dict_foreach(root->children, cursor, name, child_type) {
484     recursiveNewValueForUserStateType (typename, value, color, child_type);
485   }
486 }
487
488 void instr_new_value_for_user_state_type (const char *typename, const char *value, const char *color)
489 {
490   recursiveNewValueForUserStateType (typename, value, color, PJ_type_get_root());
491 }
492
493 int instr_platform_traced ()
494 {
495   return platform_created;
496 }
497
498 #define GRAPHICATOR_SUPPORT_FUNCTIONS
499
500
501 static xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes)
502 {
503   xbt_node_t ret = xbt_dict_get_or_null (nodes, name);
504   if (ret) return ret;
505
506   ret = xbt_graph_new_node (graph, xbt_strdup(name));
507   xbt_dict_set (nodes, name, ret, NULL);
508   return ret;
509 }
510
511 static xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges)
512 {
513   xbt_edge_t ret;
514
515   const char *sn = instr_node_name (s);
516   const char *dn = instr_node_name (d);
517   int len = strlen(sn)+strlen(dn)+1;
518   char *name = (char*)xbt_malloc(len * sizeof(char));
519
520
521   snprintf (name, len, "%s%s", sn, dn);
522   ret = xbt_dict_get_or_null (edges, name);
523   if (ret == NULL){
524     snprintf (name, len, "%s%s", dn, sn);
525     ret = xbt_dict_get_or_null (edges, name);
526   }
527
528   if (ret == NULL){
529     ret = xbt_graph_new_edge(graph, s, d, NULL);
530     xbt_dict_set (edges, name, ret, NULL);
531   }
532   free (name);
533   return ret;
534 }
535
536 static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges,
537     AS_t rc, container_t container)
538 {
539   if (!xbt_dict_is_empty(rc->routing_sons)){
540     xbt_dict_cursor_t cursor = NULL;
541     AS_t rc_son;
542     char *child_name;
543     //bottom-up recursion
544     xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
545       container_t child_container = xbt_dict_get (container->children, rc_son->name);
546       recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container);
547     }
548   }
549
550   //let's get routes
551   xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
552   container_t child1, child2;
553   const char *child1_name, *child2_name;
554   xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
555     //if child1 is not a link, a smpi node, a msg process, a msg vm or a msg task
556     if (child1->kind == INSTR_LINK || child1->kind == INSTR_SMPI || child1->kind == INSTR_MSG_PROCESS || child1->kind == INSTR_MSG_VM || child1->kind == INSTR_MSG_TASK) continue;
557
558     xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
559       //if child2 is not a link, a smpi node, a msg process or a msg task
560       if (child2->kind == INSTR_LINK || child2->kind == INSTR_SMPI || child2->kind == INSTR_MSG_PROCESS || child2->kind == INSTR_MSG_VM || child2->kind == INSTR_MSG_TASK) continue;
561
562       //if child1 is not child2
563       if (strcmp (child1_name, child2_name) == 0) continue;
564
565       //get the route
566       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
567       route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
568       rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
569                                 route, NULL);
570
571       //user might want to extract a graph using routes with only one link
572       //see --cfg=tracing/onelink_only:1 or --help-tracing for details
573       if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1) continue;
574
575       //traverse the route connecting the containers
576       unsigned int cpt;
577       void *link;
578       xbt_node_t current, previous;
579       if (route->gw_src){
580         previous = new_xbt_graph_node(graph, route->gw_src->name, nodes);
581       }else{
582         previous = new_xbt_graph_node(graph, child1_name, nodes);
583       }
584
585       xbt_dynar_foreach (route->link_list, cpt, link) {
586         char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
587         current = new_xbt_graph_node(graph, link_name, nodes);
588         new_xbt_graph_edge (graph, previous, current, edges);
589         //previous -> current
590         previous = current;
591       }
592       if (route->gw_dst){
593         current = new_xbt_graph_node(graph, route->gw_dst->name, nodes);
594       }else{
595         current = new_xbt_graph_node(graph, child2_name, nodes);
596       }
597       new_xbt_graph_edge (graph, previous, current, edges);
598       generic_free_route(route);
599     }
600   }
601
602 }
603
604 xbt_graph_t instr_routing_platform_graph (void)
605 {
606   xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
607   xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
608   xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
609   recursiveXBTGraphExtraction (ret, nodes, edges, routing_platf->root, PJ_container_get_root());
610   xbt_dict_free (&nodes);
611   xbt_dict_free (&edges);
612   return ret;
613 }
614
615 void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename)
616 {
617   unsigned int cursor = 0;
618   xbt_node_t node = NULL;
619   xbt_edge_t edge = NULL;
620   FILE *file = NULL;
621
622   file = fopen(filename, "w");
623   xbt_assert(file, "Failed to open %s \n", filename);
624
625   if (g->directed)
626     fprintf(file, "digraph test {\n");
627   else
628     fprintf(file, "graph test {\n");
629
630   fprintf(file, "  graph [overlap=scale]\n");
631
632   fprintf(file, "  node [shape=box, style=filled]\n");
633   fprintf(file,
634           "  node [width=.3, height=.3, style=filled, color=skyblue]\n\n");
635
636   xbt_dynar_foreach(g->nodes, cursor, node) {
637     fprintf(file, "  \"%s\";\n", instr_node_name(node));
638   }
639   xbt_dynar_foreach(g->edges, cursor, edge) {
640     const char *src_s = instr_node_name (edge->src);
641     const char *dst_s = instr_node_name (edge->dst);
642     if (g->directed)
643       fprintf(file, "  \"%s\" -> \"%s\";\n", src_s, dst_s);
644     else
645       fprintf(file, "  \"%s\" -- \"%s\";\n", src_s, dst_s);
646   }
647   fprintf(file, "}\n");
648   fclose(file);
649
650 }
651
652 #endif /* HAVE_TRACING */
653