Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add RoutingEdge wrapper to manage vm not destroy
[simgrid.git] / src / surf / surf_routing_vivaldi.cpp
1 #include "surf_routing_vivaldi.hpp"
2 #include "network_interface.hpp"
3
4 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_vivaldi, surf, "Routing part of surf");
5
6 static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) {
7   double src_coord, dst_coord;
8
9   src_coord = xbt_dynar_get_as(src, index, double);
10   dst_coord = xbt_dynar_get_as(dst, index, double);
11
12   return (src_coord-dst_coord)*(src_coord-dst_coord);
13 }
14
15 AS_t model_vivaldi_create(void)
16 {
17   return new AsVivaldi();
18 }
19
20 void AsVivaldi::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t route, double *lat)
21 {
22   s_surf_parsing_link_up_down_t info;
23
24   XBT_DEBUG("vivaldi_get_route_and_latency from '%s'[%d] '%s'[%d]",
25                   src->getName(), src->getId(), dst->getName(), dst->getId());
26
27   if(src->getRcType() == SURF_NETWORK_ELEMENT_AS) {
28     char *src_name = ROUTER_PEER(src->getName());
29     char *dst_name = ROUTER_PEER(dst->getName());
30     route->gw_src = (sg_routing_edge_t) xbt_lib_get_or_null(as_router_lib, src_name, ROUTING_ASR_LEVEL);
31     route->gw_dst = (sg_routing_edge_t) xbt_lib_get_or_null(as_router_lib, dst_name, ROUTING_ASR_LEVEL);
32     xbt_free(src_name);
33     xbt_free(dst_name);
34   }
35
36   double euclidean_dist;
37   xbt_dynar_t src_ctn, dst_ctn;
38   char *tmp_src_name, *tmp_dst_name;
39
40   if(src->getRcType() == SURF_NETWORK_ELEMENT_HOST){
41     tmp_src_name = HOST_PEER(src->getName());
42
43     if(p_linkUpDownList){
44       info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
45       if(info.link_up) { // link up
46         xbt_dynar_push_as(route->link_list, void*, info.link_up);
47         if (lat)
48           *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
49       }
50     }
51     src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, tmp_src_name, COORD_HOST_LEVEL);
52     if(!src_ctn ) src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, src->getName(), COORD_HOST_LEVEL);
53   }
54   else if(src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_AS){
55     tmp_src_name = ROUTER_PEER(src->getName());
56     src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(as_router_lib, tmp_src_name, COORD_ASR_LEVEL);
57   }
58   else{
59     THROW_IMPOSSIBLE;
60   }
61
62   if(dst->getRcType() == SURF_NETWORK_ELEMENT_HOST){
63     tmp_dst_name = HOST_PEER(dst->getName());
64
65     if(p_linkUpDownList){
66       info = xbt_dynar_get_as(p_linkUpDownList, dst->getId(), s_surf_parsing_link_up_down_t);
67       if(info.link_down) { // link down
68         xbt_dynar_push_as(route->link_list,void*,info.link_down);
69         if (lat)
70           *lat += static_cast<NetworkLinkPtr>(info.link_down)->getLatency();
71       }
72     }
73     dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, tmp_dst_name, COORD_HOST_LEVEL);
74     if(!dst_ctn ) dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(host_lib, dst->getName(), COORD_HOST_LEVEL);
75   }
76   else if(dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || dst->getRcType() == SURF_NETWORK_ELEMENT_AS){
77     tmp_dst_name = ROUTER_PEER(dst->getName());
78     dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(as_router_lib, tmp_dst_name, COORD_ASR_LEVEL);
79   }
80   else{
81     THROW_IMPOSSIBLE;
82   }
83
84   xbt_assert(src_ctn,"No coordinate found for element '%s'",tmp_src_name);
85   xbt_assert(dst_ctn,"No coordinate found for element '%s'",tmp_dst_name);
86   free(tmp_src_name);
87   free(tmp_dst_name);
88
89   euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn))
90                       + fabs(xbt_dynar_get_as(src_ctn, 2, double))+fabs(xbt_dynar_get_as(dst_ctn, 2, double));
91
92   if (lat){
93     XBT_DEBUG("Updating latency %f += %f",*lat,euclidean_dist);
94     *lat += euclidean_dist / 1000.0; //From .ms to .s
95   }
96 }
97
98 int AsVivaldi::parsePU(RoutingEdgePtr elm) {
99   XBT_DEBUG("Load process unit \"%s\"", elm->getName());
100   xbt_dynar_push_as(p_indexNetworkElm, sg_routing_edge_t, elm);
101   return xbt_dynar_length(p_indexNetworkElm)-1;
102 }