aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_api_scheduling_destroy_address_twice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/test_ats_api_scheduling_destroy_address_twice.c')
-rw-r--r--src/ats/test_ats_api_scheduling_destroy_address_twice.c244
1 files changed, 0 insertions, 244 deletions
diff --git a/src/ats/test_ats_api_scheduling_destroy_address_twice.c b/src/ats/test_ats_api_scheduling_destroy_address_twice.c
deleted file mode 100644
index 995538e7e..000000000
--- a/src/ats/test_ats_api_scheduling_destroy_address_twice.c
+++ /dev/null
@@ -1,244 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20/**
21 * @file ats/test_ats_api_scheduling_destroy_address.c
22 * @brief test destroying addresses in automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 *
26 */
27#include "platform.h"
28#include "gnunet_ats_service.h"
29#include "gnunet_testing_lib.h"
30#include "ats.h"
31#include "test_ats_api_common.h"
32
33/**
34 * Timeout task
35 */
36static struct GNUNET_SCHEDULER_Task * die_task;
37
38/**
39 * Statistics handle
40 */
41static struct GNUNET_STATISTICS_Handle *stats;
42
43/**
44 * Scheduling handle
45 */
46static struct GNUNET_ATS_SchedulingHandle *sched_ats;
47
48/**
49 * Return value
50 */
51static int ret;
52
53/**
54 * Test address
55 */
56static struct Test_Address test_addr;
57
58/**
59 * Test peer
60 */
61static struct PeerContext p;
62
63/**
64 * HELLO address
65 */
66struct GNUNET_HELLO_Address test_hello_address;
67
68/**
69 * Session
70 */
71static void *test_session;
72
73/**
74 * Test ats info
75 */
76struct GNUNET_ATS_Information test_ats_info[2];
77
78/**
79 * Test ats count
80 */
81static uint32_t test_ats_count;
82
83
84static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
85
86
87static int
88stat_cb(void *cls, const char *subsystem,
89 const char *name, uint64_t value,
90 int is_persistent)
91{
92 static int initial_ats_stat_cb = GNUNET_YES;
93 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
94 subsystem,name, value);
95
96 if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO))
97 {
98 fprintf (stderr, "We now expect a warning about destroying an unknown address...\n");
99 GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, test_session);
100 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
101 }
102 if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES))
103 {
104 initial_ats_stat_cb = GNUNET_NO;
105 }
106 if (1 == value)
107 {
108 GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, test_session);
109 }
110
111 return GNUNET_OK;
112}
113
114
115static void
116end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117{
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
119
120 if (die_task != NULL)
121 {
122 GNUNET_SCHEDULER_cancel (die_task);
123 die_task = NULL;
124 }
125
126 if (NULL != sched_ats)
127 {
128 GNUNET_ATS_scheduling_done (sched_ats);
129 sched_ats = NULL;
130 }
131
132 GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL);
133 if (NULL != stats)
134 {
135 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
136 stats = NULL;
137 }
138
139 free_test_address (&test_addr);
140
141 ret = 0;
142}
143
144
145static void
146end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
147{
148 die_task = NULL;
149 end ( NULL, NULL);
150 ret = GNUNET_SYSERR;
151}
152
153
154static void
155address_suggest_cb (void *cls,
156 const struct GNUNET_PeerIdentity *peer,
157 const struct GNUNET_HELLO_Address *address,
158 struct Session *session,
159 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
160 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
161{
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n");
163 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
164}
165
166
167static int
168dummy_stat (void *cls,
169 const char *subsystem,
170 const char *name,
171 uint64_t value,
172 int is_persistent)
173{
174 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
175 "Got dummy stat %s%s:%s = %llu\n",
176 is_persistent ? "!" : " ", subsystem, name, value);
177 return GNUNET_OK;
178}
179
180
181static void
182got_initial_value (void *cls, int success)
183{
184 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
185
186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n");
187
188 /* Connect to ATS scheduling */
189 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
190 if (sched_ats == NULL)
191 {
192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
193 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
194 return;
195 }
196
197 /* Set up peer */
198 memset (&p.id, '1', sizeof (p.id));
199 /* Prepare ATS Information */
200 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
201 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
202 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
203 test_ats_info[1].value = htonl(1);
204 test_ats_count = 2;
205
206 /* Adding address without session */
207 test_session = NULL;
208 create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1);
209 test_hello_address.peer = p.id;
210 test_hello_address.transport_name = test_addr.plugin;
211 test_hello_address.address = test_addr.addr;
212 test_hello_address.address_length = test_addr.addr_len;
213
214 /* Adding address */
215 GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count);
216}
217
218static void
219run (void *cls,
220 const struct GNUNET_CONFIGURATION_Handle *cfg,
221 struct GNUNET_TESTING_Peer *peer)
222{
223 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
224 stats = GNUNET_STATISTICS_create ("ats", cfg);
225 GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);
226
227 GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT,
228 &got_initial_value, &dummy_stat,
229 GNUNET_CONFIGURATION_dup (cfg));
230}
231
232
233int
234main (int argc, char *argv[])
235{
236 ret = 0;
237 if (0 != GNUNET_TESTING_peer_run ("test-ats-api",
238 "test_ats_api.conf",
239 &run, NULL))
240 return 1;
241 return ret;
242}
243
244/* end of file test_ats_api_scheduling_destroy_address.c */