aboutsummaryrefslogtreecommitdiff
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
parent70f9bcf894b28799df078330d204860e7ea7bae8 (diff)
downloadgnunet-e047b52bb409063e65abdcfcf108007fac42c95e.tar.gz
gnunet-e047b52bb409063e65abdcfcf108007fac42c95e.zip
test + fix
-rw-r--r--src/ats/Makefile.am14
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c2
-rw-r--r--src/ats/test_ats_api.c92
-rw-r--r--src/ats/test_ats_api.conf37
-rw-r--r--src/ats/test_ats_api_scheduling.c212
5 files changed, 257 insertions, 100 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 2b13fa06a..77aa71b19 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -31,19 +31,19 @@ gnunet_service_ats_LDADD = \
31 $(GN_LIBINTL) 31 $(GN_LIBINTL)
32 32
33 33
34#check_PROGRAMS = \ 34check_PROGRAMS = \
35# test_ats_api 35 test_ats_api_scheduling
36# test_ats_api_update_address 36# test_ats_api_update_address
37 37
38if ENABLE_TEST_RUN 38if ENABLE_TEST_RUN
39TESTS = $(check_PROGRAMS) 39TESTS = $(check_PROGRAMS)
40endif 40endif
41 41
42#test_ats_api_SOURCES = \ 42test_ats_api_scheduling_SOURCES = \
43# test_ats_api.c 43 test_ats_api_scheduling.c
44#test_ats_api_LDADD = \ 44test_ats_api_scheduling_LDADD = \
45# $(top_builddir)/src/util/libgnunetutil.la \ 45 $(top_builddir)/src/util/libgnunetutil.la \
46# $(top_builddir)/src/ats/libgnunetats.la 46 $(top_builddir)/src/ats/libgnunetats.la
47 47
48#test_ats_api_update_address_SOURCES = \ 48#test_ats_api_update_address_SOURCES = \
49# test_ats_api_update_address.c 49# test_ats_api_update_address.c
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 9a16269d9..f97578384 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -260,7 +260,7 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
260 if ( (address_length + 260 if ( (address_length +
261 plugin_name_length + 261 plugin_name_length +
262 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + 262 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
263 sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) || 263 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
264 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) || 264 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
265 (plugin_name[plugin_name_length - 1] != '\0') ) 265 (plugin_name[plugin_name_length - 1] != '\0') )
266 { 266 {
diff --git a/src/ats/test_ats_api.c b/src/ats/test_ats_api.c
deleted file mode 100644
index 4a4bf9772..000000000
--- a/src/ats/test_ats_api.c
+++ /dev/null
@@ -1,92 +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/ats_api.c
22 * @brief automatic transport selection 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
36#define VERBOSE GNUNET_EXTRA_LOGGING
37
38#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
39
40#define START_ARM GNUNET_YES
41
42
43static struct GNUNET_CONFIGURATION_Handle *cfg;
44
45static struct GNUNET_ATS_SchedulingHandle *ats;
46
47static void
48alloc_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
49 const char *plugin_name, struct Session *session,
50 const void *plugin_addr, size_t plugin_addr_len,
51 struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
52{
53
54}
55
56static int
57check ()
58{
59 int ret = 0;
60
61 cfg = GNUNET_CONFIGURATION_create ();
62 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, "test_ats_api.conf"))
63 {
64 GNUNET_CONFIGURATION_destroy (cfg);
65 return -1;
66 }
67
68 ats = GNUNET_ATS_init (cfg, alloc_cb, NULL);
69 GNUNET_assert (ats != NULL);
70 GNUNET_ATS_shutdown (ats);
71
72 GNUNET_CONFIGURATION_destroy (cfg);
73 return ret;
74}
75
76int
77main (int argc, char *argv[])
78{
79 int ret;
80
81 GNUNET_log_setup ("test-ats-api",
82#if VERBOSE
83 "DEBUG",
84#else
85 "WARNING",
86#endif
87 NULL);
88
89 ret = check ();
90
91 return ret;
92}
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf
index e69de29bb..c9e2d70cb 100644
--- a/src/ats/test_ats_api.conf
+++ b/src/ats/test_ats_api.conf
@@ -0,0 +1,37 @@
1[PATHS]
2SERVICEHOME = /tmp/test-ats-api-scheduling/
3
4[arm]
5PORT = 12001
6DEFAULTSERVICES = ats
7UNIXPATH = /tmp/test-ats-scheduling-arm.sock
8
9[ats]
10AUTOSTART = YES
11PORT = 12002
12HOSTNAME = localhost
13HOME = $SERVICEHOME
14CONFIG = $DEFAULTCONFIG
15BINARY = gnunet-service-ats
16ACCEPT_FROM = 127.0.0.1;
17ACCEPT_FROM6 = ::1;
18UNIXPATH = /tmp/test-ats-scheduling-ats.sock
19UNIX_MATCH_UID = YES
20UNIX_MATCH_GID = YES
21
22
23[resolver]
24PORT = 12003
25UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
26
27[statistics]
28PORT = 12004
29UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
30
31[peerinfo]
32PORT = 12005
33UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
34
35[transport]
36PORT = 12006
37UNIXPATH = /tmp/gnunet-p1-service-transport.sock \ No newline at end of file
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 */