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_add_address.c
22 * @brief test adding addresses in automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib-new.h"
30 #include "test_ats_api_common.h"
32 #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
34 static GNUNET_SCHEDULER_TaskIdentifier die_task;
35 static GNUNET_SCHEDULER_TaskIdentifier wait_task;
40 static struct GNUNET_ATS_SchedulingHandle *sched_ats;
50 static struct Test_Address test_addr;
55 static struct PeerContext p;
60 struct GNUNET_HELLO_Address test_hello_address;
65 static void *test_session;
70 struct GNUNET_ATS_Information test_ats_info[2];
75 uint32_t test_ats_count;
79 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81 die_task = GNUNET_SCHEDULER_NO_TASK;
83 if (sched_ats != NULL)
84 GNUNET_ATS_scheduling_done (sched_ats);
85 free_test_address (&test_addr);
91 end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
94 if (die_task != GNUNET_SCHEDULER_NO_TASK)
96 GNUNET_SCHEDULER_cancel (die_task);
97 die_task = GNUNET_SCHEDULER_NO_TASK;
99 if (NULL != sched_ats)
100 GNUNET_ATS_scheduling_done (sched_ats);
102 free_test_address (&test_addr);
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!\n");
114 GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id);
115 GNUNET_SCHEDULER_add_now (&end, NULL);
121 const struct GNUNET_CONFIGURATION_Handle *cfg,
122 struct GNUNET_TESTING_Peer *peer)
125 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
127 /* Connect to ATS scheduling */
128 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
129 if (sched_ats == NULL)
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
133 GNUNET_SCHEDULER_add_now (&end , NULL);
138 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.id.hashPubKey))
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
142 GNUNET_SCHEDULER_add_now (&end , NULL);
146 GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p.id)));
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
149 GNUNET_i2s_full(&p.id));
151 /* Prepare ATS Information */
152 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
153 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WLAN); /* WLAN quota is below min bw */
154 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
155 test_ats_info[1].value = htonl(1);
158 /* Adding address without session */
160 create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1);
161 test_hello_address.peer = p.id;
162 test_hello_address.transport_name = test_addr.plugin;
163 test_hello_address.address = test_addr.addr;
164 test_hello_address.address_length = test_addr.addr_len;
165 GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count);
167 GNUNET_ATS_suggest_address (sched_ats, &p.id);
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for wait period for no suggest...\n");
171 wait_task = GNUNET_SCHEDULER_add_delayed (WAIT, &end, NULL);
176 main (int argc, char *argv[])
178 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_add_address",
185 /* end of file test_ats_api_scheduling_add_address.c */