2 This file is part of GNUnet.
3 (C) 2008--2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/testbed_api_underlay.c
23 * @brief testbed underlay API implementation
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
27 #include "testbed_api_peers.h"
36 * next pointer for list
38 struct LinkProperty *next;
41 * the peer whose link is defined by these properties
43 struct GNUNET_TESTBED_Peer *peer;
46 * latency of the link in microseconds
51 * data loss on the link expressed as percentage
56 * bandwidth of the link in kilobytes per second
63 * Container for holding a peer in whitelist/blacklist
70 struct ListEntry *next;
75 struct GNUNET_TESTBED_Peer *peer;
80 * Model for configuring underlay links of a peer
83 struct GNUNET_TESTBED_UnderlayLinkModel
86 * The peer associated with this model
88 struct GNUNET_TESTBED_Peer *peer;
91 * List of peers in the list
93 struct ListEntry *entries;
96 * list of link properties
98 struct LinkProperty *props;
101 * the type of this model
103 enum GNUNET_TESTBED_UnderlayLinkModelType type;
108 * Function to free resources of list entries
110 * @param model the model
113 free_entries (struct GNUNET_TESTBED_UnderlayLinkModel *model)
117 while (NULL != (e = model->entries))
119 model->entries = e->next;
126 * Function to free resources of link properties added to the given model
128 * @param model the model
131 free_link_properties (struct GNUNET_TESTBED_UnderlayLinkModel *model)
133 struct LinkProperty *p;
135 while (NULL != (p = model->props))
137 model->props = p->next;
144 * Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer. A peer can
145 * have ONLY ONE model and it can be either a blacklist or whitelist based one.
148 * @param peer the peer for which the model has to be created
149 * @param type the type of the model
152 struct GNUNET_TESTBED_UnderlayLinkModel *
153 GNUNET_TESTBED_underlaylinkmodel_create (struct GNUNET_TESTBED_Peer *peer,
154 enum GNUNET_TESTBED_UnderlayLinkModelType type)
156 struct GNUNET_TESTBED_UnderlayLinkModel *m;
158 GNUNET_assert (0 == peer->underlay_model_exists);
159 m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel);
160 peer->underlay_model_exists = 1;
167 * Add a peer to the given model. Underlay connections to the given peer will
168 * be permitted if the model is whitelist based; otherwise they will not be
172 * @param model the model
173 * @param peer the peer to add
176 GNUNET_TESTBED_underlaylinkmodel_add_peer (struct GNUNET_TESTBED_UnderlayLinkModel *model,
177 struct GNUNET_TESTBED_Peer *peer)
179 struct ListEntry *entry;
181 entry = GNUNET_new (struct ListEntry);
183 entry->next = model->entries;
184 model->entries = entry;
189 * Set the metrics for a link to the given peer in the underlay model. The link
190 * SHOULD be permittable according to the given model.
193 * @param model the model
194 * @param peer the other end peer of the link
195 * @param latency latency of the link in microseconds
196 * @param loss data loss of the link expressed as a percentage
197 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
200 GNUNET_TESTBED_underlaylinkmodel_set_link (struct GNUNET_TESTBED_UnderlayLinkModel *model,
201 struct GNUNET_TESTBED_Peer *peer,
206 struct LinkProperty *prop;
208 prop = GNUNET_new (struct LinkProperty);
210 prop->latency = latency;
212 prop->bandwidth = bandwidth;
213 prop->next = model->props;
219 * Free the resources of the model. Use this function only if the model has not
220 * be committed and has to be unallocated. The peer can then have another model
224 * @param model the model to unallocate
227 GNUNET_TESTBED_underlaylinkmodel_free (struct GNUNET_TESTBED_UnderlayLinkModel *model)
229 model->peer->underlay_model_exists = 0;
230 free_entries (model);
231 free_link_properties (model);
237 * Commit the model. The model is freed in this function(!).
240 * @param model the model to commit
243 GNUNET_TESTBED_underlaylinkmodel_commit (struct GNUNET_TESTBED_UnderlayLinkModel *model)
245 /* FIXME: Marshal the model into a message */
247 /* do not reset the value of model->peer->underlay_model_exists */
248 free_entries (model);
249 free_link_properties (model);