diff options
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 1 | ||||
-rw-r--r-- | src/transport/test_communicator.c | 157 | ||||
-rw-r--r-- | src/transport/transport-testing2.c | 30 | ||||
-rw-r--r-- | src/transport/transport-testing2.h | 8 |
4 files changed, 167 insertions, 29 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 404bcfb7f..29ec087e1 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -697,6 +697,7 @@ receive_complete_cb (void *cls, int success) | |||
697 | { | 697 | { |
698 | (void) cls; | 698 | (void) cls; |
699 | delivering_messages--; | 699 | delivering_messages--; |
700 | |||
700 | if (GNUNET_OK != success) | 701 | if (GNUNET_OK != success) |
701 | GNUNET_STATISTICS_update (stats, | 702 | GNUNET_STATISTICS_update (stats, |
702 | "# transport transmission failures", | 703 | "# transport transmission failures", |
diff --git a/src/transport/test_communicator.c b/src/transport/test_communicator.c index 34be5d66a..d77128b09 100644 --- a/src/transport/test_communicator.c +++ b/src/transport/test_communicator.c | |||
@@ -54,14 +54,43 @@ static char **cfg_peers_name; | |||
54 | 54 | ||
55 | static int ret; | 55 | static int ret; |
56 | 56 | ||
57 | // static char *addresses[NUM_PEERS]; | 57 | static struct GNUNET_TIME_Absolute start_short; |
58 | 58 | ||
59 | static struct GNUNET_TIME_Absolute start_long; | ||
59 | 60 | ||
60 | #define PAYLOAD_SIZE 256 | 61 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; |
61 | 62 | ||
62 | // static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; | 63 | #define SHORT_MESSAGE_SIZE 128 |
63 | // static char payload[] = "TEST PAYLOAD"; | 64 | |
64 | static uint32_t payload = 42; | 65 | #define LONG_MESSAGE_SIZE 32000 |
66 | |||
67 | #define SHORT_BURST_SECONDS 2 | ||
68 | |||
69 | #define LONG_BURST_SECONDS 2 | ||
70 | |||
71 | #define SHORT_BURST_WINDOW \ | ||
72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,SHORT_BURST_SECONDS) | ||
73 | |||
74 | #define LONG_BURST_WINDOW \ | ||
75 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,SHORT_BURST_SECONDS) | ||
76 | |||
77 | #define BURST_SHORT 0 | ||
78 | |||
79 | #define BURST_LONG 1 | ||
80 | |||
81 | #define SIZE_CHECK 2 | ||
82 | |||
83 | static char short_payload[SHORT_MESSAGE_SIZE]; | ||
84 | |||
85 | static char long_payload[LONG_MESSAGE_SIZE]; | ||
86 | |||
87 | static uint32_t ack = 0; | ||
88 | |||
89 | static int phase; | ||
90 | |||
91 | static size_t long_received = 0; | ||
92 | |||
93 | static size_t short_received = 0; | ||
65 | 94 | ||
66 | static void | 95 | static void |
67 | communicator_available_cb (void *cls, | 96 | communicator_available_cb (void *cls, |
@@ -130,6 +159,73 @@ queue_create_reply_cb (void *cls, | |||
130 | } | 159 | } |
131 | 160 | ||
132 | 161 | ||
162 | static void | ||
163 | size_test (void *cls) | ||
164 | { | ||
165 | char payload[ack]; | ||
166 | |||
167 | memset (payload, 0, ack); | ||
168 | if (ack < UINT16_MAX) | ||
169 | { | ||
170 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | ||
171 | &payload, | ||
172 | sizeof(payload)); | ||
173 | return; | ||
174 | } | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
176 | "LONG Goodput (bytes/s): %lu\n", | ||
177 | (LONG_MESSAGE_SIZE * long_received) / LONG_BURST_SECONDS); | ||
178 | ret = 0; | ||
179 | GNUNET_SCHEDULER_shutdown (); | ||
180 | // Finished! | ||
181 | } | ||
182 | |||
183 | |||
184 | static void | ||
185 | long_test (void *cls) | ||
186 | { | ||
187 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( | ||
188 | start_long); | ||
189 | if (LONG_BURST_WINDOW.rel_value_us > duration.rel_value_us) | ||
190 | { | ||
191 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | ||
192 | &long_payload, | ||
193 | sizeof(long_payload)); | ||
194 | GNUNET_SCHEDULER_add_now (&long_test, NULL); | ||
195 | return; | ||
196 | } | ||
197 | phase = SIZE_CHECK; | ||
198 | ack = 5; | ||
199 | GNUNET_SCHEDULER_add_now (&size_test, NULL); | ||
200 | } | ||
201 | |||
202 | |||
203 | static void | ||
204 | short_test (void *cls) | ||
205 | { | ||
206 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( | ||
207 | start_short); | ||
208 | if (SHORT_BURST_WINDOW.rel_value_us > duration.rel_value_us) | ||
209 | { | ||
210 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | ||
211 | &short_payload, | ||
212 | sizeof(short_payload)); | ||
213 | |||
214 | GNUNET_SCHEDULER_add_now (&short_test, NULL); | ||
215 | return; | ||
216 | } | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
218 | "Short test done!\n"); | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
220 | "SHORT Goodput (bytes/s): %lu - received packets: %lu\n", | ||
221 | (SHORT_MESSAGE_SIZE * short_received) / SHORT_BURST_SECONDS, | ||
222 | short_received); | ||
223 | start_long = GNUNET_TIME_absolute_get (); | ||
224 | phase = BURST_LONG; | ||
225 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL); | ||
226 | } | ||
227 | |||
228 | |||
133 | /** | 229 | /** |
134 | * @brief Handle opening of queue | 230 | * @brief Handle opening of queue |
135 | * | 231 | * |
@@ -147,11 +243,14 @@ add_queue_cb (void *cls, | |||
147 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * | 243 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * |
148 | tc_queue) | 244 | tc_queue) |
149 | { | 245 | { |
246 | if (0 != strcmp ((char*) cls, cfg_peers_name[0])) | ||
247 | return; // TODO? | ||
150 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 248 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
151 | "Got Queue!\n"); | 249 | "Queue established, starting test...\n"); |
152 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue, | 250 | start_short = GNUNET_TIME_absolute_get (); |
153 | &payload, | 251 | my_tc = tc_queue; |
154 | sizeof(payload)); | 252 | phase = BURST_SHORT; |
253 | GNUNET_SCHEDULER_add_now (&short_test, tc_queue); | ||
155 | } | 254 | } |
156 | 255 | ||
157 | 256 | ||
@@ -168,20 +267,40 @@ void | |||
168 | incoming_message_cb (void *cls, | 267 | incoming_message_cb (void *cls, |
169 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | 268 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
170 | *tc_h, | 269 | *tc_h, |
171 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | 270 | const char*payload, |
271 | size_t payload_len) | ||
172 | { | 272 | { |
173 | char *payload_ptr; | 273 | //GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
274 | // "Receiving payload with size %lu...\n", payload_len); | ||
174 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) | 275 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) |
175 | return; // TODO? | 276 | return; // TODO? |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 277 | if (phase == BURST_SHORT) |
177 | "%s received data (%lu bytes payload)\n", | 278 | { |
178 | (char*) cls, | 279 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
179 | ntohs (msg->header.size) - sizeof (struct GNUNET_TRANSPORT_IncomingMessage)); | 280 | short_received++; |
180 | payload_ptr = (char*)&msg[1] + sizeof (struct GNUNET_MessageHeader); | 281 | } |
181 | ret = memcmp (payload_ptr, &payload, sizeof (payload)); | 282 | else if (phase == BURST_LONG) |
182 | GNUNET_SCHEDULER_shutdown (); | 283 | { |
284 | if (LONG_MESSAGE_SIZE != payload_len) | ||
285 | return; //Ignore | ||
286 | long_received++; | ||
287 | } | ||
288 | else // if (phase == SIZE_CHECK) { | ||
289 | { | ||
290 | if (ack != payload_len) | ||
291 | { | ||
292 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
293 | "Error receiving message, corrupted.\n"); | ||
294 | ret = 1; | ||
295 | GNUNET_SCHEDULER_shutdown (); | ||
296 | return; | ||
297 | } | ||
298 | ack += 5; // Next expected message size | ||
299 | GNUNET_SCHEDULER_add_now (&size_test, NULL); | ||
300 | } | ||
183 | } | 301 | } |
184 | 302 | ||
303 | |||
185 | /** | 304 | /** |
186 | * @brief Main function called by the scheduler | 305 | * @brief Main function called by the scheduler |
187 | * | 306 | * |
@@ -190,6 +309,8 @@ incoming_message_cb (void *cls, | |||
190 | static void | 309 | static void |
191 | run (void *cls) | 310 | run (void *cls) |
192 | { | 311 | { |
312 | memset (long_payload, 0, LONG_MESSAGE_SIZE); | ||
313 | memset (short_payload, 0, SHORT_MESSAGE_SIZE); | ||
193 | for (int i = 0; i < NUM_PEERS; i++) | 314 | for (int i = 0; i < NUM_PEERS; i++) |
194 | { | 315 | { |
195 | tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | 316 | 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 b354f7c2a..230c35b4f 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -358,21 +358,39 @@ check_incoming_msg (void *cls, | |||
358 | */ | 358 | */ |
359 | static void | 359 | static void |
360 | handle_incoming_msg (void *cls, | 360 | handle_incoming_msg (void *cls, |
361 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | 361 | const struct GNUNET_TRANSPORT_IncomingMessage *inc_msg) |
362 | { | 362 | { |
363 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 363 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
364 | struct GNUNET_MessageHeader *msg; | ||
365 | msg = (struct GNUNET_MessageHeader *)&inc_msg[1]; | ||
366 | size_t payload_len = ntohs (msg->size) - sizeof (struct | ||
367 | GNUNET_MessageHeader); | ||
364 | 368 | ||
365 | if (NULL != tc_h->incoming_msg_cb) | 369 | if (NULL != tc_h->incoming_msg_cb) |
366 | { | 370 | { |
367 | tc_h->incoming_msg_cb (tc_h->cb_cls, | 371 | tc_h->incoming_msg_cb (tc_h->cb_cls, |
368 | tc_h, | 372 | tc_h, |
369 | msg); | 373 | (char*) &msg[1], |
374 | payload_len); | ||
370 | } | 375 | } |
371 | else | 376 | else |
372 | { | 377 | { |
373 | LOG (GNUNET_ERROR_TYPE_WARNING, | 378 | LOG (GNUNET_ERROR_TYPE_WARNING, |
374 | "Incoming message from communicator but no handler!\n"); | 379 | "Incoming message from communicator but no handler!\n"); |
375 | } | 380 | } |
381 | if (0 != ntohl (inc_msg->fc_on)) | ||
382 | { | ||
383 | /* send ACK when done to communicator for flow control! */ | ||
384 | struct GNUNET_MQ_Envelope *env; | ||
385 | struct GNUNET_TRANSPORT_IncomingMessageAck *ack; | ||
386 | |||
387 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); | ||
388 | ack->reserved = htonl (0); | ||
389 | ack->fc_id = inc_msg->fc_id; | ||
390 | ack->sender = inc_msg->sender; | ||
391 | GNUNET_MQ_send (tc_h->c_mq, env); | ||
392 | } | ||
393 | |||
376 | GNUNET_SERVICE_client_continue (tc_h->client); | 394 | GNUNET_SERVICE_client_continue (tc_h->client); |
377 | } | 395 | } |
378 | 396 | ||
@@ -458,7 +476,9 @@ handle_add_queue_message (void *cls, | |||
458 | { | 476 | { |
459 | tc_queue = tc_queue->next; | 477 | tc_queue = tc_queue->next; |
460 | } | 478 | } |
461 | } else { | 479 | } |
480 | else | ||
481 | { | ||
462 | tc_queue = | 482 | tc_queue = |
463 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); | 483 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); |
464 | tc_queue->tc_h = tc_h; | 484 | tc_queue->tc_h = tc_h; |
@@ -802,9 +822,7 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * | |||
802 | GNUNET_TRANSPORT_TESTING_transport_communicator_send | 822 | GNUNET_TRANSPORT_TESTING_transport_communicator_send |
803 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, | 823 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, |
804 | const void *payload, | 824 | const void *payload, |
805 | size_t payload_size /*, | 825 | size_t payload_size) |
806 | GNUNET_TRANSPORT_TESTING_SuccessStatus cb, | ||
807 | void *cb_cls*/) | ||
808 | { | 826 | { |
809 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t; | 827 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t; |
810 | struct GNUNET_MessageHeader *mh; | 828 | struct GNUNET_MessageHeader *mh; |
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h index 49e4791aa..4e047828e 100644 --- a/src/transport/transport-testing2.h +++ b/src/transport/transport-testing2.h | |||
@@ -134,8 +134,8 @@ typedef void | |||
134 | struct | 134 | struct |
135 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | 135 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
136 | *tc_h, | 136 | *tc_h, |
137 | const struct | 137 | const char* payload, |
138 | GNUNET_TRANSPORT_IncomingMessage *msg); | 138 | size_t payload_len); |
139 | 139 | ||
140 | 140 | ||
141 | /** | 141 | /** |
@@ -198,6 +198,4 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send (struct | |||
198 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | 198 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue |
199 | *tc_queue, | 199 | *tc_queue, |
200 | const void *payload, | 200 | const void *payload, |
201 | size_t payload_size /*, | 201 | size_t payload_size); |
202 | GNUNET_TRANSPORT_TESTING_SuccessStatus cb, | ||
203 | void *cb_cls*/ ); | ||