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 #include "surf/surf.h"
23 #include "surf/surf_private.h"
25 XBT_LOG_NEW_DEFAULT_CATEGORY(validator,
26 "Logging specific to this SimDag example");
28 static int name_compare_hosts(const void *n1, const void *n2)
30 char name1[80], name2[80];
31 strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
32 strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
34 return strcmp(name1, name2);
37 static int name_compare_links(const void *n1, const void *n2)
39 char name1[80], name2[80];
40 strcpy(name1, SD_link_get_name(*((SD_link_t *) n1)));
41 strcpy(name2, SD_link_get_name(*((SD_link_t *) n2)));
43 return strcmp(name1, name2);
46 int main(int argc, char **argv)
48 char *platformFile = NULL;
49 int totalHosts, totalLinks;
51 xbt_dict_t props = NULL;
52 xbt_dict_cursor_t cursor = NULL;
53 xbt_lib_cursor_t cursor_src = NULL;
54 xbt_lib_cursor_t cursor_dst = NULL;
55 char *src,*dst,*key,*data;
59 const SD_workstation_t *hosts;
60 const SD_link_t *links;
62 setvbuf(stdout, NULL, _IOLBF, 0);
66 platformFile = argv[1];
67 XBT_DEBUG("%s", platformFile);
69 SD_create_environment(platformFile);
72 xbt_die("Error while loading %s: %s",platformFile,e.msg);
75 printf("<?xml version='1.0'?>\n");
76 printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n");
77 printf("<platform version=\"3\">\n");
78 printf("<AS id=\"AS0\" routing=\"Full\">\n");
81 totalHosts = SD_workstation_get_number();
82 hosts = SD_workstation_get_list();
83 qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
86 for (i = 0; i < totalHosts; i++) {
87 printf(" <host id=\"%s\" power=\"%.0f\"",
88 SD_workstation_get_name(hosts[i]),
89 SD_workstation_get_power(hosts[i]));
90 props = SD_workstation_get_properties(hosts[i]);
91 if (props && !xbt_dict_is_empty(props)) {
93 xbt_dict_foreach(props, cursor, key, data) {
94 printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data);
103 xbt_lib_foreach(as_router_lib, cursor_src, key, value) {
104 if(((network_element_info_t)xbt_lib_get_or_null(as_router_lib, key,
105 ROUTING_ASR_LEVEL))->rc_type == SURF_NETWORK_ELEMENT_ROUTER)
107 printf(" <router id=\"%s\"/>\n",key);
112 totalLinks = SD_link_get_number();
113 links = SD_link_get_list();
115 qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
117 for (i = 0; i < totalLinks; i++) {
118 printf(" <link id=\"");
120 printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"",
121 SD_link_get_name(links[i]),
122 SD_link_get_current_bandwidth(links[i]),
123 SD_link_get_current_latency(links[i]));
124 if (SD_link_get_sharing_policy(links[i]) == SD_LINK_SHARED) {
127 printf(" sharing_policy=\"FATPIPE\"/>\n");
132 xbt_lib_foreach(host_lib, cursor_src, src, value) // Routes from host
134 xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host
136 printf(" <route src=\"%s\" dst=\"%s\">\n "
139 xbt_dynar_t route=NULL;
140 routing_get_route_and_latency(src,dst,&route,NULL);
141 for(i=0;i<xbt_dynar_length(route) ;i++)
143 void *link = xbt_dynar_get_as(route,i,void *);
145 char *link_name = xbt_strdup(((surf_resource_t)link)->name);
146 printf("<link_ctn id=\"%s\"/>",link_name);
149 printf("\n </route>\n");
151 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router
153 if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
154 printf(" <route src=\"%s\" dst=\"%s\">\n "
157 xbt_dynar_t route=NULL;
158 routing_get_route_and_latency(src,dst,&route,NULL);
159 for(i=0;i<xbt_dynar_length(route) ;i++)
161 void *link = xbt_dynar_get_as(route,i,void *);
163 char *link_name = xbt_strdup(((surf_resource_t)link)->name);
164 printf("<link_ctn id=\"%s\"/>",link_name);
167 printf("\n </route>\n");
172 xbt_lib_foreach(as_router_lib, cursor_src, src, value) // Routes from router
174 if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_ROUTER){
175 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router
177 if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
178 printf(" <route src=\"%s\" dst=\"%s\">\n "
181 xbt_dynar_t route=NULL;
182 routing_get_route_and_latency(src,dst,&route,NULL);
183 for(i=0;i<xbt_dynar_length(route) ;i++)
185 void *link = xbt_dynar_get_as(route,i,void *);
187 char *link_name = xbt_strdup(((surf_resource_t)link)->name);
188 printf("<link_ctn id=\"%s\"/>",link_name);
191 printf("\n </route>\n");
194 xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host
196 printf(" <route src=\"%s\" dst=\"%s\">\n "
198 xbt_dynar_t route=NULL;
199 routing_get_route_and_latency(src,dst,&route, NULL);
200 for(i=0;i<xbt_dynar_length(route) ;i++)
202 void *link = xbt_dynar_get_as(route,i,void *);
204 char *link_name = xbt_strdup(((surf_resource_t)link)->name);
205 printf("<link_ctn id=\"%s\"/>",link_name);
208 printf("\n </route>\n");
214 printf("</platform>\n");