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)
16 xbt_assert0(surf_link != NULL, "surf_link is NULL !");
18 link = xbt_new(s_SD_link_t, 1);
19 link->surf_link = surf_link;
20 link->data = data; /* user data */
21 if (surf_workstation_model->extension_public->link_shared(surf_link))
22 link->sharing_policy = SD_LINK_SHARED;
24 link->sharing_policy = SD_LINK_FATPIPE;
26 name = SD_link_get_name(link);
27 xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
28 sd_global->link_count++;
34 * \brief Returns the link list
36 * Use SD_link_get_number() to know the array size.
38 * \return an array of \ref SD_link_t containing all links
39 * \see SD_link_get_number()
41 const SD_link_t *SD_link_get_list(void)
44 xbt_dict_cursor_t cursor;
50 xbt_assert0(SD_link_get_number() > 0, "There is no link!");
52 if (sd_global->link_list == NULL) { /* this is the first time the function is called */
53 sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count);
56 xbt_dict_foreach(sd_global->links, cursor, key, data) {
57 sd_global->link_list[i++] = (SD_link_t) data;
60 return sd_global->link_list;
64 * \brief Returns the number of links
66 * \return the number of existing links
67 * \see SD_link_get_list()
69 int SD_link_get_number(void)
72 return sd_global->link_count;
76 * \brief Returns the user data of a link
79 * \return the user data associated with this link (can be \c NULL)
80 * \see SD_link_set_data()
82 void *SD_link_get_data(SD_link_t link)
85 xbt_assert0(link != NULL, "Invalid parameter");
90 * \brief Sets the user data of a link
92 * The new data can be \c NULL. The old data should have been freed first
93 * if it was not \c NULL.
96 * \param data the new data you want to associate with this link
97 * \see SD_link_get_data()
99 void SD_link_set_data(SD_link_t link, void *data)
101 SD_CHECK_INIT_DONE();
102 xbt_assert0(link != NULL, "Invalid parameter");
107 * \brief Returns the name of a link
110 * \return the name of this link (cannot be \c NULL)
112 const char *SD_link_get_name(SD_link_t link)
114 SD_CHECK_INIT_DONE();
115 xbt_assert0(link != NULL, "Invalid parameter");
116 return surf_workstation_model->extension_public->get_link_name(link->
121 * \brief Returns the current bandwidth of a link
124 * \return the current bandwidth of this link, in bytes per second
126 double SD_link_get_current_bandwidth(SD_link_t link)
128 SD_CHECK_INIT_DONE();
129 xbt_assert0(link != NULL, "Invalid parameter");
130 return surf_workstation_model->extension_public->get_link_bandwidth(link->
135 * \brief Returns the value of a given link property
137 * \param link the inspected link
138 * \param name a property name
139 * \return value of a property (or NULL if property not set)
141 const char *SD_link_get_property_value(SD_link_t link, const char *name)
143 return xbt_dict_get_or_null(SD_link_get_properties(link), name);
147 * \brief Returns a #xbt_dict_t consisting of the list of properties assigned to a link
150 * \return the dictionary containing the properties associated with the link
152 xbt_dict_t SD_link_get_properties(SD_link_t link)
154 SD_CHECK_INIT_DONE();
155 xbt_assert0((link != NULL), "Invalid parameters");
157 return (surf_workstation_model->common_public->
158 get_properties(link->surf_link));
163 * \brief Returns the current latency of a link
166 * \return the current latency of this link, in seconds
168 double SD_link_get_current_latency(SD_link_t link)
170 SD_CHECK_INIT_DONE();
171 xbt_assert0(link != NULL, "Invalid parameter");
172 return surf_workstation_model->extension_public->get_link_latency(link->
177 * \brief Returns the sharing policy of this workstation.
180 * \return the sharing policyfor the flows going through this link:
181 * SD_LINK_SHARED or SD_LINK_FATPIPE
184 e_SD_link_sharing_policy_t SD_link_get_sharing_policy(SD_link_t link)
186 SD_CHECK_INIT_DONE();
187 xbt_assert0(link != NULL, "Invalid parameter");
188 return link->sharing_policy;
194 void __SD_link_destroy(void *link)
196 SD_CHECK_INIT_DONE();
197 xbt_assert0(link != NULL, "Invalid parameter");
198 /* link->surf_link is freed by surf_exit and link->data is freed by the user */