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. */
17 #include "src/surf/network_interface.hpp"
18 #include "simgrid/simdag.h"
22 #include "xbt/xbt_os_time.h"
23 #include "surf/surf.h"
24 #include "src/surf/surf_private.h"
26 XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier, "Logging specific to this platform parsing tool");
28 static int name_compare_hosts(const void *n1, const void *n2)
30 return strcmp(sg_host_get_name(*(sg_host_t *) n1), sg_host_get_name(*(sg_host_t *) n2));
33 static int name_compare_links(const void *n1, const void *n2)
35 return strcmp(sg_link_name(*(SD_link_t *) n1),sg_link_name(*(SD_link_t *) n2));
38 static int parse_cmdline(int *timings, char **platformFile, int argc, char **argv)
42 for (i = 1; i < argc; i++) {
43 if (strlen(argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] == '-') {
44 if (!strcmp(argv[i], "--timings")) {
51 *platformFile = argv[i];
57 static void create_environment(xbt_os_timer_t parse_time, const char *platformFile)
61 xbt_os_cputimer_start(parse_time);
62 SD_create_environment(platformFile);
63 xbt_os_cputimer_stop(parse_time);
66 xbt_die("Error while loading %s: %s", platformFile, e.msg);
70 int main(int argc, char **argv)
72 char *platformFile = NULL;
73 unsigned int totalHosts, totalLinks;
76 const char *link_ctn = "link_ctn";
78 xbt_dict_t props = NULL;
79 xbt_dict_cursor_t cursor = NULL;
80 xbt_lib_cursor_t cursor_src = NULL;
81 xbt_lib_cursor_t cursor_dst = NULL;
82 char *src,*dst,*key,*data;
86 const sg_host_t *hosts;
87 const SD_link_t *links;
88 xbt_os_timer_t parse_time = xbt_os_timer_new();
92 if (parse_cmdline(&timings, &platformFile, argc, argv) || !platformFile) {
93 xbt_die("Invalid command line arguments: expected [--timings] platformFile");
96 XBT_DEBUG("%d,%s", timings, platformFile);
98 create_environment(parse_time, platformFile);
101 XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time),
102 sg_host_count(), sg_link_count());
104 printf("<?xml version='1.0'?>\n");
105 printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n");
106 printf("<platform version=\"%d\">\n", version);
107 printf("<AS id=\"AS0\" routing=\"Full\">\n");
110 totalHosts = sg_host_count();
111 hosts = sg_host_list();
112 qsort((void *) hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts);
114 for (i = 0; i < totalHosts; i++) {
115 printf(" <host id=\"%s\" speed=\"%.0f\"", sg_host_get_name(hosts[i]), sg_host_speed(hosts[i]));
116 props = sg_host_get_properties(hosts[i]);
117 if (sg_host_core_count(hosts[i])>1) {
118 printf(" core=\"%d\"", sg_host_core_count(hosts[i]));
120 if (props && !xbt_dict_is_empty(props)) {
122 xbt_dict_foreach(props, cursor, key, data) {
123 printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data);
125 printf(" </host>\n");
132 xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
133 value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key, ROUTING_ASR_LEVEL);
134 if(value1->isRouter()) {
135 printf(" <router id=\"%s\"/>\n",key);
140 totalLinks = sg_link_count();
141 links = sg_link_list();
143 qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
145 for (i = 0; i < totalLinks; i++) {
146 printf(" <link id=\"");
148 printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"", sg_link_name(links[i]),
149 sg_link_bandwidth(links[i]), sg_link_latency(links[i]));
150 if (sg_link_is_shared(links[i])) {
153 printf(" sharing_policy=\"FATPIPE\"/>\n");
157 sg_host_t host1, host2;
158 xbt_dict_foreach(host_list, cursor_src, src, host1){ // Routes from host
159 value1 = sg_host_by_name(src)->pimpl_netcard;
160 xbt_dict_foreach(host_list, cursor_dst, dst, host2){ //to host
161 std::vector<Link*> *route = new std::vector<Link*>();
162 value2 = sg_host_by_name(dst)->pimpl_netcard;
163 routing_platf->getRouteAndLatency(value1, value2, route,NULL);
164 if (! route->empty()){
165 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
166 for (auto link: *route)
167 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
168 printf("\n </route>\n");
172 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
173 value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
174 if(value2->isRouter()){
175 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
176 std::vector<Link*> *route = new std::vector<Link*>();
177 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
178 for (auto link : *route)
179 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
181 printf("\n </route>\n");
186 xbt_lib_foreach(as_router_lib, cursor_src, src, value1){ // Routes from router
187 value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
188 if (value1->isRouter()){
189 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
190 value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
191 if(value2->isRouter()){
192 printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
193 std::vector<Link*> *route = new std::vector<Link*>();
194 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route,NULL);
195 for(auto link :*route)
196 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
198 printf("\n </route>\n");
201 xbt_dict_foreach(host_list, cursor_dst, dst, value2){ //to host
202 printf(" <route src=\"%s\" dst=\"%s\">\n ",src, dst);
203 std::vector<Link*> *route = new std::vector<Link*>();
204 value2 = sg_host_by_name(dst)->pimpl_netcard;
205 routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,route, NULL);
206 for(auto link : *route)
207 printf("<%s id=\"%s\"/>",link_ctn,link->getName());
209 printf("\n </route>\n");
215 printf("</platform>\n");
218 xbt_os_timer_free(parse_time);