Logo AND Algorithmique Numérique Distribuée

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