Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added round trip time contraint to the SDP program, this parameter
[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
21   name = SD_link_get_name(link);
22   xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
23   sd_global->link_count++;
24
25   return link;
26 }
27 /**
28  * \brief Returns the link list
29  *
30  * Use SD_link_get_number() to know the array size.
31  *
32  * \return an array of \ref SD_link_t containing all links
33  * \see SD_link_get_number()
34  */
35 const SD_link_t*  SD_link_get_list(void) {
36
37   xbt_dict_cursor_t cursor;
38   char *key;
39   void *data;
40   int i;
41   
42   SD_CHECK_INIT_DONE();
43   xbt_assert0(SD_link_get_number() > 0, "There is no link!");
44
45   if (sd_global->link_list == NULL) { /* this is the first time the function is called */
46     sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count);
47   
48     i = 0;
49     xbt_dict_foreach(sd_global->links, cursor, key, data) {
50       sd_global->link_list[i++] = (SD_link_t) data;
51     }
52   }
53   return sd_global->link_list;
54 }
55
56 /**
57  * \brief Returns the number of links
58  *
59  * \return the number of existing links
60  * \see SD_link_get_list()
61  */
62 int SD_link_get_number(void) {
63   SD_CHECK_INIT_DONE();
64   return sd_global->link_count;
65 }
66
67 /**
68  * \brief Returns the user data of a link
69  *
70  * \param link a link
71  * \return the user data associated with this link (can be \c NULL)
72  * \see SD_link_set_data()
73  */
74 void* SD_link_get_data(SD_link_t link) {
75   SD_CHECK_INIT_DONE();
76   xbt_assert0(link != NULL, "Invalid parameter");
77   return link->data;
78 }
79
80 /**
81  * \brief Sets the user data of a link
82  *
83  * The new data can be \c NULL. The old data should have been freed first
84  * if it was not \c NULL.
85  *
86  * \param link a link
87  * \param data the new data you want to associate with this link
88  * \see SD_link_get_data()
89  */
90 void SD_link_set_data(SD_link_t link, void *data) {
91   SD_CHECK_INIT_DONE();
92   xbt_assert0(link != NULL, "Invalid parameter");
93   link->data = data;
94 }
95
96 /**
97  * \brief Returns the name of a link
98  *
99  * \param link a link
100  * \return the name of this link (cannot be \c NULL)
101  */
102 const char* SD_link_get_name(SD_link_t link) {
103   SD_CHECK_INIT_DONE();
104   xbt_assert0(link != NULL, "Invalid parameter");
105   return surf_workstation_resource->extension_public->get_link_name(link->surf_link);
106 }
107
108 /**
109  * \brief Returns the current bandwidth of a link
110  *
111  * \param link a link
112  * \return the current bandwidth of this link, in Flops
113  */
114 double SD_link_get_current_bandwidth(SD_link_t link) {
115   SD_CHECK_INIT_DONE();
116   xbt_assert0(link != NULL, "Invalid parameter");
117   return surf_workstation_resource->extension_public->get_link_bandwidth(link->surf_link);
118 }
119
120 /**
121  * \brief Returns the current latency of a link
122  *
123  * \param link a link
124  * \return the current latency of this link, in seconds
125  */
126 double SD_link_get_current_latency(SD_link_t link) {
127   SD_CHECK_INIT_DONE();
128   xbt_assert0(link != NULL, "Invalid parameter");
129   return surf_workstation_resource->extension_public->get_link_latency(link->surf_link);
130 }
131
132 /* Destroys a link.
133  */
134 void __SD_link_destroy(void *link) {
135   SD_CHECK_INIT_DONE();
136   xbt_assert0(link != NULL, "Invalid parameter");
137   /* link->surf_link is freed by surf_exit and link->data is freed by the user */
138   xbt_free(link);
139 }
140