GNUnet  0.11.x
testbed_api_underlay.c
Go to the documentation of this file.
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 
27 #include "testbed_api_peers.h"
28 
29 
34 {
38  struct LinkProperty *next;
39 
44 
48  uint32_t latency;
49 
53  uint32_t loss;
54 
58  uint32_t bandwidth;
59 };
60 
61 
65 struct ListEntry
66 {
70  struct ListEntry *next;
71 
76 };
77 
78 
84 {
89 
93  struct ListEntry *entries;
94 
99 
104 }
105 
106 
112 static void
114 {
115  struct ListEntry *e;
117  while (NULL != (e = model->entries))
118  {
119  model->entries = e->next;
120  GNUNET_free (e);
121  }
122 }
123 
124 
130 static void
132 {
133  struct LinkProperty *p;
134 
135  while (NULL != (p = model->props))
136  {
137  model->props = p->next;
138  GNUNET_free (p);
139  }
140 }
141 
142 
154  enum
156  type)
157 {
159 
162  peer->underlay_model_exists = 1;
163  m->type = type;
164  return m;
165 }
166 
167 
177 void
180  model,
181  struct GNUNET_TESTBED_Peer *peer)
182 {
183  struct ListEntry *entry;
184 
185  entry = GNUNET_new (struct ListEntry);
186  entry->peer = peer;
187  entry->next = model->entries;
188  model->entries = entry;
189 }
190 
191 
203 void
206  model,
207  struct GNUNET_TESTBED_Peer *peer,
208  uint32_t latency,
209  uint32_t loss,
210  uint32_t bandwidth)
211 {
212  struct LinkProperty *prop;
213 
214  prop = GNUNET_new (struct LinkProperty);
215  prop->peer = peer;
216  prop->latency = latency;
217  prop->loss = loss;
218  prop->bandwidth = bandwidth;
219  prop->next = model->props;
220  model->props = prop;
221 }
222 
223 
232 void
235 {
236  model->peer->underlay_model_exists = 0;
237  free_entries (model);
238  free_link_properties (model);
239  gnunet_free (model);
240 }
241 
242 
249 void
252 {
253  /* FIXME: Marshal the model into a message */
254  GNUNET_break (0);
255  /* do not reset the value of model->peer->underlay_model_exists */
256  free_entries (model);
257  free_link_properties (model);
258  GNUNET_free (model);
259 }
void GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkModel *model, struct GNUNET_TESTBED_Peer *peer)
Add a peer to the given model.
struct ListEntry * next
the next pointer
struct GNUNET_TESTBED_Peer * peer
the peer whose link is defined by these properties
struct GNUNET_TESTBED_UnderlayLinkModel * GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer, enum GNUNET_TESTBED_UnderlayLinkModelType type)
Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct Experiment * e
#define GNUNET_new(type)
Allocate a struct or union of the given type.
An underlay link.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static void free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Function to free resources of link properties added to the given model.
uint8_t underlay_model_exists
Has an underlay model already set for this peer?
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
void GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Free the resources of the model.
Container for holding a peer in whitelist/blacklist.
struct LinkProperty * props
list of link properties
struct ListEntry * entries
List of peers in the list.
GNUNET_TESTBED_UnderlayLinkModelType
The type of GNUNET_TESTBED_UnderlayLinkModel.
uint32_t bandwidth
bandwidth of the link in kilobytes per second
uint32_t latency
latency of the link in microseconds
internal API to access the &#39;peers&#39; subsystem
struct GNUNET_TESTBED_UnderlayLinkModel free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Function to free resources of list entries.
void GNUNET_TESTBED_underlaylinkmodel_set_link(struct GNUNET_TESTBED_UnderlayLinkModel *model, struct GNUNET_TESTBED_Peer *peer, uint32_t latency, uint32_t loss, uint32_t bandwidth)
Set the metrics for a link to the given peer in the underlay model.
struct GNUNET_TESTBED_Peer * peer
the peer
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_TESTBED_underlaylinkmodel_commit(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Commit the model.
Model for configuring underlay links of a peer.
A peer controlled by the testing framework.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct LinkProperty * next
next pointer for list
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t loss
data loss on the link expressed as percentage