Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a0fe6ec165d4ce244d0cb4f1f4e8b5191c87aa92
[simgrid.git] / src / simdag / sd_workstation.cpp
1 /* Copyright (c) 2006-2016. 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
7 #include "src/surf/host_interface.hpp"
8 #include "src/simdag/simdag_private.h"
9 #include "simgrid/simdag.h"
10 #include "simgrid/host.h"
11 #include <simgrid/s4u/host.hpp>
12 #include "xbt/dict.h"
13 #include "xbt/lib.h"
14 #include "xbt/sysdep.h"
15 #include "surf/surf.h"
16
17 /** @brief Returns the route between two workstations
18  *
19  * Use SD_route_get_size() to know the array size.
20  *
21  * \param src a host
22  * \param dst another host
23  * \return an array of the \ref SD_link_t composing the route
24  * \see SD_route_get_size(), SD_link_t
25  */
26 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
27 {
28   void *surf_link;
29   unsigned int cpt;
30   xbt_dynar_t surf_route = NULL;
31   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
32
33   SD_link_t *list = xbt_new(SD_link_t, xbt_dynar_length(surf_route));
34   xbt_dynar_foreach(surf_route, cpt, surf_link) {
35     list[cpt] = (SD_link_t)surf_link;
36   }
37   return list;
38 }
39
40 /**
41  * \brief Returns the number of links on the route between two workstations
42  *
43  * \param src a workstation
44  * \param dst another workstation
45  * \return the number of links on the route between these two workstations
46  * \see SD_route_get_list()
47  */
48 int SD_route_get_size(sg_host_t src, sg_host_t dst)
49 {
50   xbt_dynar_t surf_route = NULL;
51   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
52   return xbt_dynar_length(surf_route);
53 }
54
55 /**
56  * \brief Returns the latency of the route between two workstations.
57  *
58  * \param src the first workstation
59  * \param dst the second workstation
60  * \return the latency of the route between the two workstations (in seconds)
61  * \see SD_route_get_bandwidth()
62  */
63 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
64 {
65   xbt_dynar_t route = NULL;
66   double latency = 0;
67
68   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
69
70   return latency;
71 }
72
73 /**
74  * \brief Returns the bandwidth of the route between two workstations,
75  * i.e. the minimum link bandwidth of all between the workstations.
76  *
77  * \param src the first workstation
78  * \param dst the second workstation
79  * \return the bandwidth of the route between the two workstations (in bytes/second)
80  * \see SD_route_get_latency()
81  */
82 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
83 {
84   xbt_dynar_t route = NULL;
85   unsigned int cpt;
86   double latency = 0;
87   double min_bandwidth = -1.0;
88   SD_link_t link;
89
90   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
91
92   xbt_dynar_foreach(route, cpt, link){
93     double bandwidth = sg_link_bandwidth(link);
94     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
95       min_bandwidth = bandwidth;
96   }
97
98   return min_bandwidth;
99 }