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.
16 /* Business methods */
17 static void cluster_get_route_and_latency(AS_t as,
18 sg_routing_edge_t src, sg_routing_edge_t dst,
19 sg_platf_route_cbarg_t route, double *lat) {
21 s_surf_parsing_link_up_down_t info;
22 XBT_DEBUG("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
26 if(src->rc_type != SURF_NETWORK_ELEMENT_ROUTER){ // No specific link for router
27 info = xbt_dynar_get_as(as->link_up_down_list,src->id,s_surf_parsing_link_up_down_t);
28 if(info.link_up) { // link up
29 xbt_dynar_push_as(route->link_list,void*,info.link_up);
31 *lat += surf_network_model->extension.network.get_link_latency(info.link_up);
35 if ( ((as_cluster_t)as)->backbone ) {
36 xbt_dynar_push_as(route->link_list,void*, ((as_cluster_t)as)->backbone) ;
38 *lat += surf_network_model->extension.network.get_link_latency(((as_cluster_t)as)->backbone);
41 if(dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER){ // No specific link for router
42 info = xbt_dynar_get_as(as->link_up_down_list,dst->id,s_surf_parsing_link_up_down_t);
43 if(info.link_down) { // link down
44 xbt_dynar_push_as(route->link_list,void*,info.link_down);
46 *lat += surf_network_model->extension.network.get_link_latency(info.link_down);
51 static void model_cluster_finalize(AS_t as) {
52 model_none_finalize(as);
55 static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) {
56 XBT_DEBUG("Load process unit \"%s\"", elm->name);
57 xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
58 return xbt_dynar_length(rc->index_network_elm)-1;
61 static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) {
62 XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
63 xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm);
64 return xbt_dynar_length(rc->index_network_elm)-1;
67 /* Creation routing model functions */
68 AS_t model_cluster_create(void)
70 AS_t result = model_none_create_sized(sizeof(s_as_cluster_t));
71 result->get_route_and_latency = cluster_get_route_and_latency;
72 result->finalize = model_cluster_finalize;
73 result->parse_AS = cluster_parse_AS;
74 result->parse_PU = cluster_parse_PU;