Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
unistd header does not exist on Windows.
[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   char *platformFile=NULL;
40   int totalHosts, totalLinks, tmp_length;
41   int i,j,k;
42   xbt_dict_t props = NULL;
43   xbt_dict_cursor_t cursor=NULL;
44   char *key,*data;
45
46   const SD_workstation_t *hosts;
47   const SD_link_t *links, *tmp;
48
49   SD_init(&argc, argv);
50
51   platformFile = argv[1];
52   DEBUG1("%s",platformFile);
53   SD_create_environment(platformFile);
54
55   printf ("<?xml version='1.0'?>\n");
56   printf ("<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n");
57   printf ("<platform version=\"2\">\n");
58  
59   totalHosts = SD_workstation_get_number();
60   hosts = SD_workstation_get_list();
61   qsort((void *)hosts, totalHosts, sizeof(SD_workstation_t),
62         name_compare_hosts);
63   
64   for (i=0;i<totalHosts;i++){
65     printf("  <host id=\"%s\" power=\"%.0f\"", 
66            SD_workstation_get_name(hosts[i]),
67            SD_workstation_get_power(hosts[i]));
68     props = SD_workstation_get_properties(hosts[i]);
69     if (xbt_dict_length(props)>0) {
70       printf(">\n");
71       xbt_dict_foreach(props,cursor,key,data) {
72         printf("    <prop id=\"%s\" value=\"%s\"/>\n",key,data);
73       }
74       printf("  </host>\n");
75     } else {
76       printf("/>\n");
77     }
78   }
79
80   totalLinks = SD_link_get_number();
81   links = SD_link_get_list();
82   qsort((void *)links, totalLinks, sizeof(SD_link_t),
83         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 }
120
121