Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the new flatifier test
[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
22 XBT_LOG_NEW_DEFAULT_CATEGORY(validator,
23                              "Logging specific to this SimDag example");
24
25 static int name_compare_hosts(const void *n1, const void *n2)
26 {
27   char name1[80], name2[80];
28   strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
29   strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
30
31   return strcmp(name1, name2);
32 }
33
34 static int name_compare_links(const void *n1, const void *n2)
35 {
36   char name1[80], name2[80];
37   strcpy(name1, SD_link_get_name(*((SD_link_t *) n1)));
38   strcpy(name2, SD_link_get_name(*((SD_link_t *) n2)));
39
40   return strcmp(name1, name2);
41 }
42
43 int main(int argc, char **argv)
44 {
45   char *platformFile = NULL;
46   int totalHosts, totalLinks, tmp_length;
47   int i, j, k;
48   xbt_dict_t props = NULL;
49   xbt_dict_cursor_t cursor = NULL;
50   char *key, *data;
51
52   const SD_workstation_t *hosts;
53   const SD_link_t *links, *tmp;
54
55   SD_init(&argc, argv);
56
57   platformFile = argv[1];
58   DEBUG1("%s", platformFile);
59   SD_create_environment(platformFile);
60
61   printf("<?xml version='1.0'?>\n");
62   printf("<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n");
63   printf("<platform version=\"2\">\n");
64   printf("<AS id=\"AS0\" routing=\"Full\">\n");
65
66   totalHosts = SD_workstation_get_number();
67   hosts = SD_workstation_get_list();
68   qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
69         name_compare_hosts);
70
71   for (i = 0; i < totalHosts; i++) {
72     printf("  <host id=\"%s\" power=\"%.0f\"",
73            SD_workstation_get_name(hosts[i]),
74            SD_workstation_get_power(hosts[i]));
75     props = SD_workstation_get_properties(hosts[i]);
76     if (xbt_dict_length(props) > 0) {
77       printf(">\n");
78       xbt_dict_foreach(props, cursor, key, data) {
79         printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
80       }
81       printf("  </host>\n");
82     } else {
83       printf("/>\n");
84     }
85   }
86
87   totalLinks = SD_link_get_number();
88   links = SD_link_get_list();
89   qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
90
91   for (i = 0; i < totalLinks; i++) {
92     printf("  <link id=\"");
93
94     printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"",
95            SD_link_get_name(links[i]),
96            SD_link_get_current_bandwidth(links[i]),
97            SD_link_get_current_latency(links[i]));
98     if (SD_link_get_sharing_policy(links[i]) == SD_LINK_SHARED) {
99       printf("/>\n");
100     } else {
101       printf(" sharing_policy=\"FATPIPE\"/>\n");
102     }
103   }
104
105   for (i = 0; i < totalHosts; i++) {
106     for (j = 0; j < totalHosts; j++) {
107       tmp = SD_route_get_list(hosts[i], hosts[j]);
108       if (tmp) {
109         printf("  <route src=\"%s\" dst=\"%s\">\n    ",
110                SD_workstation_get_name(hosts[i]),
111                SD_workstation_get_name(hosts[j]));
112
113         tmp_length = SD_route_get_size(hosts[i], hosts[j]);
114         for (k = 0; k < tmp_length; k++) {
115           printf("<link:ctn id=\"%s\"/>", SD_link_get_name(tmp[k]));
116         }
117         printf("\n  </route>\n");
118       }
119     }
120   }
121   printf("</AS>\n");
122   printf("</platform>\n");
123   SD_exit();
124
125   return 0;
126 }