aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_api_scheduling.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-14 08:10:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-14 08:10:28 +0000
commite047b52bb409063e65abdcfcf108007fac42c95e (patch)
treed4f912cb012907e20d20fda2e67ffa8017214031 /src/ats/test_ats_api_scheduling.c
parent70f9bcf894b28799df078330d204860e7ea7bae8 (diff)
downloadgnunet-e047b52bb409063e65abdcfcf108007fac42c95e.tar.gz
gnunet-e047b52bb409063e65abdcfcf108007fac42c95e.zip
test + fix
Diffstat (limited to 'src/ats/test_ats_api_scheduling.c')
-rw-r--r--src/ats/test_ats_api_scheduling.c212
1 files changed, 212 insertions, 0 deletions
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c
new file mode 100644
index 000000000..851b515ad
--- /dev/null
+++ b/src/ats/test_ats_api_scheduling.c
@@ -0,0 +1,212 @@
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.c
22 * @brief test automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 *
26 * TODO:
27 * - write test case
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 (!)
32 */
33#include "platform.h"
34#include "gnunet_ats_service.h"
35#include "ats.h"
36
37#define VERBOSE GNUNET_YES
38
39#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
40
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
42
43static GNUNET_SCHEDULER_TaskIdentifier die_task;
44
45static struct GNUNET_ATS_SchedulingHandle *ats;
46
47struct GNUNET_OS_Process * arm_proc;
48
49static int ret;
50
51struct Address
52{
53 char * plugin;
54 size_t plugin_len;
55
56 void * addr;
57 size_t addr_len;
58
59 struct GNUNET_TRANSPORT_ATS_Information * ats;
60 int ats_count;
61
62 void *session;
63};
64
65struct PeerContext
66{
67 struct GNUNET_PeerIdentity id;
68
69 struct Address * addr;
70};
71
72
73static void
74stop_arm ()
75{
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);
80 arm_proc = NULL;
81}
82
83
84static void
85end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
86{
87 die_task = GNUNET_SCHEDULER_NO_TASK;
88 if (ats != NULL)
89 GNUNET_ATS_scheduling_done (ats);
90
91 ret = GNUNET_SYSERR;
92
93 stop_arm ();
94}
95
96
97static void
98end ()
99{
100 if (die_task != GNUNET_SCHEDULER_NO_TASK)
101 {
102 GNUNET_SCHEDULER_cancel(die_task);
103 die_task = GNUNET_SCHEDULER_NO_TASK;
104 }
105
106 GNUNET_ATS_scheduling_done (ats);
107
108 ret = 0;
109
110 stop_arm ();
111}
112
113
114static void
115address_suggest_cb (void *cls,
116 const struct
117 GNUNET_PeerIdentity *
118 peer,
119 const char *plugin_name,
120 const void *plugin_addr,
121 size_t plugin_addr_len,
122 struct Session * session,
123 struct
124 GNUNET_BANDWIDTH_Value32NBO
125 bandwidth_out,
126 struct
127 GNUNET_BANDWIDTH_Value32NBO
128 bandwidth_in,
129 const struct
130 GNUNET_TRANSPORT_ATS_Information
131 * ats,
132 uint32_t ats_count)
133
134{
135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address_suggest_cb `%s'\n", GNUNET_i2s (peer));
136
137 end ();
138}
139
140void
141start_arm (const char *cfgname)
142{
143 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
144 "gnunet-service-arm",
145#if VERBOSE_ARM
146 "-L", "DEBUG",
147#endif
148 "-c", cfgname, NULL);
149}
150
151static void
152check (void *cls, char *const *args, const char *cfgfile,
153 const struct GNUNET_CONFIGURATION_Handle *cfg)
154{
155 ret = GNUNET_SYSERR;
156 struct Address addr;
157 struct PeerContext p;
158
159 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
160 start_arm (cfgfile);
161
162 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
163
164 if (ats == NULL)
165 {
166 ret = GNUNET_SYSERR;
167 return;
168 }
169
170 /* set up peer */
171 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
172
173
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
175 p.addr = &addr;
176 addr.plugin = "test";
177 addr.session = NULL;
178 addr.addr = NULL;
179 addr.addr_len = 0;
180
181 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
182
183 GNUNET_ATS_suggest_address(ats, &p.id);
184}
185
186int
187main (int argc, char *argv[])
188{
189 static char *const argv2[] = { "test_ats_api_scheduling",
190 "-c",
191 "test_ats_api.conf",
192#if VERBOSE
193 "-L", "DEBUG",
194#else
195 "-L", "WARNING",
196#endif
197 NULL
198 };
199
200 static struct GNUNET_GETOPT_CommandLineOption options[] = {
201 GNUNET_GETOPT_OPTION_END
202 };
203
204 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
205 "test_ats_api_scheduling", "nohelp", options, &check,
206 NULL);
207
208
209 return ret;
210}
211
212/* end of file test_ats_api_scheduling.c */