2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file testing/test_transport_ats.c
22 * @brief testcase for ats functionality without starting peers
25 #include "gnunet-service-transport_ats.h"
26 #include "gnunet_configuration_lib.h"
27 #include "gnunet_crypto_lib.h"
29 #define VERBOSE GNUNET_YES
31 static struct ATS_Handle *ats;
33 static struct GNUNET_CONFIGURATION_Handle *cfg;
35 static struct TransportConfiguration *tc;
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
44 struct TransportConfiguration
49 struct ATS_peer *p_head;
50 struct ATS_peer *p_tail;
52 struct ATS_mechanism *m_head;
53 struct ATS_mechanism *m_tail;
58 create_ats_information (struct ATS_peer **p, int *c_p, struct ATS_mechanism **m,
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n");
64 (*c_p) = tc->mechanisms;
66 (*c_m) = tc->mechanisms;
75 ats_calculate_bandwidth_distribution (ats);
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running ATS: %s \n",
77 (ret == 0) ? "SUCCESSFUL" : "FAILED");
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);
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Initializing ATS: %s \n",
93 (ret == 0) ? "SUCCESSFUL" : "FAILED");
103 ats_delete_problem (ats);
105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown ATS: %s \n",
106 (ret == 0) ? "SUCCESSFUL" : "FAILED");
111 /* To make compiler happy */
115 struct ATS_quality_metric *q = qm;
118 struct ATS_ressource *r = ressources;
127 iterate_peer_values (void *cls, const char *section, const char *option,
130 if (strcmp (option, "f") == 0)
131 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
135 iterate_mech_values (void *cls, const char *section, const char *option,
138 if (strcmp (option, "f") == 0)
139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
143 iterate_sections (void *cls, const char *section)
145 struct TransportConfiguration *tc = cls;
147 /* Peer definition */
148 if (99 == strlen (section))
150 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
151 struct GNUNET_HashCode h;
152 int res = GNUNET_CRYPTO_hash_from_string (section, &h);
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);
159 if (10 == strlen (section))
161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n", section);
162 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
163 iterate_mech_values, NULL);
169 static struct TransportConfiguration *
170 load_transport_configuration (char *filename)
172 struct TransportConfiguration *ret =
173 GNUNET_malloc (sizeof (struct TransportConfiguration));
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);
185 main (int argc, char *argv[])
189 GNUNET_log_setup ("test-transport-ats",
196 tc = load_transport_configuration ("test_transport_ats.data");
200 ret += shutdown_ats ();
205 /* end of test_transport_ats.c*/