Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8cf797837e286f1995644cc8c1c43416de3266b8
[simgrid.git] / src / simdag / sd_link.c
1 #include "private.h"
2 #include "simdag/simdag.h"
3 #include "xbt/dict.h"
4 #include "xbt/sysdep.h"
5 #include "surf/surf.h"
6
7 /* Creates a link and registers it in SD.
8  */
9 SD_link_t __SD_link_create(void *surf_link, void *data) {
10
11   SD_link_t link;
12   const char *name;
13
14   SD_CHECK_INIT_DONE();
15   xbt_assert0(surf_link != NULL, "surf_link is NULL !");
16
17   link = xbt_new(s_SD_link_t, 1);
18   link->surf_link = surf_link;
19   link->data = data; /* user data */
20   if(surf_workstation_model->extension_public->link_shared(surf_link))
21     link->sharing_policy=SD_LINK_SHARED;
22   else
23     link->sharing_policy=SD_LINK_FATPIPE;
24
25   name = SD_link_get_name(link);
26   xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
27   sd_global->link_count++;
28
29   return link;
30 }
31 /**
32  * \brief Returns the link list
33  *
34  * Use SD_link_get_number() to know the array size.
35  *
36  * \return an array of \ref SD_link_t containing all links
37  * \see SD_link_get_number()
38  */
39 const SD_link_t*  SD_link_get_list(void) {
40
41   xbt_dict_cursor_t cursor;
42   char *key;
43   void *data;
44   int i;
45   
46   SD_CHECK_INIT_DONE();
47   xbt_assert0(SD_link_get_number() > 0, "There is no link!");
48
49   if (sd_global->link_list == NULL) { /* this is the first time the function is called */
50     sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count);
51   
52     i = 0;
53     xbt_dict_foreach(sd_global->links, cursor, key, data) {
54       sd_global->link_list[i++] = (SD_link_t) data;
55     }
56   }
57   return sd_global->link_list;
58 }
59
60 /**
61  * \brief Returns the number of links
62  *
63  * \return the number of existing links
64  * \see SD_link_get_list()
65  */
66 int SD_link_get_number(void) {
67   SD_CHECK_INIT_DONE();
68   return sd_global->link_count;
69 }
70
71 /**
72  * \brief Returns the user data of a link
73  *
74  * \param link a link
75  * \return the user data associated with this link (can be \c NULL)
76  * \see SD_link_set_data()
77  */
78 void* SD_link_get_data(SD_link_t link) {
79   SD_CHECK_INIT_DONE();
80   xbt_assert0(link != NULL, "Invalid parameter");
81   return link->data;
82 }
83
84 /**
85  * \brief Sets the user data of a link
86  *
87  * The new data can be \c NULL. The old data should have been freed first
88  * if it was not \c NULL.
89  *
90  * \param link a link
91  * \param data the new data you want to associate with this link
92  * \see SD_link_get_data()
93  */
94 void SD_link_set_data(SD_link_t link, void *data) {
95   SD_CHECK_INIT_DONE();
96   xbt_assert0(link != NULL, "Invalid parameter");
97   link->data = data;
98 }
99
100 /**
101  * \brief Returns the name of a link
102  *
103  * \param link a link
104  * \return the name of this link (cannot be \c NULL)
105  */
106 const char* SD_link_get_name(SD_link_t link) {
107   SD_CHECK_INIT_DONE();
108   xbt_assert0(link != NULL, "Invalid parameter");
109   return surf_workstation_model->extension_public->get_link_name(link->surf_link);
110 }
111
112 /**
113  * \brief Returns the current bandwidth of a link
114  *
115  * \param link a link
116  * \return the current bandwidth of this link, in Flops
117  */
118 double SD_link_get_current_bandwidth(SD_link_t link) {
119   SD_CHECK_INIT_DONE();
120   xbt_assert0(link != NULL, "Invalid parameter");
121   return surf_workstation_model->extension_public->get_link_bandwidth(link->surf_link);
122 }
123
124 /**
125  * \brief Returns the value of a given link property
126  *
127  * \param link the inspected link
128  * \param name a property name
129  * \return value of a property (or NULL if property not set)
130  */
131 const char* SD_link_get_property_value(SD_link_t link, const char* name)
132 {
133   return xbt_dict_get_or_null(SD_link_get_properties(link), name);
134 }
135
136 /**
137  * \brief Returns a #xbt_dict_t consisting of the list of properties assigned to a link
138  *
139  * \param link a link
140  * \return the dictionary containing the properties associated with the link
141  */
142 xbt_dict_t SD_link_get_properties(SD_link_t link)
143 {
144   SD_CHECK_INIT_DONE();
145   xbt_assert0((link != NULL), "Invalid parameters");
146
147   return (surf_workstation_model->common_public->get_properties(link->surf_link));
148
149 }
150
151 /**
152  * \brief Returns the current latency of a link
153  *
154  * \param link a link
155  * \return the current latency of this link, in seconds
156  */
157 double SD_link_get_current_latency(SD_link_t link) {
158   SD_CHECK_INIT_DONE();
159   xbt_assert0(link != NULL, "Invalid parameter");
160   return surf_workstation_model->extension_public->get_link_latency(link->surf_link);
161 }
162
163 /**
164  * \brief Returns the sharing policy of this workstation.
165  *
166  * \param link a link
167  * \return the sharing policyfor the flows going through this link:
168  * SD_LINK_SHARED or SD_LINK_FATPIPE
169  *
170  */
171 e_SD_link_sharing_policy_t SD_link_get_sharing_policy (SD_link_t link) {
172   SD_CHECK_INIT_DONE();
173   xbt_assert0(link != NULL, "Invalid parameter");
174   return link->sharing_policy;
175 }
176
177  
178 /* Destroys a link.
179  */
180 void __SD_link_destroy(void *link) {
181   SD_CHECK_INIT_DONE();
182   xbt_assert0(link != NULL, "Invalid parameter");
183   /* link->surf_link is freed by surf_exit and link->data is freed by the user */
184   xbt_free(link);
185 }
186