GNUnet  0.19.5
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 "platform.h"
28 #include "testbed_api_peers.h"
29 
30 
35 {
39  struct LinkProperty *next;
40 
45 
49  uint32_t latency;
50 
54  uint32_t loss;
55 
59  uint32_t bandwidth;
60 };
61 
62 
66 struct ListEntry
67 {
71  struct ListEntry *next;
72 
77 };
78 
79 
85 {
90 
94  struct ListEntry *entries;
95 
100 
105 }
106 
107 
113 static void
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 
131 static void
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 
155  enum
157  type)
158 {
160 
164  m->type = type;
165  return m;
166 }
167 
168 
178 void
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 
204 void
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 
233 void
236 {
237  model->peer->underlay_model_exists = 0;
238  free_entries (model);
239  free_link_properties (model);
240  gnunet_free (model);
241 }
242 
243 
250 void
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 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct Experiment * e
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_TESTBED_UnderlayLinkModelType
The type of GNUNET_TESTBED_UnderlayLinkModel.
void GNUNET_TESTBED_underlaylinkmodel_free(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Free the resources of the model.
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_UnderlayLinkModel * GNUNET_TESTBED_underlaylinkmodel_create(struct GNUNET_TESTBED_Peer *peer, enum GNUNET_TESTBED_UnderlayLinkModelType type)
Create a GNUNET_TESTBED_UnderlayLinkModel for the given peer.
void GNUNET_TESTBED_underlaylinkmodel_add_peer(struct GNUNET_TESTBED_UnderlayLinkModel *model, struct GNUNET_TESTBED_Peer *peer)
Add a peer to the given model.
void GNUNET_TESTBED_underlaylinkmodel_commit(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Commit the model.
A peer controlled by the testing framework.
uint8_t underlay_model_exists
Has an underlay model already set for this peer?
Model for configuring underlay links of a peer.
struct LinkProperty * props
list of link properties
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct ListEntry * entries
List of peers in the list.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
An underlay link.
uint32_t bandwidth
bandwidth of the link in kilobytes per second
struct LinkProperty * next
next pointer for list
uint32_t latency
latency of the link in microseconds
uint32_t loss
data loss on the link expressed as percentage
struct GNUNET_TESTBED_Peer * peer
the peer whose link is defined by these properties
Container for holding a peer in whitelist/blacklist.
struct GNUNET_TESTBED_Peer * peer
the peer
struct ListEntry * next
the next pointer
internal API to access the 'peers' subsystem
struct GNUNET_TESTBED_UnderlayLinkModel free_entries(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Function to free resources of list entries.
static void free_link_properties(struct GNUNET_TESTBED_UnderlayLinkModel *model)
Function to free resources of link properties added to the given model.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.