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_scheduling.c
22 * @brief test automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 * - extend API to get performance data
29 * - implement simplistic strategy based on say 'lowest latency' or strict ordering
30 * - extend API to get peer preferences, implement proportional bandwidth assignment
31 * - re-implement API against a real ATS service (!)
34 #include "gnunet_ats_service.h"
37 #define VERBOSE GNUNET_YES
39 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
41 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
43 static GNUNET_SCHEDULER_TaskIdentifier die_task;
45 static struct GNUNET_ATS_SchedulingHandle *ats;
47 struct GNUNET_OS_Process * arm_proc;
51 struct GNUNET_TRANSPORT_ATS_Information atsi[2];
63 struct GNUNET_TRANSPORT_ATS_Information * ats;
71 struct GNUNET_PeerIdentity id;
73 struct Address * addr;
80 if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM))
81 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
82 GNUNET_OS_process_wait (arm_proc);
83 GNUNET_OS_process_close (arm_proc);
89 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
91 die_task = GNUNET_SCHEDULER_NO_TASK;
93 GNUNET_ATS_scheduling_done (ats);
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
105 if (die_task != GNUNET_SCHEDULER_NO_TASK)
107 GNUNET_SCHEDULER_cancel(die_task);
108 die_task = GNUNET_SCHEDULER_NO_TASK;
111 GNUNET_ATS_scheduling_done (ats);
120 address_suggest_cb (void *cls,
122 GNUNET_PeerIdentity *
124 const char *plugin_name,
125 const void *plugin_addr,
126 size_t plugin_addr_len,
127 struct Session * session,
129 GNUNET_BANDWIDTH_Value32NBO
132 GNUNET_BANDWIDTH_Value32NBO
135 GNUNET_TRANSPORT_ATS_Information
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", GNUNET_i2s (peer));
142 GNUNET_assert (0 == memcmp (peer, &p.id, sizeof (struct GNUNET_PeerIdentity)));
143 GNUNET_assert (0 == strcmp (plugin_name, addr.plugin));
144 GNUNET_assert (plugin_addr_len == addr.addr_len);
145 GNUNET_assert (0 == memcmp (plugin_addr, addr.plugin, plugin_addr_len));
146 GNUNET_assert (addr.session == session);
150 GNUNET_assert (ats_count == 2);
151 GNUNET_assert (atsi[0].type == htons (1));
152 GNUNET_assert (atsi[0].type == htons (2));
153 GNUNET_assert (atsi[1].type == htons (2));
154 GNUNET_assert (atsi[1].type == htons (2));
159 GNUNET_SCHEDULER_add_now(&end, NULL);
163 start_arm (const char *cfgname)
165 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
166 "gnunet-service-arm",
170 "-c", cfgname, NULL);
174 check (void *cls, char *const *args, const char *cfgfile,
175 const struct GNUNET_CONFIGURATION_Handle *cfg)
179 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
182 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
192 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
197 addr.plugin = "test";
202 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
204 atsi[0].type = htons (1);
205 atsi[0].type = htons (1);
207 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 1);
209 atsi[0].type = htons (1);
210 atsi[0].type = htons (2);
212 atsi[1].type = htons (2);
213 atsi[1].type = htons (2);
215 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, atsi, 2);
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p.id));
218 GNUNET_ATS_suggest_address(ats, &p.id);
222 main (int argc, char *argv[])
224 static char *const argv2[] = { "test_ats_api_scheduling",
235 static struct GNUNET_GETOPT_CommandLineOption options[] = {
236 GNUNET_GETOPT_OPTION_END
239 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
240 "test_ats_api_scheduling", "nohelp", options, &check,
247 /* end of file test_ats_api_scheduling.c */