1 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
2 * All rights reserved. */
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"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
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.
17 s_as_t generic_routing;
19 } s_as_cluster_t, *as_cluster_t;
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) {
26 s_surf_parsing_link_up_down_t info;
27 XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
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);
36 *lat += surf_network_model->extension.network.get_link_latency(info.link_up);
40 if ( ((as_cluster_t)as)->backbone ) {
41 xbt_dynar_push_as(route->link_list,void*, ((as_cluster_t)as)->backbone) ;
43 *lat += surf_network_model->extension.network.get_link_latency(((as_cluster_t)as)->backbone);
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);
51 *lat += surf_network_model->extension.network.get_link_latency(info.link_down);
56 static void model_cluster_finalize(AS_t as) {
57 xbt_dynar_free(&(as->link_up_down_list));
58 model_none_finalize(as);
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;
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;
73 /* Creation routing model functions */
74 AS_t model_cluster_create(void)
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;
85 void surf_routing_cluster_add_backbone(AS_t as, void* bb) {
86 ((as_cluster_t)as)->backbone = bb;