Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move e_surf_link_sharing_policy_t structure to surf.h and fix the way to create link...
[simgrid.git] / src / surf / surfxml_parse.c
index 0384741..ea7f315 100644 (file)
@@ -1,6 +1,5 @@
-/*     $Id$     */
-
-/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
+/* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -270,6 +269,7 @@ void ETag_surfxml_platform(void)
 void STag_surfxml_host(void)
 {
   surfxml_call_cb_functions(STag_surfxml_host_cb_list);
+
 }
 
 void ETag_surfxml_host(void)
@@ -438,13 +438,14 @@ void surf_parse_open(const char *file)
     }
     return;
   }
+  surf_file_to_parse = surf_fopen(file, "r");
+  xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
+
   if (!surf_input_buffer_stack)
     surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
   if (!surf_file_to_parse_stack)
     surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
 
-  surf_file_to_parse = surf_fopen(file, "r");
-  xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
   surf_parse__switch_to_buffer(surf_input_buffer);
   surf_parse_lineno = 1;
@@ -463,7 +464,6 @@ void surf_parse_close(void)
   }
 }
 
-
 static int _surf_parse(void)
 {
   return surf_parse_lex();
@@ -609,11 +609,15 @@ static void free_data(void)
 
 void parse_platform_file(const char *file)
 {
+  int parse_status;
   surf_parse_open(file);
   init_data();
-  xbt_assert1((!(*surf_parse) ()), "Parse error in %s", file);
+  parse_status = surf_parse();
   free_data();
   surf_parse_close();
+  if (parse_status)
+    xbt_dict_free(&random_data_list);
+  xbt_assert1(!parse_status, "Parse error in %s", file);
 }
 
 /* Functions to bypass route tag. Used by the route:multi tag */
@@ -693,6 +697,7 @@ static void parse_sets(void)
 }
 
 static void parse_host_foreach(void){
+
   xbt_dynar_t names = NULL;
   unsigned int cpt = 0;
   char *name;
@@ -704,7 +709,6 @@ static void parse_host_foreach(void){
   const char *surfxml_host_availability_file = A_surfxml_host_availability_file;
   const char *surfxml_host_state_file = A_surfxml_host_state_file;
 
-
   xbt_dict_t cluster_host_props = current_property_set;
 
   names = xbt_dict_get_or_null(set_list, foreach_set_name);
@@ -873,7 +877,7 @@ void manage_route(xbt_dict_t routing_table, const char *route_name,
       xbt_dynar_free(&links);
       break;
     case A_surfxml_route_action_POSTPEND:      /* add existing links in front; links + route_link_list */
-      xbt_dynar_foreach(route_link_list, cpt, value) {
+       xbt_dynar_foreach(route_link_list, cpt, value) {
         xbt_dynar_push(links, &value);
       }
       xbt_dynar_free(&route_link_list);
@@ -887,6 +891,7 @@ void manage_route(xbt_dict_t routing_table, const char *route_name,
           route_name,action));
       break;
     }
+
   }
   /* this is the final route; do not add if name is a set; add only if name is in set list */
   if (!isMultiRoute) {
@@ -1160,3 +1165,122 @@ static void add_randomness(void)
                random_std_deviation);
   xbt_dict_set(random_data_list, random_id, (void *) random, NULL);
 }
+
+/**
+ * create CPU resource via CPU Model
+ */
+void surf_host_create_resource(char *name, double power_peak,
+        double power_scale,
+        tmgr_trace_t power_trace,
+        e_surf_resource_state_t state_initial,
+        tmgr_trace_t state_trace,
+        xbt_dict_t cpu_properties)
+{
+       return surf_cpu_model->extension.cpu.
+               create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties);
+}
+
+/*
+ * create CPU resource via worsktation_ptask_L07 model
+ */
+
+void surf_wsL07_host_create_resource(char *name, double power_peak,
+        double power_scale,
+        tmgr_trace_t power_trace,
+        e_surf_resource_state_t state_initial,
+        tmgr_trace_t state_trace,
+        xbt_dict_t cpu_properties)
+{
+       surf_workstation_model->extension.workstation.
+               cpu_create_resource(name,power_peak,power_scale,power_trace,state_initial,state_trace,cpu_properties);
+}
+/*
+ * create link resource via network Model
+ */
+void surf_link_create_resource(char *name,
+        double bw_initial,
+        tmgr_trace_t bw_trace,
+        double lat_initial,
+        tmgr_trace_t lat_trace,
+        e_surf_resource_state_t
+        state_initial,
+        tmgr_trace_t state_trace,
+        e_surf_link_sharing_policy_t policy,
+        xbt_dict_t properties)
+{
+       return surf_network_model->extension.network.
+            create_resource(name,bw_initial,bw_trace,lat_initial,lat_trace,
+                        state_initial,state_trace,policy,properties);
+
+}
+
+/*
+ * create link resource via workstation_ptask_L07 model
+ */
+
+void surf_wsL07_link_create_resource(char *name,
+        double bw_initial,
+        double lat_initial)
+{
+       return surf_workstation_model->extension.workstation.
+       link_create_resource(name,bw_initial,lat_initial);
+}
+
+
+/**
+ * Route: add route element bypassing the parser :
+ * same job as parse_route_elem
+ */
+
+void surf_add_route_element(char* link_ctn_id)
+{
+       char *val;
+       val = xbt_strdup(link_ctn_id);
+       xbt_dynar_push(route_link_list,&val);
+}
+/**
+ * set route
+ */
+void surf_route_set_resource(char *source_id,char *destination_id,xbt_dynar_t links_id,int action)
+{
+       route_link_list = xbt_dynar_new(sizeof(char *), NULL);
+       routing_add_route(source_id,destination_id,links_id,action);
+
+}
+
+/**
+ * add host to routing host list
+ */
+void surf_route_add_host(char *host_id)
+{
+       routing_add_host(host_id);
+}
+
+/*
+ * Add Traces
+ */
+void surf_add_host_traces(void)
+{
+       return surf_cpu_model->extension.cpu.
+                    add_traces();
+}
+
+void surf_add_link_traces(void)
+{
+       return surf_network_model->extension.network.
+                        add_traces();
+}
+
+void surf_wsL07_add_traces(void)
+{
+       return surf_workstation_model->extension.workstation.
+                       add_traces();
+}
+/**
+ * set routes
+ */
+void surf_set_routes(void)
+{
+       routing_set_routes();
+}
+