diff options
Diffstat (limited to 'src/testbed/testbed_api_underlay.c')
-rw-r--r-- | src/testbed/testbed_api_underlay.c | 260 |
1 files changed, 0 insertions, 260 deletions
diff --git a/src/testbed/testbed_api_underlay.c b/src/testbed/testbed_api_underlay.c deleted file mode 100644 index 8c01e4503..000000000 --- a/src/testbed/testbed_api_underlay.c +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2008--2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/testbed_api_underlay.c | ||
23 | * @brief testbed underlay API implementation | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "testbed_api_peers.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * An underlay link | ||
33 | */ | ||
34 | struct LinkProperty | ||
35 | { | ||
36 | /** | ||
37 | * next pointer for list | ||
38 | */ | ||
39 | struct LinkProperty *next; | ||
40 | |||
41 | /** | ||
42 | * the peer whose link is defined by these properties | ||
43 | */ | ||
44 | struct GNUNET_TESTBED_Peer *peer; | ||
45 | |||
46 | /** | ||
47 | * latency of the link in microseconds | ||
48 | */ | ||
49 | uint32_t latency; | ||
50 | |||
51 | /** | ||
52 | * data loss on the link expressed as percentage | ||
53 | */ | ||
54 | uint32_t loss; | ||
55 | |||
56 | /** | ||
57 | * bandwidth of the link in kilobytes per second | ||
58 | */ | ||
59 | uint32_t bandwidth; | ||
60 | }; | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Container for holding a peer in whitelist/blacklist | ||
65 | */ | ||
66 | struct ListEntry | ||
67 | { | ||
68 | /** | ||
69 | * the next pointer | ||
70 | */ | ||
71 | struct ListEntry *next; | ||
72 | |||
73 | /** | ||
74 | * the peer | ||
75 | */ | ||
76 | struct GNUNET_TESTBED_Peer *peer; | ||
77 | }; | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Model for configuring underlay links of a peer | ||
82 | * @ingroup underlay | ||
83 | */ | ||
84 | struct GNUNET_TESTBED_UnderlayLinkModel | ||
85 | { | ||
86 | /** | ||
87 | * The peer associated with this model | ||
88 | */ | ||
89 | struct GNUNET_TESTBED_Peer *peer; | ||
90 | |||
91 | /** | ||
92 | * List of peers in the list | ||
93 | */ | ||
94 | struct ListEntry *entries; | ||
95 | |||
96 | /** | ||
97 | * list of link properties | ||
98 | */ | ||
99 | struct LinkProperty *props; | ||
100 | |||
101 | /** | ||
102 | * the type of this model | ||
103 | */ | ||
104 | enum GNUNET_TESTBED_UnderlayLinkModelType type; | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Function to free resources of list entries | ||
110 | * | ||
111 | * @param model the model | ||
112 | */ | ||
113 | static void | ||
114 | free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model) | ||
115 | { | ||
116 | struct ListEntry *e; | ||
117 | |||
118 | while (NULL != (e = model->entries)) | ||
119 | { | ||
120 | model->entries = e->next; | ||
121 | GNUNET_free (e); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Function to free resources of link properties added to the given model | ||
128 | * | ||
129 | * @param model the model | ||
130 | */ | ||
131 | static void | ||
132 | free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model) | ||
133 | { | ||
134 | struct LinkProperty *p; | ||
135 | |||
136 | while (NULL != (p = model->props)) | ||
137 | { | ||
138 | model->props = p->next; | ||
139 | GNUNET_free (p); | ||
140 | } | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can | ||
146 | * have ONLY ONE model and it can be either a blacklist or whitelist based one. | ||
147 | * | ||
148 | * @ingroup underlay | ||
149 | * @param peer the peer for which the model has to be created | ||
150 | * @param type the type of the model | ||
151 | * @return the model | ||
152 | */ | ||
153 | struct GNUNET_TESTBED_UnderlayLinkModel * | ||
154 | GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer, | ||
155 | enum | ||
156 | GNUNET_TESTBED_UnderlayLinkModelType | ||
157 | type) | ||
158 | { | ||
159 | struct GNUNET_TESTBED_UnderlayLinkModel *m; | ||
160 | |||
161 | GNUNET_assert (0 == peer->underlay_model_exists); | ||
162 | m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel); | ||
163 | peer->underlay_model_exists = 1; | ||
164 | m->type = type; | ||
165 | return m; | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Add a peer to the given model. Underlay connections to the given peer will | ||
171 | * be permitted if the model is whitelist based; otherwise they will not be | ||
172 | * permitted. | ||
173 | * | ||
174 | * @ingroup underlay | ||
175 | * @param model the model | ||
176 | * @param peer the peer to add | ||
177 | */ | ||
178 | void | ||
179 | GNUNET_TESTBED_underlaylinkmodel_add_peer (struct | ||
180 | GNUNET_TESTBED_UnderlayLinkModel * | ||
181 | model, | ||
182 | struct GNUNET_TESTBED_Peer *peer) | ||
183 | { | ||
184 | struct ListEntry *entry; | ||
185 | |||
186 | entry = GNUNET_new (struct ListEntry); | ||
187 | entry->peer = peer; | ||
188 | entry->next = model->entries; | ||
189 | model->entries = entry; | ||
190 | } | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Set the metrics for a link to the given peer in the underlay model. The link | ||
195 | * SHOULD be permittable according to the given model. | ||
196 | * | ||
197 | * @ingroup underlay | ||
198 | * @param model the model | ||
199 | * @param peer the other end peer of the link | ||
200 | * @param latency latency of the link in microseconds | ||
201 | * @param loss data loss of the link expressed as a percentage | ||
202 | * @param bandwidth bandwidth of the link in kilobytes per second [kB/s] | ||
203 | */ | ||
204 | void | ||
205 | GNUNET_TESTBED_underlaylinkmodel_set_link (struct | ||
206 | GNUNET_TESTBED_UnderlayLinkModel * | ||
207 | model, | ||
208 | struct GNUNET_TESTBED_Peer *peer, | ||
209 | uint32_t latency, | ||
210 | uint32_t loss, | ||
211 | uint32_t bandwidth) | ||
212 | { | ||
213 | struct LinkProperty *prop; | ||
214 | |||
215 | prop = GNUNET_new (struct LinkProperty); | ||
216 | prop->peer = peer; | ||
217 | prop->latency = latency; | ||
218 | prop->loss = loss; | ||
219 | prop->bandwidth = bandwidth; | ||
220 | prop->next = model->props; | ||
221 | model->props = prop; | ||
222 | } | ||
223 | |||
224 | |||
225 | /** | ||
226 | * Free the resources of the model. Use this function only if the model has not | ||
227 | * be committed and has to be unallocated. The peer can then have another model | ||
228 | * created. | ||
229 | * | ||
230 | * @ingroup underlay | ||
231 | * @param model the model to unallocate | ||
232 | */ | ||
233 | void | ||
234 | GNUNET_TESTBED_underlaylinkmodel_free (struct | ||
235 | GNUNET_TESTBED_UnderlayLinkModel *model) | ||
236 | { | ||
237 | model->peer->underlay_model_exists = 0; | ||
238 | free_entries (model); | ||
239 | free_link_properties (model); | ||
240 | gnunet_free (model); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Commit the model. The model is freed in this function(!). | ||
246 | * | ||
247 | * @ingroup underlay | ||
248 | * @param model the model to commit | ||
249 | */ | ||
250 | void | ||
251 | GNUNET_TESTBED_underlaylinkmodel_commit (struct | ||
252 | GNUNET_TESTBED_UnderlayLinkModel *model) | ||
253 | { | ||
254 | /* FIXME: Marshal the model into a message */ | ||
255 | GNUNET_break (0); | ||
256 | /* do not reset the value of model->peer->underlay_model_exists */ | ||
257 | free_entries (model); | ||
258 | free_link_properties (model); | ||
259 | GNUNET_free (model); | ||
260 | } | ||