2 This file is part of GNUnet.
3 Copyright (C) 2008--2013 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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,
155 GNUNET_TESTBED_UnderlayLinkModelType
158 struct GNUNET_TESTBED_UnderlayLinkModel *m;
160 GNUNET_assert (0 == peer->underlay_model_exists);
161 m = GNUNET_new (struct GNUNET_TESTBED_UnderlayLinkModel);
162 peer->underlay_model_exists = 1;
169 * Add a peer to the given model. Underlay connections to the given peer will
170 * be permitted if the model is whitelist based; otherwise they will not be
174 * @param model the model
175 * @param peer the peer to add
178 GNUNET_TESTBED_underlaylinkmodel_add_peer (struct
179 GNUNET_TESTBED_UnderlayLinkModel *
181 struct GNUNET_TESTBED_Peer *peer)
183 struct ListEntry *entry;
185 entry = GNUNET_new (struct ListEntry);
187 entry->next = model->entries;
188 model->entries = entry;
193 * Set the metrics for a link to the given peer in the underlay model. The link
194 * SHOULD be permittable according to the given model.
197 * @param model the model
198 * @param peer the other end peer of the link
199 * @param latency latency of the link in microseconds
200 * @param loss data loss of the link expressed as a percentage
201 * @param bandwidth bandwidth of the link in kilobytes per second [kB/s]
204 GNUNET_TESTBED_underlaylinkmodel_set_link (struct
205 GNUNET_TESTBED_UnderlayLinkModel *
207 struct GNUNET_TESTBED_Peer *peer,
212 struct LinkProperty *prop;
214 prop = GNUNET_new (struct LinkProperty);
216 prop->latency = latency;
218 prop->bandwidth = bandwidth;
219 prop->next = model->props;
225 * Free the resources of the model. Use this function only if the model has not
226 * be committed and has to be unallocated. The peer can then have another model
230 * @param model the model to unallocate
233 GNUNET_TESTBED_underlaylinkmodel_free (struct
234 GNUNET_TESTBED_UnderlayLinkModel *model)
236 model->peer->underlay_model_exists = 0;
237 free_entries (model);
238 free_link_properties (model);
244 * Commit the model. The model is freed in this function(!).
247 * @param model the model to commit
250 GNUNET_TESTBED_underlaylinkmodel_commit (struct
251 GNUNET_TESTBED_UnderlayLinkModel *model)
253 /* FIXME: Marshal the model into a message */
255 /* do not reset the value of model->peer->underlay_model_exists */
256 free_entries (model);
257 free_link_properties (model);