Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
integrate the peer creation in sg_platf properly
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Nov 2011 15:00:57 +0000 (16:00 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 8 Nov 2011 21:43:39 +0000 (22:43 +0100)
include/simgrid/platf.h
src/include/simgrid/platf_interface.h
src/include/surf/surfxml_parse_values.h
src/surf/sg_platf.c
src/surf/surf_routing.c
src/surf/surfxml_parse.c
src/surf/surfxml_parseplatf.c

index e17d1b2..ec702b4 100644 (file)
@@ -68,6 +68,18 @@ typedef struct {
   xbt_dict_t properties;
 } s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
 
+typedef struct s_surf_parsing_peer_arg *sg_platf_peer_cbarg_t;
+typedef struct s_surf_parsing_peer_arg {
+  const char* id;
+  double power;
+  double bw_in;
+  double bw_out;
+  double lat;
+  const char* coord;
+  tmgr_trace_t availability_trace;
+  tmgr_trace_t state_trace;
+} s_surf_parsing_peer_arg_t;
+
 
 XBT_PUBLIC(void) sg_platf_open(void);  // Start a new platform
 XBT_PUBLIC(void) sg_platf_close(void); // Finish the creation of the platform
@@ -78,6 +90,7 @@ XBT_PUBLIC(void) sg_platf_new_AS_close(void);                            // That
 XBT_PUBLIC(void) sg_platf_new_host  (sg_platf_host_cbarg_t   host);   // Add an host  to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_router(sg_platf_router_cbarg_t router); // Add a router to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_link  (sg_platf_link_cbarg_t link);     // Add a link   to the currently described AS
+XBT_PUBLIC(void) sg_platf_new_peer(sg_platf_peer_cbarg_t peer);       // Add a peer   to the currently described AS
 
 
 #endif                          /* SG_PLATF_H */
index 69f3286..4afc6ed 100644 (file)
@@ -20,10 +20,12 @@ void sg_platf_exit(void);
 typedef void (*sg_platf_host_cb_t)(sg_platf_host_cbarg_t);
 typedef void (*sg_platf_router_cb_t)(sg_platf_router_cbarg_t);
 typedef void (*sg_platf_link_cb_t)(sg_platf_link_cbarg_t);
+typedef void (*sg_platf_peer_cb_t)(sg_platf_peer_cbarg_t);
 
 void sg_platf_host_add_cb(sg_platf_host_cb_t);
 void sg_platf_router_add_cb(sg_platf_router_cb_t);
 void sg_platf_link_add_cb(sg_platf_link_cb_t);
+void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct);
 void sg_platf_postparse_add_cb(void_f_void_t fct);
 
 
index bbd97c7..5cc5762 100644 (file)
@@ -7,17 +7,6 @@
 #ifndef SURFXML_PARSE_VALUES_H_
 #define SURFXML_PARSE_VALUES_H_
 
-typedef struct s_surf_parsing_peer_arg *surf_parsing_peer_arg_t;
-typedef struct s_surf_parsing_peer_arg {
-       const char* id;
-       double power;
-       double bw_in;
-       double bw_out;
-       double lat;
-       const char* coord;
-       tmgr_trace_t availability_trace;
-       tmgr_trace_t state_trace;
-} s_surf_parsing_peer_arg_t;
 
 typedef struct s_surf_parsing_cluster_arg *surf_parsing_cluster_arg_t;
 typedef struct s_surf_parsing_cluster_arg {
@@ -46,6 +35,5 @@ typedef struct s_surf_parsing_link_up_down {
 
 
 extern surf_parsing_cluster_arg_t struct_cluster;
-extern surf_parsing_peer_arg_t struct_peer;
 
 #endif /* SURFXML_PARSE_VALUES_H_ */
index c111a40..f19336a 100644 (file)
@@ -14,6 +14,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
 xbt_dynar_t sg_platf_link_cb_list = NULL;   // of sg_platf_link_cb_t
 xbt_dynar_t sg_platf_router_cb_list = NULL; // of sg_platf_router_cb_t
+xbt_dynar_t sg_platf_peer_cb_list = NULL; // of sg_platf_peer_cb_t
 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
 
 /** Module management function: creates all internal data structures */
@@ -21,6 +22,7 @@ void sg_platf_init(void) {
   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
   sg_platf_router_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
+  sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
 }
 /** Module management function: frees all internal data structures */
@@ -28,6 +30,7 @@ void sg_platf_exit(void) {
   xbt_dynar_free(&sg_platf_host_cb_list);
   xbt_dynar_free(&sg_platf_router_cb_list);
   xbt_dynar_free(&sg_platf_postparse_cb_list);
+  xbt_dynar_free(&sg_platf_peer_cb_list);
 }
 
 void sg_platf_new_host(sg_platf_host_cbarg_t h){
@@ -51,6 +54,13 @@ void sg_platf_new_link(sg_platf_link_cbarg_t link){
     (*fun) (link);
   }
 }
+void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
+  unsigned int iterator;
+  sg_platf_peer_cb_t fun;
+  xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
+    (*fun) (peer);
+  }
+}
 
 void sg_platf_open() { /* Do nothing: just for symmetry of user code */ }
 
@@ -72,6 +82,9 @@ void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
 void sg_platf_router_add_cb(sg_platf_router_cb_t fct) {
   xbt_dynar_push(sg_platf_router_cb_list, &fct);
 }
+void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
+  xbt_dynar_push(sg_platf_peer_cb_list, &fct);
+}
 void sg_platf_postparse_add_cb(void_f_void_t fct) {
   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
 }
index 9f6f2e2..cb103a7 100644 (file)
@@ -51,7 +51,7 @@ xbt_dict_t cluster_host_link = NULL; /* for tag cluster */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 
-static void routing_parse_Speer(void);          /* peer bypass */
+static void routing_parse_Speer(sg_platf_peer_cbarg_t peer);          /* peer bypass */
 static void routing_parse_Srandom(void);        /* random bypass */
 
 static char* replace_random_parameter(char * chaine);
@@ -897,9 +897,7 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_
   surfxml_add_callback(STag_surfxml_cluster_cb_list,
                        &routing_parse_Scluster);
 
-  surfxml_add_callback(STag_surfxml_peer_cb_list,
-                         &routing_parse_Speer);
-
+  sg_platf_peer_add_cb(routing_parse_Speer); // FIXME: inline in the sg_platf_new_peer instead
   sg_platf_postparse_add_cb(clean_routing_after_parse);
 
 #ifdef HAVE_TRACING
@@ -1704,7 +1702,7 @@ static void clean_routing_after_parse(void)
        xbt_dict_free(&patterns);
 }
 
-static void routing_parse_Speer(void)
+static void routing_parse_Speer(sg_platf_peer_cbarg_t peer)
 {
   static int AX_ptr = 0;
   char *host_id = NULL;
@@ -1717,51 +1715,51 @@ static void routing_parse_Speer(void)
 
   surfxml_bufferstack_push(1);
 
-  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", struct_peer->id);
-  sg_platf_new_AS_open(struct_peer->id, "Full");
+  XBT_DEBUG("<AS id=\"%s\"\trouting=\"Full\">", peer->id);
+  sg_platf_new_AS_open(peer->id, "Full");
 
   XBT_DEBUG(" ");
-  host_id = HOST_PEER(struct_peer->id);
-  router_id = ROUTER_PEER(struct_peer->id);
-  link_id_up = LINK_UP_PEER(struct_peer->id);
-  link_id_down = LINK_DOWN_PEER(struct_peer->id);
+  host_id = HOST_PEER(peer->id);
+  router_id = ROUTER_PEER(peer->id);
+  link_id_up = LINK_UP_PEER(peer->id);
+  link_id_down = LINK_DOWN_PEER(peer->id);
 
-  link_router = bprintf("%s_link_router", struct_peer->id);
-  link_backbone = bprintf("%s_backbone", struct_peer->id);
+  link_router = bprintf("%s_link_router", peer->id);
+  link_backbone = bprintf("%s_backbone", peer->id);
 
-  XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, struct_peer->power);
+  XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->power);
   s_sg_platf_host_cbarg_t host;
   memset(&host,0,sizeof(host));
   host.initial_state = SURF_RESOURCE_ON;
   host.id = host_id;
-  host.power_peak = struct_peer->power;
+  host.power_peak = peer->power;
   host.power_scale = 1.0;
-  host.power_trace = struct_peer->availability_trace;
-  host.state_trace = struct_peer->state_trace;
+  host.power_trace = peer->availability_trace;
+  host.state_trace = peer->state_trace;
   host.core_amount = 1;
   sg_platf_new_host(&host);
 
 
-  XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, struct_peer->coord);
+  XBT_DEBUG("<router id=\"%s\"\tcoordinates=\"%s\"/>", router_id, peer->coord);
   s_sg_platf_router_cbarg_t router;
   memset(&router,0,sizeof(router));
   router.id = router_id;
-  router.coord = struct_peer->coord;
+  router.coord = peer->coord;
   sg_platf_new_router(&router);
 
-  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_up, struct_peer->bw_in, struct_peer->lat);
+  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_up, peer->bw_in, peer->lat);
   s_sg_platf_link_cbarg_t link;
   memset(&link,0,sizeof(link));
   link.state = SURF_RESOURCE_ON;
   link.policy = SURF_LINK_SHARED;
   link.id = link_id_up;
-  link.bandwidth = struct_peer->bw_in;
-  link.latency = struct_peer->lat;
+  link.bandwidth = peer->bw_in;
+  link.latency = peer->lat;
   sg_platf_new_link(&link);
 
   // FIXME: dealing with full duplex is not the role of this piece of code, I'd say [Mt]
   // Instead, it should be created fullduplex, and the models will do what's needed in this case
-  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_down, struct_peer->bw_out, struct_peer->lat);
+  XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id_down, peer->bw_out, peer->lat);
   link.id = link_id_down;
   sg_platf_new_link(&link);
 
index 756f837..9235b3c 100644 (file)
@@ -337,20 +337,22 @@ void ETag_surfxml_cluster(void){
 }
 
 void STag_surfxml_peer(void){
-       struct_peer = xbt_new0(s_surf_parsing_peer_arg_t, 1);
-       struct_peer->id = A_surfxml_peer_id;
-       struct_peer->power = surf_parse_get_double(A_surfxml_peer_power);
-       struct_peer->bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
-       struct_peer->bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
-       struct_peer->lat = surf_parse_get_double(A_surfxml_peer_lat);
-       struct_peer->coord = A_surfxml_peer_coordinates;
-       struct_peer->availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
-       struct_peer->state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
+  s_surf_parsing_peer_arg_t peer;
+  memset(&peer,0,sizeof(peer));
+       peer.id = A_surfxml_peer_id;
+       peer.power = surf_parse_get_double(A_surfxml_peer_power);
+       peer.bw_in = surf_parse_get_double(A_surfxml_peer_bw_in);
+       peer.bw_out = surf_parse_get_double(A_surfxml_peer_bw_out);
+       peer.lat = surf_parse_get_double(A_surfxml_peer_lat);
+       peer.coord = A_surfxml_peer_coordinates;
+       peer.availability_trace = tmgr_trace_new(A_surfxml_peer_availability_file);
+       peer.state_trace = tmgr_trace_new(A_surfxml_peer_state_file);
+
        surfxml_call_cb_functions(STag_surfxml_peer_cb_list);
+       sg_platf_new_peer(&peer);
 }
 void ETag_surfxml_peer(void){
-       surfxml_call_cb_functions(ETag_surfxml_peer_cb_list);
-       xbt_free(struct_peer);
+  /* nothing to do here */
 }
 void STag_surfxml_link(void){
   s_sg_platf_link_cbarg_t link;
index 4445475..f1d0d4b 100644 (file)
@@ -54,7 +54,6 @@ void surfxml_bufferstack_pop(int new)
  */
 
 surf_parsing_cluster_arg_t struct_cluster = NULL;
-surf_parsing_peer_arg_t struct_peer = NULL;
 
 /*
  * Trace related stuff