aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/test_communicator_basic.c123
-rw-r--r--src/transport/transport-testing2.c34
2 files changed, 112 insertions, 45 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index ef18d6a81..176996b9d 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -80,21 +80,17 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
80 80
81#define SIZE_CHECK 2 81#define SIZE_CHECK 2
82 82
83#define MAX_BUF_LEN 10 83#define MAX_BUF_LEN 1
84 84
85static int buf_len = 0; 85static int buf_len = 0;
86 86
87static char short_payload[SHORT_MESSAGE_SIZE];
88
89static char long_payload[LONG_MESSAGE_SIZE];
90
91static uint32_t ack = 0; 87static uint32_t ack = 0;
92 88
93static int phase; 89static int phase;
94 90
95static size_t long_received = 0; 91static size_t num_received = 0;
96 92
97static size_t short_received = 0; 93static uint64_t avg_latency = 0;
98 94
99static void 95static void
100communicator_available_cb (void *cls, 96communicator_available_cb (void *cls,
@@ -163,20 +159,42 @@ queue_create_reply_cb (void *cls,
163} 159}
164 160
165 161
162static char*
163make_payload (size_t payload_size)
164{
165 char *payload = GNUNET_malloc (payload_size);
166 struct GNUNET_TIME_Absolute ts;
167 struct GNUNET_TIME_AbsoluteNBO ts_n;
168 GNUNET_assert (payload_size >= 8); // So that out timestamp fits
169 ts = GNUNET_TIME_absolute_get ();
170 ts_n = GNUNET_TIME_absolute_hton (ts);
171 memset (payload, 0, payload_size);
172 memcpy (payload, &ts_n, sizeof (struct GNUNET_TIME_AbsoluteNBO));
173 return payload;
174}
175
176
166static void 177static void
167size_test (void *cls) 178size_test (void *cls)
168{ 179{
169 char payload[ack]; 180 char *payload;
170 phase = SIZE_CHECK; 181 phase = SIZE_CHECK;
171 182
172 memset (payload, 0, ack); 183 if (ack < 64000) // Leave some room for our protocol.
173 if (ack < 64000) //Leave some room for our protocol.
174 { 184 {
185 payload = make_payload (ack);
175 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 186 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
176 &payload, 187 payload,
177 sizeof(payload)); 188 ack);
189 GNUNET_free (payload);
178 return; 190 return;
179 } 191 }
192 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
193 "Size packet test done.\n");
194 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
195 "#packets: %lu -- latency: %lu\n",
196 num_received,
197 avg_latency);
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
181 "Finished\n"); 199 "Finished\n");
182 GNUNET_SCHEDULER_shutdown (); 200 GNUNET_SCHEDULER_shutdown ();
@@ -189,23 +207,34 @@ long_test (void *cls)
189{ 207{
190 struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( 208 struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration (
191 start_long); 209 start_long);
210 char *payload;
192 if (LONG_BURST_WINDOW.rel_value_us > duration.rel_value_us) 211 if (LONG_BURST_WINDOW.rel_value_us > duration.rel_value_us)
193 { 212 {
213 //FIXME: Not sure how aggressive we should be here, our transport does not
214 //implement congestion control or flow control... (also for the other three
194 if (buf_len < MAX_BUF_LEN) 215 if (buf_len < MAX_BUF_LEN)
195 { 216 {
217 payload = make_payload (LONG_MESSAGE_SIZE);
196 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 218 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
197 &long_payload, 219 payload,
198 sizeof(long_payload)); 220 LONG_MESSAGE_SIZE);
199 buf_len++; 221 buf_len++;
222 GNUNET_free (payload);
223 GNUNET_SCHEDULER_add_now (&long_test, NULL);
200 } 224 }
201 GNUNET_SCHEDULER_add_now (&long_test, NULL);
202 return; 225 return;
203 } 226 }
204 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 227 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
205 "LONG Goodput (bytes/s): %lu - received packets: %lu\n", 228 "Long size packet test done.\n");
206 (LONG_MESSAGE_SIZE * long_received) / LONG_BURST_SECONDS, 229 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
207 long_received); 230 "goodput: %lu b/s -- #packets: %lu -- latency: %lu\n",
208 ack = 5; 231 (LONG_MESSAGE_SIZE * num_received) / LONG_BURST_SECONDS,
232 num_received,
233 avg_latency);
234 ack = 10;
235 num_received = 0;
236 buf_len = 0;
237 avg_latency = 0;
209 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, NULL); 238 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, NULL);
210} 239}
211 240
@@ -215,27 +244,33 @@ short_test (void *cls)
215{ 244{
216 struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( 245 struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration (
217 start_short); 246 start_short);
247 char *payload;
218 if (SHORT_BURST_WINDOW.rel_value_us > duration.rel_value_us) 248 if (SHORT_BURST_WINDOW.rel_value_us > duration.rel_value_us)
219 { 249 {
220 if (buf_len < MAX_BUF_LEN) 250 if (buf_len < MAX_BUF_LEN)
221 { 251 {
252 payload = make_payload (SHORT_MESSAGE_SIZE);
222 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 253 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
223 &short_payload, 254 payload,
224 sizeof(short_payload)); 255 SHORT_MESSAGE_SIZE);
225 buf_len++; 256 buf_len++;
257 GNUNET_free (payload);
258 GNUNET_SCHEDULER_add_now (&short_test, NULL);
226 } 259 }
227 GNUNET_SCHEDULER_add_now (&short_test, NULL);
228 return; 260 return;
229 } 261 }
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Short test done!\n");
232 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 262 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
233 "SHORT Goodput (bytes/s): %lu - received packets: %lu\n", 263 "Short size packet test done.\n");
234 (SHORT_MESSAGE_SIZE * short_received) / SHORT_BURST_SECONDS, 264 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
235 short_received); 265 "goodput: %lu b/s -- #packets: %lu -- latency: %lu\n",
266 (SHORT_MESSAGE_SIZE * num_received) / SHORT_BURST_SECONDS,
267 num_received,
268 avg_latency);
236 start_long = GNUNET_TIME_absolute_get (); 269 start_long = GNUNET_TIME_absolute_get ();
237 phase = BURST_LONG; 270 phase = BURST_LONG;
238 buf_len = 0; 271 buf_len = 0;
272 avg_latency = 0;
273 num_received = 0;
239 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL); 274 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL);
240} 275}
241 276
@@ -269,6 +304,25 @@ add_queue_cb (void *cls,
269} 304}
270 305
271 306
307static void
308update_avg_latency (const char*payload)
309{
310 struct GNUNET_TIME_AbsoluteNBO *ts_n;
311 struct GNUNET_TIME_Absolute ts;
312 struct GNUNET_TIME_Relative latency;
313
314 ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload;
315 ts = GNUNET_TIME_absolute_ntoh (*ts_n);
316 latency = GNUNET_TIME_absolute_get_duration (ts);
317 if (1 == num_received)
318 avg_latency = latency.rel_value_us;
319 else
320 avg_latency = ((avg_latency * (num_received - 1)) + latency.rel_value_us)
321 / num_received;
322
323}
324
325
272/** 326/**
273 * @brief Handle an incoming message 327 * @brief Handle an incoming message
274 * 328 *
@@ -290,14 +344,20 @@ incoming_message_cb (void *cls,
290 if (phase == BURST_SHORT) 344 if (phase == BURST_SHORT)
291 { 345 {
292 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); 346 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len);
293 short_received++; 347 num_received++;
348 update_avg_latency (payload);
349 if (buf_len == MAX_BUF_LEN)
350 GNUNET_SCHEDULER_add_now (&short_test, NULL);
294 buf_len--; 351 buf_len--;
295 } 352 }
296 else if (phase == BURST_LONG) 353 else if (phase == BURST_LONG)
297 { 354 {
298 if (LONG_MESSAGE_SIZE != payload_len) 355 if (LONG_MESSAGE_SIZE != payload_len)
299 return; // Ignore 356 return; // Ignore
300 long_received++; 357 num_received++;
358 update_avg_latency (payload);
359 if (buf_len == MAX_BUF_LEN)
360 GNUNET_SCHEDULER_add_now (&long_test, NULL);
301 buf_len--; 361 buf_len--;
302 } 362 }
303 else // if (phase == SIZE_CHECK) { 363 else // if (phase == SIZE_CHECK) {
@@ -312,6 +372,8 @@ incoming_message_cb (void *cls,
312 GNUNET_SCHEDULER_shutdown (); 372 GNUNET_SCHEDULER_shutdown ();
313 return; 373 return;
314 } 374 }
375 num_received++;
376 update_avg_latency (payload);
315 ack += 5; // Next expected message size 377 ack += 5; // Next expected message size
316 GNUNET_SCHEDULER_add_now (&size_test, NULL); 378 GNUNET_SCHEDULER_add_now (&size_test, NULL);
317 } 379 }
@@ -327,8 +389,7 @@ static void
327run (void *cls) 389run (void *cls)
328{ 390{
329 ret = 0; 391 ret = 0;
330 memset (long_payload, 0, LONG_MESSAGE_SIZE); 392 num_received = 0;
331 memset (short_payload, 0, SHORT_MESSAGE_SIZE);
332 for (int i = 0; i < NUM_PEERS; i++) 393 for (int i = 0; i < NUM_PEERS; i++)
333 { 394 {
334 tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 395 tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index 547f8611b..ba58776fb 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -137,6 +137,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
137 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb; 137 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb;
138 138
139 /** 139 /**
140 * Our service handle
141 */
142 struct GNUNET_SERVICE_Handle *sh;
143
144 /**
140 * @brief Closure to the callback 145 * @brief Closure to the callback
141 */ 146 */
142 void *cb_cls; 147 void *cb_cls;
@@ -637,21 +642,15 @@ transport_communicator_start (
637 tc_h), 642 tc_h),
638 GNUNET_MQ_handler_end () 643 GNUNET_MQ_handler_end ()
639 }; 644 };
640 struct GNUNET_SERVICE_Handle *h;
641 645
642 h = GNUNET_SERVICE_start ("transport", 646
647 tc_h->sh = GNUNET_SERVICE_start ("transport",
643 tc_h->cfg, 648 tc_h->cfg,
644 &connect_cb, 649 &connect_cb,
645 &disconnect_cb, 650 &disconnect_cb,
646 tc_h, 651 tc_h,
647 mh); 652 mh);
648 if (NULL == h) 653 GNUNET_assert (NULL != tc_h->sh);
649 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n");
650 else
651 {
652 LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n");
653 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
654 }
655} 654}
656 655
657 656
@@ -665,11 +664,11 @@ shutdown_communicator (void *cls)
665{ 664{
666 struct GNUNET_OS_Process *proc = cls; 665 struct GNUNET_OS_Process *proc = cls;
667 666
668 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM)) 667 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
669 { 668 {
670 LOG (GNUNET_ERROR_TYPE_WARNING, 669 LOG (GNUNET_ERROR_TYPE_WARNING,
671 "Error shutting down communicator with SIGERM, trying SIGKILL\n"); 670 "Error shutting down communicator with SIGERM, trying SIGKILL\n");
672 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL)) 671 if (0 != GNUNET_OS_process_kill (proc, SIGKILL))
673 { 672 {
674 LOG (GNUNET_ERROR_TYPE_ERROR, 673 LOG (GNUNET_ERROR_TYPE_ERROR,
675 "Error shutting down communicator with SIGERM and SIGKILL\n"); 674 "Error shutting down communicator with SIGERM and SIGKILL\n");
@@ -710,8 +709,15 @@ communicator_start (
710 } 709 }
711 LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n"); 710 LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n");
712 GNUNET_free (binary); 711 GNUNET_free (binary);
713 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator, 712}
714 tc_h->c_proc); 713
714
715static void
716do_shutdown (void *cls)
717{
718 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
719 shutdown_communicator(tc_h->c_proc);
720 shutdown_service(tc_h->sh);
715} 721}
716 722
717 723
@@ -769,10 +775,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
769 /* Schedule start communicator */ 775 /* Schedule start communicator */
770 communicator_start (tc_h, 776 communicator_start (tc_h,
771 binary_name); 777 binary_name);
778 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, tc_h);
772 return tc_h; 779 return tc_h;
773} 780}
774 781
775
776/** 782/**
777 * @brief Instruct communicator to open a queue 783 * @brief Instruct communicator to open a queue
778 * 784 *