2 This file is part of GNUnet.
3 (C) 2010,2011 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 ats/test_ats_api_bandwidth_consumption.c
22 * @brief test automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 #include "gnunet_ats_service.h"
31 #define VERBOSE GNUNET_YES
33 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
37 static GNUNET_SCHEDULER_TaskIdentifier die_task;
39 static struct GNUNET_ATS_SchedulingHandle *ats;
41 static struct GNUNET_ATS_PerformanceHandle *atp;
43 static struct GNUNET_OS_Process * arm_proc;
45 static struct GNUNET_BANDWIDTH_Value32NBO bw_in;
47 static struct GNUNET_BANDWIDTH_Value32NBO bw_out;
59 struct GNUNET_TRANSPORT_ATS_Information * ats;
67 struct GNUNET_PeerIdentity id;
69 struct Address * addr;
76 if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM))
77 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
78 GNUNET_OS_process_wait (arm_proc);
79 GNUNET_OS_process_close (arm_proc);
85 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
87 die_task = GNUNET_SCHEDULER_NO_TASK;
89 GNUNET_ATS_scheduling_done (ats);
91 GNUNET_ATS_performance_done (atp);
102 if (die_task != GNUNET_SCHEDULER_NO_TASK)
104 GNUNET_SCHEDULER_cancel(die_task);
105 die_task = GNUNET_SCHEDULER_NO_TASK;
108 GNUNET_ATS_scheduling_done (ats);
110 GNUNET_ATS_performance_done (atp);
117 void performance_cb (void *cls,
119 GNUNET_PeerIdentity *
121 const char *plugin_name,
122 const void *plugin_addr,
123 size_t plugin_addr_len,
125 GNUNET_BANDWIDTH_Value32NBO
128 GNUNET_BANDWIDTH_Value32NBO
131 GNUNET_TRANSPORT_ATS_Information
139 address_suggest_cb (void *cls,
141 GNUNET_PeerIdentity *
143 const char *plugin_name,
144 const void *plugin_addr,
145 size_t plugin_addr_len,
146 struct Session * session,
148 GNUNET_BANDWIDTH_Value32NBO
151 GNUNET_BANDWIDTH_Value32NBO
154 GNUNET_TRANSPORT_ATS_Information
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer));
161 bw_in = bandwidth_in;
162 bw_out = bandwidth_out;
166 start_arm (const char *cfgname)
168 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
169 "gnunet-service-arm",
173 "-c", cfgname, NULL);
177 check (void *cls, char *const *args, const char *cfgfile,
178 const struct GNUNET_CONFIGURATION_Handle *cfg)
182 struct PeerContext p;
184 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
187 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
195 atp = GNUNET_ATS_performance_init (cfg, &performance_cb, NULL);
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
200 end_badly(NULL, NULL);
205 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
210 addr.plugin = "test";
215 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
217 GNUNET_ATS_suggest_address(ats, &p.id);
221 main (int argc, char *argv[])
223 static char *const argv2[] = { "test_ats_api_bandwidth_consumption",
234 static struct GNUNET_GETOPT_CommandLineOption options[] = {
235 GNUNET_GETOPT_OPTION_END
238 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
239 "test_ats_api_bandwidth_consumption", "nohelp", options, &check,
246 /* end of file test_ats_api_bandwidth_consumption.c */