aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-11 17:10:31 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-11 17:10:31 +0000
commit81defaa37bf4211f443f74384944642030807018 (patch)
tree7487470c9a7523644f53f6fb9a5f92ba5d2af8c1
parent9e8d96ae528a7bc3e38d212129ee63727a21d612 (diff)
downloadgnunet-81defaa37bf4211f443f74384944642030807018.tar.gz
gnunet-81defaa37bf4211f443f74384944642030807018.zip
add proper test for bandwidth reservation
-rw-r--r--src/ats/Makefile.am10
-rw-r--r--src/ats/test_ats_api_bandwidth_consumption.c249
-rw-r--r--src/ats/test_ats_lib.c11
-rw-r--r--src/ats/test_ats_reservation_api.c144
4 files changed, 165 insertions, 249 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 63917b907..cdefaba70 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -99,6 +99,7 @@ gnunet_service_ats_LDADD = \
99if HAVE_TESTING 99if HAVE_TESTING
100TESTING_TESTS = \ 100TESTING_TESTS = \
101 test_ats_api_proportional \ 101 test_ats_api_proportional \
102 test_ats_reservation_api_proportional \
102 test_ats_api_ril 103 test_ats_api_ril
103if HAVE_LIBGLPK 104if HAVE_LIBGLPK
104TESTING_TESTS += \ 105TESTING_TESTS += \
@@ -123,6 +124,15 @@ test_ats_api_proportional_LDADD = \
123 $(top_builddir)/src/testing/libgnunettesting.la \ 124 $(top_builddir)/src/testing/libgnunettesting.la \
124 libgnunetats.la 125 libgnunetats.la
125 126
127test_ats_reservation_api_proportional_SOURCES = \
128 test_ats_reservation_api.c \
129 test_ats_lib.c test_ats_lib.h
130test_ats_reservation_api_proportional_LDADD = \
131 $(top_builddir)/src/util/libgnunetutil.la \
132 $(top_builddir)/src/hello/libgnunethello.la \
133 $(top_builddir)/src/testing/libgnunettesting.la \
134 libgnunetats.la
135
126test_ats_api_ril_SOURCES = \ 136test_ats_api_ril_SOURCES = \
127 test_ats_api.c \ 137 test_ats_api.c \
128 test_ats_lib.c test_ats_lib.h 138 test_ats_lib.c test_ats_lib.h
diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c
deleted file mode 100644
index 59a97dfb0..000000000
--- a/src/ats/test_ats_api_bandwidth_consumption.c
+++ /dev/null
@@ -1,249 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (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 "gnunet_testing_lib.h"
30#include "ats.h"
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33
34static struct GNUNET_SCHEDULER_Task * die_task;
35
36static struct GNUNET_SCHEDULER_Task * consume_task;
37
38static struct GNUNET_ATS_SchedulingHandle *ats;
39
40static struct GNUNET_ATS_PerformanceHandle *atp;
41
42/**
43 * Connectivity handle
44 */
45static struct GNUNET_ATS_ConnectivityHandle *connect_ats;
46
47static struct GNUNET_ATS_ReservationContext *sh;
48
49static struct PeerContext *p;
50
51static uint32_t bw_in;
52
53static uint32_t bw_out;
54
55static int ret;
56
57struct Address
58{
59 char *plugin;
60
61 size_t plugin_len;
62
63 void *addr;
64
65 size_t addr_len;
66
67 struct GNUNET_ATS_Information *ats;
68
69 int ats_count;
70
71 void *session;
72};
73
74struct PeerContext
75{
76 struct GNUNET_PeerIdentity id;
77
78 struct Address *addr;
79};
80
81
82static void
83end ()
84{
85 if (NULL != connect_ats)
86 {
87 GNUNET_ATS_connectivity_done (connect_ats);
88 connect_ats = NULL;
89 }
90 if (die_task != NULL)
91 {
92 GNUNET_SCHEDULER_cancel (die_task);
93 die_task = NULL;
94 }
95 if (consume_task != NULL)
96 {
97 GNUNET_SCHEDULER_cancel (consume_task);
98 consume_task = NULL;
99 }
100 if (sh != NULL)
101 {
102 GNUNET_ATS_reserve_bandwidth_cancel (sh);
103 sh = NULL;
104 }
105 if (ats != NULL)
106 {
107 GNUNET_ATS_scheduling_done (ats);
108 ats = NULL;
109 }
110 if (atp != NULL)
111 {
112 GNUNET_ATS_performance_done (atp);
113 atp = NULL;
114 }
115 GNUNET_free (p->addr);
116 GNUNET_free (p);
117 p = NULL;
118 ret = 0;
119}
120
121
122static void
123end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124{
125 die_task = NULL;
126 end ();
127 ret = GNUNET_SYSERR;
128}
129
130
131static void
132performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
133 const char *plugin_name, const void *plugin_addr,
134 size_t plugin_addr_len,
135 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
136 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
137 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
138{
139
140}
141
142
143static void
144reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
145 int32_t amount, struct GNUNET_TIME_Relative res_delay)
146{
147 sh = NULL;
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount,
150 GNUNET_i2s (peer), res_delay.rel_value);
151}
152
153
154static void
155consume_bandwidth (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156{
157 consume_task = NULL;
158 int32_t to_reserve = 500;
159
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
161 "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
162 to_reserve, GNUNET_i2s (&p->id));
163
164 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb,
165 NULL);
166}
167
168
169static void
170address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
171 const char *plugin_name, const void *plugin_addr,
172 size_t plugin_addr_len, struct Session *session,
173 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
174 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
175 const struct GNUNET_ATS_Information *ats,
176 uint32_t ats_count)
177{
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n",
179 GNUNET_i2s (peer));
180
181 bw_in = ntohl (bandwidth_in.value__);
182 bw_out = ntohl (bandwidth_out.value__);
183
184 consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL);
185}
186
187
188static void
189run (void *cls,
190 const struct GNUNET_CONFIGURATION_Handle *cfg,
191 struct GNUNET_TESTING_Peer *peer)
192{
193 struct Address *addr;
194
195 ret = GNUNET_SYSERR;
196 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
197 connect_ats = GNUNET_ATS_connectivity_init (mycfg);
198
199 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
200 if (ats == NULL)
201 {
202 ret = GNUNET_SYSERR;
203 end ();
204 return;
205 }
206 p = GNUNET_new (struct PeerContext);
207 addr = GNUNET_new (struct Address);
208
209 atp = GNUNET_ATS_performance_init (cfg, NULL, NULL);
210 if (atp == NULL)
211 {
212 ret = GNUNET_SYSERR;
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
214 end_badly (NULL, NULL);
215 GNUNET_free (p);
216 GNUNET_free (addr);
217 return;
218 }
219
220 /* set up peer */
221 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
222 &p->id.hashPubKey);
223
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
225 GNUNET_i2s (&p->id));
226 p->addr = addr;
227 addr->plugin = "test";
228 addr->session = NULL;
229 addr->addr = NULL;
230 addr->addr_len = 0;
231
232 GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr,
233 addr->addr_len, addr->session, NULL, 0);
234
235 GNUNET_ATS_connectivity_suggest (connect_ats, &p->id);
236}
237
238
239int
240main (int argc, char *argv[])
241{
242 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_bandwidth_consumption",
243 "test_ats_api.conf",
244 &run, NULL))
245 return 1;
246 return ret;
247}
248
249/* end of file test_ats_api_bandwidth_consumption.c */
diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c
index b55881b6e..9a9726124 100644
--- a/src/ats/test_ats_lib.c
+++ b/src/ats/test_ats_lib.c
@@ -541,6 +541,7 @@ reservation_cb (void *cls,
541 struct Command *cmd = cls; 541 struct Command *cmd = cls;
542 struct GNUNET_PeerIdentity pid; 542 struct GNUNET_PeerIdentity pid;
543 543
544 cmd->details.reserve_bandwidth.rc = NULL;
544 make_peer (cmd->details.reserve_bandwidth.pid, 545 make_peer (cmd->details.reserve_bandwidth.pid,
545 &pid); 546 &pid);
546 GNUNET_assert (0 == memcmp (peer, 547 GNUNET_assert (0 == memcmp (peer,
@@ -551,6 +552,11 @@ reservation_cb (void *cls,
551 case GNUNET_OK: 552 case GNUNET_OK:
552 if (amount != cmd->details.reserve_bandwidth.amount) 553 if (amount != cmd->details.reserve_bandwidth.amount)
553 { 554 {
555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
556 "Unexpectedly failed to reserve %d bytes with delay %s!\n",
557 (int) amount,
558 GNUNET_STRINGS_relative_time_to_string (res_delay,
559 GNUNET_YES));
554 GNUNET_break (0); 560 GNUNET_break (0);
555 GNUNET_SCHEDULER_shutdown (); 561 GNUNET_SCHEDULER_shutdown ();
556 return; 562 return;
@@ -564,6 +570,11 @@ reservation_cb (void *cls,
564 if ( (amount != cmd->details.reserve_bandwidth.amount) || 570 if ( (amount != cmd->details.reserve_bandwidth.amount) ||
565 (0 == res_delay.rel_value_us) ) 571 (0 == res_delay.rel_value_us) )
566 { 572 {
573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
574 "Unexpectedly reserved %d bytes with delay %s!\n",
575 (int) amount,
576 GNUNET_STRINGS_relative_time_to_string (res_delay,
577 GNUNET_YES));
567 GNUNET_break (0); 578 GNUNET_break (0);
568 GNUNET_SCHEDULER_shutdown (); 579 GNUNET_SCHEDULER_shutdown ();
569 return; 580 return;
diff --git a/src/ats/test_ats_reservation_api.c b/src/ats/test_ats_reservation_api.c
new file mode 100644
index 000000000..e45ffe2cc
--- /dev/null
+++ b/src/ats/test_ats_reservation_api.c
@@ -0,0 +1,144 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 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_reservation_api.c
22 * @brief test ATS
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "test_ats_lib.h"
27
28/**
29 * Global timeout for the testcase.
30 */
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
32
33/**
34 * Definition of the test as a sequence of commands.
35 */
36static struct Command test_commands[] = {
37 /* 0: add initial address */
38 {
39 .code = CMD_ADD_ADDRESS,
40 .label = "add-address-0-0",
41 .details.add_address = {
42 .pid = 0,
43 .addr_num = 0,
44 .session = 0,
45 .properties = {
46 /* use network with 65k quota! */
47 .scope = GNUNET_ATS_NET_WAN
48 }
49 }
50 },
51 /* 1: some solver still require explicit start */
52 {
53 .code = CMD_REQUEST_CONNECTION_START,
54 .label = "request-0",
55 .details.request_connection_start = {
56 .pid = 0
57 }
58 },
59 /* 2: check we got an address */
60 {
61 .code = CMD_AWAIT_ADDRESS_SUGGESTION,
62 .details.await_address_suggestion = {
63 .add_label = "add-address-0-0"
64 }
65 },
66 /* 3: reserve 32k -- should work */
67 {
68 .code = CMD_RESERVE_BANDWIDTH,
69 .label = "initial reservation",
70 .details.reserve_bandwidth = {
71 .pid = 0,
72 .amount = 32 * 1024,
73 .expected_result = GNUNET_OK
74 }
75 },
76 /* 4: reserve another 32k -- might work */
77 {
78 .code = CMD_RESERVE_BANDWIDTH,
79 .details.reserve_bandwidth = {
80 .pid = 0,
81 .amount = 32 * 1024,
82 .expected_result = GNUNET_NO
83 }
84 },
85 /* 5: reserve another 128k -- might work */
86 {
87 .code = CMD_RESERVE_BANDWIDTH,
88 .label = "big reservation",
89 .details.reserve_bandwidth = {
90 .pid = 0,
91 .amount = 128 * 1024,
92 .expected_result = GNUNET_NO
93 }
94 },
95 /* 6: reserve another 32k -- should now fail */
96 {
97 .code = CMD_RESERVE_BANDWIDTH,
98 .label = "failing reservation",
99 .details.reserve_bandwidth = {
100 .pid = 0,
101 .amount = 32 * 1024,
102 .expected_result = GNUNET_SYSERR
103 }
104 },
105 /* 7: remove address */
106 {
107 .code = CMD_DEL_ADDRESS,
108 .details.del_address = {
109 .add_label = "add-address-0-0"
110 }
111 },
112 /* 8: check we got disconnected */
113 {
114 .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
115 .details.await_disconnect_suggestion = {
116 .pid = 0
117 }
118 },
119 /* 9: just for symmetry, also stop asking for the connection */
120 {
121 .code = CMD_REQUEST_CONNECTION_STOP,
122 .details.request_connection_stop = {
123 .connect_label = "request-0",
124 }
125 },
126 /* Test ends successfully */
127 {
128 .code = CMD_END_PASS
129 }
130};
131
132
133int
134main (int argc,
135 char *argv[])
136{
137 return TEST_ATS_run (argc,
138 argv,
139 test_commands,
140 TIMEOUT);
141}
142
143
144/* end of file test_ats_reservation_api.c */