2 #include "simdag/simdag.h"
4 #include "xbt/sysdep.h"
7 /* Creates a link and registers it in SD.
9 SD_link_t __SD_link_create(void *surf_link, void *data) {
15 xbt_assert0(surf_link != NULL, "surf_link is NULL !");
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;
23 link->sharing_policy=SD_LINK_FATPIPE;
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++;
32 * \brief Returns the link list
34 * Use SD_link_get_number() to know the array size.
36 * \return an array of \ref SD_link_t containing all links
37 * \see SD_link_get_number()
39 const SD_link_t* SD_link_get_list(void) {
41 xbt_dict_cursor_t cursor;
47 xbt_assert0(SD_link_get_number() > 0, "There is no link!");
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);
53 xbt_dict_foreach(sd_global->links, cursor, key, data) {
54 sd_global->link_list[i++] = (SD_link_t) data;
57 return sd_global->link_list;
61 * \brief Returns the number of links
63 * \return the number of existing links
64 * \see SD_link_get_list()
66 int SD_link_get_number(void) {
68 return sd_global->link_count;
72 * \brief Returns the user data of a link
75 * \return the user data associated with this link (can be \c NULL)
76 * \see SD_link_set_data()
78 void* SD_link_get_data(SD_link_t link) {
80 xbt_assert0(link != NULL, "Invalid parameter");
85 * \brief Sets the user data of a link
87 * The new data can be \c NULL. The old data should have been freed first
88 * if it was not \c NULL.
91 * \param data the new data you want to associate with this link
92 * \see SD_link_get_data()
94 void SD_link_set_data(SD_link_t link, void *data) {
96 xbt_assert0(link != NULL, "Invalid parameter");
101 * \brief Returns the name of a link
104 * \return the name of this link (cannot be \c NULL)
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);
113 * \brief Returns the current bandwidth of a link
116 * \return the current bandwidth of this link, in bytes per second
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);
125 * \brief Returns the value of a given link property
127 * \param link the inspected link
128 * \param name a property name
129 * \return value of a property (or NULL if property not set)
131 const char* SD_link_get_property_value(SD_link_t link, const char* name)
133 return xbt_dict_get_or_null(SD_link_get_properties(link), name);
137 * \brief Returns a #xbt_dict_t consisting of the list of properties assigned to a link
140 * \return the dictionary containing the properties associated with the link
142 xbt_dict_t SD_link_get_properties(SD_link_t link)
144 SD_CHECK_INIT_DONE();
145 xbt_assert0((link != NULL), "Invalid parameters");
147 return (surf_workstation_model->common_public->get_properties(link->surf_link));
152 * \brief Returns the current latency of a link
155 * \return the current latency of this link, in seconds
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);
164 * \brief Returns the sharing policy of this workstation.
167 * \return the sharing policyfor the flows going through this link:
168 * SD_LINK_SHARED or SD_LINK_FATPIPE
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;
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 */