aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-24 15:51:16 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-24 15:51:16 +0000
commit93ec94ec45d51c60e0237b7f66adb7bcdbc23fbe (patch)
tree5454d00bac4c738b7bb998769a1c5f2a9484c867 /src/transport
parentb7e1636fb0a053199b1574c9176e0b39c0b0c7d8 (diff)
downloadgnunet-93ec94ec45d51c60e0237b7f66adb7bcdbc23fbe.tar.gz
gnunet-93ec94ec45d51c60e0237b7f66adb7bcdbc23fbe.zip
convert last test to new send api
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/test_quota_compliance.c198
-rw-r--r--src/transport/test_transport_defaults.conf2
-rw-r--r--src/transport/transport-testing-send.c2
3 files changed, 34 insertions, 168 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index e574cd8f6..5bd3f0237 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -32,20 +32,13 @@
32/** 32/**
33 * Testcase timeout 33 * Testcase timeout
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480)
36 36
37/** 37#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80)
38 * How long until we give up on transmitting the message?
39 */
40#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
41
42#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
43 38
44 39
45static struct GNUNET_SCHEDULER_Task *measure_task; 40static struct GNUNET_SCHEDULER_Task *measure_task;
46 41
47struct GNUNET_TRANSPORT_TransmitHandle *th;
48
49static char *gen_cfgs[2]; 42static char *gen_cfgs[2];
50 43
51static unsigned long long quota_in[] = { 10000, 10000 }; 44static unsigned long long quota_in[] = { 10000, 10000 };
@@ -60,24 +53,9 @@ static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
60 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise 53 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
61 * messages may be dropped even for a reliable transport. 54 * messages may be dropped even for a reliable transport.
62 */ 55 */
63#define TOTAL_MSGS (1024 * 2) 56#define TOTAL_MSGS (1024 * 32)
64
65#define MTYPE 12345
66
67GNUNET_NETWORK_STRUCT_BEGIN
68struct TestMessage
69{
70 struct GNUNET_MessageHeader header;
71
72 uint32_t num GNUNET_PACKED;
73};
74GNUNET_NETWORK_STRUCT_END
75 57
76static int msg_scheduled; 58static unsigned long long total_bytes_recv;
77
78static int msg_sent;
79
80static unsigned long long total_bytes_sent;
81 59
82static struct GNUNET_TIME_Absolute start_time; 60static struct GNUNET_TIME_Absolute start_time;
83 61
@@ -89,24 +67,24 @@ report ()
89 unsigned long long datarate; 67 unsigned long long datarate;
90 68
91 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 69 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
92 datarate = (total_bytes_sent * 1000 * 1000) / delta; 70 datarate = (total_bytes_recv * 1000 * 1000) / delta;
93 71
94 FPRINTF (stderr, 72 FPRINTF (stderr,
95 "Throughput was %llu b/s\n", 73 "Throughput was %llu b/s\n",
96 datarate); 74 datarate);
97 75 ccc->global_ret = GNUNET_OK;
98 if (datarate > quota_in[1]) 76 if (datarate > 1.1 * quota_in[1])
99 { 77 {
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
101 "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", 79 "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n",
102 datarate, 80 datarate,
103 quota_in[1]); 81 quota_in[1]);
104 ccc->global_ret = GNUNET_SYSERR; 82 ccc->global_ret = GNUNET_SYSERR;
105 } 83 }
106 if (datarate > quota_out[0]) 84 if (datarate > 1.1 * quota_out[0])
107 { 85 {
108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 86 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
109 "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", 87 "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n",
110 datarate, 88 datarate,
111 quota_out[0]); 89 quota_out[0]);
112 ccc->global_ret = GNUNET_SYSERR; 90 ccc->global_ret = GNUNET_SYSERR;
@@ -130,22 +108,18 @@ custom_shutdown (void *cls)
130 GNUNET_SCHEDULER_cancel (measure_task); 108 GNUNET_SCHEDULER_cancel (measure_task);
131 measure_task = NULL; 109 measure_task = NULL;
132 } 110 }
133 if (NULL != th)
134 {
135 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
136 th = NULL;
137 }
138 report (); 111 report ();
139} 112}
140 113
141 114
142static unsigned int 115static size_t
143get_size (unsigned int iter) 116get_size (unsigned int iter)
144{ 117{
145 unsigned int ret; 118 size_t ret;
146 119
147 ret = (iter * iter * iter); 120 ret = (iter * iter * iter) % 60000;
148 return sizeof (struct TestMessage) + (ret % 60000); 121 ret += sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage);
122 return ret;
149} 123}
150 124
151 125
@@ -155,11 +129,12 @@ notify_receive (void *cls,
155 const struct GNUNET_PeerIdentity *sender, 129 const struct GNUNET_PeerIdentity *sender,
156 const struct GNUNET_MessageHeader *message) 130 const struct GNUNET_MessageHeader *message)
157{ 131{
158 const struct TestMessage *hdr; 132 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr;
159 133
160 hdr = (const struct TestMessage *) message; 134 hdr = (const struct GNUNET_TRANSPORT_TESTING_TestMessage *) message;
161 if (MTYPE != ntohs (message->type)) 135 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->type))
162 return; 136 return;
137 total_bytes_recv += ntohs (message->size);
163 138
164 { 139 {
165 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 140 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
@@ -176,123 +151,6 @@ notify_receive (void *cls,
176} 151}
177 152
178 153
179static size_t
180notify_ready (void *cls,
181 size_t size,
182 void *buf)
183{
184 static int n;
185 char *cbuf = buf;
186 struct TestMessage hdr;
187 unsigned int s;
188 unsigned int ret;
189
190 th = NULL;
191 if (NULL == buf)
192 {
193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
194 "Timeout occurred while waiting for transmit_ready for message %u of %u\n",
195 msg_scheduled, TOTAL_MSGS);
196 GNUNET_SCHEDULER_shutdown ();
197 ccc->global_ret = GNUNET_SYSERR;
198 return 0;
199 }
200
201 ret = 0;
202 s = get_size (n);
203 GNUNET_assert (size >= s);
204 GNUNET_assert (buf != NULL);
205 cbuf = buf;
206 do
207 {
208 hdr.header.size = htons (s);
209 hdr.header.type = htons (MTYPE);
210 hdr.num = htonl (n);
211 msg_sent = n;
212 GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
213 ret += sizeof (struct TestMessage);
214 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
215 ret += s - sizeof (struct TestMessage);
216#if VERBOSE
217 if (n % 5000 == 0)
218 {
219#endif
220 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
221
222 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
223 "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n",
224 n, s,
225 ccc->p[1]->no,
226 GNUNET_i2s (&ccc->p[1]->id),
227 ccc->p[0]->no,
228 receiver_s);
229 GNUNET_free (receiver_s);
230#if 0
231 }
232#endif
233 n++;
234 s = get_size (n);
235 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
236 break; /* sometimes pack buffer full, sometimes not */
237 }
238 while (size - ret >= s);
239 if (n < TOTAL_MSGS)
240 {
241 if (th == NULL)
242 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
243 &ccc->p[0]->id,
244 s,
245 TIMEOUT_TRANSMIT,
246 &notify_ready,
247 NULL);
248 msg_scheduled = n;
249 }
250 if (n % 5000 == 0)
251 {
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Returning total message block of size %u\n",
254 ret);
255 }
256 total_bytes_sent += ret;
257 if (n == TOTAL_MSGS)
258 {
259 FPRINTF (stderr, "%s", "\n");
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "All messages sent\n");
262 }
263 return ret;
264}
265
266
267static void
268notify_disconnect (void *cls,
269 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
270 const struct GNUNET_PeerIdentity *other)
271{
272 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
273 me,
274 other);
275 if (th != NULL)
276 {
277 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
278 th = NULL;
279 }
280}
281
282
283static void
284sendtask ()
285{
286 start_time = GNUNET_TIME_absolute_get ();
287 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
288 &ccc->p[0]->id,
289 get_size (0),
290 TIMEOUT_TRANSMIT,
291 &notify_ready,
292 NULL);
293}
294
295
296static void 154static void
297measure (void *cls) 155measure (void *cls)
298{ 156{
@@ -316,11 +174,18 @@ measure (void *cls)
316static void 174static void
317start_task (void *cls) 175start_task (void *cls)
318{ 176{
177 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
178 .num_messages = TOTAL_MSGS,
179 .get_size_cb = &get_size
180 };
181
182 sc.ccc = ccc;
319 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 183 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
320 &measure, 184 &measure,
321 NULL); 185 NULL);
322 GNUNET_SCHEDULER_add_now (&sendtask, 186 start_time = GNUNET_TIME_absolute_get ();
323 NULL); 187 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
188 &sc);
324} 189}
325 190
326 191
@@ -386,7 +251,7 @@ check (void *cls,
386 .config_file = "test_quota_compliance_data.conf", 251 .config_file = "test_quota_compliance_data.conf",
387 .rec = &notify_receive, 252 .rec = &notify_receive,
388 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 253 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
389 .nd = &notify_disconnect, 254 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
390 .shutdown_task = &custom_shutdown, 255 .shutdown_task = &custom_shutdown,
391 .timeout = TIMEOUT 256 .timeout = TIMEOUT
392 }; 257 };
@@ -429,7 +294,8 @@ check (void *cls,
429 294
430 295
431int 296int
432main (int argc, char *argv[]) 297main (int argc,
298 char *argv[])
433{ 299{
434 if (GNUNET_OK != 300 if (GNUNET_OK !=
435 GNUNET_TRANSPORT_TESTING_main (2, 301 GNUNET_TRANSPORT_TESTING_main (2,
diff --git a/src/transport/test_transport_defaults.conf b/src/transport/test_transport_defaults.conf
index e13553572..95a57c954 100644
--- a/src/transport/test_transport_defaults.conf
+++ b/src/transport/test_transport_defaults.conf
@@ -7,7 +7,7 @@ GNUNET_TEST_HOME = /tmp/test-transport-api/
7TIMEOUT = 300 s 7TIMEOUT = 300 s
8 8
9[transport] 9[transport]
10#PREFIX = valgrind 10# PREFIX = valgrind
11 11
12[nat] 12[nat]
13DISABLEV6 = NO 13DISABLEV6 = NO
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c
index cbf294bcf..92d5833b0 100644
--- a/src/transport/transport-testing-send.c
+++ b/src/transport/transport-testing-send.c
@@ -27,7 +27,7 @@
27/** 27/**
28 * Acceptable transmission delay. 28 * Acceptable transmission delay.
29 */ 29 */
30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
31 31
32 32
33static size_t 33static size_t