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_init.c
22 * @brief test automatic transport selection scheduling API init/shutdown
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 #include "gnunet_ats_service.h"
29 #include "gnunet_testing_lib.h"
31 #include "test_ats_api_common.h"
35 static GNUNET_SCHEDULER_TaskIdentifier die_task;
40 struct GNUNET_STATISTICS_Handle *stats;
45 static struct GNUNET_ATS_SchedulingHandle *sched_ats;
53 static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
56 stat_cb(void *cls, const char *subsystem,
57 const char *name, uint64_t value,
61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
62 subsystem,name, value);
65 GNUNET_SCHEDULER_add_now (&end, NULL);
72 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
76 if (die_task != GNUNET_SCHEDULER_NO_TASK)
78 GNUNET_SCHEDULER_cancel (die_task);
79 die_task = GNUNET_SCHEDULER_NO_TASK;
82 if (NULL != sched_ats)
84 GNUNET_ATS_scheduling_done (sched_ats);
88 GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL);
91 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
98 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
100 die_task = GNUNET_SCHEDULER_NO_TASK;
106 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
107 struct Session *session,
108 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
109 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
110 const struct GNUNET_ATS_Information *atsi,
113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n");
114 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
121 const struct GNUNET_CONFIGURATION_Handle *cfg,
122 struct GNUNET_TESTING_Peer *peer)
124 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
125 stats = GNUNET_STATISTICS_create ("ats", cfg);
126 GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);
128 /* Connect to ATS scheduling */
129 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
130 if (sched_ats == NULL)
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
133 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
140 main (int argc, char *argv[])
143 if (0 != GNUNET_TESTING_peer_run ("test-ats-api",
150 /* end of file test_ats_api_scheduling_init.c */