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_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;
32 static struct GNUNET_CONFIGURATION_Handle * cfg;
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
37 "ATS Result callback\n");
40 struct TransportConfiguration
45 struct ATS_peer * p_head;
46 struct ATS_peer * p_tail;
48 struct ATS_mechanism * m_head;
49 struct ATS_mechanism * m_tail;
52 struct TransportConfiguration *tc;
55 void create_topology (int c_peers, int c_mechanisms)
58 peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer));
59 for (c=0 ; c<c_peers; c++)
61 peers[c].f = 1.0 / c_peers;
62 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &peers[c].peer.hashPubKey);
63 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s \n", GNUNET_i2s (&peers[c].peer));
64 peers[c].m_head = NULL;
65 peers[c].m_tail = NULL;
67 mechanisms = GNUNET_malloc ( c_mechanisms * sizeof (struct ATS_mechanism));
68 for (c=0 ; c<c_mechanisms; c++)
70 mechanisms[c].peer = &peers[c];
75 void delete_topology (void)
78 GNUNET_free (mechanisms);
82 void create_ats_information (struct ATS_peer **p, int * c_p,
83 struct ATS_mechanism ** m, int * c_m)
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 "ATS needs addresses\n");
90 (*c_p) = tc->mechanisms;
92 (*c_m) = tc->mechanisms;
100 ats_calculate_bandwidth_distribution(ats, NULL);
102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
103 "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
111 ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
112 create_ats_information,
114 //GNUNET_assert (ats != NULL);
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
122 int shutdown_ats (void)
126 ats_delete_problem (ats);
128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
129 "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
133 /* To make compiler happy */
136 struct ATS_quality_metric * q = qm;
138 struct ATS_ressource * r = ressources;
142 void iterate_peer_values (void *cls,
147 if (strcmp (option, "f") == 0)
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
149 "\t %s %s\n", option, value);
152 void iterate_mech_values (void *cls,
157 if (strcmp (option, "f") == 0)
158 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
159 "\t %s %s\n", option, value);
162 void iterate_sections (void *cls,
165 struct TransportConfiguration * tc = cls;
166 /* Peer definition */
167 if (99 == strlen(section))
169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
171 int res =GNUNET_CRYPTO_hash_from_string(section, &h);
172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
173 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL);
176 if (10 == strlen(section))
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
179 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL);
184 void destroy_transport_configuration (char * filename)
186 GNUNET_CONFIGURATION_destroy (cfg);
190 struct TransportConfiguration * load_transport_configuration (char * filename)
192 struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
193 cfg = GNUNET_CONFIGURATION_create();
194 GNUNET_CONFIGURATION_load(cfg, filename);
195 GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret);
201 main (int argc, char *argv[])
205 GNUNET_log_setup ("test-transport-ats",
213 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
214 "HAVE_LIBGLPK not set, exiting testcase\n");
223 tc = load_transport_configuration ("test.ats");
232 ret += shutdown_ats ();
239 /* end of test_transport_ats.c*/