aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_api_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/test_ats_api_common.c')
-rw-r--r--src/ats/test_ats_api_common.c302
1 files changed, 0 insertions, 302 deletions
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c
deleted file mode 100644
index 2bfebaa6d..000000000
--- a/src/ats/test_ats_api_common.c
+++ /dev/null
@@ -1,302 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20/**
21 * @file ats/test_ats_api_common.c
22 * @brief shared functions for ats test
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 */
26
27#include "test_ats_api_common.h"
28#define BIG_M_STRING "unlimited"
29
30
31void
32create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen)
33{
34
35 dest->plugin = GNUNET_strdup (plugin);
36 dest->session = session;
37 if (addrlen > 0)
38 {
39 dest->addr = GNUNET_malloc (addrlen);
40 memcpy (dest->addr, addr, addrlen);
41 }
42 else
43 dest->addr = NULL;
44 dest->addr_len = addrlen;
45}
46
47
48void
49free_test_address (struct Test_Address *dest)
50{
51 GNUNET_free_non_null (dest->plugin);
52 dest->plugin = NULL;
53 GNUNET_free_non_null (dest->addr);
54 dest->addr = NULL;
55}
56
57
58int
59compare_addresses (const struct GNUNET_HELLO_Address *address1,
60 void *session1,
61 const struct GNUNET_HELLO_Address *address2,
62 void *session2)
63{
64 if (0 !=
65 memcmp (&address1->peer,
66 &address2->peer,
67 sizeof (struct GNUNET_PeerIdentity)))
68 {
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
70 "Suggestion with invalid peer id'\n");
71 return GNUNET_SYSERR;
72 }
73 if (0 != strcmp (address1->transport_name, address2->transport_name))
74 {
75 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
76 "Suggestion with invalid plugin'\n");
77 return GNUNET_SYSERR;
78 }
79 if (address1->address_length != address2->address_length)
80 {
81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
82 "Suggestion with invalid address length\n");
83 return GNUNET_SYSERR;
84 }
85 if (0 != memcmp (address1->address, address2->address, address2->address_length))
86 {
87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
88 "Suggestion with invalid address\n");
89 return GNUNET_SYSERR;
90 }
91 if (session1 != session2)
92 {
93 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
94 "Suggestion with invalid session1 %p vs session2 %p'\n",
95 session1, session2);
96 return GNUNET_SYSERR;
97 }
98 return GNUNET_OK;
99}
100
101
102int
103compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is,
104 const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should)
105{
106 unsigned int c_o;
107 unsigned int c_i;
108 uint32_t type1;
109 uint32_t type2;
110 uint32_t val1;
111 uint32_t val2;
112 int res = GNUNET_OK;
113
114 for (c_o = 0; c_o < ats_count_is; c_o++)
115 {
116 for (c_i = 0; c_i < ats_count_should; c_i++)
117 {
118 type1 = ntohl(ats_is[c_o].type);
119 type2 = ntohl(ats_should[c_i].type);
120 if (type1 == type2)
121 {
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
123 "ATS type `%s'\n",
124 GNUNET_ATS_print_property_type (type1));
125 val1 = ntohl(ats_is[c_o].value);
126 val2 = ntohl(ats_should[c_i].value);
127 if (val1 != val2)
128 {
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "ATS value `%s' not equal: %u != %u\n",
131 GNUNET_ATS_print_property_type (type1),
132 val1, val2);
133 res = GNUNET_SYSERR;
134 }
135 else
136 {
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "ATS value `%s' equal: %u == %u\n",
139 GNUNET_ATS_print_property_type (type1),
140 val1, val2);
141 }
142 }
143 }
144 }
145 return res;
146}
147
148
149/**
150 * Load quotas for networks from configuration
151 *
152 * @param cfg configuration handle
153 * @param out_dest where to write outbound quotas
154 * @param in_dest where to write inbound quotas
155 * @param dest_length length of inbound and outbound arrays
156 * @return number of networks loaded
157 */
158unsigned int
159load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
160 unsigned long long *out_dest,
161 unsigned long long *in_dest,
162 int dest_length)
163{
164 char *entry_in = NULL;
165 char *entry_out = NULL;
166 char *quota_out_str;
167 char *quota_in_str;
168 int c;
169 int res;
170
171 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
172 {
173 in_dest[c] = 0;
174 out_dest[c] = 0;
175 GNUNET_asprintf (&entry_out,
176 "%s_QUOTA_OUT",
177 GNUNET_ATS_print_network_type (c));
178 GNUNET_asprintf (&entry_in,
179 "%s_QUOTA_IN",
180 GNUNET_ATS_print_network_type (c));
181
182 /* quota out */
183 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, &quota_out_str))
184 {
185 res = GNUNET_NO;
186 if (0 == strcmp(quota_out_str, BIG_M_STRING))
187 {
188 out_dest[c] = GNUNET_ATS_MaxBandwidth;
189 res = GNUNET_YES;
190 }
191 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
192 res = GNUNET_YES;
193 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
194 res = GNUNET_YES;
195
196 if (GNUNET_NO == res)
197 {
198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
199 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
200 GNUNET_ATS_print_network_type (c),
201 quota_out_str,
202 GNUNET_ATS_DefaultBandwidth);
203 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
204 }
205 else
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Outbound quota configure for network `%s' is %llu\n",
209 GNUNET_ATS_print_network_type (c),
210 out_dest[c]);
211 }
212 GNUNET_free (quota_out_str);
213 }
214 else
215 {
216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
217 _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
218 GNUNET_ATS_print_network_type (c),
219 GNUNET_ATS_DefaultBandwidth);
220 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
221 }
222
223 /* quota in */
224 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, &quota_in_str))
225 {
226 res = GNUNET_NO;
227 if (0 == strcmp(quota_in_str, BIG_M_STRING))
228 {
229 in_dest[c] = GNUNET_ATS_MaxBandwidth;
230 res = GNUNET_YES;
231 }
232 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
233 res = GNUNET_YES;
234 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
235 res = GNUNET_YES;
236
237 if (GNUNET_NO == res)
238 {
239 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
240 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
241 GNUNET_ATS_print_network_type (c),
242 quota_in_str,
243 GNUNET_ATS_DefaultBandwidth);
244 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
245 }
246 else
247 {
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
249 "Inbound quota configured for network `%s' is %llu\n",
250 GNUNET_ATS_print_network_type (c),
251 in_dest[c]);
252 }
253 GNUNET_free (quota_in_str);
254 }
255 else
256 {
257 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
258 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
259 GNUNET_ATS_print_network_type (c),
260 GNUNET_ATS_DefaultBandwidth);
261 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
262 }
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Loaded quota for network `%s' (in/out): %llu %llu\n",
265 GNUNET_ATS_print_network_type (c),
266 in_dest[c],
267 out_dest[c]);
268 GNUNET_free (entry_out);
269 GNUNET_free (entry_in);
270 }
271 return GNUNET_ATS_NetworkTypeCount;
272}
273
274/**
275 * Create a ATS_address with the given information
276 * @param peer peer
277 * @param plugin_name plugin
278 * @param plugin_addr address
279 * @param plugin_addr_len address length
280 * @param session_id session
281 * @return the ATS_Address
282 */
283struct ATS_Address *
284create_address (const struct GNUNET_PeerIdentity *peer,
285 const char *plugin_name,
286 const void *plugin_addr, size_t plugin_addr_len,
287 uint32_t session_id)
288{
289 struct ATS_Address *aa = NULL;
290
291 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
292 aa->peer = *peer;
293 aa->addr_len = plugin_addr_len;
294 aa->addr = &aa[1];
295 aa->plugin = (char *) &aa[1] + plugin_addr_len;
296 memcpy (&aa[1], plugin_addr, plugin_addr_len);
297 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
298 aa->session_id = session_id;
299 return aa;
300}
301
302/* end of file test_ats_api_common.c */