Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This commit breaks the simgrid-java execution; Revert "Avoid unnecessary loop."
[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
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
11
12 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
13  * Note that a router is created, easing the interconnexion with the rest of the world.
14  */
15
16 typedef struct {
17   s_as_t generic_routing;
18   void *backbone;
19 } s_as_cluster_t, *as_cluster_t;
20
21 /* Business methods */
22 static void cluster_get_route_and_latency(AS_t as,
23     network_element_t src, network_element_t dst,
24                                           route_t route, double *lat) {
25
26       s_surf_parsing_link_up_down_t info;
27           XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
28               src->name,src->id,
29               dst->name,dst->id);
30
31           if(src->rc_type != SURF_NETWORK_ELEMENT_ROUTER){ // No specific link for router
32         info = xbt_dynar_get_as(as->link_up_down_list,src->id,s_surf_parsing_link_up_down_t);
33         if(info.link_up) { // 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
40           if ( ((as_cluster_t)as)->backbone ) {
41             xbt_dynar_push_as(route->link_list,void*, ((as_cluster_t)as)->backbone) ;
42       if (lat)
43         *lat += surf_network_model->extension.network.get_link_latency(((as_cluster_t)as)->backbone);
44           }
45
46           if(dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER){ // No specific link for router
47         info = xbt_dynar_get_as(as->link_up_down_list,dst->id,s_surf_parsing_link_up_down_t);
48         if(info.link_down) { // link down
49           xbt_dynar_push_as(route->link_list,void*,info.link_down);
50         if (lat)
51           *lat += surf_network_model->extension.network.get_link_latency(info.link_down);
52         }
53           }
54 }
55
56 static void model_cluster_finalize(AS_t as) {
57   xbt_dynar_free(&(as->link_up_down_list));
58   model_none_finalize(as);
59 }
60
61 static int cluster_parse_PU(AS_t rc, network_element_t elm) {
62   XBT_DEBUG("Load process unit \"%s\"", elm->name);
63   xbt_dynar_push_as(rc->index_network_elm,network_element_t,elm);
64   return xbt_dynar_length(rc->index_network_elm)-1;
65 }
66
67 static int cluster_parse_AS(AS_t rc, network_element_t elm) {
68   XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
69   xbt_dynar_push_as(rc->index_network_elm,network_element_t,elm);
70   return xbt_dynar_length(rc->index_network_elm)-1;
71 }
72
73 /* Creation routing model functions */
74 AS_t model_cluster_create(void)
75 {
76   AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
77   result->get_route_and_latency = cluster_get_route_and_latency;
78   result->finalize = model_cluster_finalize;
79   result->parse_AS = cluster_parse_AS;
80   result->parse_PU = cluster_parse_PU;
81
82   return (AS_t) result;
83 }
84
85 void surf_routing_cluster_add_backbone(AS_t as, void* bb) {
86   ((as_cluster_t)as)->backbone = bb;
87 }