Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / simdag / sd_link.c
1 /* Copyright (c) 2006-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
7 #include "private.h"
8 #include "simdag/simdag.h"
9 #include "xbt/dict.h"
10 #include "xbt/sysdep.h"
11 #include "surf/surf.h"
12 #include "surf/surf_resource.h"
13
14
15 /* Creates a link and registers it in SD.
16  */
17 SD_link_t __SD_link_create(void *surf_link, void *data)
18 {
19
20   SD_link_t link;
21   const char *name;
22
23   link = xbt_new(s_SD_link_t, 1);
24   link->surf_link = surf_link;
25   link->data = data;            /* user data */
26   if (surf_workstation_model->extension.workstation.link_shared(surf_link))
27     link->sharing_policy = SD_LINK_SHARED;
28   else
29     link->sharing_policy = SD_LINK_FATPIPE;
30
31   name = SD_link_get_name(link);
32   xbt_lib_set(link_lib,name,SD_LINK_LEVEL,link);
33
34   return link;
35 }
36
37 /**
38  * \brief Returns the link list
39  *
40  * Use SD_link_get_number() to know the array size.
41  *
42  * \return an array of \ref SD_link_t containing all links
43  * \see SD_link_get_number()
44  */
45 const SD_link_t *SD_link_get_list(void)
46 {
47
48   xbt_lib_cursor_t cursor;
49   char *key;
50   void **data;
51   int i;
52
53   if (sd_global->link_list == NULL) {   /* this is the first time the function is called */
54     sd_global->link_list = xbt_new(SD_link_t, xbt_lib_length(link_lib));
55
56     i = 0;
57     xbt_lib_foreach(link_lib, cursor, key, data) {
58                 sd_global->link_list[i++] = (SD_link_t) data[SD_LINK_LEVEL];
59     }
60   }
61   return sd_global->link_list;
62 }
63
64 /**
65  * \brief Returns the number of links
66  *
67  * \return the number of existing links
68  * \see SD_link_get_list()
69  */
70 int SD_link_get_number(void)
71 {
72   return xbt_lib_length(link_lib);
73 }
74
75 /**
76  * \brief Returns the user data of a link
77  *
78  * \param link a link
79  * \return the user data associated with this link (can be \c NULL)
80  * \see SD_link_set_data()
81  */
82 void *SD_link_get_data(SD_link_t link)
83 {
84   return link->data;
85 }
86
87 /**
88  * \brief Sets the user data of a link
89  *
90  * The new data can be \c NULL. The old data should have been freed first
91  * if it was not \c NULL.
92  *
93  * \param link a link
94  * \param data the new data you want to associate with this link
95  * \see SD_link_get_data()
96  */
97 void SD_link_set_data(SD_link_t link, void *data)
98 {
99   link->data = data;
100 }
101
102 /**
103  * \brief Returns the name of a link
104  *
105  * \param link a link
106  * \return the name of this link (cannot be \c NULL)
107  */
108 const char *SD_link_get_name(SD_link_t link)
109 {
110   return surf_resource_name(link->surf_link);
111 }
112
113 /**
114  * \brief Returns the current bandwidth of a link
115  *
116  * \param link a link
117  * \return the current bandwidth of this link, in bytes per second
118  */
119 double SD_link_get_current_bandwidth(SD_link_t link)
120 {
121   return surf_workstation_model->extension.workstation.
122       get_link_bandwidth(link->surf_link);
123 }
124
125 /**
126  * \brief Returns the current latency of a link
127  *
128  * \param link a link
129  * \return the current latency of this link, in seconds
130  */
131 double SD_link_get_current_latency(SD_link_t link)
132 {
133   return surf_workstation_model->extension.workstation.
134       get_link_latency(link->surf_link);
135 }
136
137 /**
138  * \brief Returns the sharing policy of this workstation.
139  *
140  * \param link a link
141  * \return the sharing policyfor the flows going through this link:
142  * SD_LINK_SHARED or SD_LINK_FATPIPE
143  *
144  */
145 e_SD_link_sharing_policy_t SD_link_get_sharing_policy(SD_link_t link)
146 {
147   return link->sharing_policy;
148 }