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");
64 printf("<AS id=\"AS0\" routing=\"Full\">\n");
66 totalHosts = SD_workstation_get_number();
67 hosts = SD_workstation_get_list();
68 qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
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) {
78 xbt_dict_foreach(props, cursor, key, data) {
79 printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data);
87 totalLinks = SD_link_get_number();
88 links = SD_link_get_list();
89 qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
91 for (i = 0; i < totalLinks; i++) {
92 printf(" <link id=\"");
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) {
101 printf(" sharing_policy=\"FATPIPE\"/>\n");
105 for (i = 0; i < totalHosts; i++) {
106 for (j = 0; j < totalHosts; j++) {
107 tmp = SD_route_get_list(hosts[i], hosts[j]);
109 printf(" <route src=\"%s\" dst=\"%s\">\n ",
110 SD_workstation_get_name(hosts[i]),
111 SD_workstation_get_name(hosts[j]));
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]));
117 printf("\n </route>\n");
122 printf("</platform>\n");