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,
42 "ATS Result callback\n");
45 struct TransportConfiguration
50 struct ATS_peer * p_head;
51 struct ATS_peer * p_tail;
53 struct ATS_mechanism * m_head;
54 struct ATS_mechanism * m_tail;
59 create_ats_information (struct ATS_peer **p, int * c_p,
60 struct ATS_mechanism ** m, int * c_m)
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
63 "ATS needs addresses\n");
66 (*c_p) = tc->mechanisms;
68 (*c_m) = tc->mechanisms;
76 ats_calculate_bandwidth_distribution (ats);
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
78 "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
87 ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
88 create_ats_information,
90 //GNUNET_assert (ats != NULL);
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
93 "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
102 ats_delete_problem (ats);
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
110 /* To make compiler happy */
114 struct ATS_quality_metric * q = qm;
116 struct ATS_ressource * r = ressources;
124 iterate_peer_values (void *cls,
129 if (strcmp (option, "f") == 0)
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "\t %s %s\n", option, value);
135 iterate_mech_values (void *cls,
140 if (strcmp (option, "f") == 0)
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
142 "\t %s %s\n", option, value);
146 iterate_sections (void *cls,
149 struct TransportConfiguration * tc = cls;
150 /* Peer definition */
151 if (99 == strlen(section))
153 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
155 int res =GNUNET_CRYPTO_hash_from_string(section, &h);
156 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
157 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL);
160 if (10 == strlen(section))
162 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
163 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL);
169 static struct TransportConfiguration *
170 load_transport_configuration (char * filename)
172 struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
174 cfg = GNUNET_CONFIGURATION_create();
175 GNUNET_assert (GNUNET_OK ==
176 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*/