1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. 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. */
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
15 "Logging specific to the SURF parsing module");
17 int ETag_surfxml_include_state(void);
19 #include "simgrid_dtd.c"
24 static void surf_parse_error(char *msg) {
25 xbt_die("Parse error on line %d: %s\n", surf_parse_lineno, msg);
28 void surf_parse_get_double(double *value, const char *string) {
29 int ret = sscanf(string, "%lg", value);
31 surf_parse_error(bprintf("%s is not a double", string));
34 void surf_parse_get_int(int *value, const char *string) {
35 int ret = sscanf(string, "%d", value);
37 surf_parse_error(bprintf("%s is not an integer", string));
42 * All the callback lists that can be overiden anywhere.
43 * (this list should probably be reduced to the bare minimum to allow the models to work)
46 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
47 //xbt_dynar_t STag_surfxml_host_cb_list = NULL;
48 xbt_dynar_t surf_parse_host_cb_list = NULL; // of functions of type: surf_parsing_host_arg_t -> void
49 xbt_dynar_t STag_surfxml_platform_cb_list = NULL;
50 xbt_dynar_t ETag_surfxml_platform_cb_list = NULL;
51 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
52 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
53 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
54 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
55 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
56 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
57 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
58 xbt_dynar_t STag_surfxml_link_ctn_cb_list = NULL;
59 xbt_dynar_t ETag_surfxml_link_ctn_cb_list = NULL;
60 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
61 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
62 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
63 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
64 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
65 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
66 xbt_dynar_t STag_surfxml_cluster_cb_list = NULL;
67 xbt_dynar_t ETag_surfxml_cluster_cb_list = NULL;
68 xbt_dynar_t STag_surfxml_peer_cb_list = NULL;
69 xbt_dynar_t ETag_surfxml_peer_cb_list = NULL;
70 xbt_dynar_t STag_surfxml_trace_cb_list = NULL;
71 xbt_dynar_t ETag_surfxml_trace_cb_list = NULL;
72 xbt_dynar_t STag_surfxml_trace_connect_cb_list = NULL;
73 xbt_dynar_t ETag_surfxml_trace_connect_cb_list = NULL;
74 xbt_dynar_t STag_surfxml_random_cb_list = NULL;
75 xbt_dynar_t ETag_surfxml_random_cb_list = NULL;
76 xbt_dynar_t STag_surfxml_AS_cb_list = NULL;
77 xbt_dynar_t ETag_surfxml_AS_cb_list = NULL;
78 xbt_dynar_t STag_surfxml_ASroute_cb_list = NULL;
79 xbt_dynar_t ETag_surfxml_ASroute_cb_list = NULL;
80 xbt_dynar_t STag_surfxml_bypassRoute_cb_list = NULL;
81 xbt_dynar_t ETag_surfxml_bypassRoute_cb_list = NULL;
82 xbt_dynar_t STag_surfxml_include_cb_list = NULL;
83 xbt_dynar_t ETag_surfxml_include_cb_list = NULL;
85 /* The default current property receiver. Setup in the corresponding opening callbacks. */
86 xbt_dict_t current_property_set = NULL;
87 /* dictionary of random generator data */
88 xbt_dict_t random_data_list = NULL;
90 /* Call all the callbacks of a specific SAX event */
91 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
93 YY_BUFFER_STATE surf_input_buffer;
94 FILE *surf_file_to_parse = NULL;
96 static void parse_Stag_trace(void);
97 static void parse_Etag_trace(void);
98 static void parse_Stag_trace_connect(void);
100 static void init_randomness(void);
101 static void add_randomness(void);
104 * Stuff relative to the <include> tag
107 static xbt_dynar_t surf_input_buffer_stack = NULL;
108 static xbt_dynar_t surf_file_to_parse_stack = NULL;
110 void STag_surfxml_include(void)
112 XBT_INFO("STag_surfxml_include '%s'",A_surfxml_include_file);
113 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old filename
115 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new filename
116 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n",
117 A_surfxml_include_file);
118 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
119 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
120 surf_parse_push_buffer_state(surf_input_buffer);
124 void ETag_surfxml_include(void) {
125 /* Nothing to do when done with reading the include tag.
126 * Instead, the handling should be deferred until the EOF of current buffer -- see below */
129 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
131 * This function is called automatically by sedding the parser in buildtools/Cmake/MaintainerMode.cmake
132 * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
133 * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
134 * error message in that case.
136 * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
137 * directly: a command line flag could instruct it to do the correct thing when #include is encountered
140 int ETag_surfxml_include_state(void)
143 XBT_INFO("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
144 if(xbt_dynar_length(surf_input_buffer_stack)!= 0)
146 fclose(surf_file_to_parse);
147 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
148 surf_parse_pop_buffer_state();
149 xbt_dynar_pop(surf_input_buffer_stack,surf_input_buffer);
154 void surf_parse_init_callbacks(void)
156 STag_surfxml_platform_cb_list =
157 xbt_dynar_new(sizeof(void_f_void_t), NULL);
158 ETag_surfxml_platform_cb_list =
159 xbt_dynar_new(sizeof(void_f_void_t), NULL);
161 surf_parse_host_cb_list = xbt_dynar_new(sizeof(surf_parse_host_fct_t), NULL);
163 ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
164 STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
165 ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
166 STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
167 ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
168 STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
169 ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
170 STag_surfxml_link_ctn_cb_list =
171 xbt_dynar_new(sizeof(void_f_void_t), NULL);
172 ETag_surfxml_link_ctn_cb_list =
173 xbt_dynar_new(sizeof(void_f_void_t), NULL);
174 STag_surfxml_process_cb_list =
175 xbt_dynar_new(sizeof(void_f_void_t), NULL);
176 ETag_surfxml_process_cb_list =
177 xbt_dynar_new(sizeof(void_f_void_t), NULL);
178 STag_surfxml_argument_cb_list =
179 xbt_dynar_new(sizeof(void_f_void_t), NULL);
180 ETag_surfxml_argument_cb_list =
181 xbt_dynar_new(sizeof(void_f_void_t), NULL);
182 STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
183 ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
184 STag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
185 ETag_surfxml_trace_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
186 STag_surfxml_trace_connect_cb_list =
187 xbt_dynar_new(sizeof(void_f_void_t), NULL);
188 ETag_surfxml_trace_connect_cb_list =
189 xbt_dynar_new(sizeof(void_f_void_t), NULL);
190 STag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
191 ETag_surfxml_random_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
192 STag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
193 ETag_surfxml_AS_cb_list = xbt_dynar_new(sizeof(void_f_void_t), NULL);
194 STag_surfxml_ASroute_cb_list =
195 xbt_dynar_new(sizeof(void_f_void_t), NULL);
196 ETag_surfxml_ASroute_cb_list =
197 xbt_dynar_new(sizeof(void_f_void_t), NULL);
198 STag_surfxml_bypassRoute_cb_list =
199 xbt_dynar_new(sizeof(void_f_void_t), NULL);
200 ETag_surfxml_bypassRoute_cb_list =
201 xbt_dynar_new(sizeof(void_f_void_t), NULL);
202 STag_surfxml_cluster_cb_list =
203 xbt_dynar_new(sizeof(void_f_void_t), NULL);
204 ETag_surfxml_cluster_cb_list =
205 xbt_dynar_new(sizeof(void_f_void_t), NULL);
206 STag_surfxml_peer_cb_list =
207 xbt_dynar_new(sizeof(void_f_void_t), NULL);
208 ETag_surfxml_peer_cb_list =
209 xbt_dynar_new(sizeof(void_f_void_t), NULL);
210 STag_surfxml_include_cb_list =
211 xbt_dynar_new(sizeof(void_f_void_t), NULL);
212 ETag_surfxml_include_cb_list =
213 xbt_dynar_new(sizeof(void_f_void_t), NULL);
216 void surf_parse_reset_callbacks(void)
218 surf_parse_free_callbacks();
219 surf_parse_init_callbacks();
222 void surf_parse_free_callbacks(void)
224 xbt_dynar_free(&surf_parse_host_cb_list);
226 xbt_dynar_free(&STag_surfxml_platform_cb_list);
227 xbt_dynar_free(&ETag_surfxml_platform_cb_list);
228 xbt_dynar_free(&ETag_surfxml_host_cb_list);
229 xbt_dynar_free(&STag_surfxml_router_cb_list);
230 xbt_dynar_free(&ETag_surfxml_router_cb_list);
231 xbt_dynar_free(&STag_surfxml_link_cb_list);
232 xbt_dynar_free(&ETag_surfxml_link_cb_list);
233 xbt_dynar_free(&STag_surfxml_route_cb_list);
234 xbt_dynar_free(&ETag_surfxml_route_cb_list);
235 xbt_dynar_free(&STag_surfxml_link_ctn_cb_list);
236 xbt_dynar_free(&ETag_surfxml_link_ctn_cb_list);
237 xbt_dynar_free(&STag_surfxml_process_cb_list);
238 xbt_dynar_free(&ETag_surfxml_process_cb_list);
239 xbt_dynar_free(&STag_surfxml_argument_cb_list);
240 xbt_dynar_free(&ETag_surfxml_argument_cb_list);
241 xbt_dynar_free(&STag_surfxml_prop_cb_list);
242 xbt_dynar_free(&ETag_surfxml_prop_cb_list);
243 xbt_dynar_free(&STag_surfxml_trace_cb_list);
244 xbt_dynar_free(&ETag_surfxml_trace_cb_list);
245 xbt_dynar_free(&STag_surfxml_trace_connect_cb_list);
246 xbt_dynar_free(&ETag_surfxml_trace_connect_cb_list);
247 xbt_dynar_free(&STag_surfxml_random_cb_list);
248 xbt_dynar_free(&ETag_surfxml_random_cb_list);
249 xbt_dynar_free(&STag_surfxml_AS_cb_list);
250 xbt_dynar_free(&ETag_surfxml_AS_cb_list);
251 xbt_dynar_free(&STag_surfxml_ASroute_cb_list);
252 xbt_dynar_free(&ETag_surfxml_ASroute_cb_list);
253 xbt_dynar_free(&STag_surfxml_bypassRoute_cb_list);
254 xbt_dynar_free(&ETag_surfxml_bypassRoute_cb_list);
255 xbt_dynar_free(&STag_surfxml_cluster_cb_list);
256 xbt_dynar_free(&ETag_surfxml_cluster_cb_list);
257 xbt_dynar_free(&STag_surfxml_peer_cb_list);
258 xbt_dynar_free(&ETag_surfxml_peer_cb_list);
259 xbt_dynar_free(&STag_surfxml_include_cb_list);
260 xbt_dynar_free(&ETag_surfxml_include_cb_list);
263 /* Stag and Etag parse functions */
265 void STag_surfxml_platform(void)
268 surf_parse_get_double(&version, A_surfxml_platform_version);
270 xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
271 "You're using an ancient XML file.\n"
272 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
273 "instead of MBytes, MFlops and seconds.\n"
275 "Use simgrid_update_xml to update your file automatically. "
276 "This program is installed automatically with SimGrid, or "
277 "available in the tools/ directory of the source archive.\n"
279 "Please check also out the SURF section of the ChangeLog for "
280 "the 3.1 version for more information. \n"
282 "Last, do not forget to also update your values for "
283 "the calls to MSG_task_create (if any).");
284 xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
285 "You're using an old XML file.\n"
286 "Use simgrid_update_xml to update your file automatically. "
287 "This program is installed automatically with SimGrid, or "
288 "available in the tools/ directory of the source archive.");
290 surfxml_call_cb_functions(STag_surfxml_platform_cb_list);
294 void STag_surfxml_host(void){
295 // XBT_INFO("STag_surfxml_host [%s]",A_surfxml_host_id);
296 s_surf_parsing_host_arg_t host;
297 memset(&host,0,sizeof(host));
299 host.V_host_id = xbt_strdup(A_surfxml_host_id);
300 host.V_host_power_peak = get_cpu_power(A_surfxml_host_power);
301 surf_parse_get_double(&(host.V_host_power_scale), A_surfxml_host_availability);
302 surf_parse_get_int(&(host.V_host_core),A_surfxml_host_core);
303 host.V_host_power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
304 host.V_host_state_trace = tmgr_trace_new(A_surfxml_host_state_file);
305 xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
306 (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
307 if (A_surfxml_host_state == A_surfxml_host_state_ON)
308 host.V_host_state_initial = SURF_RESOURCE_ON;
309 if (A_surfxml_host_state == A_surfxml_host_state_OFF)
310 host.V_host_state_initial = SURF_RESOURCE_OFF;
311 host.V_host_coord = xbt_strdup(A_surfxml_host_coordinates);
313 surf_parse_host(&host);
315 void surf_parse_host(surf_parsing_host_arg_t h){
316 unsigned int iterator;
317 surf_parse_host_fct_t fun;
318 xbt_dynar_foreach(surf_parse_host_cb_list, iterator, fun) {
322 void surf_parse_host_add_cb(surf_parse_host_fct_t fct) {
323 xbt_dynar_push(surf_parse_host_cb_list, &fct);
325 void ETag_surfxml_host(void){
326 surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
330 void STag_surfxml_router(void){
331 struct_router = xbt_new0(s_surf_parsing_router_arg_t, 1);
332 struct_router->V_router_id = xbt_strdup(A_surfxml_router_id);
333 struct_router->V_router_coord = xbt_strdup(A_surfxml_router_coordinates);
334 surfxml_call_cb_functions(STag_surfxml_router_cb_list);
336 void ETag_surfxml_router(void){
337 surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
338 xbt_free(struct_router->V_router_id);
339 xbt_free(struct_router->V_router_coord);
340 xbt_free(struct_router);
343 void STag_surfxml_cluster(void){
344 struct_cluster = xbt_new0(s_surf_parsing_cluster_arg_t, 1);
345 struct_cluster->V_cluster_id = xbt_strdup(A_surfxml_cluster_id);
346 struct_cluster->V_cluster_prefix = xbt_strdup(A_surfxml_cluster_prefix);
347 struct_cluster->V_cluster_suffix = xbt_strdup(A_surfxml_cluster_suffix);
348 struct_cluster->V_cluster_radical = xbt_strdup(A_surfxml_cluster_radical);
349 surf_parse_get_double(&struct_cluster->S_cluster_power,A_surfxml_cluster_power);
350 surf_parse_get_int(&struct_cluster->S_cluster_core,A_surfxml_cluster_core);
351 surf_parse_get_double(&struct_cluster->S_cluster_bw,A_surfxml_cluster_bw);
352 surf_parse_get_double(&struct_cluster->S_cluster_lat,A_surfxml_cluster_lat);
353 if(strcmp(A_surfxml_cluster_bb_bw,""))
354 surf_parse_get_double(&struct_cluster->S_cluster_bb_bw,A_surfxml_cluster_bb_bw);
355 if(strcmp(A_surfxml_cluster_bb_lat,""))
356 surf_parse_get_double(&struct_cluster->S_cluster_bb_lat,A_surfxml_cluster_bb_lat);
357 if(!strcmp(A_surfxml_cluster_router_id,""))
358 struct_cluster->S_cluster_router_id = bprintf("%s%s_router%s",
359 struct_cluster->V_cluster_prefix,
360 struct_cluster->V_cluster_id,
361 struct_cluster->V_cluster_suffix);
363 struct_cluster->S_cluster_router_id = xbt_strdup(A_surfxml_cluster_router_id);
365 struct_cluster->V_cluster_sharing_policy = AX_surfxml_cluster_sharing_policy;
366 struct_cluster->V_cluster_bb_sharing_policy = AX_surfxml_cluster_bb_sharing_policy;
368 struct_cluster->V_cluster_availability_file = xbt_strdup(A_surfxml_cluster_availability_file);
369 struct_cluster->V_cluster_state_file = xbt_strdup(A_surfxml_cluster_state_file);
371 surfxml_call_cb_functions(STag_surfxml_cluster_cb_list);
373 void ETag_surfxml_cluster(void){
374 surfxml_call_cb_functions(ETag_surfxml_cluster_cb_list);
375 xbt_free(struct_cluster->V_cluster_id);
376 xbt_free(struct_cluster->V_cluster_prefix);
377 xbt_free(struct_cluster->V_cluster_suffix);
378 xbt_free(struct_cluster->V_cluster_radical);
379 xbt_free(struct_cluster->S_cluster_router_id);
380 xbt_free(struct_cluster->V_cluster_availability_file);
381 xbt_free(struct_cluster->V_cluster_state_file);
382 xbt_free(struct_cluster);
385 void STag_surfxml_peer(void){
386 struct_peer = xbt_new0(s_surf_parsing_peer_arg_t, 1);
387 struct_peer->V_peer_id = xbt_strdup(A_surfxml_peer_id);
388 struct_peer->V_peer_power = xbt_strdup(A_surfxml_peer_power);
389 struct_peer->V_peer_bw_in = xbt_strdup(A_surfxml_peer_bw_in);
390 struct_peer->V_peer_bw_out = xbt_strdup(A_surfxml_peer_bw_out);
391 struct_peer->V_peer_lat = xbt_strdup(A_surfxml_peer_lat);
392 struct_peer->V_peer_coord = xbt_strdup(A_surfxml_peer_coordinates);
393 struct_peer->V_peer_availability_trace = xbt_strdup(A_surfxml_peer_availability_file);
394 struct_peer->V_peer_state_trace = xbt_strdup(A_surfxml_peer_state_file);
395 surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
397 void ETag_surfxml_peer(void){
398 surfxml_call_cb_functions(ETag_surfxml_peer_cb_list);
399 xbt_free(struct_peer->V_peer_id);
400 xbt_free(struct_peer->V_peer_power);
401 xbt_free(struct_peer->V_peer_bw_in);
402 xbt_free(struct_peer->V_peer_bw_out);
403 xbt_free(struct_peer->V_peer_lat);
404 xbt_free(struct_peer->V_peer_coord);
405 xbt_free(struct_peer->V_peer_availability_trace);
406 xbt_free(struct_peer->V_peer_state_trace);
407 xbt_free(struct_peer);
409 void STag_surfxml_link(void){
410 struct_lnk = xbt_new0(s_surf_parsing_link_arg_t, 1);
411 struct_lnk->V_link_id = xbt_strdup(A_surfxml_link_id);
412 surf_parse_get_double(&(struct_lnk->V_link_bandwidth),A_surfxml_link_bandwidth);
413 struct_lnk->V_link_bandwidth_file = tmgr_trace_new(A_surfxml_link_bandwidth_file);
414 surf_parse_get_double(&(struct_lnk->V_link_latency),A_surfxml_link_latency);
415 struct_lnk->V_link_latency_file = tmgr_trace_new(A_surfxml_link_latency_file);
416 xbt_assert((A_surfxml_link_state == A_surfxml_link_state_ON) ||
417 (A_surfxml_link_state == A_surfxml_link_state_OFF), "Invalid state");
418 if (A_surfxml_link_state == A_surfxml_link_state_ON)
419 struct_lnk->V_link_state = SURF_RESOURCE_ON;
420 if (A_surfxml_link_state == A_surfxml_link_state_OFF)
421 struct_lnk->V_link_state = SURF_RESOURCE_OFF;
422 struct_lnk->V_link_state_file = tmgr_trace_new(A_surfxml_link_state_file);
423 struct_lnk->V_link_sharing_policy = A_surfxml_link_sharing_policy;
425 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_SHARED)
426 struct_lnk->V_policy_initial_link = SURF_LINK_SHARED;
429 if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FATPIPE)
430 struct_lnk->V_policy_initial_link = SURF_LINK_FATPIPE;
431 else if (A_surfxml_link_sharing_policy == A_surfxml_link_sharing_policy_FULLDUPLEX)
432 struct_lnk->V_policy_initial_link = SURF_LINK_FULLDUPLEX;
437 void surf_parse_link(void){
438 surfxml_call_cb_functions(STag_surfxml_link_cb_list);
440 void ETag_surfxml_link(void){
441 surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
442 xbt_free(struct_lnk->V_link_id);
443 xbt_free(struct_lnk);
446 void STag_surfxml_route(void){
447 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
449 void STag_surfxml_link_ctn(void){
450 surfxml_call_cb_functions(STag_surfxml_link_ctn_cb_list);
452 void STag_surfxml_process(void){
453 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
455 void STag_surfxml_argument(void){
456 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
458 void STag_surfxml_prop(void){
459 surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
461 void STag_surfxml_trace(void){
462 surfxml_call_cb_functions(STag_surfxml_trace_cb_list);
464 void STag_surfxml_trace_connect(void){
465 surfxml_call_cb_functions(STag_surfxml_trace_connect_cb_list);
467 void STag_surfxml_AS(void){
468 surfxml_call_cb_functions(STag_surfxml_AS_cb_list);
470 void STag_surfxml_ASroute(void){
471 surfxml_call_cb_functions(STag_surfxml_ASroute_cb_list);
473 void STag_surfxml_bypassRoute(void){
474 surfxml_call_cb_functions(STag_surfxml_bypassRoute_cb_list);
476 void STag_surfxml_config(void){
477 XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
478 xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
479 current_property_set = xbt_dict_new();
482 void ETag_surfxml_config(void){
483 xbt_dict_cursor_t cursor = NULL;
487 xbt_dict_foreach(current_property_set, cursor, key, elem) {
488 cfg = bprintf("%s:%s",key,elem);
489 if(xbt_cfg_is_default_value(_surf_cfg_set, key))
490 xbt_cfg_set_parse(_surf_cfg_set, cfg);
492 XBT_INFO("The custom configuration '%s' is already defined by user!",key);
495 XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
496 current_property_set = NULL;
498 void STag_surfxml_random(void){
499 surfxml_call_cb_functions(STag_surfxml_random_cb_list);
502 #define parse_method(type,name) \
503 void type##Tag_surfxml_##name(void) \
504 { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }
505 parse_method(E, platform);
506 parse_method(E, route);
507 parse_method(E, link_ctn);
508 parse_method(E, process);
509 parse_method(E, argument);
510 parse_method(E, prop);
511 parse_method(E, trace);
512 parse_method(E, trace_connect);
513 parse_method(E, random);
515 parse_method(E, ASroute);
516 parse_method(E, bypassRoute);
518 /* Open and Close parse file */
520 void surf_parse_open(const char *file)
522 static int warned = 0; /* warn only once */
526 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. "
527 "If it is not what you want, go fix your code.");
533 if (!surf_input_buffer_stack)
534 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
535 if (!surf_file_to_parse_stack)
536 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
538 surf_file_to_parse = surf_fopen(file, "r");
539 xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
540 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
541 surf_parse__switch_to_buffer(surf_input_buffer);
542 surf_parse_lineno = 1;
545 void surf_parse_close(void)
547 if (surf_input_buffer_stack)
548 xbt_dynar_free(&surf_input_buffer_stack);
549 if (surf_file_to_parse_stack)
550 xbt_dynar_free(&surf_file_to_parse_stack);
552 if (surf_file_to_parse) {
553 surf_parse__delete_buffer(surf_input_buffer);
554 fclose(surf_file_to_parse);
555 surf_file_to_parse = NULL; //Must be reset for Bypass
559 /* Call the lexer to parse the currently opened file. This pointer to function enables bypassing of the parser */
561 static int _surf_parse(void) {
562 return surf_parse_lex();
564 int_f_void_t surf_parse = _surf_parse;
567 /* Aux parse functions */
569 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
571 xbt_dynar_push(cb_list, &function);
574 void surfxml_del_callback(xbt_dynar_t cb_list, void_f_void_t function)
578 void_f_void_t null_f=NULL;
581 it = xbt_dynar_search(cb_list,&function);
584 if (e.category == not_found_error) {
586 xbt_die("Trying to remove a callback that is not here! This should not happen");
591 xbt_dynar_replace(cb_list, it,&null_f);
594 static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
596 unsigned int iterator;
598 xbt_dynar_foreach(cb_list, iterator, fun) {
604 /* Prop tag functions */
606 void parse_properties(const char* prop_id, const char* prop_value)
609 if (!current_property_set)
610 current_property_set = xbt_dict_new(); // Maybe, it should raise an error
611 if(!strcmp(prop_id,"coordinates")){
612 if(!strcmp(prop_value,"yes") && !COORD_HOST_LEVEL)
614 XBT_INFO("Configuration change: Set '%s' to '%s'", prop_id, prop_value);
615 COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
616 COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
618 if(strcmp(A_surfxml_prop_value,"yes"))
619 xbt_die("Setting XML prop coordinates must be \"yes\"");
622 value = xbt_strdup(prop_value);
623 xbt_dict_set(current_property_set, prop_id, value, free);
630 void parse_properties_XML(void)
632 parse_properties(A_surfxml_prop_id, A_surfxml_prop_value);
636 /* Random tag functions */
638 double get_cpu_power(const char *power)
640 double power_scale = 0.0;
643 random_data_t random = NULL;
644 /* randomness is inserted like this: power="$rand(my_random)" */
645 if (((p = strstr(power, "$rand(")) != NULL)
646 && ((q = strstr(power, ")")) != NULL)) {
648 generator = xbt_malloc(q - (p + 6) + 1);
649 memcpy(generator, p + 6, q - (p + 6));
650 generator[q - (p + 6)] = '\0';
651 random = xbt_dict_get_or_null(random_data_list, generator);
652 xbt_assert(random, "Random generator %s undefined", generator);
653 power_scale = random_generate(random);
656 surf_parse_get_double(&power_scale, power);
661 double random_min, random_max, random_mean, random_std_deviation,
665 static void init_randomness(void)
667 random_id = A_surfxml_random_id;
668 surf_parse_get_double(&random_min, A_surfxml_random_min);
669 surf_parse_get_double(&random_max, A_surfxml_random_max);
670 surf_parse_get_double(&random_mean, A_surfxml_random_mean);
671 surf_parse_get_double(&random_std_deviation,
672 A_surfxml_random_std_deviation);
673 random_generator = A_surfxml_random_generator;
676 static void add_randomness(void)
678 /* If needed aditional properties can be added by using the prop tag */
679 random_data_t random =
680 random_new(random_generator, 0, random_min, random_max, random_mean,
681 random_std_deviation);
682 xbt_dict_set(random_data_list, random_id, (void *) random,
687 * create CPU resource via CPU Model
689 void* surf_host_create_resource(char *name, double power_peak,
691 tmgr_trace_t power_trace, int core,
692 e_surf_resource_state_t state_initial,
693 tmgr_trace_t state_trace,
694 xbt_dict_t cpu_properties)
696 return surf_cpu_model->extension.cpu.create_resource(name, power_peak,
706 * create CPU resource via worsktation_ptask_L07 model
709 void* surf_wsL07_host_create_resource(char *name, double power_peak,
711 tmgr_trace_t power_trace,
712 e_surf_resource_state_t state_initial,
713 tmgr_trace_t state_trace,
714 xbt_dict_t cpu_properties)
716 return surf_workstation_model->extension.workstation.cpu_create_resource(name,
726 * create link resource via network Model
728 void* surf_link_create_resource(char *name,
730 tmgr_trace_t bw_trace,
732 tmgr_trace_t lat_trace,
733 e_surf_resource_state_t
735 tmgr_trace_t state_trace,
736 e_surf_link_sharing_policy_t policy,
737 xbt_dict_t properties)
739 return surf_network_model->extension.network.create_resource(name,
751 * create link resource via workstation_ptask_L07 model
754 void* surf_wsL07_link_create_resource(char *name,
756 tmgr_trace_t bw_trace,
758 tmgr_trace_t lat_trace,
759 e_surf_resource_state_t
761 tmgr_trace_t state_trace,
762 e_surf_link_sharing_policy_t
763 policy, xbt_dict_t properties)
765 return surf_workstation_model->extension.workstation.
766 link_create_resource(name, bw_initial, bw_trace, lat_initial,
767 lat_trace, state_initial, state_trace, policy,
772 * add host to the network element list
774 void surf_route_add_host(const char *host_id)
776 routing_add_host(host_id);
782 void surf_routing_add_route(const char *src_id, const char *dst_id,
783 xbt_dynar_t links_id)
787 routing_set_route(src_id, dst_id);
788 xbt_dynar_foreach(links_id, i, link_id) {
789 routing_add_link(link_id);
793 routing_store_route();
799 void surf_add_host_traces(void)
801 return surf_cpu_model->extension.cpu.add_traces();
804 void surf_add_link_traces(void)
806 return surf_network_model->extension.network.add_traces();
809 void surf_wsL07_add_traces(void)
811 return surf_workstation_model->extension.workstation.add_traces();