Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d5658b627ba4e9d5808c6217d03b7658ff8a4606
[simgrid.git] / src / surf / surf_routing_cluster.c
1 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6 #include "surf_routing_private.h"
7
8 /* Global vars */
9 extern routing_global_t global_routing;
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
12
13 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
14  * Note that a router is created, easing the interconnexion with the rest of the world.
15  */
16
17 static xbt_dict_t cluster_host_link = NULL;
18
19 /* Business methods */
20 static route_extended_t cluster_get_route(AS_t as,
21                                           const char *src,
22                                           const char *dst) {
23
24           xbt_dynar_t links_list = xbt_dynar_new(global_routing->size_of_link, NULL);
25
26           surf_parsing_link_up_down_t info;
27
28           info = xbt_dict_get_or_null(cluster_host_link,src);
29           if(info) xbt_dynar_push_as(links_list,void*,info->link_up); //link_up
30
31           info = xbt_dict_get_or_null(cluster_host_link,as->name);
32           if(info)  xbt_dynar_push_as(links_list,void*,info->link_up); //link_bb
33
34           info = xbt_dict_get_or_null(cluster_host_link,dst);
35           if(info) xbt_dynar_push_as(links_list,void*,info->link_down); //link_down
36
37           route_extended_t new_e_route = NULL;
38           new_e_route = xbt_new0(s_route_extended_t, 1);
39           new_e_route->generic_route.link_list = links_list;
40
41           return new_e_route;
42 }
43
44 /* Creation routing model functions */
45 AS_t model_cluster_create(void)
46 {
47   AS_t result = model_none_create();
48   result->get_route = cluster_get_route;
49
50   return (AS_t) result;
51 }
52
53 void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info) {
54   if(!cluster_host_link)
55     cluster_host_link = xbt_dict_new();
56
57  xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
58 }