aboutsummaryrefslogtreecommitdiff
path: root/src/ats-test/test_transport_ats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-test/test_transport_ats.c')
-rw-r--r--src/ats-test/test_transport_ats.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/src/ats-test/test_transport_ats.c b/src/ats-test/test_transport_ats.c
new file mode 100644
index 000000000..0d16cd1b8
--- /dev/null
+++ b/src/ats-test/test_transport_ats.c
@@ -0,0 +1,205 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 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 testing/test_transport_ats.c
22 * @brief testcase for ats functionality without starting peers
23 */
24#include "platform.h"
25#include "gnunet-service-transport_ats.h"
26#include "gnunet_configuration_lib.h"
27#include "gnunet_crypto_lib.h"
28
29#define VERBOSE GNUNET_YES
30
31static struct ATS_Handle *ats;
32
33static struct GNUNET_CONFIGURATION_Handle *cfg;
34
35static struct TransportConfiguration *tc;
36
37
38static void
39ats_result_cb ()
40{
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
42}
43
44struct TransportConfiguration
45{
46 int peers;
47 int mechanisms;
48
49 struct ATS_peer *p_head;
50 struct ATS_peer *p_tail;
51
52 struct ATS_mechanism *m_head;
53 struct ATS_mechanism *m_tail;
54};
55
56
57static void
58create_ats_information (struct ATS_peer **p, int *c_p, struct ATS_mechanism **m,
59 int *c_m)
60{
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n");
62
63 (*p) = tc->p_head;
64 (*c_p) = tc->mechanisms;
65 (*m) = tc->m_head;
66 (*c_m) = tc->mechanisms;
67}
68
69
70static int
71run_ats ()
72{
73 int ret = 0;
74
75 ats_calculate_bandwidth_distribution (ats);
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running ATS: %s \n",
77 (ret == 0) ? "SUCCESSFUL" : "FAILED");
78 return ret;
79}
80
81
82static int
83init_ats ()
84{
85 int ret = 0;
86
87 ats =
88 ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
89 create_ats_information, ats_result_cb);
90 //GNUNET_assert (ats != NULL);
91
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Initializing ATS: %s \n",
93 (ret == 0) ? "SUCCESSFUL" : "FAILED");
94 return ret;
95}
96
97
98static int
99shutdown_ats ()
100{
101 int ret = 0;
102
103 ats_delete_problem (ats);
104 ats_shutdown (ats);
105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown ATS: %s \n",
106 (ret == 0) ? "SUCCESSFUL" : "FAILED");
107 return ret;
108}
109
110
111/* To make compiler happy */
112void
113dummy ()
114{
115 struct ATS_quality_metric *q = qm;
116
117 q = NULL;
118 struct ATS_ressource *r = ressources;
119
120 r = NULL;
121 q++;
122 r++;
123}
124
125
126static void
127iterate_peer_values (void *cls, const char *section, const char *option,
128 const char *value)
129{
130 if (strcmp (option, "f") == 0)
131 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
132}
133
134static void
135iterate_mech_values (void *cls, const char *section, const char *option,
136 const char *value)
137{
138 if (strcmp (option, "f") == 0)
139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
140}
141
142static void
143iterate_sections (void *cls, const char *section)
144{
145 struct TransportConfiguration *tc = cls;
146
147 /* Peer definition */
148 if (99 == strlen (section))
149 {
150 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
151 GNUNET_HashCode h;
152 int res = GNUNET_CRYPTO_hash_from_string (section, &h);
153
154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
155 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
156 iterate_peer_values, NULL);
157 tc->peers++;
158 }
159 if (10 == strlen (section))
160 {
161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n", section);
162 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
163 iterate_mech_values, NULL);
164 tc->peers++;
165 }
166}
167
168
169static struct TransportConfiguration *
170load_transport_configuration (char *filename)
171{
172 struct TransportConfiguration *ret =
173 GNUNET_malloc (sizeof (struct TransportConfiguration));
174
175 cfg = GNUNET_CONFIGURATION_create ();
176 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, filename));
177 GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret);
178 GNUNET_CONFIGURATION_destroy (cfg);
179 cfg = NULL;
180 return ret;
181}
182
183
184int
185main (int argc, char *argv[])
186{
187 int ret = 0;
188
189 GNUNET_log_setup ("test-transport-ats",
190#if VERBOSE
191 "DEBUG",
192#else
193 "INFO",
194#endif
195 NULL);
196 tc = load_transport_configuration ("test_transport_ats.data");
197 ats = NULL;
198 ret += init_ats ();
199 ret += run_ats ();
200 ret += shutdown_ats ();
201 return ret;
202
203}
204
205/* end of test_transport_ats.c*/