Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update platfrom version to 3.
[simgrid.git] / teshsuite / simdag / platforms / flatifier.c
1 /* Copyright (c) 2008, 2009, 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 #ifndef _XBT_WIN32
8 #include <unistd.h>
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <time.h>
14 #include <string.h>
15 #include <math.h>
16
17
18 #include "simdag/simdag.h"
19 #include "xbt/log.h"
20 #include "xbt/dict.h"
21 #include "xbt/ex.h"
22
23 XBT_LOG_NEW_DEFAULT_CATEGORY(validator,
24                              "Logging specific to this SimDag example");
25
26 static int name_compare_hosts(const void *n1, const void *n2)
27 {
28   char name1[80], name2[80];
29   strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
30   strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
31
32   return strcmp(name1, name2);
33 }
34
35 static int name_compare_links(const void *n1, const void *n2)
36 {
37   char name1[80], name2[80];
38   strcpy(name1, SD_link_get_name(*((SD_link_t *) n1)));
39   strcpy(name2, SD_link_get_name(*((SD_link_t *) n2)));
40
41   return strcmp(name1, name2);
42 }
43
44 int main(int argc, char **argv)
45 {
46   char *platformFile = NULL;
47   int totalHosts, totalLinks, tmp_length;
48   int i, j, k;
49   xbt_dict_t props = NULL;
50   xbt_dict_cursor_t cursor = NULL;
51   char *key, *data;
52   xbt_ex_t e;
53
54   const SD_workstation_t *hosts;
55   const SD_link_t *links, *tmp;
56
57   SD_init(&argc, argv);
58
59   platformFile = argv[1];
60   DEBUG1("%s", platformFile);
61   TRY {
62     SD_create_environment(platformFile);
63   } CATCH(e) {
64     xbt_die(bprintf("Error while loading %s: %s",platformFile,e.msg));     
65   }
66    
67
68   printf("<?xml version='1.0'?>\n");
69   printf("<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n");
70   printf("<platform version=\"3\">\n");
71   printf("<AS id=\"AS0\" routing=\"Full\">\n");
72
73   totalHosts = SD_workstation_get_number();
74   hosts = SD_workstation_get_list();
75   qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
76         name_compare_hosts);
77
78   for (i = 0; i < totalHosts; i++) {
79     printf("  <host id=\"%s\" power=\"%.0f\"",
80            SD_workstation_get_name(hosts[i]),
81            SD_workstation_get_power(hosts[i]));
82     props = SD_workstation_get_properties(hosts[i]);
83     if (xbt_dict_length(props) > 0) {
84       printf(">\n");
85       xbt_dict_foreach(props, cursor, key, data) {
86         printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
87       }
88       printf("  </host>\n");
89     } else {
90       printf("/>\n");
91     }
92   }
93
94   totalLinks = SD_link_get_number();
95   links = SD_link_get_list();
96   qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
97
98   for (i = 0; i < totalLinks; i++) {
99     printf("  <link id=\"");
100
101     printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"",
102            SD_link_get_name(links[i]),
103            SD_link_get_current_bandwidth(links[i]),
104            SD_link_get_current_latency(links[i]));
105     if (SD_link_get_sharing_policy(links[i]) == SD_LINK_SHARED) {
106       printf("/>\n");
107     } else {
108       printf(" sharing_policy=\"FATPIPE\"/>\n");
109     }
110   }
111
112   for (i = 0; i < totalHosts; i++) {
113     for (j = 0; j < totalHosts; j++) {
114       tmp = SD_route_get_list(hosts[i], hosts[j]);
115       if (tmp) {
116         printf("  <route src=\"%s\" dst=\"%s\">\n    ",
117                SD_workstation_get_name(hosts[i]),
118                SD_workstation_get_name(hosts[j]));
119
120         tmp_length = SD_route_get_size(hosts[i], hosts[j]);
121         for (k = 0; k < tmp_length; k++) {
122           printf("<link_ctn id=\"%s\"/>", SD_link_get_name(tmp[k]));
123         }
124         printf("\n  </route>\n");
125       }
126     }
127   }
128   printf("</AS>\n");
129   printf("</platform>\n");
130   SD_exit();
131
132   return 0;
133 }