1 /* Copyright (c) 2007-2009 Da SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simdag/simdag.h"
9 #include "xbt/sysdep.h"
10 #include "surf/surf.h"
12 /* Creates a link and registers it in SD.
14 SD_link_t __SD_link_create(void *surf_link, void *data)
21 xbt_assert0(surf_link != NULL, "surf_link is NULL !");
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;
29 link->sharing_policy = SD_LINK_FATPIPE;
31 name = SD_link_get_name(link);
32 xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
33 sd_global->link_count++;
39 * \brief Returns the link list
41 * Use SD_link_get_number() to know the array size.
43 * \return an array of \ref SD_link_t containing all links
44 * \see SD_link_get_number()
46 const SD_link_t *SD_link_get_list(void)
49 xbt_dict_cursor_t cursor;
55 xbt_assert0(SD_link_get_number() > 0, "There is no link!");
57 if (sd_global->link_list == NULL) { /* this is the first time the function is called */
58 sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count);
61 xbt_dict_foreach(sd_global->links, cursor, key, data) {
62 sd_global->link_list[i++] = (SD_link_t) data;
65 return sd_global->link_list;
69 * \brief Returns the number of links
71 * \return the number of existing links
72 * \see SD_link_get_list()
74 int SD_link_get_number(void)
77 return sd_global->link_count;
81 * \brief Returns the user data of a link
84 * \return the user data associated with this link (can be \c NULL)
85 * \see SD_link_set_data()
87 void *SD_link_get_data(SD_link_t link)
90 xbt_assert0(link != NULL, "Invalid parameter");
95 * \brief Sets the user data of a link
97 * The new data can be \c NULL. The old data should have been freed first
98 * if it was not \c NULL.
101 * \param data the new data you want to associate with this link
102 * \see SD_link_get_data()
104 void SD_link_set_data(SD_link_t link, void *data)
106 SD_CHECK_INIT_DONE();
107 xbt_assert0(link != NULL, "Invalid parameter");
112 * \brief Returns the name of a link
115 * \return the name of this link (cannot be \c NULL)
117 const char *SD_link_get_name(SD_link_t link)
119 SD_CHECK_INIT_DONE();
120 xbt_assert0(link != NULL, "Invalid parameter");
121 return surf_resource_name(link->surf_link);
125 * \brief Returns the current bandwidth of a link
128 * \return the current bandwidth of this link, in bytes per second
130 double SD_link_get_current_bandwidth(SD_link_t link)
132 SD_CHECK_INIT_DONE();
133 xbt_assert0(link != NULL, "Invalid parameter");
134 return surf_workstation_model->extension.workstation.
135 get_link_bandwidth(link->surf_link);
139 * \brief Returns the current latency of a link
142 * \return the current latency of this link, in seconds
144 double SD_link_get_current_latency(SD_link_t link)
146 SD_CHECK_INIT_DONE();
147 xbt_assert0(link != NULL, "Invalid parameter");
148 return surf_workstation_model->extension.workstation.
149 get_link_latency(link->surf_link);
153 * \brief Returns the sharing policy of this workstation.
156 * \return the sharing policyfor the flows going through this link:
157 * SD_LINK_SHARED or SD_LINK_FATPIPE
160 e_SD_link_sharing_policy_t SD_link_get_sharing_policy(SD_link_t link)
162 SD_CHECK_INIT_DONE();
163 xbt_assert0(link != NULL, "Invalid parameter");
164 return link->sharing_policy;
170 void __SD_link_destroy(void *link)
172 SD_CHECK_INIT_DONE();
173 xbt_assert0(link != NULL, "Invalid parameter");
174 /* link->surf_link is freed by surf_exit and link->data is freed by the user */