Logo AND Algorithmique Numérique Distribuée

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