aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-10-14 08:58:34 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-10-14 08:58:34 +0000
commit52dc9ad9af5d242f8c80cd7f70cf5e788516e651 (patch)
tree9656d4cea70c8bdf5585c665cf8266cf265ac79c
parentaf2d0c2e264cfe9d93c686d0c22cfa3408680d03 (diff)
downloadgnunet-52dc9ad9af5d242f8c80cd7f70cf5e788516e651.tar.gz
gnunet-52dc9ad9af5d242f8c80cd7f70cf5e788516e651.zip
-rw-r--r--src/ats/Makefile.am12
-rw-r--r--src/ats/test_ats_api.conf19
-rw-r--r--src/ats/test_ats_api_bandwidth_consumption.c246
-rw-r--r--src/ats/test_ats_api_scheduling.c1
4 files changed, 257 insertions, 21 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index abec8e625..74f8abcb8 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -33,9 +33,9 @@ gnunet_service_ats_LDADD = \
33 33
34 34
35check_PROGRAMS = \ 35check_PROGRAMS = \
36 test_ats_api_scheduling 36 test_ats_api_scheduling \
37# test_ats_api_update_address 37 test_ats_api_bandwidth_consumption
38 38
39if ENABLE_TEST_RUN 39if ENABLE_TEST_RUN
40TESTS = $(check_PROGRAMS) 40TESTS = $(check_PROGRAMS)
41endif 41endif
@@ -46,6 +46,12 @@ test_ats_api_scheduling_LDADD = \
46 $(top_builddir)/src/util/libgnunetutil.la \ 46 $(top_builddir)/src/util/libgnunetutil.la \
47 $(top_builddir)/src/ats/libgnunetats.la 47 $(top_builddir)/src/ats/libgnunetats.la
48 48
49test_ats_api_bandwidth_consumption_SOURCES = \
50 test_ats_api_bandwidth_consumption.c
51test_ats_api_bandwidth_consumption_LDADD = \
52 $(top_builddir)/src/util/libgnunetutil.la \
53 $(top_builddir)/src/ats/libgnunetats.la
54
49#test_ats_api_update_address_SOURCES = \ 55#test_ats_api_update_address_SOURCES = \
50# test_ats_api_update_address.c 56# test_ats_api_update_address.c
51#test_ats_api_update_address_LDADD = \ 57#test_ats_api_update_address_LDADD = \
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf
index c9e2d70cb..8ee71a7e8 100644
--- a/src/ats/test_ats_api.conf
+++ b/src/ats/test_ats_api.conf
@@ -17,21 +17,4 @@ ACCEPT_FROM = 127.0.0.1;
17ACCEPT_FROM6 = ::1; 17ACCEPT_FROM6 = ::1;
18UNIXPATH = /tmp/test-ats-scheduling-ats.sock 18UNIXPATH = /tmp/test-ats-scheduling-ats.sock
19UNIX_MATCH_UID = YES 19UNIX_MATCH_UID = YES
20UNIX_MATCH_GID = YES 20UNIX_MATCH_GID = YES \ No newline at end of file
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_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c
new file mode 100644
index 000000000..5ff19fd83
--- /dev/null
+++ b/src/ats/test_ats_api_bandwidth_consumption.c
@@ -0,0 +1,246 @@
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_bandwidth_consumption.c
22 * @brief test 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 "ats.h"
30
31#define VERBOSE GNUNET_YES
32
33#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36
37static GNUNET_SCHEDULER_TaskIdentifier die_task;
38
39static struct GNUNET_ATS_SchedulingHandle *ats;
40
41static struct GNUNET_ATS_PerformanceHandle *atp;
42
43static struct GNUNET_OS_Process * arm_proc;
44
45static struct GNUNET_BANDWIDTH_Value32NBO bw_in;
46
47static struct GNUNET_BANDWIDTH_Value32NBO bw_out;
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 if (atp != NULL)
91 GNUNET_ATS_performance_done (atp);
92
93 ret = GNUNET_SYSERR;
94
95 stop_arm ();
96}
97
98
99static void
100end ()
101{
102 if (die_task != GNUNET_SCHEDULER_NO_TASK)
103 {
104 GNUNET_SCHEDULER_cancel(die_task);
105 die_task = GNUNET_SCHEDULER_NO_TASK;
106 }
107
108 GNUNET_ATS_scheduling_done (ats);
109
110 GNUNET_ATS_performance_done (atp);
111
112 ret = 0;
113
114 stop_arm ();
115}
116
117void performance_cb (void *cls,
118 const struct
119 GNUNET_PeerIdentity *
120 peer,
121 const char *plugin_name,
122 const void *plugin_addr,
123 size_t plugin_addr_len,
124 struct
125 GNUNET_BANDWIDTH_Value32NBO
126 bandwidth_out,
127 struct
128 GNUNET_BANDWIDTH_Value32NBO
129 bandwidth_in,
130 const struct
131 GNUNET_TRANSPORT_ATS_Information
132 * ats,
133 uint32_t ats_count)
134{
135
136}
137
138static void
139address_suggest_cb (void *cls,
140 const struct
141 GNUNET_PeerIdentity *
142 peer,
143 const char *plugin_name,
144 const void *plugin_addr,
145 size_t plugin_addr_len,
146 struct Session * session,
147 struct
148 GNUNET_BANDWIDTH_Value32NBO
149 bandwidth_out,
150 struct
151 GNUNET_BANDWIDTH_Value32NBO
152 bandwidth_in,
153 const struct
154 GNUNET_TRANSPORT_ATS_Information
155 * ats,
156 uint32_t ats_count)
157
158{
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer));
160
161 bw_in = bandwidth_in;
162 bw_out = bandwidth_out;
163}
164
165void
166start_arm (const char *cfgname)
167{
168 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
169 "gnunet-service-arm",
170#if VERBOSE_ARM
171 "-L", "DEBUG",
172#endif
173 "-c", cfgname, NULL);
174}
175
176static void
177check (void *cls, char *const *args, const char *cfgfile,
178 const struct GNUNET_CONFIGURATION_Handle *cfg)
179{
180 ret = GNUNET_SYSERR;
181 struct Address addr;
182 struct PeerContext p;
183
184 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
185 start_arm (cfgfile);
186
187 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
188 if (ats == NULL)
189 {
190 ret = GNUNET_SYSERR;
191 end ();
192 return;
193 }
194
195 atp = GNUNET_ATS_performance_init (cfg, &performance_cb, NULL);
196 if (atp == NULL)
197 {
198 ret = GNUNET_SYSERR;
199 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
200 end_badly(NULL, NULL);
201 return;
202 }
203
204 /* set up peer */
205 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
206
207
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
209 p.addr = &addr;
210 addr.plugin = "test";
211 addr.session = NULL;
212 addr.addr = NULL;
213 addr.addr_len = 0;
214
215 GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
216
217 GNUNET_ATS_suggest_address(ats, &p.id);
218}
219
220int
221main (int argc, char *argv[])
222{
223 static char *const argv2[] = { "test_ats_api_bandwidth_consumption",
224 "-c",
225 "test_ats_api.conf",
226#if VERBOSE
227 "-L", "DEBUG",
228#else
229 "-L", "WARNING",
230#endif
231 NULL
232 };
233
234 static struct GNUNET_GETOPT_CommandLineOption options[] = {
235 GNUNET_GETOPT_OPTION_END
236 };
237
238 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
239 "test_ats_api_bandwidth_consumption", "nohelp", options, &check,
240 NULL);
241
242
243 return ret;
244}
245
246/* end of file test_ats_api_bandwidth_consumption.c */
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c
index 851b515ad..88bd8b7ba 100644
--- a/src/ats/test_ats_api_scheduling.c
+++ b/src/ats/test_ats_api_scheduling.c
@@ -164,6 +164,7 @@ check (void *cls, char *const *args, const char *cfgfile,
164 if (ats == NULL) 164 if (ats == NULL)
165 { 165 {
166 ret = GNUNET_SYSERR; 166 ret = GNUNET_SYSERR;
167 end ();
167 return; 168 return;
168 } 169 }
169 170