Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge get_route and get_latency in routings too
[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 typedef struct {
18   s_as_t generic_routing;
19   void *backbone;
20 } s_as_cluster_t, *as_cluster_t;
21
22
23 static xbt_dict_t cluster_host_link = NULL;
24
25 /* Business methods */
26 static void cluster_get_route_and_latency(AS_t as,
27                                           const char *src, const char *dst,
28                                           route_t route, double *lat) {
29
30           surf_parsing_link_up_down_t info;
31
32           info = xbt_dict_get_or_null(cluster_host_link,src);
33           if(info) { // link up
34             xbt_dynar_push_as(route->link_list,void*,info->link_up);
35       if (lat)
36         *lat += surf_network_model->extension.network.get_link_latency(info->link_up);
37           }
38
39           if ( ((as_cluster_t)as)->backbone ) {
40             xbt_dynar_push_as(route->link_list,void*, ((as_cluster_t)as)->backbone) ;
41       if (lat)
42         *lat += surf_network_model->extension.network.get_link_latency(((as_cluster_t)as)->backbone);
43           }
44
45           info = xbt_dict_get_or_null(cluster_host_link,dst);
46           if(info) { // link down
47             xbt_dynar_push_as(route->link_list,void*,info->link_down);
48       if (lat)
49         *lat += surf_network_model->extension.network.get_link_latency(info->link_down);
50           }
51 }
52
53 static void model_cluster_finalize(AS_t as) {
54   xbt_dict_free(&cluster_host_link);
55   model_none_finalize(as);
56 }
57 /* Creation routing model functions */
58 AS_t model_cluster_create(void)
59 {
60   AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
61   result->get_route_and_latency = cluster_get_route_and_latency;
62   result->finalize = model_cluster_finalize;
63
64   return (AS_t) result;
65 }
66
67 void surf_routing_cluster_add_link(const char* host_id,surf_parsing_link_up_down_t info) {
68   if(!cluster_host_link)
69     cluster_host_link = xbt_dict_new();
70
71  xbt_dict_set(cluster_host_link,host_id,info,xbt_free);
72 }
73
74 void surf_routing_cluster_add_backbone(AS_t as, void* bb) {
75   ((as_cluster_t)as)->backbone = bb;
76 }