Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a function to have type of an element.
authornavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 7 Oct 2010 15:10:16 +0000 (15:10 +0000)
committernavarrop <navarrop@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 7 Oct 2010 15:10:16 +0000 (15:10 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8373 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/surf/surf_private.h
src/surf/surf_routing.c
teshsuite/simdag/platforms/basic_parsing_test.c
teshsuite/simdag/platforms/is_router_test.c [new file with mode: 0644]
teshsuite/simdag/platforms/two_clusters_one_name.xml [new file with mode: 0644]

index 9f33fc0..8f42b3a 100644 (file)
@@ -87,64 +87,39 @@ int __surf_is_absolute_file_path(const char *file_path);
 /*
  * One link routing list
  */
-typedef struct s_onelink s_onelink_t, *onelink_t;
-struct s_onelink{
+typedef struct s_onelink {
        char *src;
        char *dst;
        void *link_ptr;
-};
-
+} s_onelink_t, *onelink_t;
 
 /**
  * Routing logic
  */
 
-typedef enum {
-  SURF_NETWORK_ELEMENT_NULL = 0,   /* NULL */
-  SURF_NETWORK_ELEMENT_HOST,       /* host type */
-  SURF_NETWORK_ELEMENT_ROUTER,     /* router type */
-  SURF_NETWORK_ELEMENT_GATEWAY,    /* gateway type of the AS */
-  SURF_NETWORK_ELEMENT_AS,         /* AS type */
-  SURF_NETWORK_ELEMENT_AS_GATEWAY, /* gateway type for internals AS */
-  SURF_NETWORK_ELEMENT_LINK        /* link type */
-} e_surf_network_element_type_t;
-
-typedef struct s_model_type s_model_type_t, *model_type_t;
-typedef struct s_network_element s_network_element_t, *network_element_t;
-typedef struct s_route s_route_t, *route_t;
-typedef struct s_route_limits s_route_limits_t, *route_limits_t;
-typedef struct s_route_extended s_route_extended_t, *route_extended_t;
-typedef struct s_routing_component s_routing_component_t, *routing_component_t;
-//typedef struct s_routing_global s_routing_global_t, *routing_global_t;
-
-struct s_model_type {
-  const char *name;
-  const char *desc;
-  void* (*create)();
-  void (*load)();
-  void (*unload)();
-  void (*end)();
-};
-
-struct s_network_element {
-  //int id;
-  e_surf_network_element_type_t type;
-};
+typedef struct s_model_type {
+         const char *name;
+         const char *desc;
+         void* (*create)();
+         void (*load)();
+         void (*unload)();
+         void (*end)();
+} s_model_type_t, *model_type_t;
 
-struct s_route {
+typedef struct s_route  {
   xbt_dynar_t link_list;
-};
+} s_route_t, *route_t;
 
-struct s_route_limits {
-  char* src_gateway;
-  char* dst_gateway;
-};
+typedef struct s_route_limits {
+         char* src_gateway;
+         char* dst_gateway;
+} s_route_limits_t, *route_limits_t;
 
-struct s_route_extended {
-  s_route_t generic_route;
-  char* src_gateway;
-  char* dst_gateway;
-};
+typedef struct s_route_extended {
+         s_route_t generic_route;
+         char* src_gateway;
+         char* dst_gateway;
+} s_route_extended_t, *route_extended_t;
 
 /* This enum used in the routing structure helps knowing in which situation we are. */
 typedef enum {
@@ -153,32 +128,47 @@ typedef enum {
   SURF_ROUTING_RECURSIVE   /**< Recursive case: also return gateway informations */
 } e_surf_routing_hierarchy_t;
 
-struct s_routing_component {
-  model_type_t routing;
-  e_surf_routing_hierarchy_t hierarchy;
-  char *name;
-  struct s_routing_component* routing_father;
-  xbt_dict_t routing_sons;
-  route_extended_t (*get_route)(routing_component_t rc, const char* src, const char* dst);
-  xbt_dynar_t (*get_onelink_routes)(routing_component_t rc);
-  int (*is_router)(routing_component_t rc, const char *name);
-  route_extended_t (*get_bypass_route)(routing_component_t rc, const char* src, const char* dst);
-  void (*finalize)(routing_component_t rc);
-  void (*set_processing_unit)(routing_component_t rc, const char* name);
-  void (*set_autonomous_system)(routing_component_t rc, const char* name);
-  void (*set_route)(routing_component_t rc, const char* src, const char* dst, route_t route);
-  void (*set_ASroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t route);
-  void (*set_bypassroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route);
-};
+typedef enum {
+  SURF_NETWORK_ELEMENT_NULL = 0,   /* NULL */
+  SURF_NETWORK_ELEMENT_HOST,       /* host type */
+  SURF_NETWORK_ELEMENT_ROUTER,     /* router type */
+  SURF_NETWORK_ELEMENT_AS,         /* AS type */
+} e_surf_network_element_type_t;
+
+typedef struct s_routing_component *routing_component_t;
+typedef struct s_routing_component {
+         model_type_t routing;
+         e_surf_routing_hierarchy_t hierarchy;
+         char *name;
+         struct s_routing_component* routing_father;
+         xbt_dict_t routing_sons;
+         route_extended_t (*get_route)(routing_component_t rc, const char* src, const char* dst);
+         xbt_dynar_t (*get_onelink_routes)(routing_component_t rc);
+         e_surf_network_element_type_t (*get_network_element_type) (const char *name);
+         route_extended_t (*get_bypass_route)(routing_component_t rc, const char* src, const char* dst);
+         void (*finalize)(routing_component_t rc);
+         void (*set_processing_unit)(routing_component_t rc, const char* name);
+         void (*set_autonomous_system)(routing_component_t rc, const char* name);
+         void (*set_route)(routing_component_t rc, const char* src, const char* dst, route_t route);
+         void (*set_ASroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t route);
+         void (*set_bypassroute)(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route);
+} s_routing_component_t;
+
+typedef struct s_network_element_info {
+       routing_component_t rc_component;
+       e_surf_network_element_type_t rc_type;
+} s_network_element_info_t, *network_element_info_t;
+
+typedef int *network_element_t;
 
 struct s_routing_global {
   routing_component_t root;
-  xbt_dict_t where_network_elements; /* char* -> s_routing_component* */
+  xbt_dict_t where_network_elements; /* char* -> network_element_info_t */
   void *loopback;
   size_t size_of_link;
   xbt_dynar_t (*get_route)(const char* src, const char* dst);
   xbt_dynar_t (*get_onelink_routes)(void);
-  int (*is_router)(const char *name);
+  e_surf_network_element_type_t (*get_network_element_type)(const char *name);
   void (*finalize)(void);
   xbt_dynar_t last_route;
 };
index 0e1c663..0db9896 100644 (file)
@@ -101,7 +101,6 @@ static void generic_set_bypassroute(routing_component_t rc, const char* src, con
 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
 
 static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc);
-static int generic_is_router (routing_component_t rc, const char *name);
 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst);
 
 /* ************************************************************************** */
@@ -128,13 +127,17 @@ static xbt_dynar_t link_list = NULL; /* temporary store of current list link of
  * \brief Add a "host" to the network element list
  */
 static void  parse_S_host(char* host_id) {
-  if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
+       network_element_info_t info = NULL;
+       if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,host_id),
       "Reading a host, processing unit \"%s\" already exist",host_id);
   xbt_assert1(current_routing->set_processing_unit,
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
   (*(current_routing->set_processing_unit))(current_routing,host_id);
-  xbt_dict_set(global_routing->where_network_elements,host_id,(void*)current_routing,NULL);
+  info = xbt_new0(s_network_element_info_t,1);
+  info->rc_component=current_routing;
+  info->rc_type=SURF_NETWORK_ELEMENT_HOST;
+  xbt_dict_set(global_routing->where_network_elements,host_id,(void*)info,NULL);
 }
 
 /*
@@ -160,13 +163,18 @@ static void parse_S_host_lua(char *host_id)
  * \brief Add a "router" to the network element list
  */
 static void parse_S_router(void) {
+  network_element_info_t info = NULL;
+
   if( current_routing->hierarchy == SURF_ROUTING_NULL ) current_routing->hierarchy = SURF_ROUTING_BASE;
   xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,A_surfxml_router_id),
       "Reading a router, processing unit \"%s\" already exist",A_surfxml_router_id);
   xbt_assert1(current_routing->set_processing_unit,
       "no defined method \"set_processing_unit\" in \"%s\"",current_routing->name);
   (*(current_routing->set_processing_unit))(current_routing,A_surfxml_router_id);
-  xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)current_routing,NULL); 
+  info = xbt_new0(s_network_element_info_t,1);
+  info->rc_component=current_routing;
+  info->rc_type=SURF_NETWORK_ELEMENT_ROUTER;
+  xbt_dict_set(global_routing->where_network_elements,A_surfxml_router_id,(void*)info,NULL);
   #ifdef HAVE_TRACING
     TRACE_surf_host_declaration (A_surfxml_router_id, 0);
   #endif
@@ -352,7 +360,7 @@ static void parse_S_AS(char* AS_id,char* AS_routing) {
     new_routing->routing_father = NULL;
     global_routing->root = new_routing;
     
-  } else if( current_routing != NULL && global_routing->root != NULL ) { 
+  } else if( current_routing != NULL && global_routing->root != NULL ) {
     
     xbt_assert1(!xbt_dict_get_or_null(current_routing->routing_sons,AS_id),
            "The AS \"%s\" already exist",AS_id);
@@ -404,9 +412,13 @@ static void parse_E_AS(char *AS_id) {
   if( current_routing == NULL ) {
     THROW1(arg_error,0,"Close AS(%s), that never open",AS_id);
   } else {
+         network_element_info_t info = NULL;
       xbt_assert1(!xbt_dict_get_or_null(global_routing->where_network_elements,current_routing->name),
           "The AS \"%s\" already exist",current_routing->name);
-      xbt_dict_set(global_routing->where_network_elements,current_routing->name,current_routing->routing_father,NULL);
+      info = xbt_new0(s_network_element_info_t,1);
+      info->rc_component=current_routing->routing_father;
+      info->rc_type=SURF_NETWORK_ELEMENT_AS;
+      xbt_dict_set(global_routing->where_network_elements,current_routing->name,info,NULL);
       (*(current_routing->routing->unload))();
       (*(current_routing->routing->end))();
       current_routing = current_routing->routing_father;
@@ -719,11 +731,11 @@ static xbt_dynar_t get_onelink_routes(void)
   return recursive_get_onelink_routes (global_routing->root);
 }
 
-static int is_router(const char *name)
+static e_surf_network_element_type_t get_network_element_type(const char *name)
 {
-       routing_component_t rc=NULL;
+       network_element_info_t rc=NULL;
        rc = xbt_dict_get(global_routing->where_network_elements,name);
-       return rc->is_router(rc, name);
+       return rc->rc_type;
 }
 
 /**
@@ -739,7 +751,7 @@ void routing_model_create(size_t size_of_links, void* loopback) {
   global_routing->root = NULL;
   global_routing->get_route = get_route;
   global_routing->get_onelink_routes = get_onelink_routes;
-  global_routing->is_router = is_router;
+  global_routing->get_network_element_type = get_network_element_type;
   global_routing->finalize = finalize;
   global_routing->loopback = loopback;
   global_routing->size_of_link = size_of_links;
@@ -816,16 +828,6 @@ static xbt_dynar_t full_get_onelink_routes(routing_component_t rc)
   return ret;
 }
 
-static int full_is_router(routing_component_t rc, const char *name)
-{
-  routing_component_full_t routing = (routing_component_full_t)rc;
-
-  if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
-         return 1;
-  else
-         return 0;
-}
-
 static route_extended_t full_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
   
@@ -887,7 +889,6 @@ static void* model_full_create(void) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = full_get_route;
   new_component->generic_routing.get_onelink_routes = full_get_onelink_routes;
-  new_component->generic_routing.is_router = full_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = full_finalize;
   new_component->to_index = xbt_dict_new();
@@ -1014,16 +1015,6 @@ static xbt_dynar_t floyd_get_onelink_routes(routing_component_t rc)
   return ret;
 }
 
-static int floyd_is_router(routing_component_t rc, const char *name)
-{
-  routing_component_floyd_t routing = (routing_component_floyd_t)rc;
-
-  if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
-         return 1;
-  else
-         return 0;
-}
-
 static route_extended_t floyd_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
   
@@ -1124,7 +1115,6 @@ static void* model_floyd_create(void) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = floyd_get_route;
   new_component->generic_routing.get_onelink_routes = floyd_get_onelink_routes;
-  new_component->generic_routing.is_router = floyd_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = floyd_finalize;
   new_component->to_index = xbt_dict_new();
@@ -1378,16 +1368,6 @@ static xbt_dynar_t dijkstra_get_onelink_routes(routing_component_t rc)
   xbt_die("\"dijkstra_get_onelink_routes\" function not implemented yet");
 }
 
-static int dijkstra_is_router(routing_component_t rc, const char *name)
-{
-  routing_component_dijkstra_t routing = (routing_component_dijkstra_t)rc;
-
-  if(SURF_NETWORK_ELEMENT_ROUTER == ( (network_element_t) xbt_dict_get(routing->to_index , name) )->type )
-         return 1;
-  else
-         return 0;
-}
-
 static route_extended_t dijkstra_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
   
@@ -1594,7 +1574,6 @@ static void* model_dijkstra_both_create(int cached) {
   new_component->generic_routing.set_bypassroute = generic_set_bypassroute;
   new_component->generic_routing.get_route = dijkstra_get_route;
   new_component->generic_routing.get_onelink_routes = dijkstra_get_onelink_routes;
-  new_component->generic_routing.is_router = dijkstra_is_router;
   new_component->generic_routing.get_bypass_route = generic_get_bypassroute;
   new_component->generic_routing.finalize = dijkstra_finalize;
   new_component->cached = cached;
@@ -1843,15 +1822,6 @@ static xbt_dynar_t rulebased_get_onelink_routes(routing_component_t rc)
   xbt_die("\"rulebased_get_onelink_routes\" function not implemented yet");
 }
 
-static int rulebased_is_router(routing_component_t rc, const char *name)
-{
-         //routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
-
-//PIERRE FIXME
-
-       xbt_die("\"rulebased_is_router\" function not implemented yet");
-}
-
 /* Business methods */
 static route_extended_t rulebased_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
@@ -1955,7 +1925,6 @@ static void* model_rulebased_create(void) {
   new_component->generic_routing.set_ASroute = model_rulebased_set_ASroute;
   new_component->generic_routing.set_bypassroute = model_rulebased_set_bypassroute;
   new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
-  new_component->generic_routing.is_router = rulebased_is_router;
   new_component->generic_routing.get_route = rulebased_get_route;
   new_component->generic_routing.get_bypass_route = NULL; //rulebased_get_bypass_route;
   new_component->generic_routing.finalize = rulebased_finalize;
@@ -1992,9 +1961,6 @@ typedef struct {
 static xbt_dynar_t none_get_onelink_routes(routing_component_t rc){
   return NULL;
 }
-static int none_is_router(routing_component_t rc, const char *name){
-  return -1;
-}
 static route_extended_t none_get_route(routing_component_t rc, const char* src,const char* dst){
   return NULL;
 }
@@ -2018,7 +1984,6 @@ static void* model_none_create(void) {
   new_component->generic_routing.set_bypassroute = NULL;
   new_component->generic_routing.get_route = none_get_route;
   new_component->generic_routing.get_onelink_routes = none_get_onelink_routes;
-  new_component->generic_routing.is_router = none_is_router;
   new_component->generic_routing.get_bypass_route = none_get_bypass_route;
   new_component->generic_routing.finalize = none_finalize;
   return new_component;
@@ -2222,11 +2187,6 @@ static xbt_dynar_t generic_get_onelink_routes (routing_component_t rc)
   xbt_die("\"generic_get_onelink_routes\" not implemented yet");
 }
 
-static int generic_is_router (routing_component_t rc, const char *name)
-{
-  xbt_die("\"generic_is_router\" not implemented yet");
-}
-
 static route_extended_t generic_get_bypassroute(routing_component_t rc, const char* src, const char* dst) {
   model_type_t modeltype = rc->routing;
   xbt_dict_t dict_bypassRoutes;
index 0bb7711..6455f43 100644 (file)
@@ -53,7 +53,6 @@ if(argc == 3)
                        SD_route_get_current_latency(w1, w2),
                        SD_route_get_current_bandwidth(w1, w2));
 
-         printf("%s is router : %d\n",name1,global_routing->is_router(name1));
        }
        if(!strcmp(argv[2],"FULL_LINK"))
        {
diff --git a/teshsuite/simdag/platforms/is_router_test.c b/teshsuite/simdag/platforms/is_router_test.c
new file mode 100644 (file)
index 0000000..3520683
--- /dev/null
@@ -0,0 +1,38 @@
+/* Copyright (c) 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. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "simdag/simdag.h"
+#include "surf/surf_private.h"
+
+extern routing_global_t global_routing;
+
+int main(int argc, char **argv)
+{
+  /* initialisation of SD */
+  int size;
+  xbt_dict_t eltms = xbt_dict_new();
+  SD_init(&argc, argv);
+  xbt_dict_cursor_t cursor=NULL;
+   char *key,*data;
+
+  /* creation of the environment */
+  SD_create_environment(argv[1]);
+
+  eltms = global_routing->where_network_elements;
+  size = xbt_dict_size(eltms);
+
+  printf("Workstation number: %d, link number: %d, elmts number: %d\n",SD_workstation_get_number(), SD_link_get_number(),size);
+
+  xbt_dict_foreach(eltms,cursor,key,data) {
+     printf("   - Seen: \"%s\" is type : %d\n",key,(int) global_routing->get_network_element_type(key));
+  }
+  //printf("%s is router : %d\n",name1,global_routing->is_router(name1));
+  xbt_dict_free(&eltms);
+  SD_exit();
+  return 0;
+}
diff --git a/teshsuite/simdag/platforms/two_clusters_one_name.xml b/teshsuite/simdag/platforms/two_clusters_one_name.xml
new file mode 100644 (file)
index 0000000..b4156ba
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version='1.0'?>
+ <!DOCTYPE platform SYSTEM "simgrid.dtd">
+ <platform version="2">
+ <AS  id="AS0"  routing="Full">
+       
+     <cluster id="bob_cluster" prefix="bob" suffix=".hamburger.edu"
+           radical="0-1" power="1000000000" bw="125000000" lat="5E-5"
+           bb_bw="2250000000" bb_lat="5E-4"/>
+   
+     <cluster id="bob_cluster_1" prefix="bob" suffix=".hamburger.edu"
+           radical="2-3" power="1000000000" bw="125000000" lat="5E-5"
+           bb_bw="2250000000" bb_lat="5E-4"/>
+       
+     <link id="backbone" bandwidth="1250000000" latency="5E-4"/>  
+        
+        <ASroute 
+        src="bob_cluster" 
+        dst="bob_cluster_1" 
+        gw_src="bob_bob_cluster_router.hamburger.edu" 
+        gw_dst="bob_bob_cluster_1_router.hamburger.edu">
+               <link_ctn id="backbone"/>
+     </ASroute>  
+         
+        <ASroute 
+        src="bob_cluster_1" 
+        dst="bob_cluster" 
+        gw_src="bob_bob_cluster_1_router.hamburger.edu" 
+        gw_dst="bob_bob_cluster_router.hamburger.edu">
+               <link_ctn id="backbone"/>
+     </ASroute>   
+        
+ </AS>
+ </platform>
\ No newline at end of file