1 /* Copyright (c) 2008-2015. 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. */
7 #include "src/internal_config.h"
18 #include "src/surf/network_interface.hpp"
19 #include "simgrid/simdag.h"
23 #include "xbt/xbt_os_time.h"
24 #include "surf/surf.h"
25 #include "src/surf/surf_private.h"
27 XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier, "Logging specific to this platform parsing tool");
29 static int name_compare_hosts(const void *n1, const void *n2)
31 return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
34 static int name_compare_links(const void *n1, const void *n2)
36 return strcmp(sg_link_name(*(SD_link_t *) n1),sg_link_name(*(SD_link_t *) n2));
39 static int parse_cmdline(int *timings, char **platformFile, int argc, char **argv)
43 for (i = 1; i < argc; i++) {
44 if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-') {
45 if (!strcmp(argv[i], "--timings")) {
52 *platformFile = argv[i];
58 static void create_environment(xbt_os_timer_t parse_time, const char *platformFile)
62 xbt_os_cputimer_start(parse_time);
63 SD_create_environment(platformFile);
64 xbt_os_cputimer_stop(parse_time);
67 xbt_die("Error while loading %s: %s", platformFile, e.msg);
71 int main(int argc, char **argv)
73 char *platformFile = NULL;
74 unsigned int totalHosts, totalLinks;
77 const char *link_ctn = "link_ctn";
79 xbt_dict_t props = NULL;
80 xbt_dict_cursor_t cursor = NULL;
81 xbt_lib_cursor_t cursor_src = NULL;
82 xbt_lib_cursor_t cursor_dst = NULL;
83 char *src,*dst,*key,*data;
87 const sg_host_t *hosts;
88 const SD_link_t *links;
89 xbt_os_timer_t parse_time = xbt_os_timer_new();
93 if (parse_cmdline(&timings, &platformFile, argc, argv) || !platformFile) {
94 xbt_die("Invalid command line arguments: expected [--timings] platformFile");
97 XBT_DEBUG("%d,%s", timings, platformFile);
99 create_environment(parse_time, platformFile);
102 XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time),
103 sg_host_count(), sg_link_count());
105 printf("<?xml version='1.0'?>\n");
106 printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n");
107 printf("<platform version=\"%d\">\n", version);
108 printf("<AS id=\"AS0\" routing=\"Full\">\n");
111 totalHosts = sg_host_count();
112 hosts = sg_host_list();
113 qsort((void *) hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts);
115 for (i = 0; i < totalHosts; i++) {
116 printf(" <host id=\"%s\" speed=\"%.0f\"", sg_host_get_name(hosts[i]), sg_host_speed(hosts[i]));
117 props = sg_host_get_properties(hosts[i]);
118 if (sg_host_core_count(hosts[i])>1) {
119 printf(" core=\"%d\"", sg_host_core_count(hosts[i]));
121 if (props && !xbt_dict_is_empty(props)) {
123 xbt_dict_foreach(props, cursor, key, data) {
124 printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data);
126 printf(" </host>\n");
133 xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
134 value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key, ROUTING_ASR_LEVEL);
135 if(value1->isRouter()) {
136 printf(" <router id=\"%s\"/>\n",key);
141 totalLinks = sg_link_count();
142 links = sg_link_list();
144 qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
146 for (i = 0; i < totalLinks; i++) {
147 printf(" <link id=\"");
149 printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"", sg_link_name(links[i]),
150 sg_link_bandwidth(links[i]), sg_link_latency(links[i]));
151 if (sg_link_is_shared(links[i])) {
154 printf(" sharing_policy=\"FATPIPE\"/>\n");
158 sg_host_t host1, host2;
159 xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
160 value1 = sg_host_by_name(src)->pimpl_netcard;
161 xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
162 std::vector<Link*> *route = new std::vector<Link*>();
163 value2 = sg_host_by_name(dst)->pimpl_netcard;
164 routing_platf->getRouteAndLatency(value1, value2, route,NULL);
165 if (! route->empty()){
166 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
167 for (auto link: *route)
168 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
169 printf("\n </route>\n");
173 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
174 value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
175 if(value2->isRouter()){
176 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
177 std::vector<Link*> *route = new std::vector<Link*>();
178 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
179 for (auto link : *route)
180 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
182 printf("\n </route>\n");
187 xbt_lib_foreach(as_router_lib, cursor_src, src, value1){ // Routes from router
188 value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
189 if (value1->isRouter()){
190 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
191 value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
192 if(value2->isRouter()){
193 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
194 std::vector<Link*> *route = new std::vector<Link*>();
195 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
196 for(auto link :*route)
197 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
199 printf("\n </route>\n");
202 xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
203 printf(" <route src=\"%s\" dst=\"%s\">\n ",src, dst);
204 std::vector<Link*> *route = new std::vector<Link*>();
205 value2 = sg_host_by_name(dst)->pimpl_netcard;
206 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, NULL);
207 for(auto link : *route)
208 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
210 printf("\n </route>\n");
216 printf("</platform>\n");
219 xbt_os_timer_free(parse_time);