1 /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
18 #include "simdag/simdag.h"
22 XBT_LOG_NEW_DEFAULT_CATEGORY(validator,
23 "Logging specific to this SimDag example");
25 static int name_compare_hosts(const void *n1, const void *n2)
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)));
31 return strcmp(name1, name2);
34 static int name_compare_links(const void *n1, const void *n2)
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)));
40 return strcmp(name1, name2);
43 int main(int argc, char **argv)
45 char *platformFile = NULL;
46 int totalHosts, totalLinks, tmp_length;
48 xbt_dict_t props = NULL;
49 xbt_dict_cursor_t cursor = NULL;
52 const SD_workstation_t *hosts;
53 const SD_link_t *links, *tmp;
57 platformFile = argv[1];
58 DEBUG1("%s", platformFile);
59 SD_create_environment(platformFile);
61 printf("<?xml version='1.0'?>\n");
62 printf("<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n");
63 printf("<platform version=\"2\">\n");
65 totalHosts = SD_workstation_get_number();
66 hosts = SD_workstation_get_list();
67 qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
70 for (i = 0; i < totalHosts; i++) {
71 printf(" <host id=\"%s\" power=\"%.0f\"",
72 SD_workstation_get_name(hosts[i]),
73 SD_workstation_get_power(hosts[i]));
74 props = SD_workstation_get_properties(hosts[i]);
75 if (xbt_dict_length(props) > 0) {
77 xbt_dict_foreach(props, cursor, key, data) {
78 printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data);
86 totalLinks = SD_link_get_number();
87 links = SD_link_get_list();
88 qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
90 for (i = 0; i < totalLinks; i++) {
91 printf(" <link id=\"");
93 printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"",
94 SD_link_get_name(links[i]),
95 SD_link_get_current_bandwidth(links[i]),
96 SD_link_get_current_latency(links[i]));
97 if (SD_link_get_sharing_policy(links[i]) == SD_LINK_SHARED) {
100 printf(" sharing_policy=\"FATPIPE\"/>\n");
104 for (i = 0; i < totalHosts; i++) {
105 for (j = 0; j < totalHosts; j++) {
106 tmp = SD_route_get_list(hosts[i], hosts[j]);
108 printf(" <route src=\"%s\" dst=\"%s\">\n ",
109 SD_workstation_get_name(hosts[i]),
110 SD_workstation_get_name(hosts[j]));
112 tmp_length = SD_route_get_size(hosts[i], hosts[j]);
113 for (k = 0; k < tmp_length; k++) {
114 printf("<link:ctn id=\"%s\"/>", SD_link_get_name(tmp[k]));
116 printf("\n </route>\n");
120 printf("</platform>\n");